base_from_ccf.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_index_lib/logic"
  5. "eta_gn/eta_index_lib/models"
  6. "eta_gn/eta_index_lib/services"
  7. "eta_gn/eta_index_lib/utils"
  8. "strconv"
  9. "time"
  10. )
  11. // CCFController CCF化纤信息
  12. type CCFController struct {
  13. BaseAuthController
  14. }
  15. // Add
  16. // @Title 新增CCF指标接口
  17. // @Description 新增CCF指标接口
  18. // @Success 200 {object} models.AddEdbInfoReq
  19. // @router /add [post]
  20. func (this *CCFController) 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. ob := new(models.BaseFromCCF)
  43. cacheKey = utils.CACHE_EDB_DATA_ADD + strconv.Itoa(ob.GetSource()) + "_" + req.EdbCode
  44. if utils.Rc.IsExist(cacheKey) {
  45. br.Ret = 501
  46. br.Success = true
  47. br.Msg = "系统处理中,请稍后重试"
  48. return
  49. }
  50. utils.Rc.SetNX(cacheKey, 1, 1*time.Minute)
  51. defer func() {
  52. _ = utils.Rc.Delete(cacheKey)
  53. }()
  54. if err = ob.Add(req.EdbCode); err != nil {
  55. br.Msg = "获取指标信息失败!"
  56. br.ErrMsg = "获取指标信息失败 AddEdbDataFromCCF,Err:" + err.Error()
  57. return
  58. }
  59. br.Ret = 200
  60. br.Success = true
  61. br.Msg = "获取成功"
  62. }
  63. // Refresh
  64. // @Title 刷新CCF指标接口
  65. // @Description 刷新CCF指标接口
  66. // @Success 200 {object} models.RefreshEdbInfoReq
  67. // @router /refresh [post]
  68. func (this *CCFController) Refresh() {
  69. br := new(models.BaseResponse).Init()
  70. var cacheKey string
  71. defer func() {
  72. if br.ErrMsg == "" {
  73. br.IsSendEmail = false
  74. }
  75. this.Data["json"] = br
  76. this.ServeJSON()
  77. }()
  78. var req models.RefreshEdbInfoReq
  79. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  80. if err != nil {
  81. br.Msg = "参数解析异常!"
  82. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  83. return
  84. }
  85. if req.EdbCode == "" {
  86. br.Msg = "请输入指标编码!"
  87. br.ErrMsg = "请输入指标编码,指标编码为空"
  88. return
  89. }
  90. if req.EdbInfoId < 0 {
  91. br.Msg = "请输入指标ID!"
  92. br.ErrMsg = "请输入指标ID"
  93. return
  94. }
  95. ob := new(models.BaseFromCCF)
  96. source := ob.GetSource()
  97. // 获取指标详情
  98. edbInfo, err := models.GetEdbInfoByEdbCode(source, req.EdbCode)
  99. if err != nil {
  100. br.Msg = "指标不存在!"
  101. br.ErrMsg = "指标不存在"
  102. return
  103. }
  104. cacheKey = utils.CACHE_EDB_DATA_REFRESH + strconv.Itoa(source) + "_" + req.EdbCode
  105. if utils.Rc.IsExist(cacheKey) {
  106. br.Ret = 501
  107. br.Success = true
  108. br.Msg = "系统处理中,请稍后重试"
  109. return
  110. }
  111. utils.Rc.SetNX(cacheKey, 1, 1*time.Minute)
  112. defer func() {
  113. _ = utils.Rc.Delete(cacheKey)
  114. }()
  115. if req.EdbInfoId <= 0 {
  116. req.EdbInfoId = edbInfo.EdbInfoId
  117. }
  118. err = ob.Refresh(req.EdbInfoId, req.EdbCode, req.StartDate)
  119. if err != nil && err.Error() != utils.ErrNoRow() {
  120. br.Msg = "刷新指标信息失败!"
  121. br.ErrMsg = "刷新指标信息失败 RefreshEdbDataFromCCF,Err:" + err.Error()
  122. return
  123. }
  124. // 更新指标最大最小值
  125. err, errMsg := models.UnifiedModifyEdbInfoMaxAndMinInfo(edbInfo)
  126. if err != nil {
  127. br.Msg = errMsg
  128. br.ErrMsg = err.Error()
  129. return
  130. }
  131. // 更新ES
  132. go logic.UpdateEs(edbInfo.EdbInfoId)
  133. br.Ret = 200
  134. br.Success = true
  135. br.Msg = "获取成功"
  136. }
  137. // HandleEdbData
  138. // @Title 处理CCF指标的接口
  139. // @Description 处理CCF指标的接口
  140. // @Success 200 string "操作成功"
  141. // @router /handle/edb_data [post]
  142. func (this *CCFController) HandleEdbData() {
  143. br := new(models.BaseResponse).Init()
  144. defer func() {
  145. if br.ErrMsg == "" {
  146. br.IsSendEmail = false
  147. }
  148. this.Data["json"] = br
  149. this.ServeJSON()
  150. }()
  151. var req models.HandleCCFEdbDataReq
  152. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  153. if err != nil {
  154. br.Msg = "参数解析异常!"
  155. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  156. return
  157. }
  158. // 处理excel表数据
  159. if err = services.HandleCCFIndex(&req); err != nil {
  160. br.Msg = "处理失败"
  161. br.ErrMsg = "处理失败,Err:" + err.Error()
  162. return
  163. }
  164. br.Ret = 200
  165. br.Success = true
  166. br.Msg = "处理成功"
  167. }
  168. // HandleTableData
  169. // @Title 处理CCF装置表格的接口
  170. // @Description 处理CCF装置表格的接口
  171. // @Success 200 string "操作成功"
  172. // @router /handle/table_data [post]
  173. func (this *CCFController) HandleTableData() {
  174. br := new(models.BaseResponse).Init()
  175. defer func() {
  176. if br.ErrMsg == "" {
  177. br.IsSendEmail = false
  178. }
  179. this.Data["json"] = br
  180. this.ServeJSON()
  181. }()
  182. var req models.HandleCCFStockTableReq
  183. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  184. if err != nil {
  185. br.Msg = "参数解析异常!"
  186. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  187. return
  188. }
  189. if req.Table == nil {
  190. br.Msg = "表格信息为空"
  191. br.ErrMsg = "表格信息为空"
  192. return
  193. }
  194. if err = services.HandleCCFStockTable(&req); err != nil {
  195. br.Msg = "处理失败"
  196. br.ErrMsg = "处理失败,Err:" + err.Error()
  197. return
  198. }
  199. br.Ret = 200
  200. br.Success = true
  201. br.Msg = "处理成功"
  202. }