From 6746dbd9cf31a619ae5700f133e3e1ae1a5e7742 Mon Sep 17 00:00:00 2001 From: wenjianzhang Date: Wed, 17 Mar 2021 11:16:53 +0800 Subject: [PATCH] =?UTF-8?q?feat=E2=9C=A8=20=EF=BC=9A=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=B8=AD=E6=B7=BB=E5=8A=A0=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E5=89=8D=E5=8F=B0=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apis/system/sys_config/sys_config.go | 8 ++++-- app/admin/models/system/sys_config.go | 7 +++-- app/admin/service/dto/sys_config.go | 3 ++ .../version/1615948084336_migrate.go | 28 +++++++++++++++++++ 4 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 cmd/migrate/migration/version/1615948084336_migrate.go diff --git a/app/admin/apis/system/sys_config/sys_config.go b/app/admin/apis/system/sys_config/sys_config.go index 1789451c..9d547749 100644 --- a/app/admin/apis/system/sys_config/sys_config.go +++ b/app/admin/apis/system/sys_config/sys_config.go @@ -56,12 +56,16 @@ func (e *SysConfig) GetSysConfigBySysApp(c *gin.Context) { log.Error(err) return } - d.ConfigKey = "sys_app_" + err = d.Bind(c) if err != nil { log.Errorf("参数验证失败, error:%s", err) e.Error(c, 500, err, "参数验证失败") return } + + // 控制只读前台的数据 + d.IsFrontend = 1 + list := make([]system.SysConfig, 0) s := service.SysConfig{} @@ -73,7 +77,7 @@ func (e *SysConfig) GetSysConfigBySysApp(c *gin.Context) { e.Error(c, 500, err, "查询失败") return } - mp :=make(map[string]string) + mp := make(map[string]string) for i := 0; i < len(list); i++ { key := list[i].ConfigKey if key != "" { diff --git a/app/admin/models/system/sys_config.go b/app/admin/models/system/sys_config.go index f07e7cd5..80f2c3f3 100644 --- a/app/admin/models/system/sys_config.go +++ b/app/admin/models/system/sys_config.go @@ -9,8 +9,9 @@ type SysConfig struct { ConfigName string `json:"configName" gorm:"type:varchar(128);comment:ConfigName"` // ConfigKey string `json:"configKey" gorm:"type:varchar(128);comment:ConfigKey"` // ConfigValue string `json:"configValue" gorm:"type:varchar(255);comment:ConfigValue"` // - ConfigType string `json:"configType" gorm:"type:varchar(64);comment:ConfigType"` // - Remark string `json:"remark" gorm:"type:varchar(128);comment:Remark"` // + ConfigType string `json:"configType" gorm:"type:varchar(64);comment:ConfigType"` + IsFrontend int `json:"isFrontend" gorm:"type:varchar(64);comment:是否前台"` // + Remark string `json:"remark" gorm:"type:varchar(128);comment:Remark"` // models.ControlBy models.ModelTime } @@ -26,4 +27,4 @@ func (e *SysConfig) Generate() models.ActiveRecord { func (e *SysConfig) GetId() interface{} { return e.Id -} +} \ No newline at end of file diff --git a/app/admin/service/dto/sys_config.go b/app/admin/service/dto/sys_config.go index 38433f18..014e6d58 100644 --- a/app/admin/service/dto/sys_config.go +++ b/app/admin/service/dto/sys_config.go @@ -18,6 +18,7 @@ type SysConfigSearch struct { ConfigName string `form:"configName" search:"type:contains;column:config_name;table:sys_config" comment:""` ConfigKey string `form:"configKey" search:"type:contains;column:config_key;table:sys_config" comment:""` ConfigType string `form:"configType" search:"type:exact;column:config_type;table:sys_config" comment:""` + IsFrontend int `json:"isFrontend" search:"type:exact;column:is_frontend;table:sys_config" comment:""` } func (m *SysConfigSearch) GetNeedSearch() interface{} { @@ -41,6 +42,7 @@ type SysConfigControl struct { ConfigKey string `uri:"configKey" json:"configKey" comment:""` ConfigValue string `json:"configValue" comment:""` ConfigType string `json:"configType" comment:""` + IsFrontend int `json:"isFrontend"` Remark string `json:"remark" comment:""` } @@ -73,6 +75,7 @@ func (s *SysConfigControl) Generate() (*system.SysConfig, error) { ConfigKey: s.ConfigKey, ConfigValue: s.ConfigValue, ConfigType: s.ConfigType, + IsFrontend: s.IsFrontend, Remark: s.Remark, }, nil } diff --git a/cmd/migrate/migration/version/1615948084336_migrate.go b/cmd/migrate/migration/version/1615948084336_migrate.go new file mode 100644 index 00000000..0478d823 --- /dev/null +++ b/cmd/migrate/migration/version/1615948084336_migrate.go @@ -0,0 +1,28 @@ +package version + +import ( + "gorm.io/gorm" + "runtime" + + "go-admin/cmd/migrate/migration" + common "go-admin/common/models" +) + +func init() { + _, fileName, _, _ := runtime.Caller(0) + migration.Migrate.SetVersion(migration.GetFilename(fileName), _1615948084336Test) +} + +func _1615948084336Test(db *gorm.DB, version string) error { + return db.Transaction(func(tx *gorm.DB) error { + + err := tx.Exec("alter table sys_config add is_frontend int default 1 null comment '是否前台参数' after config_type").Error + if err != nil { + return err + } + + return tx.Create(&common.Migration{ + Version: version, + }).Error + }) +} \ No newline at end of file