|
- package svc
-
- import (
- "egg-im/internal/business/comm/db"
- "egg-im/internal/business/comm/md"
- db2 "egg-im/pkg/db"
- "fmt"
- )
-
- // 单挑记录获取
- func SysCfgGet(key string) string {
- return db.DbSysCfg.SysCfgGetWithDb(key)
- }
-
- // 多条记录获取
- func SysCfgFind(keys ...string) map[string]string {
- tmp := SysCfgFindComm(keys...)
- return tmp
- }
-
- // SysCfgFindComm get cfg by master id
- func SysCfgFindComm(keys ...string) map[string]string {
- res := map[string]string{}
- cfgKey := fmt.Sprintf(md.KEY_SYS_CFG_CACHE)
- err := db2.RedisUtil.GetJson(cfgKey, &res)
- if err != nil || len(res) == 0 {
- cfgList, _ := db.DbSysCfg.SysCfgGetAll()
- if cfgList == nil {
- return nil
- }
- for _, v := range *cfgList {
- res[v.Key] = v.Val
- }
- db2.RedisUtil.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
- }
-
- // SysCfgCleanCache 清理系统配置信息
- func SysCfgCleanCache() {
- db2.RedisUtil.Del(md.KEY_SYS_CFG_CACHE)
- }
-
- // SysCfgSet 写入系统设置
- func SysCfgSet(key, val, memo string) bool {
- cfg, err := db.DbSysCfg.SysCfgGetOne(key)
- if err != nil || cfg == nil {
- return db.DbSysCfg.SysCfgInsert(key, val, memo)
- }
- if memo != "" && cfg.Memo != memo {
- cfg.Memo = memo
- }
- SysCfgCleanCache()
- return db.DbSysCfg.SysCfgUpdate(key, val, cfg.Memo)
- }
|