dengbiao преди 4 месеца
родител
ревизия
6baac52dd7
променени са 6 файла, в които са добавени 28 реда и са изтрити 57 реда
  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 Целия файл

@@ -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)


+ 5
- 5
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
}


+ 0
- 7
app/db/model/sys_cfg.go Целия файл

@@ -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 Целия файл

@@ -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)


+ 17
- 39
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)
}

+ 1
- 1
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


Зареждане…
Отказ
Запис