|
- package svc
-
- import (
- "applet/app/db/implement"
- db "code.fnuoos.com/zhimeng/model.git/src"
- "github.com/gin-gonic/gin"
- "xorm.io/xorm"
-
- "applet/app/md"
- "applet/app/utils/cache"
- )
-
- // 单挑记录获取
- func SysCfgGet(c *gin.Context, key string) string {
- masterId := GetMasterId(c)
- eg := db.DBs[masterId]
- sysCfgDb := implement.NewSysCfgDb(eg, masterId)
- return sysCfgDb.SysCfgGetWithDb(key)
- }
-
- // 多条记录获取
- func SysCfgFind(c *gin.Context, keys ...string) map[string]string {
- var masterId string
- if c == nil {
- masterId = ""
- } else {
- masterId = GetMasterId(c)
- }
- tmp := SysCfgFindComm(masterId, keys...)
- return tmp
- }
- func SysCfgFindComm(masterId string, keys ...string) map[string]string {
- var eg *xorm.Engine
- if masterId == "" {
- eg = db.Db
- } else {
- eg = db.DBs[masterId]
- }
- res := map[string]string{}
- //TODO::判断keys长度(大于10个直接查数据库)
- sysCfgDb := implement.NewSysCfgDb(eg, masterId)
- if len(keys) > 10 {
- cfgList, _ := sysCfgDb.SysCfgGetAll()
- if cfgList == nil {
- return nil
- }
- for _, v := range *cfgList {
- res[v.K] = v.V
- }
- } else {
- for _, key := range keys {
- res[key] = sysCfgDb.SysCfgGetWithDb(key)
- }
- }
- return res
- }
-
- // 清理系统配置信息
- func SysCfgCleanCache() {
- cache.Del(md.KEY_SYS_CFG_CACHE)
- }
-
- // 写入系统设置
- func SysCfgSet(c *gin.Context, key, val, memo string) bool {
- masterId := GetMasterId(c)
- eg := db.DBs[masterId]
- sysCfgDb := implement.NewSysCfgDb(eg, masterId)
-
- cfg, err := sysCfgDb.SysCfgGetOne(key)
- if err != nil || cfg == nil {
- return sysCfgDb.SysCfgInsert(key, val, memo)
- }
- if memo != "" && cfg.Memo != memo {
- cfg.Memo = memo
- }
- SysCfgCleanCache()
- return sysCfgDb.SysCfgUpdate(key, val)
- }
|