base_from_hisugar.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_index_lib/logic"
  5. "eta/eta_index_lib/models"
  6. "eta/eta_index_lib/services"
  7. "eta/eta_index_lib/utils"
  8. "strconv"
  9. "time"
  10. )
  11. // HisugarController 泛糖科技
  12. type HisugarController struct {
  13. BaseAuthController
  14. }
  15. // Add
  16. // @Title 新增泛糖科技指标接口
  17. // @Description 新增泛糖科技指标接口
  18. // @Success 200 {object} models.AddEdbInfoReq
  19. // @router /add [post]
  20. func (this *HisugarController) Add() {
  21. br := new(models.BaseResponse).Init()
  22. var cacheKey string
  23. defer func() {
  24. if br.ErrMsg == "" {
  25. br.IsSendEmail = false
  26. }
  27. this.Data["json"] = br
  28. this.ServeJSON()
  29. }()
  30. var req models.AddEdbInfoReq
  31. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  32. if err != nil {
  33. br.Msg = "参数解析异常!"
  34. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  35. return
  36. }
  37. if req.EdbCode == "" {
  38. br.Msg = "请输入指标编码!"
  39. br.ErrMsg = "请输入指标编码,指标编码为空"
  40. return
  41. }
  42. source := utils.DATA_SOURCE_HISUGAR
  43. cacheKey = utils.CACHE_EDB_DATA_ADD + strconv.Itoa(source) + "_" + req.EdbCode
  44. if !utils.Rc.IsExist(cacheKey) {
  45. utils.Rc.SetNX(cacheKey, 1, 1*time.Minute)
  46. err = models.AddEdbDataFromHisugar(req.EdbCode)
  47. if err != nil {
  48. br.Msg = "获取指标信息失败!"
  49. br.ErrMsg = "获取指标信息失败 AddEdbDataFromHisugar,Err:" + err.Error()
  50. return
  51. }
  52. br.Ret = 200
  53. br.Success = true
  54. br.Msg = "获取成功"
  55. } else {
  56. br.Ret = 501
  57. br.Success = true
  58. br.Msg = "系统处理中,请稍后重试"
  59. }
  60. }
  61. // Refresh
  62. // @Title 刷新泛糖科技指标接口
  63. // @Description 刷新泛糖科技指标接口
  64. // @Success 200 {object} models.RefreshEdbInfoReq
  65. // @router /refresh [post]
  66. func (this *HisugarController) Refresh() {
  67. br := new(models.BaseResponse).Init()
  68. var cacheKey string
  69. defer func() {
  70. utils.Rc.Delete(cacheKey)
  71. this.Data["json"] = br
  72. this.ServeJSON()
  73. }()
  74. source := utils.DATA_SOURCE_HISUGAR
  75. var req models.RefreshEdbInfoReq
  76. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  77. if err != nil {
  78. br.Msg = "参数解析异常!"
  79. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  80. return
  81. }
  82. if req.EdbCode == "" {
  83. br.Msg = "请输入指标编码!"
  84. br.ErrMsg = "请输入指标编码,指标编码为空"
  85. return
  86. }
  87. if req.EdbInfoId <= 0 {
  88. br.Msg = "请输入指标ID!"
  89. br.ErrMsg = "请输入指标ID"
  90. return
  91. }
  92. cacheKey = utils.CACHE_EDB_DATA_REFRESH + strconv.Itoa(source) + "_" + req.EdbCode
  93. if utils.Rc.IsExist(cacheKey) {
  94. br.Ret = 501
  95. br.Success = true
  96. br.Msg = "系统处理中,请稍后重试"
  97. return
  98. }
  99. utils.Rc.SetNX(cacheKey, 1, 1*time.Minute)
  100. // 获取指标详情
  101. edbInfo, err := models.GetEdbInfoById(req.EdbInfoId)
  102. if err != nil {
  103. br.Msg = "指标不存在!"
  104. br.ErrMsg = "指标不存在"
  105. return
  106. }
  107. err = models.RefreshEdbDataFromHisugar(req.EdbInfoId, req.EdbCode, req.StartDate)
  108. if err != nil && err.Error() != utils.ErrNoRow() {
  109. br.Msg = "刷新指标信息失败!"
  110. br.ErrMsg = "刷新指标信息失败 RefreshEdbDataFromHisugar,Err:" + err.Error()
  111. return
  112. }
  113. // 更新指标最大最小值
  114. err, errMsg := models.UnifiedModifyEdbInfoMaxAndMinInfo(edbInfo)
  115. if err != nil {
  116. br.Msg = errMsg
  117. br.ErrMsg = err.Error()
  118. return
  119. }
  120. // 更新ES
  121. go logic.UpdateEs(edbInfo.EdbInfoId)
  122. br.Ret = 200
  123. br.Success = true
  124. br.Msg = "获取成功"
  125. }
  126. // HandleEdbData
  127. // @Title 处理泛糖科技指标的接口
  128. // @Description 处理泛糖科技指标的接口
  129. // @Success 200 string "操作成功"
  130. // @router /handle/edb_data [post]
  131. func (this *HisugarController) HandleEdbData() {
  132. br := new(models.BaseResponse).Init()
  133. defer func() {
  134. if br.ErrMsg == "" {
  135. br.IsSendEmail = false
  136. }
  137. this.Data["json"] = br
  138. this.ServeJSON()
  139. }()
  140. var req models.HandleHisugarEdbDataReq
  141. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  142. if err != nil {
  143. br.Msg = "参数解析异常!"
  144. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  145. return
  146. }
  147. if err = services.HandleHisugarIndex(req.List); err != nil {
  148. br.Msg = "处理失败"
  149. br.ErrMsg = "处理失败,Err:" + err.Error()
  150. return
  151. }
  152. br.Ret = 200
  153. br.Success = true
  154. br.Msg = "处理成功"
  155. }