diff --git a/app/api/admin/api/config.go b/app/api/admin/api/config.go index 8731e94..9986e21 100644 --- a/app/api/admin/api/config.go +++ b/app/api/admin/api/config.go @@ -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) } diff --git a/app/api/admin/api/technology.go b/app/api/admin/api/technology.go index 934c87d..a101c83 100644 --- a/app/api/admin/api/technology.go +++ b/app/api/admin/api/technology.go @@ -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) } diff --git a/app/api/admin/controller/config.go b/app/api/admin/controller/config.go index 924bdf0..85a29c3 100644 --- a/app/api/admin/controller/config.go +++ b/app/api/admin/controller/config.go @@ -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 { - return err - } - config.SystemConfig[k] = v + if err := model2.Updates(mSysConfig.SysConfig, map[string]interface{}{ + "`name`": name, "`value`": value, "updated_at": now, + }, tx); err != nil { + return err } + config.SystemConfig[mSysConfig.Key] = value return nil }) } diff --git a/app/api/admin/controller/technology/patent.go b/app/api/admin/controller/technology/patent.go index 8b33880..ab6227d 100644 --- a/app/api/admin/controller/technology/patent.go +++ b/app/api/admin/controller/technology/patent.go @@ -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 详细信息 diff --git a/app/api/admin/model/sys_config.go b/app/api/admin/model/sys_config.go index 607e30e..d4c7050 100644 --- a/app/api/admin/model/sys_config.go +++ b/app/api/admin/model/sys_config.go @@ -7,5 +7,5 @@ type SysConfig struct { } func NewSysConfig() *SysConfig { - return &SysConfig{} + return &SysConfig{model.NewSysConfig()} } diff --git a/app/api/admin/model/sys_patent.go b/app/api/admin/model/sys_patent.go index 84c56dd..8e6f3e6 100644 --- a/app/api/admin/model/sys_patent.go +++ b/app/api/admin/model/sys_patent.go @@ -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 { diff --git a/app/common/model/model.go b/app/common/model/model.go index f82366e..adb79d1 100644 --- a/app/common/model/model.go +++ b/app/common/model/model.go @@ -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:"-"` } diff --git a/router/address.go b/router/address.go index e49efaf..4cd2021 100644 --- a/router/address.go +++ b/router/address.go @@ -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") diff --git a/utils/encrypt.go b/utils/encrypt.go index 5077a4e..4f6157e 100644 --- a/utils/encrypt.go +++ b/utils/encrypt.go @@ -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