Browse Source

update

master
dengbiao 4 weeks ago
parent
commit
6baac52dd7
6 changed files with 28 additions and 57 deletions
  1. +1
    -1
      app/db/dao/sys_cfg_dao.go
  2. +5
    -5
      app/db/implement/sys_cfg_implement.go
  3. +0
    -7
      app/db/model/sys_cfg.go
  4. +4
    -4
      app/svc/svc_master.go
  5. +17
    -39
      app/svc/svc_sys_cfg_get.go
  6. +1
    -1
      go.mod

+ 1
- 1
app/db/dao/sys_cfg_dao.go View File

@@ -1,6 +1,6 @@
package dao package dao


import "applet/app/db/model"
import "code.fnuoos.com/zhimeng/model.git/src/model"


type SysCfgDao interface { type SysCfgDao interface {
SysCfgGetAll() (*[]model.SysCfg, error) SysCfgGetAll() (*[]model.SysCfg, error)


+ 5
- 5
app/db/implement/sys_cfg_implement.go View File

@@ -2,10 +2,10 @@


import ( import (
"applet/app/db/dao" "applet/app/db/dao"
"applet/app/db/model"
"applet/app/md" "applet/app/md"
"applet/app/utils/cache" "applet/app/utils/cache"
"applet/app/utils/logx" "applet/app/utils/logx"
"code.fnuoos.com/zhimeng/model.git/src/model"
"fmt" "fmt"
"xorm.io/xorm" "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 { 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) _, err := s.Db.InsertOne(&cfg)
if err != nil { if err != nil {
logx.Error(err) logx.Error(err)
@@ -61,7 +61,7 @@ func (s SysCfgDb) SysCfgInsert(key, val, memo string) bool {
} }


func (s SysCfgDb) SysCfgUpdate(key, val 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) _, err := s.Db.Where("`key`=?", key).Cols("val").Update(&cfg)
if err != nil { if err != nil {
logx.Error(err) 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 { if err != nil {
_ = logx.Error(err) _ = logx.Error(err)
return "" return ""
@@ -100,7 +100,7 @@ func (s SysCfgDb) SysCfgGetWithDb(HKey string) string {
return "" return ""
} }
} }
return cfg.Val
return cfg.V
} }
return get return get
} }


+ 0
- 7
app/db/model/sys_cfg.go View File

@@ -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)"`
}

+ 4
- 4
app/svc/svc_master.go View File

@@ -20,17 +20,17 @@ func GetMasterId(c *gin.Context) (masterId string) {
if masterId == "" { if masterId == "" {
//TODO::通过域名查找masterId //TODO::通过域名查找masterId
host := c.Request.Host 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 { if err != nil {
e.OutErr(c, e.ERR_DB_ORM, err) e.OutErr(c, e.ERR_DB_ORM, err)
return return
} }
if agentAppDomain == nil {
if userAppDomain == nil {
e.OutErr(c, e.ERR_NOT_FAN, "域名不存在") e.OutErr(c, e.ERR_NOT_FAN, "域名不存在")
return return
} }
masterId = utils.IntToStr(agentAppDomain.Uuid)
masterId = utils.IntToStr(userAppDomain.Uuid)
c.Set("master_id", masterId) c.Set("master_id", masterId)
} }
fmt.Println("master_id:::::::", masterId) fmt.Println("master_id:::::::", masterId)


+ 17
- 39
app/svc/svc_sys_cfg_get.go View File

@@ -1,6 +1,7 @@
package svc package svc


import ( import (
"applet/app/db/implement"
db "code.fnuoos.com/zhimeng/model.git/src" db "code.fnuoos.com/zhimeng/model.git/src"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"xorm.io/xorm" "xorm.io/xorm"
@@ -11,9 +12,10 @@ import (


// 单挑记录获取 // 单挑记录获取
func SysCfgGet(c *gin.Context, key string) string { 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 { if c == nil {
masterId = "" masterId = ""
} else { } else {
masterId = c.GetString("mid")
masterId = GetMasterId(c)
} }
tmp := SysCfgFindComm(masterId, keys...) tmp := SysCfgFindComm(masterId, keys...)
return tmp return tmp
@@ -36,51 +38,23 @@ func SysCfgFindComm(masterId string, keys ...string) map[string]string {
} }
res := map[string]string{} res := map[string]string{}
//TODO::判断keys长度(大于10个直接查数据库) //TODO::判断keys长度(大于10个直接查数据库)
sysCfgDb := implement.NewSysCfgDb(eg, masterId)
if len(keys) > 10 { if len(keys) > 10 {
cfgList, _ := db.SysCfgGetAll(eg)
cfgList, _ := sysCfgDb.SysCfgGetAll()
if cfgList == nil { if cfgList == nil {
return nil return nil
} }
for _, v := range *cfgList { for _, v := range *cfgList {
res[v.Key] = v.Val
res[v.K] = v.V
} }
} else { } else {
for _, key := range keys { for _, key := range keys {
res[key] = db.SysCfgGetWithDb(eg, masterId, key)
res[key] = sysCfgDb.SysCfgGetWithDb(key)
} }
} }
return res 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() { func SysCfgCleanCache() {
cache.Del(md.KEY_SYS_CFG_CACHE) cache.Del(md.KEY_SYS_CFG_CACHE)
@@ -88,13 +62,17 @@ func SysCfgCleanCache() {


// 写入系统设置 // 写入系统设置
func SysCfgSet(c *gin.Context, key, val, memo string) bool { 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 { 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 { if memo != "" && cfg.Memo != memo {
cfg.Memo = memo cfg.Memo = memo
} }
SysCfgCleanCache() SysCfgCleanCache()
return db.SysCfgUpdate(db.DBs[c.GetString("mid")], key, val, cfg.Memo)
return sysCfgDb.SysCfgUpdate(key, val)
} }

+ 1
- 1
go.mod View File

@@ -5,7 +5,7 @@ go 1.18
//replace code.fnuoos.com/zhimeng/model.git => E:/company/ad/models //replace code.fnuoos.com/zhimeng/model.git => E:/company/ad/models


require ( 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/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
github.com/boombuler/barcode v1.0.1 github.com/boombuler/barcode v1.0.1
github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5 github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5


Loading…
Cancel
Save