From 6baac52dd7da974029818f185de9da2a49566c78 Mon Sep 17 00:00:00 2001 From: dengbiao Date: Wed, 21 Aug 2024 16:21:31 +0800 Subject: [PATCH] update --- app/db/dao/sys_cfg_dao.go | 2 +- app/db/implement/sys_cfg_implement.go | 10 ++--- app/db/model/sys_cfg.go | 7 ---- app/svc/svc_master.go | 8 ++-- app/svc/svc_sys_cfg_get.go | 56 ++++++++------------------- go.mod | 2 +- 6 files changed, 28 insertions(+), 57 deletions(-) delete mode 100644 app/db/model/sys_cfg.go diff --git a/app/db/dao/sys_cfg_dao.go b/app/db/dao/sys_cfg_dao.go index d66f4f3..a4f9308 100644 --- a/app/db/dao/sys_cfg_dao.go +++ b/app/db/dao/sys_cfg_dao.go @@ -1,6 +1,6 @@ package dao -import "applet/app/db/model" +import "code.fnuoos.com/zhimeng/model.git/src/model" type SysCfgDao interface { SysCfgGetAll() (*[]model.SysCfg, error) diff --git a/app/db/implement/sys_cfg_implement.go b/app/db/implement/sys_cfg_implement.go index b9d9f90..0690a77 100644 --- a/app/db/implement/sys_cfg_implement.go +++ b/app/db/implement/sys_cfg_implement.go @@ -2,10 +2,10 @@ import ( "applet/app/db/dao" - "applet/app/db/model" "applet/app/md" "applet/app/utils/cache" "applet/app/utils/logx" + "code.fnuoos.com/zhimeng/model.git/src/model" "fmt" "xorm.io/xorm" ) @@ -51,7 +51,7 @@ func (s SysCfgDb) SysCfgGetOne(key string) (*model.SysCfg, error) { } func (s SysCfgDb) SysCfgInsert(key, val, memo string) bool { - cfg := model.SysCfg{Key: key, Val: val, Memo: memo} + cfg := model.SysCfg{K: key, V: val, Memo: memo} _, err := s.Db.InsertOne(&cfg) if err != nil { logx.Error(err) @@ -61,7 +61,7 @@ func (s SysCfgDb) SysCfgInsert(key, val, memo string) bool { } func (s SysCfgDb) SysCfgUpdate(key, val string) bool { - cfg := model.SysCfg{Key: key, Val: val} + cfg := model.SysCfg{K: key, V: val} _, err := s.Db.Where("`key`=?", key).Cols("val").Update(&cfg) if err != nil { logx.Error(err) @@ -88,7 +88,7 @@ func (s SysCfgDb) SysCfgGetWithDb(HKey string) string { } // 设置缓存 - _, err = cache.HSet(cacheKey, HKey, cfg.Val) + _, err = cache.HSet(cacheKey, HKey, cfg.V) if err != nil { _ = logx.Error(err) return "" @@ -100,7 +100,7 @@ func (s SysCfgDb) SysCfgGetWithDb(HKey string) string { return "" } } - return cfg.Val + return cfg.V } return get } diff --git a/app/db/model/sys_cfg.go b/app/db/model/sys_cfg.go deleted file mode 100644 index 22d906b..0000000 --- a/app/db/model/sys_cfg.go +++ /dev/null @@ -1,7 +0,0 @@ -package model - -type SysCfg struct { - Key string `json:"key" xorm:"not null pk comment('键') VARCHAR(127)"` - Val string `json:"val" xorm:"comment('值') TEXT"` - Memo string `json:"memo" xorm:"not null default '' comment('备注') VARCHAR(255)"` -} diff --git a/app/svc/svc_master.go b/app/svc/svc_master.go index d500e80..c9f5c49 100644 --- a/app/svc/svc_master.go +++ b/app/svc/svc_master.go @@ -20,17 +20,17 @@ func GetMasterId(c *gin.Context) (masterId string) { if masterId == "" { //TODO::通过域名查找masterId host := c.Request.Host - agentAppDomainDb := implement.NewAgentAppDomainDb(db.Db) - agentAppDomain, err := agentAppDomainDb.GetAgentAppDomainByHost(host) + userAppDomainDb := implement.NewUserAppDomainDb(db.Db) + userAppDomain, err := userAppDomainDb.GetMediumAppDomainByHost(host) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err) return } - if agentAppDomain == nil { + if userAppDomain == nil { e.OutErr(c, e.ERR_NOT_FAN, "域名不存在") return } - masterId = utils.IntToStr(agentAppDomain.Uuid) + masterId = utils.IntToStr(userAppDomain.Uuid) c.Set("master_id", masterId) } fmt.Println("master_id:::::::", masterId) diff --git a/app/svc/svc_sys_cfg_get.go b/app/svc/svc_sys_cfg_get.go index bb99785..060a84b 100644 --- a/app/svc/svc_sys_cfg_get.go +++ b/app/svc/svc_sys_cfg_get.go @@ -1,6 +1,7 @@ package svc import ( + "applet/app/db/implement" db "code.fnuoos.com/zhimeng/model.git/src" "github.com/gin-gonic/gin" "xorm.io/xorm" @@ -11,9 +12,10 @@ import ( // 单挑记录获取 func SysCfgGet(c *gin.Context, key string) string { - mid := c.GetString("mid") - eg := db.DBs[mid] - return db.SysCfgGetWithDb(eg, mid, key) + masterId := GetMasterId(c) + eg := db.DBs[masterId] + sysCfgDb := implement.NewSysCfgDb(eg, masterId) + return sysCfgDb.SysCfgGetWithDb(key) } // 多条记录获取 @@ -22,7 +24,7 @@ func SysCfgFind(c *gin.Context, keys ...string) map[string]string { if c == nil { masterId = "" } else { - masterId = c.GetString("mid") + masterId = GetMasterId(c) } tmp := SysCfgFindComm(masterId, keys...) return tmp @@ -36,51 +38,23 @@ func SysCfgFindComm(masterId string, keys ...string) map[string]string { } res := map[string]string{} //TODO::判断keys长度(大于10个直接查数据库) + sysCfgDb := implement.NewSysCfgDb(eg, masterId) if len(keys) > 10 { - cfgList, _ := db.SysCfgGetAll(eg) + cfgList, _ := sysCfgDb.SysCfgGetAll() if cfgList == nil { return nil } for _, v := range *cfgList { - res[v.Key] = v.Val + res[v.K] = v.V } } else { for _, key := range keys { - res[key] = db.SysCfgGetWithDb(eg, masterId, key) + res[key] = sysCfgDb.SysCfgGetWithDb(key) } } return res } -// 多条记录获取 -func EgSysCfgFind(keys ...string) map[string]string { - var e *xorm.Engine - res := map[string]string{} - if len(res) == 0 { - cfgList, _ := db.SysCfgGetAll(e) - if cfgList == nil { - return nil - } - for _, v := range *cfgList { - res[v.Key] = v.Val - } - // 先不设置缓存 - // cache.SetJson(md.KEY_SYS_CFG_CACHE, res, 60) - } - if len(keys) == 0 { - return res - } - tmp := map[string]string{} - for _, v := range keys { - if val, ok := res[v]; ok { - tmp[v] = val - } else { - tmp[v] = "" - } - } - return tmp -} - // 清理系统配置信息 func SysCfgCleanCache() { cache.Del(md.KEY_SYS_CFG_CACHE) @@ -88,13 +62,17 @@ func SysCfgCleanCache() { // 写入系统设置 func SysCfgSet(c *gin.Context, key, val, memo string) bool { - cfg, err := db.SysCfgGetOne(db.DBs[c.GetString("mid")], key) + masterId := GetMasterId(c) + eg := db.DBs[masterId] + sysCfgDb := implement.NewSysCfgDb(eg, masterId) + + cfg, err := sysCfgDb.SysCfgGetOne(key) if err != nil || cfg == nil { - return db.SysCfgInsert(db.DBs[c.GetString("mid")], key, val, memo) + return sysCfgDb.SysCfgInsert(key, val, memo) } if memo != "" && cfg.Memo != memo { cfg.Memo = memo } SysCfgCleanCache() - return db.SysCfgUpdate(db.DBs[c.GetString("mid")], key, val, cfg.Memo) + return sysCfgDb.SysCfgUpdate(key, val) } diff --git a/go.mod b/go.mod index e39f718..cd12e99 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.18 //replace code.fnuoos.com/zhimeng/model.git => E:/company/ad/models require ( - code.fnuoos.com/zhimeng/model.git v0.0.3-0.20240820125928-6ce4c06dda24 + code.fnuoos.com/zhimeng/model.git v0.0.3-0.20240821082038-bfd73b32452e github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5 github.com/boombuler/barcode v1.0.1 github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5