123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780 |
- package data_manage
- import (
- "encoding/json"
- "hongze/hz_crm_api/controllers"
- "hongze/hz_crm_api/models"
- "hongze/hz_crm_api/models/data_manage"
- "hongze/hz_crm_api/models/system"
- "hongze/hz_crm_api/services/data"
- "hongze/hz_crm_api/utils"
- )
- // EdbClassifyController 数据管理-分类模块
- type EdbClassifyController struct {
- controllers.BaseAuthController
- }
- //
- //// @Title 分类列表
- //// @Description 分类列表接口
- //// @Success 200 {object} data_manage.EdbClassifyListResp
- //// @router /classify/list [get]
- //func (this *EdbClassifyController) List() {
- // br := new(models.BaseResponse).Init()
- // defer func() {
- // this.Data["json"] = br
- // this.ServeJSON()
- // }()
- // rootList, err := data_manage.GetEdbClassifyByParentId(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
- // }
- //
- // fmt.Println("start:", time.Now())
- // nodeAll := make([]*data_manage.EdbClassifyItems, 0)
- // for k := range rootList {
- // rootNode := rootList[k]
- // data.EdbClassifyListMakeTree(classifyAll, rootNode)
- // nodeAll = append(nodeAll, rootNode)
- // }
- // fmt.Println("end:", time.Now())
- // resp := new(data_manage.EdbClassifyListResp)
- // resp.AllNodes = nodeAll
- // br.Ret = 200
- // br.Success = true
- // br.Msg = "获取成功"
- // br.Data = resp
- //}
- // 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
- }
- // 获取当前账号的不可见指标
- 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)
- for _, v := range allEdbInfo {
- // 如果指标不可见,那么就不返回该指标
- if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok {
- continue
- }
- button := data.GetEdbOpButton(this.SysUser, v.SysUserId, v.EdbType, utils.EDB_INFO_TYPE)
- 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 {
- button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId)
- 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 {
- button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId)
- 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
- 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)
- 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.ClassifyName)
- 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
- }
- // @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, err, errMsg := data.DeleteCheck(req.ClassifyId, req.EdbInfoId)
- if errMsg != `` {
- br.Msg = errMsg
- br.ErrMsg = errMsg
- if err != nil {
- br.ErrMsg = err.Error()
- } else {
- br.IsSendEmail = false
- }
- return
- }
- //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
- 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.AdminId, sysUser.RealName, 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 {
- 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
- }
- ////判断分类是否存在
- //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
- }
- //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 {
- button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId)
- 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 {
- button := data.GetEdbClassifyOpButton(this.SysUser, v.SysUserId)
- 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
- }
- }
- }
- resp := new(data_manage.EdbClassifyListResp)
- resp.AllNodes = nodeAll
- resp.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
- }
- // 获取当前账号的不可见指标
- 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)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- list := make([]*data_manage.EdbClassifyItems, 0)
- for _, v := range allEdbInfo {
- // 如果指标不可见,那么就不返回该指标
- if _, ok := noPermissionEdbInfoIdMap[v.EdbInfoId]; ok {
- continue
- }
- button := data.GetEdbOpButton(this.SysUser, v.SysUserId, v.EdbType, utils.EDB_INFO_TYPE)
- 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
- }
|