feat:完善项目
This commit is contained in:
@ -38,12 +38,14 @@ func (a *Config) Add(c *gin.Context) {
|
|||||||
|
|
||||||
func (a *Config) Edit(c *gin.Context) {
|
func (a *Config) Edit(c *gin.Context) {
|
||||||
form := &struct {
|
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 {
|
if err := api.Bind(form)(c); err != nil {
|
||||||
api.APIFailure(err.(error))(c)
|
api.APIFailure(err.(error))(c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err := controller.NewConfig()().Form(form.Params)
|
err := controller.NewConfig()().Form(form.Convert(), form.Name, form.Value)
|
||||||
api.APIResponse(err)(c)
|
api.APIResponse(err)(c)
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"SciencesServer/app/api/admin/controller/technology"
|
"SciencesServer/app/api/admin/controller/technology"
|
||||||
"SciencesServer/app/basic/api"
|
"SciencesServer/app/basic/api"
|
||||||
"SciencesServer/app/session"
|
"SciencesServer/app/session"
|
||||||
|
"SciencesServer/utils"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -80,8 +81,7 @@ func (*Technology) PatentBind(c *gin.Context) {
|
|||||||
api.APIFailure(err.(error))(c)
|
api.APIFailure(err.(error))(c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err := technology.NewPatent()(api.GetSession()(c).(*session.Admin)).Bind(form.Convert(),
|
err := technology.NewPatent()(api.GetSession()(c).(*session.Admin)).Bind(form.Convert(), utils.StringToUnit64(form.UID))
|
||||||
(&api.IDStringForm{ID: form.UID}).Convert())
|
|
||||||
api.APIResponse(err)(c)
|
api.APIResponse(err)(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,11 @@ type Config struct{}
|
|||||||
|
|
||||||
type ConfigHandle func() *Config
|
type ConfigHandle func() *Config
|
||||||
|
|
||||||
|
type ConfigInfo struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
*model2.SysConfig
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Config) Config(kind, page, pageSize int) (*controller.ReturnPages, error) {
|
func (c *Config) Config(kind, page, pageSize int) (*controller.ReturnPages, error) {
|
||||||
mSysConfig := model.NewSysConfig()
|
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 {
|
if err := model2.Pages(mSysConfig.SysConfig, &out, page, pageSize, &count, where...); err != nil {
|
||||||
return nil, err
|
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 {
|
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
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -62,25 +75,26 @@ func (c *Config) Add(kind int, name, key string, value interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) Form(params map[string]interface{}) error {
|
func (c *Config) Form(id uint64, name string, value interface{}) error {
|
||||||
if len(params) <= 0 {
|
mSysConfig := model.NewSysConfig()
|
||||||
|
mSysConfig.ID = id
|
||||||
|
|
||||||
|
isExist, err := model2.FirstField(mSysConfig.SysConfig, []string{"id", "`key`"})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
|
} else if !isExist {
|
||||||
|
return errors.New("操作错误,数据不存在")
|
||||||
}
|
}
|
||||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||||
mSysConfig := model.NewSysConfig()
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
for k, v := range params {
|
if err := model2.Updates(mSysConfig.SysConfig, map[string]interface{}{
|
||||||
if _, has := config.SystemConfig[k]; !has {
|
"`name`": name, "`value`": value, "updated_at": now,
|
||||||
return errors.New("UnKnown Config Key :" + k)
|
}, tx); err != nil {
|
||||||
}
|
return err
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
config.SystemConfig[mSysConfig.Key] = value
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"SciencesServer/serve/orm"
|
"SciencesServer/serve/orm"
|
||||||
"SciencesServer/utils"
|
"SciencesServer/utils"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -24,6 +25,7 @@ type (
|
|||||||
PatentInfo struct {
|
PatentInfo struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
UID string `json:"uid"`
|
UID string `json:"uid"`
|
||||||
|
*model.SysPatentInfo
|
||||||
}
|
}
|
||||||
// PatentDetailInfo 专利详细信息
|
// PatentDetailInfo 专利详细信息
|
||||||
PatentDetailInfo struct {
|
PatentDetailInfo struct {
|
||||||
@ -111,7 +113,16 @@ func (c *Patent) Instance(tenantID uint64, title, ipc string, page, pageSize int
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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 详细信息
|
// Detail 详细信息
|
||||||
|
@ -7,5 +7,5 @@ type SysConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewSysConfig() *SysConfig {
|
func NewSysConfig() *SysConfig {
|
||||||
return &SysConfig{}
|
return &SysConfig{model.NewSysConfig()}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"SciencesServer/app/common/model"
|
"SciencesServer/app/common/model"
|
||||||
"SciencesServer/serve/orm"
|
"SciencesServer/serve/orm"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SysPatent 专利信息
|
// SysPatent 专利信息
|
||||||
@ -13,8 +14,16 @@ type SysPatent struct {
|
|||||||
|
|
||||||
// SysPatentInfo 专利信息
|
// SysPatentInfo 专利信息
|
||||||
type SysPatentInfo struct {
|
type SysPatentInfo struct {
|
||||||
*model.SysPatent
|
model.Model
|
||||||
UID string `json:"uid"`
|
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) {
|
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").
|
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",
|
Select("p.id", "p.title", "p.apply_code", "p.inventor", "p.apply_name", "p.apply_at", "u.uid",
|
||||||
"p.shelf_status", "p.created_at").
|
"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))
|
model.NewUserPatent().TableName(), model.DeleteStatusForNot))
|
||||||
|
|
||||||
if len(where) > 0 {
|
if len(where) > 0 {
|
||||||
|
@ -21,7 +21,7 @@ type IModel interface {
|
|||||||
|
|
||||||
// Model
|
// Model
|
||||||
type Model struct {
|
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:"-"`
|
Database string `json:"-" gorm:"-"`
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ func registerAdminAPI(app *gin.Engine) {
|
|||||||
_config.GET("/identity", _api.Identity)
|
_config.GET("/identity", _api.Identity)
|
||||||
_config.GET("/industry", _api.Industry)
|
_config.GET("/industry", _api.Industry)
|
||||||
_api2 := new(api1.Config)
|
_api2 := new(api1.Config)
|
||||||
_config.POST("/", _api2.Index)
|
_config.POST("", _api2.Index)
|
||||||
_config.POST("/add", _api2.Add)
|
_config.POST("/add", _api2.Add)
|
||||||
_config.POST("/edit", _api2.Edit)
|
_config.POST("/edit", _api2.Edit)
|
||||||
}
|
}
|
||||||
@ -237,11 +237,6 @@ func registerAdminAPI(app *gin.Engine) {
|
|||||||
menu.POST("/status", _api.Status)
|
menu.POST("/status", _api.Status)
|
||||||
menu.POST("/delete", _api.Delete)
|
menu.POST("/delete", _api.Delete)
|
||||||
}
|
}
|
||||||
// Config 配置管理
|
|
||||||
//config := v1.Group("/config")
|
|
||||||
//{
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
// Auth 权限管理
|
// Auth 权限管理
|
||||||
auth := v1.Group("/auth")
|
auth := v1.Group("/auth")
|
||||||
{
|
{
|
||||||
@ -309,11 +304,12 @@ func registerAdminAPI(app *gin.Engine) {
|
|||||||
technology.POST("/patent/detail", _api.PatentDetail)
|
technology.POST("/patent/detail", _api.PatentDetail)
|
||||||
technology.POST("/patent/add", _api.PatentForm)
|
technology.POST("/patent/add", _api.PatentForm)
|
||||||
technology.POST("/patent/edit", _api.PatentForm)
|
technology.POST("/patent/edit", _api.PatentForm)
|
||||||
|
technology.POST("/patent/bind", _api.PatentBind)
|
||||||
technology.POST("/patent/delete", _api.PatentDelete)
|
technology.POST("/patent/delete", _api.PatentDelete)
|
||||||
technology.GET("/patent/ipc", _api.PatentIPC)
|
technology.GET("/patent/ipc", _api.PatentIPC)
|
||||||
technology.POST("/patent/add", _api.PatentIPCForm)
|
technology.POST("/patent/ipc/add", _api.PatentIPCForm)
|
||||||
technology.POST("/patent/edit", _api.PatentIPCForm)
|
technology.POST("/patent/ipc/edit", _api.PatentIPCForm)
|
||||||
technology.POST("/patent/delete", _api.PatentIPCDelete)
|
technology.POST("/patent/ipc/delete", _api.PatentIPCDelete)
|
||||||
}
|
}
|
||||||
// Activity 活动管理
|
// Activity 活动管理
|
||||||
activity := v1.Group("/activity")
|
activity := v1.Group("/activity")
|
||||||
|
@ -59,7 +59,7 @@ func HashCompare(src, compare []byte) bool {
|
|||||||
func HASHIDEncode(src int) string {
|
func HASHIDEncode(src int) string {
|
||||||
hd := hashids.NewData()
|
hd := hashids.NewData()
|
||||||
hd.Salt = salt
|
hd.Salt = salt
|
||||||
hd.MinLength = 8
|
hd.MinLength = 12
|
||||||
h := hashids.NewWithData(hd)
|
h := hashids.NewWithData(hd)
|
||||||
e, _ := h.Encode([]int{src})
|
e, _ := h.Encode([]int{src})
|
||||||
return e
|
return e
|
||||||
|
Reference in New Issue
Block a user