面包店
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

svc_sys_cfg_get.go 1.9 KiB

8 mesi fa
8 mesi fa
8 mesi fa
8 mesi fa
8 mesi fa
8 mesi fa
8 mesi fa
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package svc
  2. import (
  3. "applet/app/admin/md"
  4. "applet/app/db"
  5. "applet/app/utils/cache"
  6. "fmt"
  7. "github.com/gin-gonic/gin"
  8. )
  9. // 单挑记录获取
  10. func SysCfgGet(c *gin.Context, key string) string {
  11. sysCfgDb := db.SysCfgDb{}
  12. sysCfgDb.Set()
  13. return sysCfgDb.SysCfgGetWithDb(key)
  14. }
  15. func SysCfgDel(c *gin.Context, key string) bool {
  16. sysCfgDb := db.SysCfgDb{}
  17. sysCfgDb.Set()
  18. err := sysCfgDb.SysCfgDel(key)
  19. if err != nil {
  20. return false
  21. }
  22. return true
  23. }
  24. // 多条记录获取
  25. func SysCfgFind(keys ...string) map[string]string {
  26. tmp := SysCfgFindComm(keys...)
  27. return tmp
  28. }
  29. // SysCfgFindComm get cfg by master id
  30. func SysCfgFindComm(keys ...string) map[string]string {
  31. sysCfgDb := db.SysCfgDb{}
  32. sysCfgDb.Set()
  33. res := map[string]string{}
  34. cfgKey := fmt.Sprintf("%s:cfg_cache")
  35. err := cache.GetJson(cfgKey, &res)
  36. if err != nil || len(res) == 0 {
  37. cfgList, _ := sysCfgDb.SysCfgGetAll()
  38. if cfgList == nil {
  39. return nil
  40. }
  41. for _, v := range *cfgList {
  42. res[v.Key] = v.Val
  43. }
  44. cache.SetJson(cfgKey, res, 1800)
  45. }
  46. if len(keys) == 0 {
  47. return res
  48. }
  49. tmp := map[string]string{}
  50. for _, v := range keys {
  51. if val, ok := res[v]; ok {
  52. tmp[v] = val
  53. } else {
  54. tmp[v] = ""
  55. }
  56. }
  57. return tmp
  58. }
  59. // 清理系统配置信息
  60. func SysCfgCleanCache(c *gin.Context) {
  61. 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"}
  62. for _, v := range tmp {
  63. cacheKey := fmt.Sprintf(md.AppCfgCacheKey, v)
  64. cache.Del(cacheKey)
  65. }
  66. }
  67. // 写入系统设置
  68. func SysCfgSet(c *gin.Context, key, val, memo string) bool {
  69. sysCfgDb := db.SysCfgDb{}
  70. sysCfgDb.Set()
  71. cfg, err := sysCfgDb.SysCfgGetOne(key)
  72. if err != nil || cfg == nil {
  73. return sysCfgDb.SysCfgInsert(key, val, memo)
  74. }
  75. if memo != "" && cfg.Memo != memo {
  76. cfg.Memo = memo
  77. }
  78. SysCfgCleanCache(c)
  79. return sysCfgDb.SysCfgUpdate(key, val)
  80. }