base_from_baiinfo.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. // 百川盈孚
  12. type BaiinfoController struct {
  13. BaseAuthController
  14. }
  15. // @Title 新增Baiinfo指标接口
  16. // @Description 新增Baiinfo指标接口
  17. // @Success 200 {object} models.AddEdbInfoReq
  18. // @router /add [post]
  19. func (this *BaiinfoController) Add() {
  20. br := new(models.BaseResponse).Init()
  21. var cacheKey string
  22. defer func() {
  23. utils.Rc.Delete(cacheKey)
  24. this.Data["json"] = br
  25. this.ServeJSON()
  26. }()
  27. source := utils.DATA_SOURCE_BAIINFO
  28. var req models.AddEdbInfoReq
  29. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  30. if err != nil {
  31. br.Msg = "参数解析异常!"
  32. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  33. return
  34. }
  35. if req.EdbCode == "" {
  36. br.Msg = "请输入指标编码!"
  37. br.ErrMsg = "请输入指标编码,指标编码为空"
  38. return
  39. }
  40. cacheKey = utils.CACHE_EDB_DATA_ADD + strconv.Itoa(source) + "_" + req.EdbCode
  41. if !utils.Rc.IsExist(cacheKey) {
  42. utils.Rc.SetNX(cacheKey, 1, 1*time.Minute)
  43. err = models.AddEdbDataFromBaiinfo(req.EdbCode)
  44. if err != nil {
  45. br.Msg = "获取指标信息失败!"
  46. br.ErrMsg = "获取指标信息失败 AddEdbDataFromBaiinfo,Err:" + err.Error()
  47. return
  48. }
  49. br.Ret = 200
  50. br.Success = true
  51. br.Msg = "获取成功"
  52. } else {
  53. br.Ret = 501
  54. br.Success = true
  55. br.Msg = "系统处理中,请稍后重试"
  56. }
  57. }
  58. // @Title 刷新baiinfo指标接口
  59. // @Description 刷新baiinfo指标接口
  60. // @Success 200 {object} models.RefreshEdbInfoReq
  61. // @router /refresh [post]
  62. func (this *BaiinfoController) Refresh() {
  63. br := new(models.BaseResponse).Init()
  64. var cacheKey string
  65. defer func() {
  66. this.Data["json"] = br
  67. this.ServeJSON()
  68. }()
  69. source := utils.DATA_SOURCE_BAIINFO
  70. var req models.RefreshEdbInfoReq
  71. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  72. if err != nil {
  73. br.Msg = "参数解析异常!"
  74. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  75. return
  76. }
  77. if req.EdbCode == "" {
  78. br.Msg = "请输入指标编码!"
  79. br.ErrMsg = "请输入指标编码,指标编码为空"
  80. return
  81. }
  82. if req.EdbInfoId < 0 {
  83. br.Msg = "请输入指标ID!"
  84. br.ErrMsg = "请输入指标ID"
  85. return
  86. }
  87. // 获取指标详情
  88. edbInfo, err := models.GetEdbInfoByEdbCode(source, req.EdbCode)
  89. if err != nil {
  90. br.Msg = "指标不存在!"
  91. br.ErrMsg = "指标不存在"
  92. return
  93. }
  94. cacheKey = utils.CACHE_EDB_DATA_REFRESH + strconv.Itoa(source) + "_" + req.EdbCode
  95. if utils.Rc.IsExist(cacheKey) {
  96. br.Ret = 501
  97. br.Success = true
  98. br.Msg = "系统处理中,请稍后重试"
  99. return
  100. }
  101. utils.Rc.SetNX(cacheKey, 1, 1*time.Minute)
  102. defer func() {
  103. utils.Rc.Delete(cacheKey)
  104. }()
  105. if req.EdbInfoId <= 0 {
  106. req.EdbInfoId = edbInfo.EdbInfoId
  107. }
  108. err = models.RefreshEdbDataFromBaiinfo(req.EdbInfoId, req.EdbCode, req.StartDate)
  109. if err != nil && err.Error() != utils.ErrNoRow() {
  110. br.Msg = "刷新指标信息失败!"
  111. br.ErrMsg = "刷新指标信息失败 RefreshEdbDataFromBaiinfo,Err:" + err.Error()
  112. return
  113. }
  114. // 更新指标最大最小值
  115. err, errMsg := models.UnifiedModifyEdbInfoMaxAndMinInfo(edbInfo)
  116. if err != nil {
  117. br.Msg = errMsg
  118. br.ErrMsg = err.Error()
  119. return
  120. }
  121. // 更新ES
  122. go logic.UpdateEs(edbInfo.EdbInfoId)
  123. br.Ret = 200
  124. br.Success = true
  125. br.Msg = "获取成功"
  126. }
  127. // HandleExcelData
  128. // @Title 处理卓创(红桃3)指标的接口
  129. // @Description 处理卓创(红桃3)指标的接口
  130. // @Success 200 {object} models.HandleMysteelIndexResp
  131. // @router /handle/excel_data [post]
  132. func (this *BaiinfoController) HandleExcelData() {
  133. br := new(models.BaseResponse).Init()
  134. defer func() {
  135. this.Data["json"] = br
  136. this.ServeJSON()
  137. }()
  138. var req models.HandleBaiinfoExcelDataReq
  139. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  140. if err != nil {
  141. br.Msg = "参数解析异常!"
  142. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  143. return
  144. }
  145. // 处理excel表数据
  146. services.HandleBaiinfoIndex(req.BaseFilePath, req.RenameFilePath, req.IndexName, req.IndexCode, req.ExcelDataMap)
  147. br.Ret = 200
  148. br.Success = true
  149. br.Msg = "处理成功"
  150. }