controller.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package platformconfig
  2. import (
  3. "bet24.com/servers/adminserver/dao"
  4. "net/http"
  5. "sort"
  6. "strings"
  7. "bet24.com/log"
  8. coreClient "bet24.com/servers/coreservice/client"
  9. "github.com/gin-gonic/gin"
  10. )
  11. type (
  12. configInfo struct {
  13. CfgKey string
  14. }
  15. configList struct {
  16. RecordCount int
  17. List []configInfo
  18. }
  19. )
  20. // 获取配置列表
  21. func GetConfigList(c *gin.Context) {
  22. var resp configList
  23. list := coreClient.GetPlatformConfigList()
  24. for _, v := range list {
  25. resp.List = append(resp.List, configInfo{CfgKey: v})
  26. }
  27. sort.SliceStable(resp.List, func(i, j int) bool {
  28. return resp.List[i].CfgKey <= resp.List[j].CfgKey
  29. })
  30. c.JSON(http.StatusOK, resp)
  31. return
  32. }
  33. // 获取配置信息
  34. func GetConfig(c *gin.Context) {
  35. var req req_base
  36. if err := c.ShouldBind(&req); err != nil {
  37. log.Debug("%s shouldBind err %v", "platformConfig.GetConfig", err)
  38. return
  39. }
  40. ret := coreClient.GetPlatformConfig(req.CfgKey)
  41. c.String(http.StatusOK, ret)
  42. return
  43. }
  44. // 设置配置
  45. func SetConfig(c *gin.Context) {
  46. var req req_base
  47. if err := c.ShouldBind(&req); err != nil {
  48. log.Debug("%s shouldBind err %v", "platformConfig.SetConfig", err)
  49. return
  50. }
  51. req.CfgValue = strings.ReplaceAll(req.CfgValue, "[7B]", "{")
  52. req.CfgValue = strings.ReplaceAll(req.CfgValue, "[7D]", "}")
  53. req.CfgValue = strings.ReplaceAll(req.CfgValue, "[2A]", "*")
  54. req.CfgValue = strings.ReplaceAll(req.CfgValue, "[25]", "%")
  55. req.CfgValue = strings.ReplaceAll(req.CfgValue, "[43]", "+")
  56. coreClient.SetPlatformConfig(req.CfgKey, req.CfgValue)
  57. addOperationLog(req)
  58. log.Release("platformConfig.SetConfig %+v", req)
  59. c.JSON(http.StatusOK, "")
  60. return
  61. }
  62. // 添加操作日志
  63. func addOperationLog(req req_base) {
  64. if req.Eq == 0 {
  65. return
  66. }
  67. user := dao.NewGetInfo()
  68. user.In.AdminUserID = req.OpUserID
  69. user.DoAction(nil)
  70. objLog := dao.NewPlatformConfigLog()
  71. objLog.In.OpUserID = req.OpUserID
  72. objLog.In.OpUserName = req.OpUserName
  73. objLog.In.Memo = user.Out.Memo
  74. objLog.In.IPAddress = req.IpAddress
  75. objLog.In.KeyName = req.CfgKey
  76. objLog.In.Eq = req.Eq
  77. objLog.DoAction(nil)
  78. }
  79. // 获取操作记录
  80. func GetConfigLog(c *gin.Context) {
  81. var req req_base
  82. if err := c.ShouldBind(&req); err != nil {
  83. log.Debug("%s shouldBind err %v", "platformConfig.GetConfigLog", err)
  84. return
  85. }
  86. objLog := dao.NewPlatformConfigGetList()
  87. objLog.In.OpUserID = req.OpUserID
  88. objLog.In.KeyName = req.CfgKey
  89. objLog.DoAction(nil)
  90. c.JSON(http.StatusOK, objLog.Out)
  91. return
  92. }