1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048 |
- package controllers
- import (
- "encoding/json"
- "eta/eta_forum_admin/models"
- "eta/eta_forum_admin/models/system"
- "eta/eta_forum_admin/services"
- "eta/eta_forum_admin/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "sort"
- "strconv"
- "strings"
- "time"
- )
- type ChartClassifyController struct {
- BaseAuthController
- }
- func (this *ChartClassifyController) ChartClassifyListV2() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- resp := new(models.ChartClassifyListResp)
-
- 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 {
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- fmt.Println("source redis")
- return
- }
- }
- }
- }
- rootList, err := models.GetChartClassifyByParentId(0, utils.CHART_SOURCE_DEFAULT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- classifyAll, err := models.GetChartClassifyAll(utils.CHART_SOURCE_DEFAULT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- allChartInfo, err := models.GetChartInfoAll([]int{utils.CHART_SOURCE_DEFAULT})
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- chartInfoMap := make(map[int][]*models.ChartClassifyItems)
- for _, v := range allChartInfo {
- chartInfoMap[v.ChartClassifyId] = append(chartInfoMap[v.ChartClassifyId], v)
- }
- rootChildMap := make(map[int][]*models.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([]*models.ChartClassifyItems, 0)
- v.Children = items
- }
- }
- nodeAll := make([]*models.ChartClassifyItems, 0)
- for _, v := range rootList {
- if existItems, ok := rootChildMap[v.ChartClassifyId]; ok {
- v.Children = existItems
- } else {
- items := make([]*models.ChartClassifyItems, 0)
- v.Children = items
- }
- nodeAll = append(nodeAll, v)
- }
-
-
-
-
-
-
-
-
- resp.AllNodes = nodeAll
-
- if utils.Re == nil {
- redisData, _ := json.Marshal(resp)
- utils.Rc.Put(key, redisData, 2*time.Hour)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- func (this *ChartClassifyController) SimpleList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
-
-
-
- reqParentId, _ := this.GetInt("ParentId")
- sysUserIds := this.GetString("SysUserIds")
- adminIdsSlice := make([]int, 0)
- if sysUserIds != "" {
- adminIds := strings.Split(sysUserIds, ",")
- if len(adminIds) == 0 {
- br.Msg = "请选择正确的创建人"
- return
- }
- for _, adminId := range adminIds {
- adminIdInt, e := strconv.Atoi(adminId)
- if e != nil {
- br.Msg = "请选择正确的创建人"
- return
- }
- adminIdsSlice = append(adminIdsSlice, adminIdInt)
- }
- }
- parentId := 0
- nodeAll := make([]*models.ChartClassifyItems, 0)
-
-
- if reqParentId == -1 {
- initClassify := &models.ChartClassifyItems{
- ChartClassifyId: 0,
- ChartInfoId: 0,
- ChartClassifyName: "未分类",
- ChartClassifyNameEn: "",
- ParentId: 0,
- Level: 1,
- Sort: 0,
- }
- nodeAll = append(nodeAll, initClassify)
- } else {
- parentId = reqParentId
- }
- rootList := make([]*models.ChartClassifyItems, 0)
- rootListTmp := make([]*models.ChartClassifyItems, 0)
- var err error
- if reqParentId == -1 || reqParentId > 0 {
- rootListTmp, err = models.GetChartClassifyByParentId(parentId, utils.CHART_SOURCE_DEFAULT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- if len(adminIdsSlice) > 0 {
-
- hasClassifyMap, e, _ := services.GetChartClassifyListByAdmins(adminIdsSlice)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取创建人图表失败,Err:" + e.Error()
- return
- }
- for _, v := range rootListTmp {
- if _, ok := hasClassifyMap[v.ChartClassifyId]; ok {
- rootList = append(rootList, v)
- }
- }
- } else {
- rootList = rootListTmp
- }
- }
- var sortList models.ChartClassifyItemList
- if reqParentId >= 0 {
-
- var e error
- allChartInfo := make([]*models.ChartClassifyItems, 0)
- if len(adminIdsSlice) > 0 {
- allChartInfo, e = models.GetChartInfoAllByClassifyIdAndAdmin(utils.CHART_SOURCE_DEFAULT, parentId, adminIdsSlice)
- } else {
- allChartInfo, e = models.GetChartInfoAllByClassifyId(utils.CHART_SOURCE_DEFAULT, parentId)
- }
- if e != nil && e.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表信息失败,Err:" + e.Error()
- return
- }
- if len(allChartInfo) > 0 {
-
- adminIds := make([]int, 0)
- for _, v := range allChartInfo {
- adminIds = append(adminIds, v.SysUserId)
- }
- adminCompanyMap, er := services.GetCompanyNameByAdmins(adminIds)
- if er != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取机构失败,Err:" + er.Error()
- return
- }
- for _, v := range allChartInfo {
- v.Children = make([]*models.ChartClassifyItems, 0)
- if n, ok := adminCompanyMap[v.SysUserId]; ok {
- v.Company = n
- }
- nodeAll = append(nodeAll, v)
- }
- }
- }
- if len(rootList) > 0 {
- for _, v := range rootList {
- v.Children = make([]*models.ChartClassifyItems, 0)
- nodeAll = append(nodeAll, v)
- }
- }
- if len(nodeAll) > 0 {
-
- 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
- }
- }
- }
- resp := new(models.ChartClassifyListResp)
- if len(nodeAll) > 0 {
- resp.AllNodes = sortList
- } else {
- resp.AllNodes = nodeAll
- }
- resp.Language = language
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- func (this *ChartClassifyController) ChartClassifyItems() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- rootList, err := models.GetChartClassifyByParentId(0, utils.CHART_SOURCE_DEFAULT)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- classifyAll, err := models.GetChartClassifyAll(utils.CHART_SOURCE_DEFAULT)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- nodeAll := make([]*models.ChartClassifyItems, 0)
- for k := range rootList {
- rootNode := rootList[k]
- services.ChartClassifyItemsMakeTree(this.SysUser, classifyAll, rootNode)
- 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
-
-
-
-
- resp := models.ChartClassifyListResp{
- AllNodes: nodeAll,
- Language: language,
- CanOpClassify: canOpClassify,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- func (this *ChartClassifyController) AddChartClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.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 := services.AddChartClassify(req.ChartClassifyName, req.ParentId, 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
- }
- func (this *ChartClassifyController) EditChartClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.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 := services.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
- }
- func (this *ChartClassifyController) DeleteChartClassifyCheck() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.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
-
- if req.ChartClassifyId > 0 && req.ChartInfoId == 0 {
-
-
-
- count, err := models.GetChartInfoCountByClassifyId(req.ChartClassifyId)
- 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 := models.GetChartClassifyCountByClassifyId(req.ChartClassifyId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "删除失败"
- br.ErrMsg = "分类下是否含有图表失败,Err:" + err.Error()
- return
- }
- if classifyCount > 0 {
- deleteStatus = 2
- tipsMsg = "确认删除当前目录及包含的子目录吗"
- }
- }
- if deleteStatus == 0 {
- tipsMsg = "可删除,进行删除操作"
- }
- resp := new(models.ChartClassifyDeleteCheckResp)
- resp.DeleteStatus = deleteStatus
- resp.TipsMsg = tipsMsg
- br.Ret = 200
- br.Msg = "检测成功"
- br.Success = true
- br.Data = resp
- }
- 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 models.DeleteChartClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ChartClassifyId < 0 {
- br.Msg = "参数错误"
- br.IsSendEmail = false
- return
- }
-
- _, err = models.GetChartClassifyById(req.ChartClassifyId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "分类不存在,请刷新"
- return
- }
- br.Msg = "操作失败"
- br.Msg = "获取分类信息失败,Err:" + err.Error()
- return
- }
-
- count, err := models.GetChartInfoCountByClassifyId(req.ChartClassifyId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "删除失败"
- br.ErrMsg = "判断名称是否已存在失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- br.Msg = "该目录下存在关联指标,不可删除"
- br.IsSendEmail = false
- return
- }
- err = models.DeleteChartClassify(req.ChartClassifyId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- resp := new(models.AddChartInfoResp)
- br.Ret = 200
- br.Msg = "删除成功"
- br.Success = true
- br.Data = resp
- br.IsAddLog = true
- }
- 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 models.MoveChartClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ClassifyId <= 0 && req.ChartInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "请选择分类或者图表"
- return
- }
-
-
- err, errMsg := services.MoveChartClassify(req, sysUser, 0)
- 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 = "移动成功"
- }
- func getChartClassifyListForMeV2(adminInfo system.Admin, resp *models.ChartClassifyListResp) (errMsg string, err error) {
- rootList, err := models.GetChartClassifyByParentId(0, utils.CHART_SOURCE_DEFAULT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- errMsg = "获取失败"
- return
- }
- classifyAll, err := models.GetChartClassifyAll(utils.CHART_SOURCE_DEFAULT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- errMsg = "获取失败"
- return
- }
- rootChildMap := make(map[int][]*models.ChartClassifyItems)
- for _, v := range classifyAll {
- rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
- }
- nodeAll := make([]*models.ChartClassifyItems, 0)
- for _, v := range rootList {
- if existItems, ok := rootChildMap[v.ChartClassifyId]; ok {
- v.Children = existItems
- } else {
- items := make([]*models.ChartClassifyItems, 0)
- v.Children = items
- }
- nodeAll = append(nodeAll, v)
- }
- resp.AllNodes = nodeAll
- return
- }
- 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(models.ChartClassifyListResp)
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- sysUserIds := this.GetString("SysUserIds")
- chartClassifyId, _ := this.GetInt("ChartClassifyId")
- if chartClassifyId < 0 && chartClassifyId != -1 {
- br.Msg = "参数错误"
- return
- }
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- condition := ""
- pars := make([]interface{}, 0)
- 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)
- }
- if chartClassifyId >= 0 {
- condition += " AND chart_classify_id = ?"
- pars = append(pars, chartClassifyId)
- }
- allChartInfo, err := models.GetChartInfoByConditionPage(utils.CHART_SOURCE_DEFAULT, condition, pars, startSize, pageSize)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- total, err := models.GetChartInfoTotalByCondition(utils.CHART_SOURCE_DEFAULT, condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表总数失败,Err:" + err.Error()
- return
- }
- if len(allChartInfo) > 0 {
- adminIds := make([]int, 0)
- for _, v := range allChartInfo {
- adminIds = append(adminIds, v.SysUserId)
- }
- adminCompanyMap, er := services.GetCompanyNameByAdmins(adminIds)
- if er != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取机构失败,Err:" + er.Error()
- return
- }
- for k, v := range allChartInfo {
- v.Children = make([]*models.ChartClassifyItems, 0)
- if n, ok := adminCompanyMap[v.SysUserId]; ok {
- allChartInfo[k].Company = n
- }
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- resp.AllNodes = allChartInfo
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- func (this *ChartClassifyController) ModifyChartClassify() {
- 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 models.ModifyChartClassifyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if !req.SelectAll && req.ChartInfoIds == "" {
- br.Msg = "请选择图表"
- return
- }
- if req.ChartClassifyId < 0 {
- br.Msg = "请选择新分类"
- return
- }
- var chartIds []int
- if req.SelectAll {
-
- chartClassifyIds := req.ChartClassifyIds
- sysUserIds := req.SysUserIds
- chartName := req.ChartName
- condition := " AND source = ? "
- pars := make([]interface{}, 0)
- pars = append(pars, utils.CHART_SOURCE_DEFAULT)
- if chartClassifyIds != "" {
- classifyIds := strings.Split(chartClassifyIds, ",")
- if len(classifyIds) == 0 {
- br.Msg = "请选择正确的分类"
- return
- }
- classifyIdSlice := make([]int, 0)
- for _, id := range classifyIds {
- tmp, e := strconv.Atoi(id)
- if e != nil {
- br.Msg = "请选择正确的分类"
- return
- }
- classifyIdSlice = append(classifyIdSlice, tmp)
- }
- condition += " AND chart_classify_id in (" + utils.GetOrmInReplace(len(classifyIdSlice)) + ") "
- pars = append(pars, classifyIdSlice)
- }
- 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)
- }
- if chartName != "" {
- condition = " AND chart_name LIKE ? "
- pars = append(pars, utils.GetLikeKeyword(chartName))
- }
- allChartInfo, err := models.GetChartInfoItemsByCondition(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
-
- if len(allChartInfo) > 100 {
- br.Msg = "最多只能选择100个图表"
- return
- }
- for _, v := range allChartInfo {
- chartIds = append(chartIds, v.ChartInfoId)
- }
- } else {
- chartIdStr := strings.Split(req.ChartInfoIds, ",")
- if len(chartIdStr) == 0 {
- br.Msg = "请选择正确的图表"
- return
- }
- for _, id := range chartIdStr {
- tmp, e := strconv.Atoi(id)
- if e != nil {
- br.Msg = "请选择正确的分类"
- return
- }
- chartIds = append(chartIds, tmp)
- }
-
- if len(chartIds) > 100 {
- br.Msg = "最多只能选择100个图表"
- return
- }
- }
- if len(chartIds) == 0 {
- br.Msg = "请选择正确的图表"
- return
- }
- err = models.UpdateChartClassifyIdByChartInfoId(chartIds, req.ChartClassifyId)
- if err != nil {
- br.Msg = "更新失败"
- br.ErrMsg = "更新图表分类失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
|