chart_info_section.go 5.8 KB

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