You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

67 lines
1.4 KiB

  1. package svc
  2. import (
  3. "egg-im/internal/business/comm/db"
  4. "egg-im/internal/business/comm/md"
  5. db2 "egg-im/pkg/db"
  6. "fmt"
  7. )
  8. // 单挑记录获取
  9. func SysCfgGet(key string) string {
  10. return db.DbSysCfg.SysCfgGetWithDb(key)
  11. }
  12. // 多条记录获取
  13. func SysCfgFind(keys ...string) map[string]string {
  14. tmp := SysCfgFindComm(keys...)
  15. return tmp
  16. }
  17. // SysCfgFindComm get cfg by master id
  18. func SysCfgFindComm(keys ...string) map[string]string {
  19. res := map[string]string{}
  20. cfgKey := fmt.Sprintf(md.KEY_SYS_CFG_CACHE)
  21. err := db2.RedisUtil.GetJson(cfgKey, &res)
  22. if err != nil || len(res) == 0 {
  23. cfgList, _ := db.DbSysCfg.SysCfgGetAll()
  24. if cfgList == nil {
  25. return nil
  26. }
  27. for _, v := range *cfgList {
  28. res[v.Key] = v.Val
  29. }
  30. db2.RedisUtil.SetJson(cfgKey, res, 1800)
  31. }
  32. if len(keys) == 0 {
  33. return res
  34. }
  35. tmp := map[string]string{}
  36. for _, v := range keys {
  37. if val, ok := res[v]; ok {
  38. tmp[v] = val
  39. } else {
  40. tmp[v] = ""
  41. }
  42. }
  43. return tmp
  44. }
  45. // SysCfgCleanCache 清理系统配置信息
  46. func SysCfgCleanCache() {
  47. db2.RedisUtil.Del(md.KEY_SYS_CFG_CACHE)
  48. }
  49. // SysCfgSet 写入系统设置
  50. func SysCfgSet(key, val, memo string) bool {
  51. cfg, err := db.DbSysCfg.SysCfgGetOne(key)
  52. if err != nil || cfg == nil {
  53. return db.DbSysCfg.SysCfgInsert(key, val, memo)
  54. }
  55. if memo != "" && cfg.Memo != memo {
  56. cfg.Memo = memo
  57. }
  58. SysCfgCleanCache()
  59. return db.DbSysCfg.SysCfgUpdate(key, val, cfg.Memo)
  60. }