|
- package svc
-
- import (
- cfgMd "applet/app/cfg"
- db2 "applet/app/db"
- db "applet/app/db/im"
- "applet/app/utils/cache"
- )
-
- // 多条记录获取
- 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{}
- cfgList, _ := db.SysCfgGetAll(db2.DbIm)
- if cfgList == nil {
- return nil
- }
- for _, v := range *cfgList {
- res[v.Key] = v.Val
- }
-
- 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() {
- cache.SelectDb(1) //TODO::IM统一放1号库
- cache.Del(cfgMd.IM_KEY_SYS_CFG_CACHE)
- }
-
- // SysCfgSet 写入系统设置
- func SysCfgSet(key, val, memo string) bool {
- cfg, err := db.SysCfgGetOne(db2.DbIm, key)
- if err != nil || cfg == nil {
- return db.SysCfgInsert(db2.DbIm, key, val, memo)
- }
- if memo != "" && cfg.Memo != memo {
- cfg.Memo = memo
- }
- SysCfgCleanCache()
- return db.SysCfgUpdate(db2.DbIm, key, val, cfg.Memo)
- }
|