12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178 |
- 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
- }
- // ChartClassifyListV2
- // @Title 图表分类列表
- // @Description 图表分类列表接口
- // @Param IsShowMe query bool true "是否只看我的,true、false"
- // @Success 200 {object} models.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(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)
- }
- //
- //
- //nodeAll := make([]*models.ChartClassifyItems, 0)
- //for k := range rootList {
- // rootNode := rootList[k]
- // services.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)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // SimpleList
- // @Title 单层分类列表
- // @Description 单层分类列表
- // @Success 200 {object} data_manage.EdbClassifyListResp
- // @router /classify/simple [get]
- 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 = utils.HzCompanyName
- //}
- 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 {
- //根据sort值排序
- 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
- }
- // ChartClassifyItems
- // @Title 获取所有图表分类接口-不包含图表
- // @Description 获取所有图表分类接口-不包含图表
- // @Success 200 {object} models.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 := 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
- // 如果不是 超管 或者 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 := models.ChartClassifyListResp{
- AllNodes: nodeAll,
- Language: language,
- CanOpClassify: canOpClassify,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 新增图表分类
- // @Description 新增图表分类接口
- // @Param request body models.AddChartClassifyReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /classify/add [post]
- 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
- }
- // EditChartClassify
- // @Title 修改图表分类
- // @Description 修改图表分类接口
- // @Param request body models.EditChartClassifyReq true "type json string"
- // @Success 200 Ret=200 修改成功
- // @router /classify/edit [post]
- 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
- }
- // @Title 删除图表检测接口
- // @Description 删除图表检测接口
- // @Param request body models.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 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 {
- // 查找分类
- /*item, err := models.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
- }
- // todo 删除是否需要加权限校验
- {
- haveOperaAuth := data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(item.IsJoinPermission, item.ChartClassifyId, permissionClassifyIdList)
- button := services.GetChartClassifyOpButton(this.SysUser, item.SysUserId, haveOperaAuth)
- if !button.OpButton {
- br.Msg = "无操作权限"
- br.IsSendEmail = false
- return
- }
- }*/
- //判断图表分类下,是否含有图表
- 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
- }
- // @Title 删除图表分类/图表
- // @Description 删除图表分类/图表接口
- // @Param request body models.DeleteChartClassifyReq true "type json string"
- // @Success 200 Ret=200 删除成功
- // @router /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 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
- }
- // ChartClassifyMove
- // @Title 图表分类移动接口
- // @Description 图表分类移动接口
- // @Success 200 {object} models.MoveChartClassifyReq
- // @router /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 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
- }
- //判断分类是否存在
- /*chartClassifyInfo, err := models.GetChartClassifyById(req.ClassifyId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "分类不存在,请刷新页面"
- return
- }
- br.Msg = "移动失败"
- br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
- return
- }
- // 校验移动的父级目录下是否有重名分类
- exists, e := models.GetChartClassifyByParentIdAndName(req.ParentClassifyId, chartClassifyInfo.ChartClassifyName, req.ClassifyId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- br.Msg = "移动失败"
- br.ErrMsg = "获取父级目录下的同名分类失败, Err: " + e.Error()
- return
- }
- if exists != nil {
- br.Msg = "移动失败,分类名称已存在"
- 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 := models.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 := models.GetChartClassifyById(req.PrevClassifyId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
- return
- }
- //如果是移动在两个兄弟节点之间
- if req.NextClassifyId > 0 {
- //下一个兄弟节点
- nextClassify, err := models.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`
- _ = models.UpdateChartClassifySortByParentId(prevClassify.ParentId, prevClassify.ChartClassifyId, prevClassify.Sort, updateSortStr)
- } else {
- //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
- if nextClassify.Sort-prevClassify.Sort == 1 {
- //变更兄弟节点的排序
- updateSortStr := `sort + 1`
- _ = models.UpdateChartClassifySortByParentId(prevClassify.ParentId, 0, prevClassify.Sort, updateSortStr)
- }
- }
- }
- chartClassifyInfo.Sort = prevClassify.Sort + 1
- chartClassifyInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- } else {
- firstClassify, err := models.GetFirstChartClassifyByParentId(chartClassifyInfo.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 `
- _ = models.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
- }
- }*/
- 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 = "移动成功"
- }
- // getChartClassifyListForMe 获取我创建的图表分类
- 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
- }
- // ChartClassifyChartListV2
- // @Title 根据图表分类获取图表列表
- // @Description 根据图表分类获取图表列表接口
- // @Param SysUserIds query string true "根据创建人查询"
- // @Param ChartClassifyId query bool true "图片分类id"
- // @Success 200 {object} models.ChartClassifyListResp
- // @router /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(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 {
- // 查询所有子分类
- childClassify, e, _ := services.GetChildClassifyByClassifyId(chartClassifyId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取分类信息失败, GetEdbClassify,Err:" + e.Error()
- return
- }
- var classifyIds []int
- for _, v := range childClassify {
- classifyIds = append(classifyIds, v.ChartClassifyId)
- }
- condition += fmt.Sprintf(` AND chart_classify_id IN (%s) `, utils.GetOrmInReplace(len(classifyIds)))
- pars = append(pars, classifyIds)
- } else 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 = utils.HzCompanyName
- //}
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- resp.AllNodes = allChartInfo
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // ModifyChartClassify
- // @Title 批量修改图表分类
- // @Description 批量修改图表分类
- // @Param SysUserIds query string true "根据创建人查询"
- // @Param ChartClassifyIds query string true "图片分类id"
- // @Success 200 {object} models.ChartClassifyListResp
- // @router /modify_chart_classify [post]
- 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
- }
- // 判断是否超过100 个
- 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)
- }
- // 判断是否超过100 个
- 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 = "操作成功"
- }
- // ClassifyTree
- // @Title 多层分类列表树
- // @Description 多层分类列表树
- // @Success 200 {object} data_manage.EdbClassifyListResp
- // @router /classify/tree [get]
- func (this *ChartClassifyController) ClassifyTree() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- allList, err := models.GetChartClassify()
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- nodeAll := make([]*models.ChartClassifyItems, 0)
- list := make([]*models.ChartClassifyItems, 0)
- var sortList models.ChartClassifyItemList
- if len(allList) > 0 {
- nodeAll = services.GetClassifyTreeRecursive(allList, 0)
- //根据sort值排序
- 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
- }
- }
- }
- initClassify := &models.ChartClassifyItems{
- ChartClassifyId: 0,
- ChartInfoId: 0,
- ChartClassifyName: "未分类",
- ChartClassifyNameEn: "",
- ParentId: 0,
- Level: 1,
- Sort: 0,
- }
- list = append(list, initClassify)
- list = append(list, sortList...)
- resp := new(models.ChartClassifyListResp)
- resp.AllNodes = list
- resp.Language = language
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // ClassifyRealTree
- // @Title 多层分类列表树
- // @Description 多层分类列表树
- // @Success 200 {object} data_manage.EdbClassifyListResp
- // @router /classify/real_tree [get]
- func (this *ChartClassifyController) ClassifyRealTree() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- allList, err := models.GetChartClassify()
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- nodeAll := make([]*models.ChartClassifyItems, 0)
- list := make([]*models.ChartClassifyItems, 0)
- var sortList models.ChartClassifyItemList
- if len(allList) > 0 {
- nodeAll = services.GetClassifyTreeRecursive(allList, 0)
- //根据sort值排序
- 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
- }
- }
- }
- list = append(list, sortList...)
- resp := new(models.ChartClassifyListResp)
- resp.AllNodes = list
- resp.Language = language
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|