base_from_sci.go 3.5 KB

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