package data_manage import ( "encoding/json" "eta/eta_api/controllers" "eta/eta_api/models" "eta/eta_api/models/data_manage" "eta/eta_api/models/system" "eta/eta_api/services/data" "eta/eta_api/services/data/data_manage_permission" "eta/eta_api/utils" "sort" ) // PredictEdbClassifyController 数据管理-预测指标分类模块 type PredictEdbClassifyController struct { controllers.BaseAuthController } // List // @Title 预测指标分类列表 // @Description 预测指标分类列表接口 // @Param IsOnlyMe query bool false "是否只看我的" // @Success 200 {object} data_manage.EdbClassifyListResp // @router /predict_classify/list [get] //func (this *PredictEdbClassifyController) List() { // br := new(models.BaseResponse).Init() // defer func() { // this.Data["json"] = br // this.ServeJSON() // }() // // isOnlyMe, _ := this.GetBool("IsOnlyMe") // // rootList, err := data_manage.GetEdbClassifyByParentId(0, 1) // if err != nil && err.Error() != utils.ErrNoRow() { // br.Msg = "获取失败" // br.ErrMsg = "获取数据失败,Err:" + err.Error() // return // } // // 获取当前账号的不可见指标 // obj := data_manage.EdbInfoNoPermissionAdmin{} // confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId) // if err != nil && err.Error() != utils.ErrNoRow() { // br.Msg = "获取失败" // br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error() // return // } // noPermissionEdbInfoIdMap := make(map[int]bool) // for _, v := range confList { // noPermissionEdbInfoIdMap[v.EdbInfoId] = true // } // // allEdbInfo, err := data_manage.GetPredictEdbInfoAll(1) // if err != nil && err.Error() != utils.ErrNoRow() { // br.Msg = "获取失败" // br.ErrMsg = "获取数据失败,Err:" + err.Error() // return // } // edbInfoMap := make(map[int][]*data_manage.EdbClassifyItems) // for _, v := range allEdbInfo { // // 如果指标不可见,那么就不返回该指标 // if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok { // continue // } // button := data.GetPredictEdbOpButton(this.SysUser, v.SysUserId) // button.AddButton = false //不管有没有权限,指标都是没有添加按钮的 // button.OpButton = false // button.DeleteButton = false // v.Button = button // if isOnlyMe { // if v.SysUserId == this.SysUser.AdminId { // edbInfoMap[v.ClassifyId] = append(edbInfoMap[v.ClassifyId], v) // } // } else { // edbInfoMap[v.ClassifyId] = append(edbInfoMap[v.ClassifyId], v) // } // } // rootChildMap := make(map[int][]*data_manage.EdbClassifyItems) // for _, v := range rootList { // button := data.GetPredictEdbClassifyOpButton(this.SysUser, v.SysUserId) // v.Button = button // // rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v) // if existItems, ok := edbInfoMap[v.ClassifyId]; ok { // v.Children = existItems // } else { // items := make([]*data_manage.EdbClassifyItems, 0) // v.Children = items // } // } // nodeAll := make([]*data_manage.EdbClassifyItems, 0) // for _, v := range rootList { // nodeAll = append(nodeAll, v) // } // // // 是否允许添加分类 // canOpClassify := true // // // 如果不是 超管 或者 ficc管理员 或者 ficc研究员,那么就没有权限 // //if !utils.InArrayByStr([]string{utils.ROLE_TYPE_CODE_ADMIN, utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_RESEARCHR, utils.ROLE_TYPE_CODE_FICC_RESEARCHR}, this.SysUser.RoleTypeCode) { // // canOpClassify = false // //} // // language := `CN` // // 指标显示的语言 // { // configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.PredictEdbLanguageVar) // if configDetail != nil { // language = configDetail.ConfigValue // } else { // configDetail, _ = system.GetDefaultConfigDetailByCode(system.PredictEdbLanguageVar) // if configDetail != nil { // language = configDetail.ConfigValue // } // } // } // // resp := data_manage.EdbClassifyListResp{ // AllNodes: nodeAll, // CanOpClassify: canOpClassify, // Language: language, // } // br.Ret = 200 // br.Success = true // br.Msg = "获取成功" // br.Data = resp //} // Items // @Title 获取所有预测指标分类接口-不包含指标 // @Description 获取所有预测指标分类接口-不包含指标 // @Success 200 {object} data_manage.EdbClassifyListResp // @router /predict_classify/items [get] func (this *PredictEdbClassifyController) Items() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() rootList, err := data_manage.GetEdbClassifyByParentId(0, 1) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } resp := new(data_manage.EdbClassifyListResp) resp.AllNodes = rootList br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // Add // @Title 新增预测指标分类 // @Description 新增预测指标分类接口 // @Param request body data_manage.AddEdbClassifyReq true "type json string" // @Success 200 Ret=200 保存成功 // @router /predict_classify/add [post] func (this *PredictEdbClassifyController) Add() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req data_manage.AddEdbClassifyReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.ClassifyName == "" { br.Msg = "请输入分类名称" br.IsSendEmail = false return } if req.ParentId < 0 { br.Msg = "参数错误" br.IsSendEmail = false return } haveOperaAuth := true if req.ParentId > 0 { parentClassify, err := data_manage.GetEdbClassifyById(req.ParentId) if err != nil { br.Msg = "获取父级分类失败" br.ErrMsg = "获取父级分类失败,Err:" + err.Error() return } // 已授权分类id permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, parentClassify.ClassifyId) if err != nil { br.Msg = "添加失败" br.ErrMsg = "获取父级分类失败,Err:" + err.Error() return } // 数据权限 haveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(parentClassify.IsJoinPermission, parentClassify.ClassifyId, permissionClassifyIdList) } button := data.GetPredictEdbClassifyOpButton(this.SysUser, 0, haveOperaAuth) if !button.AddButton { br.Msg = "不允许添加分类" br.IsSendEmail = false return } // 添加指标分类 _, err, errMsg := data.AddEdbClassify(req.ClassifyName, req.ParentId, req.Level, 1, this.SysUser.AdminId, this.SysUser.AdminName, this.Lang) if errMsg != `` { br.Msg = errMsg br.ErrMsg = errMsg if err != nil { br.ErrMsg = errMsg + ";Err:" + err.Error() } else { br.IsSendEmail = false } return } br.Ret = 200 br.Msg = "保存成功" br.Success = true br.IsAddLog = true } // Edit // @Title 修改预测指标分类 // @Description 修改预测指标分类接口 // @Param request body data_manage.EditEdbClassifyReq true "type json string" // @Success 200 Ret=200 修改成功 // @router /predict_classify/edit [post] func (this *PredictEdbClassifyController) Edit() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req data_manage.EditEdbClassifyReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.ClassifyName == "" { br.Msg = "请输入分类名称" br.IsSendEmail = false return } if req.ClassifyId < 0 { br.Msg = "参数错误" br.IsSendEmail = false return } err, errMsg := data.EditEdbClassify(req.ClassifyId, req.ClassifyName, this.Lang, this.SysUser) if errMsg != `` { br.Msg = errMsg br.ErrMsg = errMsg if err != nil { br.ErrMsg = errMsg + ";Err:" + err.Error() } else { br.IsSendEmail = false } return } br.Ret = 200 br.Msg = "保存成功" br.Success = true br.IsAddLog = true } // DeleteCheck // @Title 删除检测接口 // @Description 删除检测接口 // @Param request body data_manage.ClassifyDeleteCheckReq true "type json string" // @Success 200 Ret=200 检测成功 // @router /predict_classify/delete/check [post] func (this *PredictEdbClassifyController) DeleteCheck() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req data_manage.ClassifyDeleteCheckReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.ClassifyId < 0 && req.EdbInfoId <= 0 { br.Msg = "参数错误" br.IsSendEmail = false return } deleteStatus, tipsMsg, tableList, err, errMsg := data.DeleteCheck(req.ClassifyId, req.EdbInfoId, this.SysUser) if errMsg != `` { br.Msg = errMsg br.ErrMsg = errMsg if err != nil { br.ErrMsg = err.Error() } else { br.IsSendEmail = false } return } resp := new(data_manage.ClassifyDeleteCheckResp) resp.DeleteStatus = deleteStatus resp.TipsMsg = tipsMsg resp.TableList = tableList br.Ret = 200 br.Msg = "检测成功" br.Success = true br.Data = resp } // Delete // @Title 删除分类/指标 // @Description 删除分类/指标接口 // @Param request body data_manage.DeleteEdbClassifyReq true "type json string" // @Success 200 Ret=200 新增成功 // @router /predict_classify/delete [post] func (this *PredictEdbClassifyController) Delete() { 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 } var req data_manage.DeleteEdbClassifyReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.ClassifyId < 0 && req.EdbInfoId <= 0 { br.Msg = "参数错误" br.IsSendEmail = false return } nextItem, _, err, errMsg := data.Delete(req.ClassifyId, req.EdbInfoId, sysUser, string(this.Ctx.Input.RequestBody), this.Ctx.Input.URI()) if errMsg != `` { br.Msg = errMsg br.ErrMsg = errMsg if err != nil { br.ErrMsg = err.Error() } else { br.IsSendEmail = false } return } resp := data_manage.AddEdbInfoResp{} if nextItem != nil { resp = data_manage.AddEdbInfoResp{ EdbInfoId: nextItem.EdbInfoId, UniqueCode: nextItem.UniqueCode, ClassifyId: nextItem.ClassifyId, } } br.Ret = 200 br.Msg = "删除成功" br.Success = true br.IsAddLog = true br.Data = resp } // Move // EdbClassifyMove // @Title 分类移动接口 // @Description 分类移动接口 // @Success 200 {object} data_manage.MoveEdbClassifyReq // @router /predict_classify/move [post] func (this *PredictEdbClassifyController) Move() { 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 } var req data_manage.MoveEdbClassifyReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.ClassifyId <= 0 && req.EdbInfoId <= 0 { br.Msg = "参数错误" br.ErrMsg = "请选择拖动目标,分类目录或者指标" return } err, errMsg := data.MoveEdbClassify(req, sysUser, 1) if errMsg != `` { br.Msg = errMsg br.ErrMsg = errMsg if err != nil { br.ErrMsg = err.Error() } else { br.IsSendEmail = false } return } ////判断分类是否存在 //edbClassifyInfo, err := data_manage.GetEdbClassifyById(req.ClassifyId) //if err != nil { // br.Msg = "移动失败" // br.ErrMsg = "获取分类信息失败,Err:" + err.Error() // return //} //updateCol := make([]string, 0) // ////判断上级id是否一致,如果不一致的话,那么需要移动该分类层级 //if edbClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 { // parentEdbClassifyInfo, err := data_manage.GetEdbClassifyById(req.ParentClassifyId) // if err != nil { // br.Msg = "移动失败" // br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error() // return // } // edbClassifyInfo.ParentId = parentEdbClassifyInfo.ClassifyId // edbClassifyInfo.Level = parentEdbClassifyInfo.Level + 1 // edbClassifyInfo.ModifyTime = time.Now() // updateCol = append(updateCol, "ParentId", "Level", "ModifyTime") //} // ////如果有传入 上一个兄弟节点分类id //if req.PrevClassifyId > 0 { // prevClassify, err := data_manage.GetEdbClassifyById(req.PrevClassifyId) // if err != nil { // br.Msg = "移动失败" // br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error() // return // } // // //如果是移动在两个兄弟节点之间 // if req.NextClassifyId > 0 { // //下一个兄弟节点 // nextClassify, err := data_manage.GetEdbClassifyById(req.NextClassifyId) // if err != nil { // br.Msg = "移动失败" // br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error() // return // } // //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1 // if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == edbClassifyInfo.Sort { // //变更兄弟节点的排序 // updateSortStr := `sort + 2` // _ = data_manage.UpdateEdbClassifySortByParentId(prevClassify.ParentId, prevClassify.ClassifyId, prevClassify.Sort, updateSortStr) // } else { // //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了 // if nextClassify.Sort-prevClassify.Sort == 1 { // //变更兄弟节点的排序 // updateSortStr := `sort + 1` // _ = data_manage.UpdateEdbClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr) // } // } // } // // edbClassifyInfo.Sort = prevClassify.Sort + 1 // edbClassifyInfo.ModifyTime = time.Now() // updateCol = append(updateCol, "Sort", "ModifyTime") //} else { // firstClassify, err := data_manage.GetFirstEdbClassifyByParentId(edbClassifyInfo.ParentId) // if err != nil && err.Error() != utils.ErrNoRow() { // br.Msg = "移动失败" // br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error() // return // } // // //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序 // if firstClassify != nil && firstClassify.Sort == 0 { // updateSortStr := ` sort + 1 ` // _ = data_manage.UpdateEdbClassifySortByParentId(firstClassify.ParentId, firstClassify.ClassifyId-1, 0, updateSortStr) // } // // edbClassifyInfo.Sort = 0 //那就是排在第一位 // edbClassifyInfo.ModifyTime = time.Now() // updateCol = append(updateCol, "Sort", "ModifyTime") //} // ////更新 //if len(updateCol) > 0 { // err = edbClassifyInfo.Update(updateCol) // if err != nil { // br.Msg = "移动失败" // br.ErrMsg = "修改失败,Err:" + err.Error() // return // } //} br.Ret = 200 br.Success = true br.Msg = "移动成功" } // ListV2 // @Title 预测指标分类列表 // @Description 预测指标分类列表接口 // @Param IsOnlyMe query bool false "是否只看我的" // @Success 200 {object} data_manage.EdbClassifyListResp // @router /predict_classify/list/v2 [get] //func (this *PredictEdbClassifyController) ListV2() { // br := new(models.BaseResponse).Init() // defer func() { // this.Data["json"] = br // this.ServeJSON() // }() // // isOnlyMe, _ := this.GetBool("IsOnlyMe") // // rootList, err := data_manage.GetEdbClassifyByParentId(0, 1) // if err != nil && err.Error() != utils.ErrNoRow() { // br.Msg = "获取失败" // br.ErrMsg = "获取数据失败,Err:" + err.Error() // return // } // // 获取当前账号的不可见指标 // obj := data_manage.EdbInfoNoPermissionAdmin{} // confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId) // if err != nil && err.Error() != utils.ErrNoRow() { // br.Msg = "获取失败" // br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error() // return // } // noPermissionEdbInfoIdMap := make(map[int]bool) // for _, v := range confList { // noPermissionEdbInfoIdMap[v.EdbInfoId] = true // } // // allEdbInfo, err := data_manage.GetPredictEdbInfoAll(1) // if err != nil && err.Error() != utils.ErrNoRow() { // br.Msg = "获取失败" // br.ErrMsg = "获取数据失败,Err:" + err.Error() // return // } // edbInfoMap := make(map[int][]*data_manage.EdbClassifyItems) // for _, v := range allEdbInfo { // // 如果指标不可见,那么就不返回该指标 // if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok { // continue // } // button := data.GetPredictEdbOpButton(this.SysUser, v.SysUserId) // button.AddButton = false //不管有没有权限,指标都是没有添加按钮的 // button.OpButton = false // button.DeleteButton = false // v.Button = button // if isOnlyMe { // if v.SysUserId == this.SysUser.AdminId { // edbInfoMap[v.ClassifyId] = append(edbInfoMap[v.ClassifyId], v) // } // } else { // edbInfoMap[v.ClassifyId] = append(edbInfoMap[v.ClassifyId], v) // } // } // rootTwoList, err := data_manage.GetEdbClassifyByParentIdTwo(1) // if err != nil && err.Error() != utils.ErrNoRow() { // br.Msg = "获取失败" // br.ErrMsg = "获取数据失败,Err:" + err.Error() // return // } // classifyAll, err := data_manage.GetEdbClassifyAllV2(1) // if err != nil && err.Error() != utils.ErrNoRow() { // br.Msg = "获取失败" // br.ErrMsg = "获取数据失败,Err:" + err.Error() // return // } // rootTwoMap := make(map[int][]*data_manage.EdbClassifyItems) // for _, v := range rootTwoList { // button := data.GetPredictEdbClassifyOpButton(this.SysUser, v.SysUserId) // v.Button = button // rootTwoMap[v.ParentId] = append(rootTwoMap[v.ParentId], v) // } // rootTwoChildMap := make(map[int][]*data_manage.EdbClassifyItems) // for _, v := range classifyAll { // button := data.GetPredictEdbClassifyOpButton(this.SysUser, v.SysUserId) // v.Button = button // if v.Level == 3 { // rootTwoChildMap[v.ParentId] = append(rootTwoChildMap[v.ParentId], v) // } // } // // nodeAll := make([]*data_manage.EdbClassifyItems, 0) // for _, v := range rootList { // button := data.GetPredictEdbClassifyOpButton(this.SysUser, v.SysUserId) // v.Button = button // // if existItems, ok := rootTwoMap[v.ClassifyId]; ok { // v.Children = existItems // for _, item := range existItems { // item.Button = button // // if existItems, ok := rootTwoChildMap[item.ClassifyId]; ok { // item.Children = existItems // for _, existItem := range existItems { // if _, ok := noPermissionEdbInfoIdMap[existItem.EdbInfoId]; ok { // continue // } // button := data.GetPredictEdbClassifyOpButton(this.SysUser, v.SysUserId) // button.AddButton = false //不管有没有权限,指标都是没有添加按钮的 // existItem.Button = button // if isOnlyMe { // if existItem.SysUserId == this.SysUser.AdminId { // edbInfoMap[existItem.ClassifyId] = append(edbInfoMap[v.ClassifyId], v) // } // } else { // edbInfoMap[v.ClassifyId] = append(edbInfoMap[v.ClassifyId], v) // } // } // } else { // items := make([]*data_manage.EdbClassifyItems, 0) // item.Children = items // } // } // } else { // items := make([]*data_manage.EdbClassifyItems, 0) // v.Children = items // } // nodeAll = append(nodeAll, v) // } // // // 是否允许添加一级分类 // canOpClassify := true // button := data.GetPredictEdbClassifyOpButton(this.SysUser, 0) // if !button.AddButton { // canOpClassify = false // } // // language := `CN` // // 指标显示的语言 // { // configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.PredictEdbLanguageVar) // if configDetail != nil { // language = configDetail.ConfigValue // } else { // configDetail, _ = system.GetDefaultConfigDetailByCode(system.PredictEdbLanguageVar) // if configDetail != nil { // language = configDetail.ConfigValue // } // } // } // // resp := data_manage.EdbClassifyListResp{ // AllNodes: nodeAll, // CanOpClassify: canOpClassify, // Language: language, // } // br.Ret = 200 // br.Success = true // br.Msg = "获取成功" // br.Data = resp //} // SimpleList // @Title 单层分类列表 // @Description 单层分类列表 // @Success 200 {object} data_manage.EdbClassifyListResp // @router /predict_classify/simple [get] func (this *PredictEdbClassifyController) SimpleList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() // 默认查一级分类和一级分类下的指标信息, // 如果是 子级分类,查询该子级分类的下一级分类和指标信息 // 增加标识判断是文件夹还是指标列表 parentId, _ := this.GetInt("ParentId") isOnlyMe, _ := this.GetBool("IsOnlyMe") // 如果选择了只看我的,那么只查询归属于我的账号 sysUserId := 0 if isOnlyMe { sysUserId = this.SysUser.AdminId } rootList, err := data_manage.GetEdbClassifyByParentId(parentId, 1) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } nodeAll := make([]*data_manage.EdbClassifyItems, 0) var sortList data_manage.EdbClassifyItemList if parentId > 0 { // 查询挂在当前分类上的指标列表 // 获取当前账号的不可见指标 obj := data_manage.EdbInfoNoPermissionAdmin{} confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取失败" br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error() return } noPermissionEdbInfoIdMap := make(map[int]bool) for _, v := range confList { noPermissionEdbInfoIdMap[v.EdbInfoId] = true } allEdbInfo, err := data_manage.GetEdbInfoByClassifyId(parentId, 1, sysUserId) if err != nil { br.Msg = "获取指标数据失败" br.ErrMsg = "获取指标数据失败,Err:" + err.Error() return } if len(allEdbInfo) > 0 { // 查询当前分类信息 currClassify, err := data_manage.GetEdbClassifyById(parentId) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取当前分类信息失败,Err:" + err.Error() return } // 获取所有有权限的指标和分类 permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error() return } for _, v := range allEdbInfo { // 如果指标不可见,那么就不返回该指标 if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok { continue } // 数据权限 v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList) // 按钮权限 button := data.GetPredictEdbOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth) button.AddButton = false //不管有没有权限,指标都是没有添加按钮的 button.OpButton = false button.DeleteButton = false v.Button = button v.ParentId = parentId v.Children = make([]*data_manage.EdbClassifyItems, 0) nodeAll = append(nodeAll, v) } } } if len(rootList) > 0 { // 已授权分类id permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error() return } for _, v := range rootList { // 数据权限 v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList) // 按钮权限 button := data.GetPredictEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth) v.Button = button v.Children = make([]*data_manage.EdbClassifyItems, 0) nodeAll = append(nodeAll, v) } } if len(nodeAll) > 0 { //根据sort值排序 sortList = nodeAll sort.Sort(sortList) } if isOnlyMe { sortList, err = data.GetEdbClassifyByIsMe(sysUserId, parentId, 1, sortList) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取只看我的分类列表失败,err:" + err.Error() return } } // 是否允许添加一级分类 canOpClassify := true button := data.GetPredictEdbClassifyOpButton(this.SysUser, 0, true) if !button.AddButton { canOpClassify = false } language := `CN` // 指标显示的语言 { configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.PredictEdbLanguageVar) if configDetail != nil { language = configDetail.ConfigValue } else { configDetail, _ = system.GetDefaultConfigDetailByCode(system.PredictEdbLanguageVar) if configDetail != nil { language = configDetail.ConfigValue } } } resp := new(data_manage.EdbClassifyListResp) resp.AllNodes = sortList resp.Language = language resp.CanOpClassify = canOpClassify br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // ClassifyTree // @Title 多层分类列表树 // @Description 多层分类列表树 // @Success 200 {object} data_manage.EdbClassifyListResp // @router /predict_classify/tree [get] func (this *PredictEdbClassifyController) ClassifyTree() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() allList, err := data_manage.GetPredictEdbClassifyAll() if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } nodeAll := make([]*data_manage.EdbClassifyItems, 0) var sortList data_manage.EdbClassifyItemList if len(allList) > 0 { // 已授权分类id permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error() return } for k, v := range allList { // 数据权限 v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList) // 按钮权限 button := data.GetPredictEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth) allList[k].Button = button } nodeAll = data.GetClassifyTreeRecursive(allList, 0) //根据sort值排序 sortList = nodeAll sort.Sort(sortList) } // 是否允许添加一级分类 canOpClassify := true button := data.GetPredictEdbClassifyOpButton(this.SysUser, 0, true) if !button.AddButton { canOpClassify = false } language := `CN` // 指标显示的语言 { configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.PredictEdbLanguageVar) if configDetail != nil { language = configDetail.ConfigValue } else { configDetail, _ = system.GetDefaultConfigDetailByCode(system.PredictEdbLanguageVar) if configDetail != nil { language = configDetail.ConfigValue } } } resp := new(data_manage.EdbClassifyListResp) resp.AllNodes = sortList resp.Language = language resp.CanOpClassify = canOpClassify br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp }