package data_manage import ( "encoding/json" "eta_gn/eta_api/controllers" "eta_gn/eta_api/models" "eta_gn/eta_api/models/data_manage" "eta_gn/eta_api/models/system" "eta_gn/eta_api/services/data" "eta_gn/eta_api/services/data/data_manage_permission" "eta_gn/eta_api/utils" "fmt" "sort" ) type EdbClassifyController struct { controllers.BaseAuthController } // @router /classify/list [get] func (this *EdbClassifyController) ListV2() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() classifyType, _ := this.GetInt("ClassifyType", utils.EdbClassifyTypeBase) // 默认指标库的 if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate { br.Msg = "参数有误" br.ErrMsg = fmt.Sprintf("指标分类类型有误, ClassifyType: %d", classifyType) return } edbType := utils.EdbTypeBase if classifyType == utils.EdbClassifyTypeCalculate { edbType = utils.EdbTypeCalculate } rootList, err := data_manage.GetEdbClassifyByParentId(0, int8(classifyType)) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } classifyAll, err := data_manage.GetChildEdbClassifyByClassifyType(classifyType) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } classifyMap := make(map[int]*data_manage.EdbClassifyItems) for _, v := range classifyAll { classifyMap[v.ClassifyId] = v } permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error() return } obj := data_manage.EdbInfoNoPermissionAdmin{} confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId) if err != nil && !utils.IsErrNoRow(err) { 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.GetEdbInfoByTypes(utils.EDB_INFO_TYPE, edbType) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } edbInfoMap := make(map[int][]*data_manage.EdbClassifyItems) if len(allEdbInfo) > 0 { 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 } if classifyInfo, ok := classifyMap[v.ClassifyId]; ok { v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, classifyInfo.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList) } button := data.GetEdbOpButton(this.SysUser, v.SysUserId, v.EdbType, utils.EDB_INFO_TYPE, v.HaveOperaAuth) button.AddButton = false //不管有没有权限,指标都是没有添加按钮的 v.Button = button edbInfoMap[v.ClassifyId] = append(edbInfoMap[v.ClassifyId], v) } } rootChildMap := make(map[int][]*data_manage.EdbClassifyItems) for _, v := range classifyAll { v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList) button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth) button.AddButton = false //不管有没有权限,指标都是没有添加按钮的 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 { v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList) button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth) v.Button = button if existItems, ok := rootChildMap[v.ClassifyId]; ok { v.Children = existItems } else { items := make([]*data_manage.EdbClassifyItems, 0) v.Children = items } nodeAll = append(nodeAll, v) } resp := new(data_manage.EdbClassifyListResp) resp.AllNodes = nodeAll resp.CanOpClassify = true br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @router /classify/items [get] func (this *EdbClassifyController) Items() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() classifyType, _ := this.GetInt("ClassifyType", utils.EdbClassifyTypeBase) // 默认指标库的 if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate { br.Msg = "参数有误" br.ErrMsg = fmt.Sprintf("指标分类类型有误, ClassifyType: %d", classifyType) return } rootList, err := data_manage.GetEdbClassifyByParentId(0, int8(classifyType)) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } classifyAll, err := data_manage.GetChildEdbClassifyByClassifyType(classifyType) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } nodeAll := make([]*data_manage.EdbClassifyItems, 0) for k := range rootList { rootNode := rootList[k] data.EdbClassifyItemsMakeTree(classifyAll, rootNode) nodeAll = append(nodeAll, rootNode) } resp := new(data_manage.EdbClassifyListResp) resp.AllNodes = nodeAll br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @router /classify/add [post] func (this *EdbClassifyController) AddEdbClassify() { 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 } classifyType := req.ClassifyType if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate { br.Msg = "参数有误" br.ErrMsg = fmt.Sprintf("指标分类类型有误, ClassifyType: %d", classifyType) return } _, err, errMsg := data.AddEdbClassify(req.ClassifyName, req.ParentId, req.Level, classifyType, 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 } // @router /classify/edit [post] func (this *EdbClassifyController) EditEdbClassify() { 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 } // @router /classify/delete/check [post] func (this *EdbClassifyController) DeleteEdbClassifyCheck() { 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 } if this.Lang == "en" { if utils.ViperConfig.InConfig(tipsMsg) { tipsMsg = utils.ViperConfig.GetString(tipsMsg) } } 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 } // @router /classify/delete [post] func (this *EdbClassifyController) DeleteEdbClassify() { 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, } } br.Ret = 200 br.Msg = "删除成功" br.Success = true br.IsAddLog = true br.Data = resp } // @router /edb_classify/move [post] func (this *EdbClassifyController) EdbClassifyMove() { 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 } classifyType := req.ClassifyType // 默认指标库的 if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate { br.Msg = "参数有误" br.ErrMsg = fmt.Sprintf("指标分类类型有误, ClassifyType: %d", classifyType) return } err, errMsg := data.MoveEdbClassify(req, sysUser, uint8(classifyType)) if errMsg != `` { br.Msg = errMsg br.ErrMsg = errMsg if err != nil { br.ErrMsg = err.Error() } else { br.IsSendEmail = false } return } br.Ret = 200 br.Success = true br.Msg = "移动成功" } // @router /classify/items/v2 [get] func (this *EdbClassifyController) ItemsV2() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() classifyType, _ := this.GetInt("ClassifyType", utils.EdbClassifyTypeBase) // 默认指标库的 if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate { br.Msg = "参数有误" br.ErrMsg = fmt.Sprintf("指标分类类型有误, ClassifyType: %d", classifyType) return } rootList, err := data_manage.GetEdbClassifyByParentId(0, int8(classifyType)) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } classifyAll, err := data_manage.GetChildEdbClassifyByClassifyType(classifyType) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error() return } rootChildMap := make(map[int][]*data_manage.EdbClassifyItems) for _, v := range classifyAll { v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList) button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth) button.AddButton = false //不管有没有权限,指标都是没有添加按钮的 v.Button = button rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v) } nodeAll := make([]*data_manage.EdbClassifyItems, 0) for _, v := range rootList { v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList) button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth) v.Button = button if existItems, ok := rootChildMap[v.ClassifyId]; ok { v.Children = existItems } else { items := make([]*data_manage.EdbClassifyItems, 0) v.Children = items } nodeAll = append(nodeAll, v) } language := `CN` { configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar) if configDetail != nil { language = configDetail.ConfigValue } else { configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar) if configDetail != nil { language = configDetail.ConfigValue } } } canOpClassify := true resp := data_manage.EdbClassifyListResp{ AllNodes: nodeAll, CanOpClassify: canOpClassify, Language: language, } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @router /classify/edb_info/list [get] func (this *EdbClassifyController) ClassifyEdbInfoList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() classifyId, _ := this.GetInt("ClassifyId") if classifyId <= 0 { br.Msg = "参数错误,请刷新页面" return } classifyInfo, err := data_manage.GetEdbClassifyById(classifyId) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取分类信息失败,Err:" + err.Error() return } obj := data_manage.EdbInfoNoPermissionAdmin{} confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error() return } noPermissionEdbInfoIdMap := make(map[int]bool) for _, v := range confList { noPermissionEdbInfoIdMap[v.EdbInfoId] = true } edbType := 0 switch classifyInfo.ClassifyType { case utils.EdbClassifyTypeBase: edbType = 1 case utils.EdbClassifyTypeCalculate: edbType = 2 } noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList, err := data_manage_permission.GetUserAllEdbAndClassifyNoPermissionList(this.SysUser.AdminId, utils.EDB_INFO_TYPE, edbType) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error() return } allEdbInfo, err := data_manage.GetEdbInfoByClassifyId(classifyId, utils.EDB_INFO_TYPE, edbType, 0, noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } list := make([]*data_manage.EdbClassifyItems, 0) if len(allEdbInfo) > 0 { 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, classifyInfo.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList) button := data.GetEdbOpButton(this.SysUser, v.SysUserId, v.EdbType, utils.EDB_INFO_TYPE, v.HaveOperaAuth) button.AddButton = false //不管有没有权限,指标都是没有添加按钮的 v.Button = button list = append(list, v) } } resp := new(data_manage.ClassifyEdbInfoListResp) resp.EdbInfoList = list br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @router /classify/items/v3 [get] func (this *EdbClassifyController) ItemsV3() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() classifyType, _ := this.GetInt("ClassifyType", utils.EdbClassifyTypeBase) // 默认指标库的 if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate { br.Msg = "参数有误" br.ErrMsg = fmt.Sprintf("指标分类类型有误, ClassifyType: %d", classifyType) return } rootList, err := data_manage.GetEdbClassifyByParentId(0, int8(classifyType)) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } rootTwoList, err := data_manage.GetEdbClassifyByParentIdTwo(int8(classifyType)) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } classifyAll, err := data_manage.GetEdbClassifyAllV2(int8(classifyType)) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error() return } rootTwoMap := make(map[int][]*data_manage.EdbClassifyItems) for _, v := range rootTwoList { v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList) button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth) v.Button = button rootTwoMap[v.ParentId] = append(rootTwoMap[v.ParentId], v) } rootTwoChildMap := make(map[int][]*data_manage.EdbClassifyItems) for _, v := range classifyAll { v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList) button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth) 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 { v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList) button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth) v.Button = button if existItems, ok := rootTwoMap[v.ClassifyId]; ok { v.Children = existItems for _, item := range existItems { v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList) button := data.GetEdbClassifyOpButton(this.SysUser, item.SysUserId, v.HaveOperaAuth) item.Button = button if existItems, ok := rootTwoChildMap[item.ClassifyId]; ok { for _, existItem := range existItems { v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList) button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth) button.AddButton = false //不管有没有权限,指标都是没有添加按钮的 existItem.Button = button } item.Children = existItems } else { items := make([]*data_manage.EdbClassifyItems, 0) item.Children = items } } } else { items := make([]*data_manage.EdbClassifyItems, 0) v.Children = items } nodeAll = append(nodeAll, v) } language := `CN` { configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar) if configDetail != nil { language = configDetail.ConfigValue } else { configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar) if configDetail != nil { language = configDetail.ConfigValue } } } canOpClassify := true button := data.GetEdbClassifyOpButton(this.SysUser, 0, true) if !button.AddButton { canOpClassify = false } resp := new(data_manage.EdbClassifyListResp) resp.AllNodes = nodeAll resp.Language = language resp.CanOpClassify = canOpClassify br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @router /classify/simple [get] func (this *EdbClassifyController) SimpleList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() classifyType, _ := this.GetInt("ClassifyType", utils.EdbClassifyTypeBase) // 默认指标库的 if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate { br.Msg = "参数有误" br.ErrMsg = fmt.Sprintf("指标分类类型有误, ClassifyType: %d", classifyType) return } parentId, _ := this.GetInt("ParentId") isOnlyMe, _ := this.GetBool("IsOnlyMe") sysUserId := 0 if isOnlyMe { sysUserId = this.SysUser.AdminId } rootList, err := data_manage.GetEdbClassifyByParentId(parentId, int8(classifyType)) if err != nil && !utils.IsErrNoRow(err) { 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 && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error() return } noPermissionEdbInfoIdMap := make(map[int]bool) for _, v := range confList { noPermissionEdbInfoIdMap[v.EdbInfoId] = true } edbType := 0 switch classifyType { case utils.EdbClassifyTypeBase: edbType = 1 case utils.EdbClassifyTypeCalculate: edbType = 2 } noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList, err := data_manage_permission.GetUserAllEdbAndClassifyNoPermissionList(this.SysUser.AdminId, utils.EDB_INFO_TYPE, edbType) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error() return } allEdbInfo, err := data_manage.GetEdbInfoByClassifyId(parentId, 0, edbType, sysUserId, noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList) 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.GetEdbOpButton(this.SysUser, v.SysUserId, v.EdbType, utils.EDB_INFO_TYPE, v.HaveOperaAuth) button.AddButton = false //不管有没有权限,指标都是没有添加按钮的 v.Button = button v.Children = make([]*data_manage.EdbClassifyItems, 0) v.ParentId = parentId nodeAll = append(nodeAll, v) } } } if len(rootList) > 0 { 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 { if v.IsJoinPermission == 1 && !utils.InArrayByInt(permissionClassifyIdList, v.ClassifyId) { continue } v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList) button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth) v.Button = button v.Children = make([]*data_manage.EdbClassifyItems, 0) nodeAll = append(nodeAll, v) } } if len(nodeAll) > 0 { sortList = nodeAll sort.Sort(sortList) } language := `CN` { configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar) if configDetail != nil { language = configDetail.ConfigValue } else { configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar) if configDetail != nil { language = configDetail.ConfigValue } } } canOpClassify := true button := data.GetEdbClassifyOpButton(this.SysUser, 0, true) if !button.AddButton { canOpClassify = false } 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 } // @router /classify/tree [get] func (this *EdbClassifyController) ClassifyTree() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() classifyType, _ := this.GetInt("ClassifyType", utils.EdbClassifyTypeBase) // 默认指标库的 if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate && classifyType != utils.EdbClassifyTypeOrigin { br.Msg = "参数有误" br.ErrMsg = fmt.Sprintf("指标分类类型有误, ClassifyType: %d", classifyType) return } allList := make([]*data_manage.EdbClassifyItems, 0) if classifyType == utils.EdbClassifyTypeOrigin { list, e := data_manage.GetEdbClassifyByClassifyTypes([]int{utils.EdbClassifyTypeBase, utils.EdbClassifyTypeCalculate}) if e != nil && !utils.IsErrNoRow(e) { br.Msg = "获取失败" br.ErrMsg = fmt.Sprintf("获取分类失败, %v", e) return } allList = list } else { list, err := data_manage.GetAllEdbClassifyByType(classifyType) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } allList = list } nodeAll := make([]*data_manage.EdbClassifyItems, 0) var sortList data_manage.EdbClassifyItemList if len(allList) > 0 { permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error() return } newNodes := make([]*data_manage.EdbClassifyItems, 0) for _, v := range allList { if v.IsJoinPermission == 1 && !utils.InArrayByInt(permissionClassifyIdList, v.ClassifyId) { continue } newNodes = append(newNodes, v) } for k, v := range newNodes { v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList) button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth) newNodes[k].Button = button } nodeAll = data.GetClassifyTreeRecursive(newNodes, 0) sortList = nodeAll sort.Sort(sortList) } language := `CN` { configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.EdbLanguageVar) if configDetail != nil { language = configDetail.ConfigValue } else { configDetail, _ = system.GetDefaultConfigDetailByCode(system.EdbLanguageVar) if configDetail != nil { language = configDetail.ConfigValue } } } canOpClassify := true button := data.GetEdbClassifyOpButton(this.SysUser, 0, true) if !button.AddButton { canOpClassify = false } 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 } // @router /edb_classify/move/v2 [post]