feat:完善项目

This commit is contained in:
henry
2022-01-15 09:00:47 +08:00
parent 9a41d7ff12
commit 048d116b05
9 changed files with 67 additions and 35 deletions

View File

@ -38,12 +38,14 @@ func (a *Config) Add(c *gin.Context) {
func (a *Config) Edit(c *gin.Context) {
form := &struct {
Params map[string]interface{} `json:"params" form:"params" binding:"required"`
api.IDStringForm
Name string `json:"name" form:"name" binding:"required"`
Value interface{} `json:"value" form:"value" binding:"required"`
}{}
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
err := controller.NewConfig()().Form(form.Params)
err := controller.NewConfig()().Form(form.Convert(), form.Name, form.Value)
api.APIResponse(err)(c)
}

View File

@ -4,6 +4,7 @@ import (
"SciencesServer/app/api/admin/controller/technology"
"SciencesServer/app/basic/api"
"SciencesServer/app/session"
"SciencesServer/utils"
"github.com/gin-gonic/gin"
)
@ -80,8 +81,7 @@ func (*Technology) PatentBind(c *gin.Context) {
api.APIFailure(err.(error))(c)
return
}
err := technology.NewPatent()(api.GetSession()(c).(*session.Admin)).Bind(form.Convert(),
(&api.IDStringForm{ID: form.UID}).Convert())
err := technology.NewPatent()(api.GetSession()(c).(*session.Admin)).Bind(form.Convert(), utils.StringToUnit64(form.UID))
api.APIResponse(err)(c)
}

View File

@ -18,6 +18,11 @@ type Config struct{}
type ConfigHandle func() *Config
type ConfigInfo struct {
ID string `json:"id"`
*model2.SysConfig
}
func (c *Config) Config(kind, page, pageSize int) (*controller.ReturnPages, error) {
mSysConfig := model.NewSysConfig()
@ -34,7 +39,15 @@ func (c *Config) Config(kind, page, pageSize int) (*controller.ReturnPages, erro
if err := model2.Pages(mSysConfig.SysConfig, &out, page, pageSize, &count, where...); err != nil {
return nil, err
}
return &controller.ReturnPages{Data: out, Count: count}, nil
list := make([]*ConfigInfo, 0)
for _, v := range out {
list = append(list, &ConfigInfo{
ID: v.GetEncodeID(),
SysConfig: v,
})
}
return &controller.ReturnPages{Data: list, Count: count}, nil
}
func (c *Config) Add(kind int, name, key string, value interface{}) error {
@ -42,7 +55,7 @@ func (c *Config) Add(kind int, name, key string, value interface{}) error {
var count int64
err := model2.Count(mSysConfig.SysConfig, &count, model2.NewWhere("key", key))
err := model2.Count(mSysConfig.SysConfig, &count, model2.NewWhere("`key`", key))
if err != nil {
return err
@ -62,25 +75,26 @@ func (c *Config) Add(kind int, name, key string, value interface{}) error {
return nil
}
func (c *Config) Form(params map[string]interface{}) error {
if len(params) <= 0 {
func (c *Config) Form(id uint64, name string, value interface{}) error {
mSysConfig := model.NewSysConfig()
mSysConfig.ID = id
isExist, err := model2.FirstField(mSysConfig.SysConfig, []string{"id", "`key`"})
if err != nil {
return nil
} else if !isExist {
return errors.New("操作错误,数据不存在")
}
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
mSysConfig := model.NewSysConfig()
now := time.Now()
for k, v := range params {
if _, has := config.SystemConfig[k]; !has {
return errors.New("UnKnown Config Key " + k)
}
if err := model2.UpdatesWhere(mSysConfig.SysConfig, map[string]interface{}{
"value": v, "updated_at": now,
}, []*model2.ModelWhere{model2.NewWhere("key", k)}, tx); err != nil {
if err := model2.Updates(mSysConfig.SysConfig, map[string]interface{}{
"`name`": name, "`value`": value, "updated_at": now,
}, tx); err != nil {
return err
}
config.SystemConfig[k] = v
}
config.SystemConfig[mSysConfig.Key] = value
return nil
})
}

View File

@ -9,6 +9,7 @@ import (
"SciencesServer/serve/orm"
"SciencesServer/utils"
"errors"
"fmt"
"gorm.io/gorm"
)
@ -24,6 +25,7 @@ type (
PatentInfo struct {
ID string `json:"id"`
UID string `json:"uid"`
*model.SysPatentInfo
}
// PatentDetailInfo 专利详细信息
PatentDetailInfo struct {
@ -111,7 +113,16 @@ func (c *Patent) Instance(tenantID uint64, title, ipc string, page, pageSize int
if err != nil {
return nil, err
}
return &controller.ReturnPages{Data: out, Count: count}, nil
list := make([]*PatentInfo, 0)
for _, v := range out {
list = append(list, &PatentInfo{
ID: v.GetEncodeID(),
UID: fmt.Sprintf("%d", v.UID),
SysPatentInfo: v,
})
}
return &controller.ReturnPages{Data: list, Count: count}, nil
}
// Detail 详细信息

View File

@ -7,5 +7,5 @@ type SysConfig struct {
}
func NewSysConfig() *SysConfig {
return &SysConfig{}
return &SysConfig{model.NewSysConfig()}
}

View File

@ -4,6 +4,7 @@ import (
"SciencesServer/app/common/model"
"SciencesServer/serve/orm"
"fmt"
"time"
)
// SysPatent 专利信息
@ -13,8 +14,16 @@ type SysPatent struct {
// SysPatentInfo 专利信息
type SysPatentInfo struct {
*model.SysPatent
UID string `json:"uid"`
model.Model
model.ModelTenant
Title string `json:"title"`
ApplyCode string `json:"apply_code"`
ApplyAt string `json:"apply_at"`
ApplyName string `json:"apply_name"`
Inventor string `json:"inventor"`
model.Shelf
UID uint64 `json:"-"`
CreatedAt time.Time `json:"created_at"`
}
func (m *SysPatent) IsExistParams(params map[string]interface{}) (bool, error) {
@ -35,7 +44,7 @@ func (m *SysPatent) Patent(page, pageSize int, count *int64, where ...*model.Mod
db := orm.GetDB().Table(m.TableName()+" AS p").
Select("p.id", "p.title", "p.apply_code", "p.inventor", "p.apply_name", "p.apply_at", "u.uid",
"p.shelf_status", "p.created_at").
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON p.id = u.tenant_id AND u.is_deleted = %d",
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON p.id = u.patent_id AND u.is_deleted = %d",
model.NewUserPatent().TableName(), model.DeleteStatusForNot))
if len(where) > 0 {

View File

@ -21,7 +21,7 @@ type IModel interface {
// Model
type Model struct {
ID uint64 `gorm:"column:id;primaryKey;autoIncrement;comment:主键" json:"-"`
ID uint64 `gorm:"column:id;primaryKey;autoIncrement;type:int(11);comment:主键" json:"-"`
Database string `json:"-" gorm:"-"`
}

View File

@ -165,7 +165,7 @@ func registerAdminAPI(app *gin.Engine) {
_config.GET("/identity", _api.Identity)
_config.GET("/industry", _api.Industry)
_api2 := new(api1.Config)
_config.POST("/", _api2.Index)
_config.POST("", _api2.Index)
_config.POST("/add", _api2.Add)
_config.POST("/edit", _api2.Edit)
}
@ -237,11 +237,6 @@ func registerAdminAPI(app *gin.Engine) {
menu.POST("/status", _api.Status)
menu.POST("/delete", _api.Delete)
}
// Config 配置管理
//config := v1.Group("/config")
//{
//
//}
// Auth 权限管理
auth := v1.Group("/auth")
{
@ -309,11 +304,12 @@ func registerAdminAPI(app *gin.Engine) {
technology.POST("/patent/detail", _api.PatentDetail)
technology.POST("/patent/add", _api.PatentForm)
technology.POST("/patent/edit", _api.PatentForm)
technology.POST("/patent/bind", _api.PatentBind)
technology.POST("/patent/delete", _api.PatentDelete)
technology.GET("/patent/ipc", _api.PatentIPC)
technology.POST("/patent/add", _api.PatentIPCForm)
technology.POST("/patent/edit", _api.PatentIPCForm)
technology.POST("/patent/delete", _api.PatentIPCDelete)
technology.POST("/patent/ipc/add", _api.PatentIPCForm)
technology.POST("/patent/ipc/edit", _api.PatentIPCForm)
technology.POST("/patent/ipc/delete", _api.PatentIPCDelete)
}
// Activity 活动管理
activity := v1.Group("/activity")

View File

@ -59,7 +59,7 @@ func HashCompare(src, compare []byte) bool {
func HASHIDEncode(src int) string {
hd := hashids.NewData()
hd.Salt = salt
hd.MinLength = 8
hd.MinLength = 12
h := hashids.NewWithData(hd)
e, _ := h.Encode([]int{src})
return e