edb_refresh.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_hub/models"
  5. "eta/eta_hub/models/data_manage"
  6. "eta/eta_hub/services/data"
  7. "eta/eta_hub/utils"
  8. )
  9. // SaveRelationEdbRefreshStatus
  10. // @Title 批量设置被引用的指标刷新状态接口
  11. // @Description 批量设置被引用的指标刷新状态接口
  12. // @Param request body data_manage.SaveEdbRefreshStatusReq true "type json string"
  13. // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp
  14. // @router /refresh/set [post]
  15. func (c *EdbInfoController) SaveRelationEdbRefreshStatus() {
  16. br := new(models.BaseResponse).Init()
  17. defer func() {
  18. c.Data["json"] = br
  19. c.ServeJSON()
  20. }()
  21. var req data_manage.SaveRelationEdbRefreshStatusReq
  22. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  23. if err != nil {
  24. br.Msg = "参数解析异常!"
  25. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  26. return
  27. }
  28. condition := ``
  29. pars := make([]interface{}, 0)
  30. edbType := 1 //基础指标
  31. switch req.Source {
  32. case utils.DATA_SOURCE_THS, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_WIND: // wind
  33. condition += ` AND source = ? `
  34. pars = append(pars, req.Source)
  35. case 0:
  36. req.Source = 0
  37. edbType = 2
  38. condition += ` AND edb_type = ? AND edb_info_type = 0`
  39. pars = append(pars, edbType)
  40. default:
  41. br.Msg = "暂不支持设置其他来源的指标"
  42. return
  43. }
  44. edbIdList := make([]int, 0)
  45. edbCodeList := make([]string, 0)
  46. edbIdList = req.EdbSelectIdList
  47. if len(edbIdList) <= 0 {
  48. br.Msg = "指标不能为空"
  49. return
  50. }
  51. condition += ` AND edb_info_id IN (` + utils.GetOrmInReplace(len(edbIdList)) + `) `
  52. pars = append(pars, edbIdList)
  53. //查询指标信息
  54. edbObj := new(data_manage.EdbInfo)
  55. edbList, e := edbObj.GetItemsByCondition(condition, pars, []string{}, "")
  56. if e != nil && e.Error() != utils.ErrNoRow() {
  57. br.Msg = "获取失败"
  58. br.ErrMsg = "获取数据失败,Err:" + e.Error()
  59. return
  60. }
  61. if len(edbList) == 0 {
  62. br.Msg = "未查到对应的指标"
  63. return
  64. }
  65. // 如果是钢联化工,那么需要过滤供应商暂停的指标
  66. if req.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  67. // 获取未被供应商暂停的指标
  68. tmpEdbCodeList := make([]string, 0)
  69. for _, v := range edbList {
  70. tmpEdbCodeList = append(tmpEdbCodeList, v.EdbCode)
  71. }
  72. notIsSupplierStopIndexList, e := data_manage.GetNotIsSupplierStopIndexByCodeList(tmpEdbCodeList, 0)
  73. if e != nil {
  74. br.Msg = "获取失败"
  75. br.ErrMsg = "获取数据失败,Err:" + e.Error()
  76. return
  77. }
  78. // 未被供应商暂停的指标编码
  79. notIsSupplierStopIndexCodeList := make([]string, 0)
  80. for _, v := range notIsSupplierStopIndexList {
  81. notIsSupplierStopIndexCodeList = append(notIsSupplierStopIndexCodeList, v.IndexCode)
  82. }
  83. //查询未被供应商暂停的指标信息
  84. edbList, err = data_manage.GetEdbInfoByEdbCodeList(utils.DATA_SOURCE_MYSTEEL_CHEMICAL, notIsSupplierStopIndexCodeList)
  85. if err != nil {
  86. br.Msg = "获取失败"
  87. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  88. return
  89. }
  90. if len(edbList) <= 0 {
  91. br.Ret = 200
  92. br.Msg = "保存成功"
  93. return
  94. }
  95. }
  96. fromEdbIdList := make([]int, 0)
  97. for _, v := range edbList {
  98. if req.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  99. edbCodeList = append(edbCodeList, v.EdbCode)
  100. }
  101. if v.EdbInfoType == 0 {
  102. fromEdbIdList = append(fromEdbIdList, v.EdbInfoId)
  103. }
  104. }
  105. isStop := 0
  106. if req.ModifyStatus == `暂停` {
  107. isStop = 1
  108. }
  109. // 查询计算指标ID
  110. // 查询相关的计算指标
  111. calculateEdbIdList := make([]int, 0)
  112. if isStop == 1 {
  113. hasFind := make(map[int]struct{})
  114. calculateEdbIdList, err = data.GetCalculateEdbByFromEdbInfo(fromEdbIdList, calculateEdbIdList, hasFind)
  115. if err != nil {
  116. br.Msg = "查询计算指标信息失败"
  117. br.ErrMsg = "查询计算指标信息失败,Err:" + err.Error()
  118. return
  119. }
  120. }
  121. switch req.Source {
  122. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL: // 钢联化工
  123. err = data_manage.ModifyMysteelChemicalUpdateStatusByEdbInfoIds(edbIdList, isStop, edbCodeList, calculateEdbIdList)
  124. default:
  125. err = data_manage.EdbInfoUpdateStatusByEdbInfoId(edbIdList, isStop, calculateEdbIdList)
  126. }
  127. if err != nil {
  128. br.Msg = `操作失败`
  129. br.ErrMsg = "操作失败,Err:" + err.Error()
  130. return
  131. }
  132. br.Ret = 200
  133. br.Msg = "操作成功"
  134. }