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" "sort" ) type PredictEdbClassifyController struct { controllers.BaseAuthController } // @router /predict_classify/list [get] // @router /predict_classify/items [get] func (this *PredictEdbClassifyController) Items() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() rootList, err := data_manage.GetEdbClassifyByParentId(0, 1) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } resp := new(data_manage.EdbClassifyListResp) resp.AllNodes = rootList br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @router /predict_classify/add [post] func (this *PredictEdbClassifyController) Add() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req data_manage.AddEdbClassifyReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.ClassifyName == "" { br.Msg = "请输入分类名称" br.IsSendEmail = false return } if req.ParentId < 0 { br.Msg = "参数错误" br.IsSendEmail = false return } haveOperaAuth := true if req.ParentId > 0 { parentClassify, err := data_manage.GetEdbClassifyById(req.ParentId) if err != nil { br.Msg = "获取父级分类失败" br.ErrMsg = "获取父级分类失败,Err:" + err.Error() return } permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, parentClassify.ClassifyId) if err != nil { br.Msg = "添加失败" br.ErrMsg = "获取父级分类失败,Err:" + err.Error() return } haveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(parentClassify.IsJoinPermission, parentClassify.ClassifyId, permissionClassifyIdList) } button := data.GetPredictEdbClassifyOpButton(this.SysUser, 0, haveOperaAuth) if !button.AddButton { br.Msg = "不允许添加分类" br.IsSendEmail = false return } _, err, errMsg := data.AddEdbClassify(req.ClassifyName, req.ParentId, req.Level, 1, this.SysUser.AdminId, this.SysUser.AdminName, this.Lang) if errMsg != `` { br.Msg = errMsg br.ErrMsg = errMsg if err != nil { br.ErrMsg = errMsg + ";Err:" + err.Error() } else { br.IsSendEmail = false } return } br.Ret = 200 br.Msg = "保存成功" br.Success = true br.IsAddLog = true } // @router /predict_classify/edit [post] func (this *PredictEdbClassifyController) Edit() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req data_manage.EditEdbClassifyReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.ClassifyName == "" { br.Msg = "请输入分类名称" br.IsSendEmail = false return } if req.ClassifyId < 0 { br.Msg = "参数错误" br.IsSendEmail = false return } err, errMsg := data.EditEdbClassify(req.ClassifyId, req.ClassifyName, this.Lang, this.SysUser) if errMsg != `` { br.Msg = errMsg br.ErrMsg = errMsg if err != nil { br.ErrMsg = errMsg + ";Err:" + err.Error() } else { br.IsSendEmail = false } return } br.Ret = 200 br.Msg = "保存成功" br.Success = true br.IsAddLog = true } // @router /predict_classify/delete/check [post] func (this *PredictEdbClassifyController) DeleteCheck() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req data_manage.ClassifyDeleteCheckReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.ClassifyId < 0 && req.EdbInfoId <= 0 { br.Msg = "参数错误" br.IsSendEmail = false return } deleteStatus, tipsMsg, tableList, err, errMsg := data.DeleteCheck(req.ClassifyId, req.EdbInfoId, this.SysUser) if errMsg != `` { br.Msg = errMsg br.ErrMsg = errMsg if err != nil { br.ErrMsg = err.Error() } else { br.IsSendEmail = false } return } resp := new(data_manage.ClassifyDeleteCheckResp) resp.DeleteStatus = deleteStatus resp.TipsMsg = tipsMsg resp.TableList = tableList br.Ret = 200 br.Msg = "检测成功" br.Success = true br.Data = resp } // @router /predict_classify/delete [post] func (this *PredictEdbClassifyController) Delete() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req data_manage.DeleteEdbClassifyReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.ClassifyId < 0 && req.EdbInfoId <= 0 { br.Msg = "参数错误" br.IsSendEmail = false return } nextItem, _, err, errMsg := data.Delete(req.ClassifyId, req.EdbInfoId, sysUser, string(this.Ctx.Input.RequestBody), this.Ctx.Input.URI()) if errMsg != `` { br.Msg = errMsg br.ErrMsg = errMsg if err != nil { br.ErrMsg = err.Error() } else { br.IsSendEmail = false } return } resp := data_manage.AddEdbInfoResp{} if nextItem != nil { resp = data_manage.AddEdbInfoResp{ EdbInfoId: nextItem.EdbInfoId, UniqueCode: nextItem.UniqueCode, ClassifyId: nextItem.ClassifyId, } } br.Ret = 200 br.Msg = "删除成功" br.Success = true br.IsAddLog = true br.Data = resp } // @router /predict_classify/move [post] func (this *PredictEdbClassifyController) Move() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req data_manage.MoveEdbClassifyReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.ClassifyId <= 0 && req.EdbInfoId <= 0 { br.Msg = "参数错误" br.ErrMsg = "请选择拖动目标,分类目录或者指标" return } err, errMsg := data.MoveEdbClassify(req, sysUser, 1) if errMsg != `` { br.Msg = errMsg br.ErrMsg = errMsg if err != nil { br.ErrMsg = err.Error() } else { br.IsSendEmail = false } return } br.Ret = 200 br.Success = true br.Msg = "移动成功" } // @router /predict_classify/list/v2 [get] // @router /predict_classify/simple [get] func (this *PredictEdbClassifyController) SimpleList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() parentId, _ := this.GetInt("ParentId") isOnlyMe, _ := this.GetBool("IsOnlyMe") sysUserId := 0 if isOnlyMe { sysUserId = this.SysUser.AdminId } rootList, err := data_manage.GetEdbClassifyByParentId(parentId, 1) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } nodeAll := make([]*data_manage.EdbClassifyItems, 0) var sortList data_manage.EdbClassifyItemList if parentId > 0 { noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList, err := data_manage_permission.GetUserAllEdbAndClassifyNoPermissionList(this.SysUser.AdminId, utils.PREDICT_EDB_INFO_TYPE, 0) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error() return } allEdbInfo, err := data_manage.GetEdbInfoByClassifyId(parentId, utils.PREDICT_EDB_INFO_TYPE, 0, sysUserId, noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList) if err != nil { br.Msg = "获取指标数据失败" br.ErrMsg = "获取指标数据失败,Err:" + err.Error() return } if len(allEdbInfo) > 0 { currClassify, err := data_manage.GetEdbClassifyById(parentId) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取当前分类信息失败,Err:" + err.Error() return } permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error() return } for _, v := range allEdbInfo { v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList) button := data.GetPredictEdbOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth) button.AddButton = false //不管有没有权限,指标都是没有添加按钮的 button.OpButton = false button.DeleteButton = false v.Button = button v.ParentId = parentId v.Children = make([]*data_manage.EdbClassifyItems, 0) nodeAll = append(nodeAll, v) } } } if len(rootList) > 0 { permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error() return } for _, v := range rootList { if v.IsJoinPermission == 1 && !utils.InArrayByInt(permissionClassifyIdList, v.ClassifyId) { continue } v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList) button := data.GetPredictEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth) v.Button = button v.Children = make([]*data_manage.EdbClassifyItems, 0) nodeAll = append(nodeAll, v) } } if len(nodeAll) > 0 { sortList = nodeAll sort.Sort(sortList) } canOpClassify := true button := data.GetPredictEdbClassifyOpButton(this.SysUser, 0, true) if !button.AddButton { canOpClassify = false } language := `CN` { configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.PredictEdbLanguageVar) if configDetail != nil { language = configDetail.ConfigValue } else { configDetail, _ = system.GetDefaultConfigDetailByCode(system.PredictEdbLanguageVar) if configDetail != nil { language = configDetail.ConfigValue } } } resp := new(data_manage.EdbClassifyListResp) resp.AllNodes = sortList resp.Language = language resp.CanOpClassify = canOpClassify br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @router /predict_classify/tree [get] func (this *PredictEdbClassifyController) ClassifyTree() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() allList, err := data_manage.GetPredictEdbClassifyAll() if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } nodeAll := make([]*data_manage.EdbClassifyItems, 0) var sortList data_manage.EdbClassifyItemList if len(allList) > 0 { permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(this.SysUser.AdminId, 0) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error() return } for k, v := range allList { if v.IsJoinPermission == 1 && !utils.InArrayByInt(permissionClassifyIdList, v.ClassifyId) { continue } v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList) button := data.GetPredictEdbClassifyOpButton(this.SysUser, v.SysUserId, v.HaveOperaAuth) allList[k].Button = button } nodeAll = data.GetClassifyTreeRecursive(allList, 0) sortList = nodeAll sort.Sort(sortList) } canOpClassify := true button := data.GetPredictEdbClassifyOpButton(this.SysUser, 0, true) if !button.AddButton { canOpClassify = false } language := `CN` { configDetail, _ := system.GetConfigDetailByCode(this.SysUser.AdminId, system.PredictEdbLanguageVar) if configDetail != nil { language = configDetail.ConfigValue } else { configDetail, _ = system.GetDefaultConfigDetailByCode(system.PredictEdbLanguageVar) if configDetail != nil { language = configDetail.ConfigValue } } } resp := new(data_manage.EdbClassifyListResp) resp.AllNodes = sortList resp.Language = language resp.CanOpClassify = canOpClassify br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp }