123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974 |
- 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"
- "time"
- )
- // 数据管理-分类模块
- type ChartClassifyController struct {
- controllers.BaseAuthController
- }
- // ChartClassifyListV2
- // @Title 图表分类列表
- // @Description 图表分类列表接口
- // @Success 200 {object} data_manage.ChartClassifyListResp
- // @router /chart_classify/list [get]
- func (this *ChartClassifyController) ChartClassifyListV2() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- resp := new(data_manage.ChartClassifyListResp)
- // 获取当前账号的不可见指标
- noPermissionChartIdMap := make(map[int]bool)
- {
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
- return
- }
- for _, v := range confList {
- noPermissionChartIdMap[v.ChartInfoId] = true
- }
- }
- //判断是否存在缓存,如果存在缓存,那么直接从缓存中获取
- key := utils.CACHE_CHART_CLASSIFY
- if utils.Re == nil {
- if utils.Re == nil && utils.Rc.IsExist(key) {
- if redisData, err1 := utils.Rc.RedisBytes(key); err1 == nil {
- err := json.Unmarshal(redisData, &resp)
- if err == nil && resp != nil {
- // 移除没有权限的图表
- allNodes := data.HandleNoPermissionChart(resp.AllNodes, noPermissionChartIdMap, this.SysUser.AdminId)
- resp.AllNodes = allNodes
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- fmt.Println("source redis")
- return
- }
- }
- }
- }
- rootList, err := data_manage.GetChartClassifyByParentId(0, utils.CHART_SOURCE_DEFAULT, this.SysUser.AdminId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- classifyAll, err := data_manage.GetChartClassifyAll(utils.CHART_SOURCE_DEFAULT, this.SysUser.AdminId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- allChartInfo, err := data_manage.GetChartInfoAll([]int{utils.CHART_SOURCE_DEFAULT}, this.SysUser.AdminId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- chartInfoMap := make(map[int][]*data_manage.ChartClassifyItems)
- for _, v := range allChartInfo {
- chartInfoMap[v.ChartClassifyId] = append(chartInfoMap[v.ChartClassifyId], v)
- }
- rootChildMap := make(map[int][]*data_manage.ChartClassifyItems)
- for _, v := range classifyAll {
- rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
- if existItems, ok := chartInfoMap[v.ChartClassifyId]; ok {
- v.Children = existItems
- } else {
- items := make([]*data_manage.ChartClassifyItems, 0)
- v.Children = items
- }
- }
- nodeAll := make([]*data_manage.ChartClassifyItems, 0)
- for _, v := range rootList {
- if existItems, ok := rootChildMap[v.ChartClassifyId]; ok {
- v.Children = existItems
- } else {
- items := make([]*data_manage.ChartClassifyItems, 0)
- v.Children = items
- }
- nodeAll = append(nodeAll, v)
- }
- //
- //
- //nodeAll := make([]*data_manage.ChartClassifyItems, 0)
- //for k := range rootList {
- // rootNode := rootList[k]
- // data.ChartClassifyListMakeTree(classifyAll, rootNode)
- // nodeAll = append(nodeAll, rootNode)
- //}
- resp.AllNodes = nodeAll
- // 将数据加入缓存
- if utils.Re == nil {
- redisData, _ := json.Marshal(resp)
- utils.Rc.Put(key, redisData, 2*time.Hour)
- }
- // 移除没有权限的图表
- allNodes := data.HandleNoPermissionChart(resp.AllNodes, noPermissionChartIdMap, this.SysUser.AdminId)
- resp.AllNodes = allNodes
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // getChartClassifyListForMe 获取我创建的图表
- func getChartClassifyListForMe(adminInfo system.Admin, resp *data_manage.ChartClassifyListResp) (errMsg string, err error) {
- rootList, err := data_manage.GetChartClassifyByParentId(0, utils.CHART_SOURCE_DEFAULT, adminInfo.AdminId)
- if err != nil && !utils.IsErrNoRow(err) {
- errMsg = "获取失败"
- return
- }
- classifyAll, err := data_manage.GetChartClassifyAll(utils.CHART_SOURCE_DEFAULT, adminInfo.AdminId)
- if err != nil && !utils.IsErrNoRow(err) {
- errMsg = "获取失败"
- return
- }
- allChartInfo, err := data_manage.GetChartInfoByAdminId([]int{utils.CHART_SOURCE_DEFAULT}, adminInfo.AdminId)
- if err != nil && !utils.IsErrNoRow(err) {
- errMsg = "获取失败"
- return
- }
- chartInfoMap := make(map[int][]*data_manage.ChartClassifyItems)
- for _, v := range allChartInfo {
- chartInfoMap[v.ChartClassifyId] = append(chartInfoMap[v.ChartClassifyId], v)
- }
- rootChildMap := make(map[int][]*data_manage.ChartClassifyItems)
- for _, v := range classifyAll {
- rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
- if existItems, ok := chartInfoMap[v.ChartClassifyId]; ok {
- v.Children = existItems
- } else {
- items := make([]*data_manage.ChartClassifyItems, 0)
- v.Children = items
- }
- }
- nodeAll := make([]*data_manage.ChartClassifyItems, 0)
- for _, v := range rootList {
- if existItems, ok := rootChildMap[v.ChartClassifyId]; ok {
- v.Children = existItems
- } else {
- items := make([]*data_manage.ChartClassifyItems, 0)
- v.Children = items
- }
- nodeAll = append(nodeAll, v)
- }
- resp.AllNodes = nodeAll
- return
- }
- // ChartClassifyItems
- // @Title 获取所有图表分类接口-不包含图表
- // @Description 获取所有图表分类接口-不包含图表
- // @Success 200 {object} data_manage.ChartClassifyListResp
- // @router /chart_classify/items [get]
- func (this *ChartClassifyController) ChartClassifyItems() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- rootList, err := data_manage.GetChartClassifyByParentId(0, utils.CHART_SOURCE_DEFAULT, this.SysUser.AdminId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- classifyAll, err := data_manage.GetChartClassifyAll(utils.CHART_SOURCE_DEFAULT, this.SysUser.AdminId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- // 已授权分类id
- permissionClassifyIdList, err := data_manage_permission.GetUserChartClassifyPermissionList(this.SysUser.AdminId, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
- return
- }
- nodeAll := make([]*data_manage.ChartClassifyItems, 0)
- for k := range rootList {
- rootNode := rootList[k]
- data.ChartClassifyItemsMakeTree(this.SysUser, classifyAll, rootNode, permissionClassifyIdList)
- nodeAll = append(nodeAll, rootNode)
- }
- language := `CN`
- // 指标显示的语言
- {
- configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.ChartLanguageVar)
- if configDetail != nil {
- language = configDetail.ConfigValue
- } else {
- configDetail, _ = system.GetDefaultConfigDetailByCode(system.ChartLanguageVar)
- if configDetail != nil {
- language = configDetail.ConfigValue
- }
- }
- }
- // 是否允许添加分类
- canOpClassify := true
- // 如果不是 超管 或者 ficc管理员 或者 ficc研究员,那么就没有权限
- //if !utils.InArrayByStr([]string{utils.ROLE_TYPE_CODE_ADMIN, utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_RESEARCHR, utils.ROLE_TYPE_CODE_FICC_RESEARCHR}, this.SysUser.RoleTypeCode) {
- // canOpClassify = false
- //}
- resp := data_manage.ChartClassifyListResp{
- AllNodes: nodeAll,
- Language: language,
- CanOpClassify: canOpClassify,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 新增图表分类
- // @Description 新增图表分类接口
- // @Param request body data_manage.AddChartClassifyReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /chart_classify/add [post]
- func (this *ChartClassifyController) AddChartClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req data_manage.AddChartClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ChartClassifyName == "" {
- br.Msg = "请输入分类名称"
- br.IsSendEmail = false
- return
- }
- if req.ParentId < 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
- // 新增图表分类
- _, err, errMsg, isSendEmail := data.AddChartClassify(req.ChartClassifyName, req.ParentId, req.Level, utils.CHART_SOURCE_DEFAULT, this.Lang, this.SysUser)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = "添加分类失败,Err:" + err.Error()
- br.IsSendEmail = isSendEmail
- return
- }
- br.Ret = 200
- br.Msg = "保存成功"
- br.Success = true
- }
- // EditChartClassify
- // @Title 修改图表分类
- // @Description 修改图表分类接口
- // @Param request body data_manage.EditChartClassifyReq true "type json string"
- // @Success 200 Ret=200 修改成功
- // @router /chart_classify/edit [post]
- func (this *ChartClassifyController) EditChartClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req data_manage.EditChartClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ChartClassifyName == "" {
- br.Msg = "请输入分类名称"
- br.IsSendEmail = false
- return
- }
- if req.ChartClassifyId <= 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
- // 编辑图表分类
- _, err, errMsg, isSendEmail := data.EditChartClassify(req.ChartClassifyId, utils.CHART_SOURCE_DEFAULT, req.ChartClassifyName, this.Lang, this.SysUser)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = "保存分类失败,Err:" + err.Error()
- br.IsSendEmail = isSendEmail
- return
- }
- br.Ret = 200
- br.Msg = "保存成功"
- br.Success = true
- br.IsAddLog = true
- }
- // @Title 删除图表检测接口
- // @Description 删除图表检测接口
- // @Param request body data_manage.ChartClassifyDeleteCheckResp true "type json string"
- // @Success 200 Ret=200 检测成功
- // @router /chart_classify/delete/check [post]
- func (this *ChartClassifyController) DeleteChartClassifyCheck() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req data_manage.ChartClassifyDeleteCheckReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ChartClassifyId < 0 && req.ChartInfoId <= 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
- var deleteStatus int
- var tipsMsg string
- childIds := make([]int, 0)
- //删除分类
- if req.ChartClassifyId > 0 && req.ChartInfoId == 0 {
- // 查找分类
- item, err := data_manage.GetChartClassifyById(req.ChartClassifyId)
- if err != nil {
- br.Msg = "保存失败"
- br.Msg = "获取分类信息失败,Err:" + err.Error()
- return
- }
- // 已授权分类id
- permissionClassifyIdList, err := data_manage_permission.GetUserChartClassifyPermissionList(this.SysUser.AdminId, item.ChartClassifyId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
- return
- }
- // 权限校验
- {
- haveOperaAuth := data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(item.IsJoinPermission, item.ChartClassifyId, permissionClassifyIdList)
- button := data.GetChartClassifyOpButton(this.SysUser, item.SysUserId, haveOperaAuth)
- if !button.OpButton {
- br.Msg = "无操作权限"
- br.IsSendEmail = false
- return
- }
- }
- //判断图表分类下,是否含有图表
- classifyAll, err := data_manage.GetChartClassifyAllBySource(utils.CHART_SOURCE_DEFAULT)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "获取分类数据失败,Err:" + err.Error()
- return
- }
- classifyAllMap := make(map[int]*data_manage.ChartClassifyItems)
- for _, v := range classifyAll {
- classifyAllMap[v.ChartClassifyId] = v
- }
- data.GetChartClassifyChildIds(req.ChartClassifyId, classifyAllMap, &childIds)
- condition := ``
- pars := make([]interface{}, 0)
- if len(childIds) > 0 {
- ids := utils.IntArr2joinString(childIds, ",")
- condition = ` AND chart_classify_id IN (` + ids + `) `
- } else {
- condition = ` AND chart_classify_id = ? `
- pars = append(pars, req.ChartClassifyId)
- }
- count, err := data_manage.GetChartInfoCountByCondition(condition, pars)
- if err != nil {
- br.Msg = "判断图表名称是否存在失败"
- br.ErrMsg = "判断图表名称是否存在失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- deleteStatus = 1
- tipsMsg = "该分类下关联图表不可删除"
- }
- }
- if deleteStatus != 1 && req.ChartInfoId == 0 {
- //classifyCount, err := data_manage.GetChartClassifyCountByClassifyId(req.ChartClassifyId)
- //if err != nil && !utils.IsErrNoRow(err) {
- // br.Msg = "删除失败"
- // br.ErrMsg = "分类下是否含有图表失败,Err:" + err.Error()
- // return
- //}
- if len(childIds) > 0 {
- deleteStatus = 2
- tipsMsg = "确认删除当前目录及包含的子目录吗"
- }
- }
- if deleteStatus == 0 {
- tipsMsg = "可删除,进行删除操作"
- }
- resp := new(data_manage.ChartClassifyDeleteCheckResp)
- resp.DeleteStatus = deleteStatus
- resp.TipsMsg = tipsMsg
- br.Ret = 200
- br.Msg = "检测成功"
- br.Success = true
- br.Data = resp
- }
- // @Title 删除图表分类/图表
- // @Description 删除图表分类/图表接口
- // @Param request body data_manage.DeleteChartClassifyReq true "type json string"
- // @Success 200 Ret=200 删除成功
- // @router /chart_classify/delete [post]
- func (this *ChartClassifyController) DeleteChartClassify() {
- 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.DeleteChartClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ChartClassifyId < 0 && req.ChartInfoId <= 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
- //删除分类
- if req.ChartClassifyId > 0 && req.ChartInfoId == 0 {
- // 查找分类
- item, err := data_manage.GetChartClassifyById(req.ChartClassifyId)
- if err != nil {
- br.Msg = "保存失败"
- br.Msg = "获取分类信息失败,Err:" + err.Error()
- return
- }
- // 已授权分类id
- permissionClassifyIdList, err := data_manage_permission.GetUserChartClassifyPermissionList(this.SysUser.AdminId, item.ChartClassifyId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
- return
- }
- // 权限校验
- {
- haveOperaAuth := data_manage_permission.CheckChartClassifyPermissionByPermissionIdList(item.IsJoinPermission, item.ChartClassifyId, permissionClassifyIdList)
- button := data.GetChartClassifyOpButton(this.SysUser, item.SysUserId, haveOperaAuth)
- if !button.OpButton {
- br.Msg = "无操作权限"
- br.IsSendEmail = false
- return
- }
- }
- //判断是否含有指标
- childIds := make([]int, 0)
- classifyAll, err := data_manage.GetChartClassifyAllBySource(utils.CHART_SOURCE_DEFAULT)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "获取分类数据失败,Err:" + err.Error()
- return
- }
- classifyAllMap := make(map[int]*data_manage.ChartClassifyItems)
- for _, v := range classifyAll {
- classifyAllMap[v.ChartClassifyId] = v
- }
- data.GetChartClassifyChildIds(req.ChartClassifyId, classifyAllMap, &childIds)
- condition := ``
- pars := make([]interface{}, 0)
- if len(childIds) > 0 {
- ids := utils.IntArr2joinString(childIds, ",")
- condition = ` AND chart_classify_id IN (` + ids + `) `
- } else {
- condition = ` AND chart_classify_id = ? `
- pars = append(pars, req.ChartClassifyId)
- }
- count, err := data_manage.GetChartInfoCountByCondition(condition, pars)
- if err != nil {
- br.Msg = "判断图表名称是否存在失败"
- br.ErrMsg = "判断图表名称是否存在失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- br.Msg = "该目录下存在关联指标,不可删除"
- br.IsSendEmail = false
- return
- }
- delIds := append(childIds, req.ChartClassifyId)
- err = data_manage.DeleteChartClassifyByIds(delIds)
- //err = data_manage.DeleteChartClassify(req.ChartClassifyId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- }
- resp := new(data_manage.AddChartInfoResp)
- //删除图表
- if req.ChartInfoId > 0 {
- chartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
- if err != nil {
- if utils.IsErrNoRow(err) {
- br.Msg = "图表已删除,请刷新页面"
- br.ErrMsg = "指标不存在,Err:" + err.Error()
- return
- } else {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,获取指标信息失败,Err:" + err.Error()
- return
- }
- }
- if chartInfo == nil {
- br.Msg = "图表已删除,请刷新页面"
- return
- }
- chartClassifyItem, err := data_manage.GetChartClassifyById(chartInfo.ChartClassifyId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表分类详情数据失败,Err:" + err.Error()
- return
- }
- // 已授权图表、分类id
- permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, chartInfo.ChartInfoId, chartInfo.ChartClassifyId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
- return
- }
- // 权限校验
- {
- haveOperaAuth := data_manage_permission.CheckChartPermissionByPermissionIdList(chartInfo.IsJoinPermission, chartClassifyItem.IsJoinPermission, chartInfo.ChartInfoId, chartInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
- //图表操作权限
- ok := data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, haveOperaAuth)
- if !ok {
- br.Msg = "没有该图表的操作权限"
- br.ErrMsg = "没有该图表的操作权限"
- return
- }
- }
- // 获取引用该图表的MyCharts, 用于ES删除
- var myCond string
- var myPars []interface{}
- myCond += ` AND a.chart_info_id = ? `
- myPars = append(myPars, req.ChartInfoId)
- myCharts, e := data_manage.GetMyChartListGroupByCharyInfoIdAndAdminIdByCondition(myCond, myPars)
- if e != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "获取引用图表的MyChats失败, Err: " + e.Error()
- return
- }
- myIds := make([]int, 0)
- for _, m := range myCharts {
- myIds = append(myIds, m.MyChartId)
- }
- //删除图表及关联指标
- err = data_manage.DeleteChartInfoAndData(req.ChartInfoId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- if chartInfo.ChartType == utils.CHART_TYPE_SECTION_COMBINE {
- err = data_manage.DeleteChartSeriesAndEdbMapping(req.ChartInfoId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- }
- //删除ES
- {
- go data.DeleteChartInfoToEs(req.ChartInfoId)
- // 删除MY ETA 图表 es数据
- //go data.EsDeleteMyChartInfoByChartInfoId(req.ChartInfoId)
- go data.EsDeleteMyChartInfoByMyChartIds(myIds)
- }
- var condition string
- var pars []interface{}
- condition += " AND chart_classify_id=? AND source = ? "
- pars = append(pars, chartInfo.ChartClassifyId, utils.CHART_SOURCE_DEFAULT)
- condition += " AND chart_info_id>? ORDER BY create_time ASC LIMIT 1 "
- pars = append(pars, req.ChartInfoId)
- nextItem, err := data_manage.GetChartInfoByCondition(condition, pars)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "删除失败"
- br.ErrMsg = "获取下一级图库信息失败,Err:" + err.Error()
- return
- }
- if nextItem != nil {
- resp.UniqueCode = nextItem.UniqueCode
- resp.ChartInfoId = nextItem.ChartInfoId
- } else {
- var condition string
- var pars []interface{}
- condition += " AND level=3 "
- //pars = append(pars, chartInfo.ChartClassifyId)
- condition += " AND chart_classify_id>? ORDER BY chart_classify_id ASC LIMIT 1 "
- pars = append(pars, chartInfo.ChartClassifyId)
- classifyItem, err := data_manage.GetChartClassifyByCondition(condition, pars)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "删除失败"
- br.ErrMsg = "获取下一级图库分类信息失败,Err:" + err.Error()
- return
- }
- if classifyItem != nil {
- nextItem, err = data_manage.GetNextChartInfo(chartInfo.ChartClassifyId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "删除失败"
- br.ErrMsg = "获取下一级图库信息失败,Err:" + err.Error()
- return
- }
- if nextItem != nil {
- resp.UniqueCode = nextItem.UniqueCode
- resp.ChartInfoId = nextItem.ChartInfoId
- }
- }
- }
- // 删除图表中的指标引用
- _ = data_manage.DeleteEdbRelationByObjectId(req.ChartInfoId, utils.EDB_RELATION_CHART)
- //新增操作日志
- {
- chartLog := new(data_manage.ChartInfoLog)
- chartLog.ChartName = chartInfo.ChartName
- chartLog.ChartInfoId = req.ChartInfoId
- chartLog.ChartClassifyId = chartInfo.ChartClassifyId
- chartLog.SysUserId = sysUser.AdminId
- chartLog.SysUserRealName = sysUser.RealName
- chartLog.UniqueCode = chartInfo.UniqueCode
- chartLog.CreateTime = time.Now()
- chartLog.Content = string(this.Ctx.Input.RequestBody)
- chartLog.Status = "删除图表"
- chartLog.Method = this.Ctx.Input.URI()
- go data_manage.AddChartInfoLog(chartLog)
- }
- }
- br.Ret = 200
- br.Msg = "删除成功"
- br.Success = true
- br.Data = resp
- br.IsAddLog = true
- }
- // ChartClassifyMove
- // @Title 图表分类移动接口
- // @Description 图表分类移动接口
- // @Success 200 {object} data_manage.MoveChartClassifyReq
- // @router /chart_classify/move [post]
- func (this *ChartClassifyController) ChartClassifyMove() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- 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.MoveChartClassifyReq
- 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
- }
- //判断分类是否存在
- chartClassifyInfo, err := data_manage.GetChartClassifyById(req.ClassifyId)
- if err != nil {
- if utils.IsErrNoRow(err) {
- br.Msg = "分类不存在,请刷新页面"
- return
- }
- br.Msg = "移动失败"
- br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
- return
- }
- // 校验移动的父级目录下是否有重名分类
- exists, e := data_manage.GetChartClassifyByParentIdAndName(utils.CHART_SOURCE_DEFAULT, req.ParentClassifyId, chartClassifyInfo.ChartClassifyName, req.ClassifyId)
- if e != nil && !utils.IsErrNoRow(e) {
- br.Msg = "移动失败"
- br.ErrMsg = "获取父级目录下的同名分类失败, Err: " + e.Error()
- return
- }
- if e == nil && exists.ChartClassifyId > 0 {
- br.Msg = "移动失败,分类名称已存在"
- return
- }
- // 已授权分类id
- permissionClassifyIdList, err := data_manage_permission.GetUserChartClassifyPermissionList(this.SysUser.AdminId, chartClassifyInfo.ChartClassifyId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
- return
- }
- // 权限校验
- {
- haveOperaAuth := data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(chartClassifyInfo.IsJoinPermission, chartClassifyInfo.ChartClassifyId, permissionClassifyIdList)
- button := data.GetChartClassifyOpButton(this.SysUser, chartClassifyInfo.SysUserId, haveOperaAuth)
- if !button.OpButton {
- br.Msg = "无操作权限"
- br.IsSendEmail = false
- return
- }
- }
- if chartClassifyInfo.Source != utils.CHART_SOURCE_DEFAULT {
- br.Msg = "分类异常"
- br.ErrMsg = "分类异常,不是ETA图库的分类"
- return
- }
- updateCol := make([]string, 0)
- //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
- if chartClassifyInfo.ParentId != req.ParentClassifyId && req.ParentClassifyId != 0 {
- parentChartClassifyInfo, err := data_manage.GetChartClassifyById(req.ParentClassifyId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取上级分类信息失败,Err:" + err.Error()
- return
- }
- chartClassifyInfo.ParentId = parentChartClassifyInfo.ChartClassifyId
- chartClassifyInfo.Level = parentChartClassifyInfo.Level + 1
- chartClassifyInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "ParentId", "Level", "ModifyTime")
- }
- //如果有传入 上一个兄弟节点分类id
- if req.PrevClassifyId > 0 {
- //上一个兄弟节点
- prevClassify, err := data_manage.GetChartClassifyById(req.PrevClassifyId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
- return
- }
- //如果是移动在两个兄弟节点之间
- if req.NextClassifyId > 0 {
- //下一个兄弟节点
- nextClassify, err := data_manage.GetChartClassifyById(req.NextClassifyId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
- return
- }
- //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
- if prevClassify.Sort == nextClassify.Sort || prevClassify.Sort == chartClassifyInfo.Sort {
- //变更兄弟节点的排序
- updateSortStr := `sort + 2`
- _ = data_manage.UpdateChartClassifySortByParentId(prevClassify.ParentId, prevClassify.ChartClassifyId, prevClassify.Sort, updateSortStr)
- } else {
- //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
- if nextClassify.Sort-prevClassify.Sort == 1 {
- //变更兄弟节点的排序
- updateSortStr := `sort + 1`
- _ = data_manage.UpdateChartClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
- }
- }
- }
- chartClassifyInfo.Sort = prevClassify.Sort + 1
- chartClassifyInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- } else {
- firstClassify, err := data_manage.GetFirstChartClassifyByParentId(chartClassifyInfo.ParentId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "移动失败"
- br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
- return
- }
- //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
- if firstClassify != nil && firstClassify.ChartClassifyId > 0 && firstClassify.Sort == 0 {
- updateSortStr := ` sort + 1 `
- _ = data_manage.UpdateChartClassifySortByParentId(firstClassify.ParentId, firstClassify.ChartClassifyId-1, 0, updateSortStr)
- }
- chartClassifyInfo.Sort = 0 //那就是排在第一位
- chartClassifyInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- }
- //更新
- if len(updateCol) > 0 {
- err = chartClassifyInfo.Update(updateCol)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "修改失败,Err:" + err.Error()
- return
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "移动成功"
- }
- // ChartClassifyChartListV2
- // @Title 根据图表分类获取图表列表
- // @Description 根据图表分类获取图表列表接口
- // @Param ChartClassifyId query bool true "图片分类id"
- // @Success 200 {object} data_manage.ChartClassifyListResp
- // @router /chart_classify/chart/list [get]
- func (this *ChartClassifyController) ChartClassifyChartListV2() {
- 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
- }
- resp := new(data_manage.ChartClassifyListResp)
- chartClassifyId, _ := this.GetInt("ChartClassifyId")
- if chartClassifyId <= 0 {
- br.Msg = "参数错误"
- return
- }
- // 获取当前账号的不可见指标
- noPermissionChartIdMap := make(map[int]bool)
- {
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
- return
- }
- for _, v := range confList {
- noPermissionChartIdMap[v.ChartInfoId] = true
- }
- }
- allChartInfo, err := data_manage.GetChartInfoAllByClassifyId(utils.CHART_SOURCE_DEFAULT, chartClassifyId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- // 移除没有权限的图表
- allNodes := data.HandleNoPermissionChart(allChartInfo, noPermissionChartIdMap, this.SysUser.AdminId)
- editShareChartInfoIdMap, err := data.GetAllEditSharedChartInfoIdMapByReceivedUserId(this.SysUser.AdminId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取所有有编辑权限的分享图表失败,Err:" + err.Error()
- return
- }
- for k, item := range allNodes {
- item.Button = data.GetChartOpButton(this.SysUser, item.SysUserId, item.ChartInfoId, item.HaveOperaAuth, editShareChartInfoIdMap)
- item.Button.AddButton = false
- item.Button.OpButton = false
- item.Button.DeleteButton = false
- allNodes[k] = item
- }
- resp.AllNodes = allNodes
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|