1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381 |
- 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"
- "github.com/rdlucklib/rdluck_tools/paging"
- "sort"
- "strconv"
- "strings"
- )
- // EdbClassifyController 数据管理-分类模块
- type EdbClassifyController struct {
- controllers.BaseAuthController
- }
- // ListV2
- // @Title 分类列表
- // @Description 分类列表接口
- // @Success 200 {object} data_manage.EdbClassifyListResp
- // @router /classify/list [get]
- func (this *EdbClassifyController) ListV2() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- rootList, err := data_manage.GetEdbClassifyByParentId(0, 0)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- classifyAll, err := data_manage.GetEdbClassifyAll()
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- // 分类map
- classifyMap := make(map[int]*data_manage.EdbClassifyItems)
- for _, v := range classifyAll {
- classifyMap[v.ClassifyId] = v
- }
- // 已授权分类id
- 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 && 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.GetEdbInfoAll(utils.EDB_INFO_TYPE)
- if err != nil && err.Error() != utils.ErrNoRow() {
- 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
- }
- // @Title 获取所有分类接口-不包含指标
- // @Description 获取所有分类接口-不包含指标
- // @Success 200 {object} data_manage.EdbClassifyListResp
- // @router /classify/items [get]
- func (this *EdbClassifyController) Items() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- rootList, err := data_manage.GetEdbClassifyByParentId(0, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- classifyAll, err := data_manage.GetEdbClassifyAll()
- 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
- }
- // @Title 新增分类
- // @Description 新增分类接口
- // @Param request body data_manage.AddEdbClassifyReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @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
- }
- //添加指标
- _, err, errMsg := data.AddEdbClassify(req.ClassifyName, req.ParentId, req.Level, 0, 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
- }
- //count, err := data_manage.GetEdbClassifyCount(req.ClassifyName, req.ParentId)
- //if err != nil {
- // br.Msg = "判断名称是否已存在失败"
- // br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
- // return
- //}
- //if count > 0 {
- // br.Msg = "分类名称已存在,请重新输入"
- // br.IsSendEmail = false
- // return
- //}
- ////获取该层级下最大的排序数
- //maxSort, err := data_manage.GetEdbClassifyMaxSort(req.ParentId, req.ClassifyType)
- //
- //classify := new(data_manage.EdbClassify)
- //classify.ClassifyType = req.ClassifyType
- //classify.ParentId = req.ParentId
- //classify.ClassifyName = req.ClassifyName
- //classify.HasData = 0
- //classify.CreateTime = time.Now()
- //classify.ModifyTime = time.Now()
- //classify.SysUserId = this.SysUser.AdminId
- //classify.SysUserRealName = this.SysUser.RealName
- //classify.Level = req.Level + 1
- //timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
- //classify.UniqueCode = utils.MD5(utils.DATA_PREFIX + "_" + timestamp)
- //classify.Sort = maxSort
- //
- //_, err = data_manage.AddEdbClassify(classify)
- //if err != nil {
- // br.Msg = "保存分类失败"
- // br.ErrMsg = "保存分类失败,Err:" + err.Error()
- // return
- //}
- br.Ret = 200
- br.Msg = "保存成功"
- br.Success = true
- br.IsAddLog = true
- }
- // @Title 修改分类
- // @Description 修改分类接口
- // @Param request body data_manage.EditEdbClassifyReq true "type json string"
- // @Success 200 Ret=200 修改成功
- // @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.ParentId, 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
- }
- //item, err := data_manage.GetEdbClassifyById(req.ClassifyId)
- //if err != nil {
- // br.Msg = "保存失败"
- // br.Msg = "获取分类信息失败,Err:" + err.Error()
- // return
- //}
- //
- //if item.ClassifyName != req.ClassifyName {
- // count, err := data_manage.GetEdbClassifyCount(req.ClassifyName, item.ParentId)
- // if err != nil {
- // br.Msg = "判断名称是否已存在失败"
- // br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
- // return
- // }
- // if count > 0 {
- // br.Msg = "分类名称已存在,请重新输入"
- // br.IsSendEmail = false
- // return
- // }
- //
- // err = data_manage.EditEdbClassify(req.ClassifyId, req.ClassifyName)
- // if err != nil {
- // br.Msg = "保存失败"
- // br.ErrMsg = "保存失败,Err:" + err.Error()
- // return
- // }
- //}
- br.Ret = 200
- br.Msg = "保存成功"
- br.Success = true
- br.IsAddLog = true
- }
- // @Title 删除检测接口
- // @Description 删除检测接口
- // @Param request body data_manage.ClassifyDeleteCheckReq true "type json string"
- // @Success 200 Ret=200 检测成功
- // @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)
- }
- }
- //var deleteStatus int
- //var tipsMsg string
- ////删除分类
- //if req.ClassifyId > 0 && req.EdbInfoId == 0 {
- // //判断分类下,是否含有指标
- // count, err := data_manage.GetEdbInfoCountByClassifyId(req.ClassifyId)
- // if err != nil {
- // br.Msg = "删除失败"
- // br.ErrMsg = "分类下是否含有指标失败,Err:" + err.Error()
- // return
- // }
- //
- // if count > 0 {
- // deleteStatus = 1
- // tipsMsg = "若目录关联指标不可删除"
- // }
- //}
- //
- //if deleteStatus != 1 && req.EdbInfoId == 0 {
- // classifyCount, err := data_manage.GetClassifyCountByClassifyId(req.ClassifyId)
- // if err != nil && err.Error() != utils.ErrNoRow() {
- // br.Msg = "删除失败"
- // br.ErrMsg = "分类下是否含有指标失败,Err:" + err.Error()
- // return
- // }
- // if classifyCount > 0 {
- // deleteStatus = 2
- // tipsMsg = "确认删除当前目录及包含的子目录吗"
- // }
- //}
- //
- ////删除指标
- //if req.EdbInfoId > 0 {
- // //判断指标是否用于作图,如果用于作图,则不可删除
- // chartCount, err := data_manage.GetChartEdbMappingCount(req.EdbInfoId)
- // if err != nil && err.Error() != utils.ErrNoRow() {
- // br.Msg = "删除失败"
- // br.ErrMsg = "判断指标是否被用于作图失败,Err:" + err.Error()
- // return
- // }
- // if chartCount > 0 {
- // deleteStatus = 3
- // tipsMsg = "当前指标已用作画图,不可删除"
- // }
- // //判断指标是否用于计算
- // {
- // calculateCount, err := data_manage.GetEdbInfoCalculateMappingCount(req.EdbInfoId)
- // if err != nil && err.Error() != utils.ErrNoRow() {
- // br.Msg = "删除失败"
- // br.ErrMsg = "判断指标是否被用于计算失败,GetEdbInfoCalculateCount Err:" + err.Error()
- // return
- // }
- // if calculateCount > 0 {
- // deleteStatus = 4
- // 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
- }
- // @Title 删除分类/指标
- // @Description 删除分类/指标接口
- // @Param request body data_manage.DeleteEdbClassifyReq true "type json string"
- // @Success 200 Ret=200 新增成功
- // @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
- }
- // EdbClassifyMove
- // @Title 分类移动接口
- // @Description 分类移动接口
- // @Success 200 {object} data_manage.MoveEdbClassifyReq
- // @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
- }
- err, errMsg := data.MoveEdbClassify(req, sysUser, 0)
- 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 = "移动成功"
- }
- // ItemsV2
- // @Title 分类列表
- // @Description 分类列表接口
- // @Success 200 {object} data_manage.EdbClassifyListResp
- // @router /classify/items/v2 [get]
- func (this *EdbClassifyController) ItemsV2() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- rootList, err := data_manage.GetEdbClassifyByParentId(0, 0)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- classifyAll, err := data_manage.GetEdbClassifyAll()
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- // 已授权分类id
- permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
- return
- }
- //allEdbInfo, err := data_manage.GetEdbInfoAll(0)
- //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 {
- // button := data.GetEdbOpButton(this.SysUser, v.SysUserId)
- // 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)
- }
- 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)
- //if !button.AddButton {
- // canOpClassify = false
- //}
- resp := data_manage.EdbClassifyListResp{
- AllNodes: nodeAll,
- CanOpClassify: canOpClassify,
- Language: language,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 获取分类下指标接口
- // @Description 获取分类下指标接口
- // @Param ClassifyId query int true "分类id"
- // @Success 200 {object} data_manage.EdbClassifyListResp
- // @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 && 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(classifyId, 0, 0)
- if err != nil && err.Error() != utils.ErrNoRow() {
- 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
- }
- // ItemsV3
- // @Title 分类列表
- // @Description 分类列表接口
- // @Success 200 {object} data_manage.EdbClassifyListResp
- // @router /classify/items/v3 [get]
- func (this *EdbClassifyController) ItemsV3() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- rootList, err := data_manage.GetEdbClassifyByParentId(0, 0)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- rootTwoList, err := data_manage.GetEdbClassifyByParentIdTwo(0)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- classifyAll, err := data_manage.GetEdbClassifyAllV2(0)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- // 已授权分类id
- 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
- }
- // SimpleList
- // @Title 单层分类列表
- // @Description 单层分类列表
- // @Success 200 {object} data_manage.EdbClassifyListResp
- // @router /classify/simple [get]
- func (this *EdbClassifyController) 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, 0)
- 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, 0, 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.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 {
- // 已授权分类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.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 {
- //根据sort值排序
- sortList = nodeAll
- sort.Sort(sortList)
- }
- if isOnlyMe {
- sortList, err = data.GetEdbClassifyByIsMe(sysUserId, parentId, 0, sortList)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- }
- 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
- }
- // ClassifyTree
- // @Title 多层分类列表树
- // @Description 多层分类列表树
- // @Success 200 {object} data_manage.EdbClassifyListResp
- // @router /classify/tree [get]
- func (this *EdbClassifyController) ClassifyTree() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- level, _ := this.GetInt(`Level`)
- allList, err := data_manage.GetNormalEdbClassifyAll()
- 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.GetEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth)
- allList[k].Button = button
- }
- nodeAll = data.GetClassifyTreeRecursive(allList, 0, level)
- //根据sort值排序
- 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
- }
- // EdbClassifyMoveV2
- // @Title 分类移动接口v2
- // @Description 分类移动接口v2
- // @Success 200 {object} data_manage.MoveEdbClassifyReq
- // @router /edb_classify/move/v2 [post]
- //func (this *EdbClassifyController) EdbClassifyMoveV2() {
- // 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 {
- // br.Msg = "参数错误"
- // br.ErrMsg = "分类id小于等于0"
- // return
- // }
- //
- // err, errMsg := data.MoveEdbClassify(req.ClassifyId, req.ParentClassifyId, req.PrevClassifyId, req.NextClassifyId)
- // 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 = "移动成功"
- //}
- // EdbInfoList
- // @Title 批量编辑指标列表接口
- // @Description 批量编辑指标列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param EdbInfoId query int true "指标id"
- // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
- // @Success 200 {object} data_manage.EdbInfoListResp
- // @router /classify/edb/list [get]
- func (this *EdbInfoController) ClassifyEdbInfoList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- subClassify, _ := this.GetBool("SubClassify")
- sources := this.GetString("Sources")
- keyWord := this.GetString("KeyWord")
- sysUserIds := this.GetString("SysUserIds")
- classifyIdsStr := this.GetString("ClassifyIds")
- classifyIds := strings.Split(classifyIdsStr, ",")
- var condition string
- var pars []interface{}
- // 已授权分类id
- //permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
- // return
- //}
- classifyIdsArr := make([]int, 0)
- for _, v := range classifyIds {
- if v != `` {
- id, _ := strconv.Atoi(v)
- classifyIdsArr = append(classifyIdsArr, id)
- }
- }
- //if len(permissionClassifyIdList) > 0 {
- // classifyIdsArr = utils.IntersectInt(permissionClassifyIdList, classifyIdsArr)
- //}
- condition += " AND edb_info_type = 0 "
- if len(classifyIdsArr) > 0 {
- if !subClassify {
- condition += " AND classify_id IN(" + utils.GetOrmInReplace(len(classifyIdsArr)) + ") "
- pars = append(pars, classifyIdsArr)
- } else {
- classifyAll, err := data_manage.GetNormalEdbClassifyAll()
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- finalClassifyIds := make([]int, 0)
- parents := data.GetEdbClassifyChildrenRecursiveByParentIds(classifyAll, classifyIds)
- sort.Slice(parents, func(i, j int) bool {
- return parents[i].Level < parents[i].Level
- })
- for _, v := range parents {
- finalClassifyIds = append(finalClassifyIds, v.ClassifyId)
- }
- condition += " AND classify_id IN(" + utils.GetOrmInReplace(len(finalClassifyIds)) + ") "
- pars = append(pars, finalClassifyIds)
- }
- }
- if keyWord != "" {
- keyWordArr := strings.Split(keyWord, " ")
- if len(keyWordArr) > 0 {
- for _, v := range keyWordArr {
- condition += ` AND edb_name LIKE '%` + v + `%' `
- }
- }
- }
- if sources != "" {
- condition += " AND source IN(" + utils.GetOrmInReplace(len(strings.Split(sources, ","))) + ") "
- pars = append(pars, strings.Split(sources, ","))
- }
- if sysUserIds != "" {
- adminIds := strings.Split(sysUserIds, ",")
- if len(adminIds) == 0 {
- br.Msg = "请选择正确的创建人"
- return
- }
- adminIdsSlice := make([]int, 0)
- for _, adminId := range adminIds {
- adminIdInt, e := strconv.Atoi(adminId)
- if e != nil {
- br.Msg = "请选择正确的创建人"
- return
- }
- adminIdsSlice = append(adminIdsSlice, adminIdInt)
- }
- condition += " AND sys_user_id in (" + utils.GetOrmInReplace(len(adminIds)) + ") "
- pars = append(pars, adminIdsSlice)
- }
- // 获取当前账号的不可见指标
- 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
- }
- noPermissionEdbInfoIds := make([]int, 0)
- for _, v := range confList {
- noPermissionEdbInfoIds = append(noPermissionEdbInfoIds, v.EdbInfoId)
- }
- if len(noPermissionEdbInfoIds) > 0 {
- condition += " AND edb_info_id NOT IN(" + utils.GetOrmInReplace(len(noPermissionEdbInfoIds)) + ") "
- pars = append(pars, noPermissionEdbInfoIds)
- }
- count, err := data_manage.GetEdbInfoByConditionCount(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, count)
- list, err := data_manage.GetEdbInfoListByCondition(condition, pars, startSize, pageSize, "")
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- resp := new(data_manage.EdbInfoFilterDataResp)
- resp.List = list
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|