123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- package data_manage
- import (
- "encoding/json"
- "eta_gn/eta_api/models"
- "eta_gn/eta_api/models/data_manage"
- "eta_gn/eta_api/services/data"
- "eta_gn/eta_api/services/data/data_manage_permission"
- "eta_gn/eta_api/utils"
- "strings"
- )
- // GetChartTypeList
- // @Title 获取所有图表类型
- // @Description 获取所有图表类型
- // @Success 200 {object} data_manage.AddChartInfoResp
- // @router /chart_info/type_list [get]
- func (this *ChartInfoController) GetChartTypeList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- listTmp, err := data_manage.GetChartTypeList()
- if err != nil {
- br.Msg = "获取图表类型失败"
- br.ErrMsg = "获取图表类型失败,Err:" + err.Error()
- return
- }
- //遍历list,将id和name组成map
- chartTypeMap := make(map[int][]data_manage.ChartType)
- for _, v := range listTmp {
- if v.ParentId > 0 {
- chartTypeMap[v.ParentId] = append(chartTypeMap[v.ParentId], v)
- }
- }
- list := make([]data_manage.ChartTypeList, 0)
- for _, v := range listTmp {
- if v.ParentId == 0 {
- tmp := data_manage.ChartTypeList{
- ChartTypeId: v.ChartTypeId,
- ChartTypeName: v.ChartTypeName,
- ChartTypeNameEn: v.ChartTypeNameEn,
- ParentId: v.ParentId,
- }
- child, ok := chartTypeMap[v.ChartTypeId]
- if ok {
- tmp.Child = child
- }
- list = append(list, tmp)
- }
- }
- resp := data_manage.ChartTypeListResp{List: list}
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取图表类型成功"
- }
- // PreviewSectionCombineChartInfo
- // @Title 图表-获取预览的截面组合图数据
- // @Description 图表-获取预览的截面组合图数据
- // @Param request body data_manage.PreviewSectionCombineChartReq true "type json string"
- // @Success 200 {object} data_manage.ChartEdbInfoDetailResp
- // @router /chart_info/preview/section_combine [post]
- func (this *ChartInfoController) PreviewSectionCombineChartInfo() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req data_manage.PreviewSectionCombineChartReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- chartInfo := new(data_manage.ChartInfoView)
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- chartType := utils.CHART_TYPE_SECTION_COMBINE
- edbInfoIdArr, err, errMsg := data.CheckChartExtraConfig(chartType, req.ExtraConfig)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = "添加失败:" + err.Error()
- return
- }
- chartInfo.ChartType = chartType
- mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList(edbInfoIdArr)
- if err != nil {
- br.Msg = "获取图表,指标信息失败"
- br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
- return
- }
- // 获取图表中的指标数据
- edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartEdbData(0, chartType, "", "", "", mappingList, req.ExtraConfig, "")
- if err != nil {
- br.Msg = "获取失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
- return
- }
- // 指标权限
- {
- classifyMap := make(map[int]*data_manage.EdbClassify)
- // 分类
- {
- classifyIdList := make([]int, 0)
- for _, v := range edbList {
- classifyIdList = append(classifyIdList, v.ClassifyId)
- }
- classifyList, tmpErr := data_manage.GetEdbClassifyByIdList(classifyIdList)
- if tmpErr != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类列表失败,Err:" + tmpErr.Error()
- return
- }
- for _, v := range classifyList {
- classifyMap[v.ClassifyId] = v
- }
- }
- // 获取所有有权限的指标和分类
- permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(sysUser.AdminId, 0, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
- return
- }
- for _, item := range edbList {
- // 数据权限
- if currClassify, ok := classifyMap[item.ClassifyId]; ok {
- item.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(item.IsJoinPermission, currClassify.IsJoinPermission, item.EdbInfoId, item.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
- }
- }
- }
- warnEdbList := make([]string, 0)
- for _, v := range edbList {
- if v.IsNullData {
- warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
- }
- v.HaveOperaAuth = true
- }
- if len(warnEdbList) > 0 {
- chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
- }
- // 图表的指标来源
- sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
- chartInfo.ChartSource = strings.Join(sourceNameList, ",")
- chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
- //图表操作权限
- chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
- //判断是否需要展示英文标识
- chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, utils.CHART_SOURCE_DEFAULT, chartType)
- chartInfo.Button = data_manage.ChartViewButton{
- IsEdit: chartInfo.IsEdit,
- IsEnChart: chartInfo.IsEnChart,
- IsAdd: chartInfo.IsEdit,
- IsCopy: true,
- IsSetName: chartInfo.IsSetName,
- }
- resp := new(data_manage.ChartInfoDetailResp)
- resp.ChartInfo = chartInfo
- resp.EdbInfoList = edbList
- resp.XEdbIdValue = xEdbIdValue
- resp.YDataList = yDataList
- resp.DataResp = dataResp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|