chart_info_section.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/models"
  5. "eta_gn/eta_api/models/data_manage"
  6. "eta_gn/eta_api/services/data"
  7. "eta_gn/eta_api/services/data/data_manage_permission"
  8. "eta_gn/eta_api/utils"
  9. "strings"
  10. )
  11. // @router /chart_info/type_list [get]
  12. func (this *ChartInfoController) GetChartTypeList() {
  13. br := new(models.BaseResponse).Init()
  14. defer func() {
  15. this.Data["json"] = br
  16. this.ServeJSON()
  17. }()
  18. sysUser := this.SysUser
  19. if sysUser == nil {
  20. br.Msg = "请登录"
  21. br.ErrMsg = "请登录,SysUser Is Empty"
  22. br.Ret = 408
  23. return
  24. }
  25. listTmp, err := data_manage.GetChartTypeList()
  26. if err != nil {
  27. br.Msg = "获取图表类型失败"
  28. br.ErrMsg = "获取图表类型失败,Err:" + err.Error()
  29. return
  30. }
  31. chartTypeMap := make(map[int][]data_manage.ChartType)
  32. for _, v := range listTmp {
  33. if v.ParentId > 0 {
  34. chartTypeMap[v.ParentId] = append(chartTypeMap[v.ParentId], v)
  35. }
  36. }
  37. list := make([]data_manage.ChartTypeList, 0)
  38. for _, v := range listTmp {
  39. if v.ParentId == 0 {
  40. tmp := data_manage.ChartTypeList{
  41. ChartTypeId: v.ChartTypeId,
  42. ChartTypeName: v.ChartTypeName,
  43. ChartTypeNameEn: v.ChartTypeNameEn,
  44. ParentId: v.ParentId,
  45. }
  46. child, ok := chartTypeMap[v.ChartTypeId]
  47. if ok {
  48. tmp.Child = child
  49. }
  50. list = append(list, tmp)
  51. }
  52. }
  53. resp := data_manage.ChartTypeListResp{List: list}
  54. br.Data = resp
  55. br.Ret = 200
  56. br.Success = true
  57. br.Msg = "获取图表类型成功"
  58. }
  59. // @router /chart_info/preview/section_combine [post]
  60. func (this *ChartInfoController) PreviewSectionCombineChartInfo() {
  61. br := new(models.BaseResponse).Init()
  62. defer func() {
  63. this.Data["json"] = br
  64. this.ServeJSON()
  65. }()
  66. var req data_manage.PreviewSectionCombineChartReq
  67. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  68. if err != nil {
  69. br.Msg = "参数解析异常!"
  70. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  71. return
  72. }
  73. chartInfo := new(data_manage.ChartInfoView)
  74. sysUser := this.SysUser
  75. if sysUser == nil {
  76. br.Msg = "请登录"
  77. br.ErrMsg = "请登录,SysUser Is Empty"
  78. br.Ret = 408
  79. return
  80. }
  81. chartType := utils.CHART_TYPE_SECTION_COMBINE
  82. edbInfoIdArr, err, errMsg := data.CheckChartExtraConfig(chartType, req.ExtraConfig)
  83. if err != nil {
  84. br.Msg = errMsg
  85. br.ErrMsg = "添加失败:" + err.Error()
  86. return
  87. }
  88. chartInfo.ChartType = chartType
  89. mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList(edbInfoIdArr)
  90. if err != nil {
  91. br.Msg = "获取图表,指标信息失败"
  92. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  93. return
  94. }
  95. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartEdbData(0, chartType, "", "", "", mappingList, req.ExtraConfig, "")
  96. if err != nil {
  97. br.Msg = "获取失败"
  98. if errMsg != `` {
  99. br.Msg = errMsg
  100. }
  101. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  102. return
  103. }
  104. {
  105. classifyMap := make(map[int]*data_manage.EdbClassify)
  106. {
  107. classifyIdList := make([]int, 0)
  108. for _, v := range edbList {
  109. classifyIdList = append(classifyIdList, v.ClassifyId)
  110. }
  111. classifyList, tmpErr := data_manage.GetEdbClassifyByIdList(classifyIdList)
  112. if tmpErr != nil {
  113. br.Msg = "获取失败"
  114. br.ErrMsg = "获取分类列表失败,Err:" + tmpErr.Error()
  115. return
  116. }
  117. for _, v := range classifyList {
  118. classifyMap[v.ClassifyId] = v
  119. }
  120. }
  121. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(sysUser.AdminId, 0, 0)
  122. if err != nil {
  123. br.Msg = "获取失败"
  124. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  125. return
  126. }
  127. for _, item := range edbList {
  128. if currClassify, ok := classifyMap[item.ClassifyId]; ok {
  129. item.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(item.IsJoinPermission, currClassify.IsJoinPermission, item.EdbInfoId, item.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  130. }
  131. }
  132. }
  133. warnEdbList := make([]string, 0)
  134. for _, v := range edbList {
  135. if v.IsNullData {
  136. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  137. }
  138. v.HaveOperaAuth = true
  139. }
  140. if len(warnEdbList) > 0 {
  141. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  142. }
  143. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  144. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  145. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  146. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  147. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, utils.CHART_SOURCE_DEFAULT, chartType)
  148. chartInfo.Button = data_manage.ChartViewButton{
  149. IsEdit: chartInfo.IsEdit,
  150. IsEnChart: chartInfo.IsEnChart,
  151. IsAdd: chartInfo.IsEdit,
  152. IsCopy: true,
  153. IsSetName: chartInfo.IsSetName,
  154. }
  155. resp := new(data_manage.ChartInfoDetailResp)
  156. resp.ChartInfo = chartInfo
  157. resp.EdbInfoList = edbList
  158. resp.XEdbIdValue = xEdbIdValue
  159. resp.YDataList = yDataList
  160. resp.DataResp = dataResp
  161. br.Ret = 200
  162. br.Success = true
  163. br.Msg = "获取成功"
  164. br.Data = resp
  165. }