优化sysconfig 业务
This commit is contained in:
1 parent
d1d545b29c
commit
21603d5a4c
10 files changed
+262
-307
No files matched your search
@@ -0,0 +1,93 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"go-admin/app/admin/models"
|
||||
"go-admin/common/dto"
|
||||
"go-admin/common/log"
|
||||
common "go-admin/common/models"
|
||||
"go-admin/tools"
|
||||
)
|
||||
|
||||
type SysConfigSearch struct {
|
||||
dto.Pagination `search:"-"`
|
||||
ConfigName string `form:"configName" search:"type:exact;column:config_name;table:sys_config" comment:""`
|
||||
ConfigKey string `form:"configKey" search:"type:exact;column:config_key;table:sys_config" comment:""`
|
||||
ConfigType string `form:"configType" search:"type:exact;column:config_type;table:sys_config" comment:""`
|
||||
}
|
||||
|
||||
func (m *SysConfigSearch) GetNeedSearch() interface{} {
|
||||
return *m
|
||||
}
|
||||
|
||||
func (m *SysConfigSearch) Bind(ctx *gin.Context) error {
|
||||
msgID := tools.GenerateMsgIDFromContext(ctx)
|
||||
err := ctx.ShouldBind(m)
|
||||
if err != nil {
|
||||
log.Debugf("MsgID[%s] ShouldBind error: %s", msgID, err.Error())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *SysConfigSearch) Generate() dto.Index {
|
||||
o := *m
|
||||
return &o
|
||||
}
|
||||
|
||||
type SysConfigControl struct {
|
||||
ID uint `uri:"ID" comment:"编码"` // 编码
|
||||
ConfigName string `json:"configName" comment:""`
|
||||
ConfigKey string `json:"configKey" comment:""`
|
||||
ConfigValue string `json:"configValue" comment:""`
|
||||
ConfigType string `json:"configType" comment:""`
|
||||
Remark string `json:"remark" comment:""`
|
||||
}
|
||||
|
||||
func (s *SysConfigControl) Bind(ctx *gin.Context) error {
|
||||
msgID := tools.GenerateMsgIDFromContext(ctx)
|
||||
err := ctx.ShouldBindUri(s)
|
||||
if err != nil {
|
||||
log.Debugf("MsgID[%s] ShouldBindUri error: %s", msgID, err.Error())
|
||||
return err
|
||||
}
|
||||
err = ctx.ShouldBind(s)
|
||||
if err != nil {
|
||||
log.Debugf("MsgID[%s] ShouldBind error: %#v", msgID, err.Error())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *SysConfigControl) Generate() dto.Control {
|
||||
cp := *s
|
||||
return &cp
|
||||
}
|
||||
|
||||
func (s *SysConfigControl) GenerateM() (common.ActiveRecord, error) {
|
||||
return &models.SysConfig{
|
||||
Model: gorm.Model{ID: s.ID},
|
||||
ConfigName: s.ConfigName,
|
||||
ConfigKey: s.ConfigKey,
|
||||
ConfigValue: s.ConfigValue,
|
||||
ConfigType: s.ConfigType,
|
||||
Remark: s.Remark,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *SysConfigControl) GetId() interface{} {
|
||||
return s.ID
|
||||
}
|
||||
|
||||
type SysConfigById struct {
|
||||
dto.ObjectById
|
||||
}
|
||||
|
||||
func (s *SysConfigById) Generate() dto.Control {
|
||||
cp := *s
|
||||
return &cp
|
||||
}
|
||||
|
||||
func (s *SysConfigById) GenerateM() (common.ActiveRecord, error) {
|
||||
return &models.SysConfig{}, nil
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"go-admin/app/admin/models"
|
||||
"go-admin/app/admin/service/dto"
|
||||
"go-admin/common/log"
|
||||
"go-admin/common/service"
|
||||
)
|
||||
|
||||
type SysConfig struct {
|
||||
service.Service
|
||||
}
|
||||
|
||||
// GetSysConfigByKEY 根据Key获取SysConfig
|
||||
func (e *SysConfig) GetSysConfigByKEY(c *dto.SysConfigControl) error {
|
||||
var err error
|
||||
var data models.SysConfig
|
||||
msgID := e.MsgID
|
||||
data.ConfigKey = c.ConfigKey
|
||||
err = e.Orm.Table(data.TableName()).Where("config_key = ?", data.ConfigKey).First(c).Error
|
||||
if err != nil {
|
||||
log.Errorf("msgID[%s] db error:%s", msgID, err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user