business_chart.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. package controllers
  2. import (
  3. "eta/eta_hub/models"
  4. "eta/eta_hub/models/data_manage"
  5. "eta/eta_hub/services"
  6. "eta/eta_hub/services/data"
  7. "eta/eta_hub/utils"
  8. "github.com/rdlucklib/rdluck_tools/paging"
  9. )
  10. type BusinessChartController struct {
  11. BaseAuthController
  12. }
  13. // List
  14. // @Title 图表列表
  15. // @Description 图表列表
  16. // @Param BusinessCode query string true "商家编码"
  17. // @Success 200 {object} data_manage.ChartInfoItem
  18. // @router /list [get]
  19. func (this *BusinessChartController) List() {
  20. br := new(models.BaseResponse).Init()
  21. defer func() {
  22. this.Data["json"] = br
  23. this.ServeJSON()
  24. }()
  25. businessCode := this.GetString("BusinessCode")
  26. pageSize, _ := this.GetInt("PageSize")
  27. currentIndex, _ := this.GetInt("CurrentIndex")
  28. if businessCode == "" {
  29. br.Msg = "商家编码不允许为空"
  30. return
  31. }
  32. if currentIndex <= 0 {
  33. currentIndex = 1
  34. }
  35. if pageSize <= 0 {
  36. pageSize = 100
  37. }
  38. startSize := utils.StartIndex(currentIndex, pageSize)
  39. chartOb := new(data_manage.EtaBusinessChartPermission)
  40. total, err := chartOb.GetChartListByBusinessCodeTotal(businessCode)
  41. if err != nil {
  42. br.Msg = "获取失败"
  43. br.ErrMsg = "ChartList GetItemTotal err: " + err.Error()
  44. return
  45. }
  46. page := paging.GetPaging(currentIndex, pageSize, int(total))
  47. resp := new(data_manage.BusinessChartInfoResp)
  48. if total == 0 {
  49. resp.List = make([]*data_manage.BusinessChartInfoView, 0)
  50. resp.Paging = page
  51. br.Data = resp
  52. br.Ret = 200
  53. br.Msg = "获取成功"
  54. return
  55. }
  56. chartList, err := chartOb.GetChartListByBusinessCode(businessCode, startSize, pageSize)
  57. if err != nil {
  58. br.Msg = "获取失败"
  59. br.ErrMsg = "ChartList GetChartListByBusinessCode err: " + err.Error()
  60. return
  61. }
  62. chartInfoIds := make([]int, 0)
  63. for _, v := range chartList {
  64. chartInfoIds = append(chartInfoIds, v.ChartInfoId)
  65. }
  66. descriptionList, err := chartOb.GetChartDescriptionListByChartInfoIds(chartInfoIds)
  67. if err != nil {
  68. br.Msg = "获取失败"
  69. br.ErrMsg = "ChartList GetChartDescriptionListByChartInfoIds err: " + err.Error()
  70. return
  71. }
  72. descriptionMap := make(map[int][]string)
  73. for _, v := range descriptionList {
  74. descriptionMap[v.ChartInfoId] = append(descriptionMap[v.ChartInfoId], v.Description)
  75. }
  76. edbMappingList, err := data_manage.GetChartEdbMappingList(chartInfoIds)
  77. if err != nil {
  78. br.Msg = "获取失败"
  79. br.ErrMsg = "ChartList GetChartEdbMappingList err: " + err.Error()
  80. return
  81. }
  82. edbInfoIds := make([]int, 0)
  83. chartMappingMap := make(map[int][]*data_manage.BusinessChartEdbListItem)
  84. for _, v := range edbMappingList {
  85. edbInfoIds = append(edbInfoIds, v.EdbInfoId)
  86. }
  87. edbInfoList, e := data_manage.GetEdbInfoByIdList(edbInfoIds)
  88. if e != nil {
  89. br.Msg = "获取失败"
  90. br.ErrMsg = "ChartList GetItemsByIdList err: " + e.Error()
  91. return
  92. }
  93. edbInfoMap := make(map[int]*data_manage.BusinessChartEdbListItem)
  94. // 根据chartInfoId 将edbInfoList 转换为chartMappingMap
  95. for _, v := range edbInfoList {
  96. endValue := v.EndValue
  97. if v.EdbInfoType == 0 {
  98. endValue = v.LatestValue
  99. }
  100. item := &data_manage.BusinessChartEdbListItem{
  101. EdbInfoId: v.EdbInfoId,
  102. EdbName: v.EdbName,
  103. EdbCode: v.EdbCode,
  104. EdbInfoType: v.EdbInfoType,
  105. Frequency: v.Frequency,
  106. Unit: v.Unit,
  107. EndDate: v.EndDate,
  108. EndValue: endValue,
  109. LatestDate: v.LatestDate,
  110. LatestValue: v.LatestValue,
  111. UniqueCode: v.UniqueCode,
  112. }
  113. edbInfoMap[v.EdbInfoId] = item
  114. }
  115. for _, v := range edbMappingList {
  116. item := edbInfoMap[v.EdbInfoId]
  117. chartMappingMap[v.ChartInfoId] = append(chartMappingMap[v.ChartInfoId], item)
  118. }
  119. for _, v := range chartList {
  120. v.EdbInfoList = chartMappingMap[v.ChartInfoId]
  121. description, ok := descriptionMap[v.ChartInfoId]
  122. if !ok {
  123. v.Description = make([]string, 0)
  124. } else {
  125. v.Description = description
  126. }
  127. }
  128. resp.List = chartList
  129. resp.Paging = page
  130. br.Data = resp
  131. br.Ret = 200
  132. br.Msg = "获取成功"
  133. }
  134. // ChartEdbDataList
  135. // @Title 图表指标数据列表
  136. // @Description 图表指标数据列表
  137. // @Param EdbCode query string true "指标编码"
  138. // @Success 200 {object} data_manage.EdbInfoDataResp
  139. // @router /edb/data [get]
  140. func (this *BusinessChartController) ChartEdbDataList() {
  141. br := new(models.BaseResponse).Init()
  142. defer func() {
  143. this.Data["json"] = br
  144. this.ServeJSON()
  145. }()
  146. edbInfoCode := this.GetString("EdbCode")
  147. if edbInfoCode == "" {
  148. br.Msg = "参数有误"
  149. return
  150. }
  151. edbOb := new(data_manage.EdbInfo)
  152. edbInfo, e := edbOb.GetItemByEdbCode(edbInfoCode)
  153. if e != nil {
  154. if e.Error() == utils.ErrNoRow() {
  155. br.Msg = "指标不存在"
  156. return
  157. }
  158. br.Msg = "获取失败"
  159. br.ErrMsg = "ChartEdbDataList GetItemByEdbCode err: " + e.Error()
  160. return
  161. }
  162. edbDataList, e := services.GetEdbInfoDataList(edbInfo)
  163. if e != nil {
  164. br.Msg = "获取失败"
  165. br.ErrMsg = "ChartEdbDataList GetEdbInfoDataList err: " + e.Error()
  166. return
  167. }
  168. br.Data = edbDataList
  169. br.Ret = 200
  170. br.Msg = "获取成功"
  171. }
  172. // TraceEdbInfo
  173. // @Title 指标溯源接口
  174. // @Description 指标溯源接口
  175. // @Param EdbInfoId query int true "指标id"
  176. // @Success 200 {object} data_manage.ChartListResp
  177. // @router /edb/trace [get]
  178. func (this *BusinessChartController) TraceEdbInfo() {
  179. br := new(models.BaseResponse).Init()
  180. defer func() {
  181. this.Data["json"] = br
  182. this.ServeJSON()
  183. }()
  184. edbInfoId, _ := this.GetInt("EdbInfoId")
  185. edbInfoCode := this.GetString("EdbCode")
  186. if edbInfoId <= 0 && edbInfoCode == "" {
  187. br.Msg = "参数错误"
  188. br.ErrMsg = "参数错误"
  189. return
  190. }
  191. resp, err := data.TraceEdbInfoByEdbInfoId(edbInfoId, edbInfoCode)
  192. if err != nil {
  193. br.Msg = "获取失败"
  194. br.Msg = "获取失败,Err:" + err.Error()
  195. return
  196. }
  197. br.Ret = 200
  198. br.Data = resp
  199. br.Msg = "刷新成功"
  200. }