From 0993173b1ff318a42f7b0f6dd0ddaaa99738d9dc Mon Sep 17 00:00:00 2001 From: infnan <38274826+infnan@users.noreply.github.com> Date: Thu, 18 Aug 2022 16:50:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86postgre=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: infnan <38274826+infnan@users.noreply.github.com> --- app/admin/apis/sys_config.go | 4 ++-- app/admin/models/sys_config.go | 2 +- app/admin/service/dto/sys_config.go | 6 +++--- cmd/migrate/migration/models/initdb.go | 4 ++++ common/middleware/handler/login.go | 2 +- config/pg.sql | 18 ++++++++++++++---- 6 files changed, 25 insertions(+), 11 deletions(-) diff --git a/app/admin/apis/sys_config.go b/app/admin/apis/sys_config.go index e4886bce..0a95c8b4 100644 --- a/app/admin/apis/sys_config.go +++ b/app/admin/apis/sys_config.go @@ -198,7 +198,7 @@ func (e SysConfig) Get2SysApp(c *gin.Context) { return } // 控制只读前台的数据 - req.IsFrontend = 1 + req.IsFrontend = "1" list := make([]models.SysConfig, 0) err = s.GetWithKeyList(&req, &list) if err != nil { @@ -310,4 +310,4 @@ func (e SysConfig) GetSysConfigByKEYForService(c *gin.Context) { return } e.OK(resp, s.Msg) -} \ No newline at end of file +} diff --git a/app/admin/models/sys_config.go b/app/admin/models/sys_config.go index 8bd07275..beb656be 100644 --- a/app/admin/models/sys_config.go +++ b/app/admin/models/sys_config.go @@ -10,7 +10,7 @@ type SysConfig struct { ConfigKey string `json:"configKey" gorm:"size:128;comment:ConfigKey"` // ConfigValue string `json:"configValue" gorm:"size:255;comment:ConfigValue"` // ConfigType string `json:"configType" gorm:"size:64;comment:ConfigType"` - IsFrontend int `json:"isFrontend" gorm:"size:64;comment:是否前台"` // + IsFrontend string `json:"isFrontend" gorm:"size:64;comment:是否前台"` // Remark string `json:"remark" gorm:"size:128;comment:Remark"` // models.ControlBy models.ModelTime diff --git a/app/admin/service/dto/sys_config.go b/app/admin/service/dto/sys_config.go index cbc03656..06f7467f 100644 --- a/app/admin/service/dto/sys_config.go +++ b/app/admin/service/dto/sys_config.go @@ -12,7 +12,7 @@ type SysConfigGetPageReq struct { ConfigName string `form:"configName" search:"type:contains;column:config_name;table:sys_config"` ConfigKey string `form:"configKey" search:"type:contains;column:config_key;table:sys_config"` ConfigType string `form:"configType" search:"type:exact;column:config_type;table:sys_config"` - IsFrontend int `form:"isFrontend" search:"type:exact;column:is_frontend;table:sys_config"` + IsFrontend string `form:"isFrontend" search:"type:exact;column:is_frontend;table:sys_config"` SysConfigOrder } @@ -29,7 +29,7 @@ func (m *SysConfigGetPageReq) GetNeedSearch() interface{} { } type SysConfigGetToSysAppReq struct { - IsFrontend int `form:"isFrontend" search:"type:exact;column:is_frontend;table:sys_config"` + IsFrontend string `form:"isFrontend" search:"type:exact;column:is_frontend;table:sys_config"` } func (m *SysConfigGetToSysAppReq) GetNeedSearch() interface{} { @@ -43,7 +43,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"` + IsFrontend string `json:"isFrontend"` Remark string `json:"remark" comment:""` common.ControlBy } diff --git a/cmd/migrate/migration/models/initdb.go b/cmd/migrate/migration/models/initdb.go index a9345031..ba7f4ca7 100644 --- a/cmd/migrate/migration/models/initdb.go +++ b/cmd/migrate/migration/models/initdb.go @@ -13,6 +13,10 @@ import ( func InitDb(db *gorm.DB) (err error) { filePath := "config/db.sql" if global.Driver == "postgres" { + filePath := "config/db.sql" + if err = ExecSql(db, filePath); err != nil { + return err + } filePath = "config/pg.sql" err = ExecSql(db, filePath) } else if global.Driver == "mysql" { diff --git a/common/middleware/handler/login.go b/common/middleware/handler/login.go index 619ac0f5..d17626c0 100644 --- a/common/middleware/handler/login.go +++ b/common/middleware/handler/login.go @@ -14,7 +14,7 @@ type Login struct { } func (u *Login) GetUser(tx *gorm.DB) (user SysUser, role SysRole, err error) { - err = tx.Table("sys_user").Where("username = ? and status = 2", u.Username).First(&user).Error + err = tx.Table("sys_user").Where("username = ? and status = '2'", u.Username).First(&user).Error if err != nil { log.Errorf("get user error, %s", err.Error()) return diff --git a/config/pg.sql b/config/pg.sql index 1c6836ea..ba3c0c82 100644 --- a/config/pg.sql +++ b/config/pg.sql @@ -1,11 +1,21 @@ -- 开始初始化数据 ; +create sequence if not exists sys_role_role_id_seq; +create sequence if not exists sys_user_user_id_seq; +create sequence if not exists sys_post_post_id_seq; +create sequence if not exists sys_menu_menu_id_seq; +create sequence if not exists sys_dict_type_dict_id_seq; +create sequence if not exists sys_dict_data_dict_code_seq; +create sequence if not exists sys_dept_dept_id_seq; +create sequence if not exists sys_config_config_id_seq; +create sequence if not exists sys_job_id_seq; + select setval('sys_role_role_id_seq',4); select setval('sys_user_user_id_seq',5); select setval('sys_post_post_id_seq',4); -select setval('sys_menu_menu_id_seq',268); +select setval('sys_menu_menu_id_seq',543); select setval('sys_dict_type_dict_id_seq',12); -select setval('sys_dict_data_dict_code_seq',32); +select setval('sys_dict_data_dict_code_seq',34); select setval('sys_dept_dept_id_seq',11); -select setval('sys_config_config_id_seq',4); +select setval('sys_config_config_id_seq',6); select setval('sys_job_id_seq',3); --- 数据完成 ; \ No newline at end of file +-- 数据完成 ;