chart_info_section.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta/eta_mobile/models"
  5. "eta/eta_mobile/models/data_manage"
  6. "eta/eta_mobile/services/data"
  7. "eta/eta_mobile/utils"
  8. "strings"
  9. )
  10. // GetChartTypeList
  11. // @Title 获取所有图表类型
  12. // @Description 获取所有图表类型
  13. // @Success 200 {object} data_manage.AddChartInfoResp
  14. // @router /chart_info/type_list [get]
  15. func (this *ChartInfoController) GetChartTypeList() {
  16. br := new(models.BaseResponse).Init()
  17. defer func() {
  18. this.Data["json"] = br
  19. this.ServeJSON()
  20. }()
  21. sysUser := this.SysUser
  22. if sysUser == nil {
  23. br.Msg = "请登录"
  24. br.ErrMsg = "请登录,SysUser Is Empty"
  25. br.Ret = 408
  26. return
  27. }
  28. listTmp, err := data_manage.GetChartTypeList()
  29. if err != nil {
  30. br.Msg = "获取图表类型失败"
  31. br.ErrMsg = "获取图表类型失败,Err:" + err.Error()
  32. return
  33. }
  34. //遍历list,将id和name组成map
  35. chartTypeMap := make(map[int][]data_manage.ChartType)
  36. for _, v := range listTmp {
  37. if v.ParentId > 0 {
  38. chartTypeMap[v.ParentId] = append(chartTypeMap[v.ParentId], v)
  39. }
  40. }
  41. list := make([]data_manage.ChartTypeList, 0)
  42. for _, v := range listTmp {
  43. if v.ParentId == 0 {
  44. tmp := data_manage.ChartTypeList{
  45. ChartTypeId: v.ChartTypeId,
  46. ChartTypeName: v.ChartTypeName,
  47. ChartTypeNameEn: v.ChartTypeNameEn,
  48. ParentId: v.ParentId,
  49. }
  50. child, ok := chartTypeMap[v.ChartTypeId]
  51. if ok {
  52. tmp.Child = child
  53. }
  54. list = append(list, tmp)
  55. }
  56. }
  57. resp := data_manage.ChartTypeListResp{List: list}
  58. br.Data = resp
  59. br.Ret = 200
  60. br.Success = true
  61. br.Msg = "获取图表类型成功"
  62. }
  63. // PreviewSectionCombineChartInfo
  64. // @Title 图表-获取预览的截面组合图数据
  65. // @Description 图表-获取预览的截面组合图数据
  66. // @Param request body data_manage.PreviewSectionCombineChartReq true "type json string"
  67. // @Success 200 {object} data_manage.ChartEdbInfoDetailResp
  68. // @router /chart_info/preview/section_combine [post]
  69. func (this *ChartInfoController) PreviewSectionCombineChartInfo() {
  70. br := new(models.BaseResponse).Init()
  71. defer func() {
  72. this.Data["json"] = br
  73. this.ServeJSON()
  74. }()
  75. var req data_manage.PreviewSectionCombineChartReq
  76. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  77. if err != nil {
  78. br.Msg = "参数解析异常!"
  79. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  80. return
  81. }
  82. chartInfo := new(data_manage.ChartInfoView)
  83. sysUser := this.SysUser
  84. if sysUser == nil {
  85. br.Msg = "请登录"
  86. br.ErrMsg = "请登录,SysUser Is Empty"
  87. br.Ret = 408
  88. return
  89. }
  90. chartType := utils.CHART_TYPE_SECTION_COMBINE
  91. edbInfoIdArr, err, errMsg := data.CheckChartExtraConfig(chartType, req.ExtraConfig)
  92. if err != nil {
  93. br.Msg = errMsg
  94. br.ErrMsg = "添加失败:" + err.Error()
  95. return
  96. }
  97. chartInfo.ChartType = chartType
  98. mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList(edbInfoIdArr)
  99. // 获取图表中的指标数据
  100. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartEdbData(0, chartType, "", "", "", mappingList, req.ExtraConfig, "")
  101. if err != nil {
  102. br.Msg = "获取失败"
  103. if errMsg != `` {
  104. br.Msg = errMsg
  105. }
  106. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  107. return
  108. }
  109. warnEdbList := make([]string, 0)
  110. for _, v := range edbList {
  111. if v.IsNullData {
  112. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  113. }
  114. }
  115. if len(warnEdbList) > 0 {
  116. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  117. }
  118. // 图表的指标来源
  119. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  120. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  121. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  122. //图表操作权限
  123. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  124. //判断是否需要展示英文标识
  125. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, utils.CHART_SOURCE_DEFAULT, chartType)
  126. chartInfo.Button = data_manage.ChartViewButton{
  127. IsEdit: chartInfo.IsEdit,
  128. IsEnChart: chartInfo.IsEnChart,
  129. IsAdd: chartInfo.IsAdd,
  130. IsCopy: true,
  131. IsSetName: chartInfo.IsSetName,
  132. }
  133. resp := new(data_manage.ChartInfoDetailResp)
  134. resp.ChartInfo = chartInfo
  135. resp.EdbInfoList = edbList
  136. resp.XEdbIdValue = xEdbIdValue
  137. resp.YDataList = yDataList
  138. resp.DataResp = dataResp
  139. br.Ret = 200
  140. br.Success = true
  141. br.Msg = "获取成功"
  142. br.Data = resp
  143. }