123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794 |
- 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/data_manage/request"
- "eta_gn/eta_api/models/system"
- "eta_gn/eta_api/services/data"
- "eta_gn/eta_api/services/data/data_manage_permission"
- "eta_gn/eta_api/utils"
- "fmt"
- "sort"
- )
- type EdbPublicClassifyController struct {
- controllers.BaseAuthController
- }
- func (c *EdbPublicClassifyController) SimpleList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
-
-
- classifyType := utils.EdbClassifyTypeCalculate
-
-
-
- parentId, _ := c.GetInt("ParentId")
- edbPublicClassifyObj := data_manage.EdbPublicClassify{}
- rootList, err := edbPublicClassifyObj.GetEdbClassifyItemsByParentId(parentId, int8(classifyType))
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- nodeAll := make([]*data_manage.EdbClassifyItems, 0)
- var sortList data_manage.EdbClassifyItemList
- if parentId > 0 {
-
- edbType := 0
- switch classifyType {
- case utils.EdbClassifyTypeBase:
- edbType = 1
- case utils.EdbClassifyTypeCalculate:
- edbType = 2
- }
- allEdbInfo, err := data_manage.GetEdbInfoByPublicClassifyId(parentId, 0, edbType)
- if err != nil {
- br.Msg = "获取指标数据失败"
- br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
- return
- }
- if len(allEdbInfo) > 0 {
- editShareEdbInfoIdMap, err := data.GetAllEditSharedEdbInfoIdMapByReceivedUserId(c.SysUser.AdminId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取所有有编辑权限的分享指标失败,Err:" + err.Error()
- return
- }
-
- for _, v := range allEdbInfo {
- v.HaveOperaAuth = true
- button := data.GetEdbOpButton(c.SysUser, v.SysUserId, v.EdbInfoId, v.EdbType, utils.EDB_INFO_TYPE, v.HaveOperaAuth, editShareEdbInfoIdMap)
- button.AddButton = false
- v.Button = button
- v.Children = make([]*data_manage.EdbClassifyItems, 0)
- v.ParentId = parentId
- nodeAll = append(nodeAll, v)
- }
- }
- }
- if len(rootList) > 0 {
-
- permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(c.SysUser.AdminId, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取已授权公共分类id数据失败,Err:" + err.Error()
- return
- }
- for _, v := range rootList {
-
- if v.IsJoinPermission == 1 && !utils.InArrayByInt(permissionClassifyIdList, v.ClassifyId) {
- continue
- }
-
- v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ClassifyId, permissionClassifyIdList)
-
- button := data.GetEdbClassifyOpButton(c.SysUser, v.SysUserId, v.HaveOperaAuth)
- v.Button = button
- v.Children = make([]*data_manage.EdbClassifyItems, 0)
- nodeAll = append(nodeAll, v)
- }
- }
- if len(nodeAll) > 0 {
-
- sortList = nodeAll
- sort.Sort(sortList)
- }
- language := `CN`
-
- {
- configDetail, _ := system.GetConfigDetailByCode(c.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(c.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
- }
- func (c *EdbPublicClassifyController) ClassifyTree() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
-
- classifyType := utils.EdbClassifyTypeCalculate
- edbPublicClassifyObj := data_manage.EdbPublicClassify{}
- allList, err := edbPublicClassifyObj.GetAllEdbClassifyByType(int8(classifyType))
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- var sortList data_manage.EdbClassifyItemList
- if len(allList) > 0 {
- for k, v := range allList {
-
- v.HaveOperaAuth = true
-
- button := data.GetEdbClassifyOpButton(c.SysUser, v.SysUserId, v.HaveOperaAuth)
- allList[k].Button = button
- }
- allList = data.GetClassifyTreeRecursive(allList, 0)
-
- sortList = allList
- sort.Sort(sortList)
- }
- language := `CN`
-
- canOpClassify := true
- button := data.GetEdbClassifyOpButton(c.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
- }
- func (c *EdbPublicClassifyController) AddClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- var req data_manage.AddEdbClassifyReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ClassifyName == "" {
- br.Msg = "请输入公共分类名称"
- br.IsSendEmail = false
- return
- }
- if req.ParentId < 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
-
- classifyType := utils.EdbClassifyTypeCalculate
-
- _, err, errMsg := data.AddEdbPublicClassify(req.ClassifyName, req.ParentId, uint8(classifyType), c.SysUser.AdminId, c.SysUser.RealName)
- 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
- }
- func (c *EdbPublicClassifyController) EditEdbClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- var req data_manage.EditEdbClassifyReq
- err := json.Unmarshal(c.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.EditEdbPublicClassify(req.ClassifyId, req.ClassifyName, c.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
- }
- func (c *EdbPublicClassifyController) DeleteClassifyCheck() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- var req request.PublicClassifyDeleteCheckReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
- deleteStatus, tipsMsg, _, tableList, err, errMsg := data.DeleteEdbPublicClassifyCheck(req.ClassifyId, c.SysUser)
- if errMsg != `` {
- br.Msg = errMsg
- br.ErrMsg = errMsg
- if err != nil {
- br.ErrMsg = err.Error()
- } else {
- br.IsSendEmail = false
- }
- return
- }
- if c.Lang == "en" {
- if utils.ViperConfig.InConfig(tipsMsg) {
- tipsMsg = utils.ViperConfig.GetString(tipsMsg)
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- resp := new(data_manage.ClassifyDeleteCheckResp)
- resp.DeleteStatus = deleteStatus
- resp.TipsMsg = tipsMsg
- resp.TableList = tableList
- br.Ret = 200
- br.Msg = "检测成功"
- br.Success = true
- br.Data = resp
- }
- func (c *EdbPublicClassifyController) DeleteClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.PublicClassifyDeleteCheckReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
- nextItem, _, err, errMsg := data.DeleteEdbPublicClassify(req.ClassifyId, sysUser, string(c.Ctx.Input.RequestBody), c.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
- }
- func (c *EdbPublicClassifyController) ListV2() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
-
- classifyType, _ := c.GetInt("ClassifyType", utils.EdbClassifyTypeBase)
- if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate {
- br.Msg = "参数有误"
- br.ErrMsg = fmt.Sprintf("指标公共分类类型有误, ClassifyType: %d", classifyType)
- return
- }
- edbType := utils.EdbTypeBase
- if classifyType == utils.EdbClassifyTypeCalculate {
- edbType = utils.EdbTypeCalculate
- }
- rootList, err := data_manage.GetEdbClassifyByParentId(0, int8(classifyType), c.SysUser.AdminId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
-
- classifyAll, err := data_manage.GetChildEdbClassifyByClassifyType(classifyType, c.SysUser.AdminId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
-
- classifyMap := make(map[int]*data_manage.EdbClassifyItems)
- for _, v := range classifyAll {
- classifyMap[v.ClassifyId] = v
- }
-
- permissionClassifyIdList, err := data_manage_permission.GetUserEdbClassifyPermissionList(c.SysUser.AdminId, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取已授权公共分类id数据失败,Err:" + err.Error()
- return
- }
-
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- confList, err := obj.GetAllListByAdminId(c.SysUser.AdminId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
- return
- }
- noPermissionEdbInfoIdMap := make(map[int]bool)
- for _, v := range confList {
- noPermissionEdbInfoIdMap[v.EdbInfoId] = true
- }
-
- allEdbInfo, err := data_manage.GetEdbInfoByTypes(utils.EDB_INFO_TYPE, edbType)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- edbInfoMap := make(map[int][]*data_manage.EdbClassifyItems)
- if len(allEdbInfo) > 0 {
-
- permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(c.SysUser.AdminId, 0, 0)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取所有有权限的指标和公共分类失败,Err:" + err.Error()
- return
- }
- editShareEdbInfoIdMap, err := data.GetAllEditSharedEdbInfoIdMapByReceivedUserId(c.SysUser.AdminId)
- 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(c.SysUser, v.SysUserId, v.EdbInfoId, v.EdbType, utils.EDB_INFO_TYPE, v.HaveOperaAuth, editShareEdbInfoIdMap)
- 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(c.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(c.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
- }
- func (c *EdbPublicClassifyController) EdbClassifyMove() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req data_manage.MoveEdbClassifyReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ClassifyId <= 0 && req.EdbInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "请选择拖动目标,分类目录或者指标"
- return
- }
-
- classifyType := req.ClassifyType
- if classifyType != utils.EdbClassifyTypeBase && classifyType != utils.EdbClassifyTypeCalculate {
- br.Msg = "参数有误"
- br.ErrMsg = fmt.Sprintf("指标分类类型有误, ClassifyType: %d", classifyType)
- return
- }
- err, errMsg := data.MoveEdbPublicClassify(req, sysUser, uint8(classifyType))
- if errMsg != `` {
- br.Msg = errMsg
- br.ErrMsg = errMsg
- if err != nil {
- br.ErrMsg = err.Error()
- } else {
- br.IsSendEmail = false
- }
- return
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- br.Ret = 200
- br.Success = true
- br.Msg = "移动成功"
- }
|