|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- package svc
-
- import (
- "applet/app/admin/md"
- "applet/app/db"
- "applet/app/utils/cache"
- "fmt"
- "github.com/gin-gonic/gin"
- )
-
- // 单挑记录获取
- func SysCfgGet(c *gin.Context, key string) string {
- sysCfgDb := db.SysCfgDb{}
- sysCfgDb.Set()
- return sysCfgDb.SysCfgGetWithDb(key)
- }
-
- func SysCfgDel(c *gin.Context, key string) bool {
- sysCfgDb := db.SysCfgDb{}
- sysCfgDb.Set()
- err := sysCfgDb.SysCfgDel(key)
- if err != nil {
- return false
- }
- return true
- }
-
- // 多条记录获取
- func SysCfgFind(c *gin.Context, keys ...string) map[string]string {
- var masterId string
- if c == nil {
- masterId = ""
- } else {
- masterId = c.GetString("mid")
- }
- tmp := SysCfgFindComm(masterId, keys...)
- return tmp
- }
-
- // SysCfgGetByMasterId get one config by master id
- func SysCfgGetByMasterId(masterId, key string) string {
- res := SysCfgFindComm(masterId, key)
- if _, ok := res[key]; !ok {
- return ""
- }
- return res[key]
- }
-
- // SysCfgFindComm get cfg by master id
- func SysCfgFindComm(masterId string, keys ...string) map[string]string {
- sysCfgDb := db.SysCfgDb{}
- sysCfgDb.Set()
- res := map[string]string{}
-
- cfgKey := fmt.Sprintf("%s:cfg_cache", masterId)
-
- err := cache.GetJson(cfgKey, &res)
- if err != nil || len(res) == 0 {
- cfgList, _ := sysCfgDb.SysCfgGetAll()
- if cfgList == nil {
- return nil
- }
- for _, v := range *cfgList {
- res[v.Key] = v.Val
- }
- cache.SetJson(cfgKey, res, 1800)
- }
- 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 EgSysCfgFind(keys ...string) map[string]string {
- sysCfgDb := db.SysCfgDb{}
- sysCfgDb.Set()
- res := map[string]string{}
- if len(res) == 0 {
- cfgList, _ := sysCfgDb.SysCfgGetAll()
- 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(c *gin.Context) {
- var tmp = []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
- for _, v := range tmp {
- cacheKey := fmt.Sprintf(md.AppCfgCacheKey, v)
- cache.Del(cacheKey)
- }
- }
-
- // 写入系统设置
- func SysCfgSet(c *gin.Context, key, val, memo string) bool {
- sysCfgDb := db.SysCfgDb{}
- sysCfgDb.Set()
- 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(c)
- return sysCfgDb.SysCfgUpdate(key, val)
- }
|