123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908 |
- package data
- import (
- "errors"
- "eta_gn/eta_api/models/data_manage"
- "eta_gn/eta_api/models/system"
- "eta_gn/eta_api/services/data/data_manage_permission"
- "eta_gn/eta_api/utils"
- "fmt"
- "strconv"
- "time"
- )
- func chartClassifyHaveChild(allNode []*data_manage.ChartClassifyItems, node *data_manage.ChartClassifyItems) (childs []*data_manage.ChartClassifyItems, yes bool) {
- for _, v := range allNode {
- if v.ParentId == node.ChartClassifyId {
- childs = append(childs, v)
- }
- }
- if len(childs) > 0 {
- yes = true
- }
- return
- }
- func ChartClassifyItemsMakeTree(sysUser *system.Admin, allNode []*data_manage.ChartClassifyItems, node *data_manage.ChartClassifyItems, permissionClassifyIdList []int) {
- node.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(node.IsJoinPermission, node.ChartClassifyId, permissionClassifyIdList)
- button := GetChartClassifyOpButton(sysUser, node.SysUserId, node.HaveOperaAuth)
- node.Button = button
- childs, _ := chartClassifyHaveChild(allNode, node)
- if len(childs) > 0 {
- for _, child := range childs {
- child.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(child.IsJoinPermission, child.ChartClassifyId, permissionClassifyIdList)
- childButton := GetChartClassifyOpButton(sysUser, child.SysUserId, child.HaveOperaAuth)
- if child.Level == 3 {
- childButton.AddButton = false
- }
- child.Button = childButton
-
- }
- node.Children = append(node.Children, childs[0:]...)
- for _, v := range childs {
- v.HaveOperaAuth = data_manage_permission.CheckEdbClassifyPermissionByPermissionIdList(v.IsJoinPermission, v.ChartClassifyId, permissionClassifyIdList)
-
- _, has := chartClassifyHaveChild(allNode, v)
- if has {
- ChartClassifyItemsMakeTree(sysUser, allNode, v, permissionClassifyIdList)
- } else {
- childrenArr := make([]*data_manage.ChartClassifyItems, 0)
- v.Children = childrenArr
- }
- }
- } else {
- childrenArr := make([]*data_manage.ChartClassifyItems, 0)
- node.Children = childrenArr
- }
- }
- func GetChartClassifyOpButton(sysUser *system.Admin, belongUserId int, haveOperaAuth bool) (button data_manage.ChartClassifyItemsButton) {
-
- if !haveOperaAuth {
- return
- }
-
-
- button.AddButton = true
- button.OpButton = true
- button.DeleteButton = true
- button.MoveButton = true
-
- return
- }
- func GetChartOpButton(sysUser *system.Admin, belongUserId int, haveOperaAuth bool) (button data_manage.ChartClassifyItemsButton) {
-
- if !haveOperaAuth {
- return
- }
-
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.AdminId == belongUserId || sysUser.PredictEdbPermission == 1 {
- button.AddButton = true
- button.OpButton = true
- button.DeleteButton = true
- button.MoveButton = true
- }
- return
- }
- func HandleNoPermissionChart(allNodes []*data_manage.ChartClassifyItems, noPermissionChartIdMap map[int]bool, sysUserId int) (newAllNodes []*data_manage.ChartClassifyItems) {
-
- classifyIdList := make([]int, 0)
-
- newAllNodes = make([]*data_manage.ChartClassifyItems, 0)
- for _, node := range allNodes {
-
- tmpNodeInfo := *node
- tmpNodeList := make([]*data_manage.ChartClassifyItems, 0)
- if node.Children != nil {
- for _, chartInfo := range node.Children {
-
- if _, ok := noPermissionChartIdMap[chartInfo.ChartInfoId]; ok {
- continue
- }
- tmpNodeList = append(tmpNodeList, chartInfo)
- classifyIdList = append(classifyIdList, chartInfo.ChartClassifyId)
- }
- }
- tmpNodeInfo.Children = tmpNodeList
- newAllNodes = append(newAllNodes, &tmpNodeInfo)
- classifyIdList = append(classifyIdList, node.ChartClassifyId)
- }
-
- if len(classifyIdList) > 0 {
-
- chartClassifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
- if err != nil {
- return
- }
- chartClassifyMap := make(map[int]*data_manage.ChartClassify)
- for _, v := range chartClassifyList {
- chartClassifyMap[v.ChartClassifyId] = v
- }
-
- permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(sysUserId, 0, 0)
- if err != nil {
- return
- }
- for _, node := range newAllNodes {
- if node.Children != nil {
- for _, chartInfo := range node.Children {
- if currClassify, ok := chartClassifyMap[chartInfo.ChartClassifyId]; ok {
- chartInfo.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartInfo.IsJoinPermission, currClassify.IsJoinPermission, chartInfo.ChartInfoId, chartInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
- }
- }
- }
- if currClassify, ok := chartClassifyMap[node.ChartClassifyId]; ok {
- node.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(node.IsJoinPermission, currClassify.IsJoinPermission, node.ChartInfoId, node.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
- }
- }
- }
- return
- }
- func AddChartClassify(chartClassifyName string, parentId, level, source int, lang string, sysUser *system.Admin) (classifyInfo *data_manage.ChartClassify, err error, errMsg string, isSendEmail bool) {
- isSendEmail = true
- errMsg = "保存分类失败"
-
- {
- var count int
- switch lang {
- case utils.EnLangVersion:
- count, err = data_manage.GetChartClassifyEnCount(chartClassifyName, parentId, source)
- default:
- count, err = data_manage.GetChartClassifyCount(chartClassifyName, parentId, source)
- }
- if err != nil {
- errMsg = "判断名称是否已存在失败"
- return
- }
- if count > 0 {
- errMsg = "分类名称已存在,请重新输入"
- err = errors.New(errMsg)
- isSendEmail = false
- return
- }
- }
- if level > 6 {
- errMsg = `最高只支持添加6级分类`
- return
- }
-
- maxSort, err := data_manage.GetChartClassifyMaxSort(parentId, source)
- if err != nil {
- errMsg = "获取失败"
- err = errors.New("查询排序信息失败,Err:" + err.Error())
- return
- }
-
- rootId := 0
- if parentId > 0 {
- parentClassify, tErr := data_manage.GetChartClassifyById(parentId)
- if tErr != nil {
- if utils.IsErrNoRow(tErr) {
- errMsg = "父级分类不存在"
- err = errors.New(errMsg)
- return
- }
- errMsg = "获取失败"
- err = errors.New("获取分类信息失败,Err:" + tErr.Error())
- return
- }
- rootId = parentClassify.RootId
- }
- classifyInfo = new(data_manage.ChartClassify)
- classifyInfo.ParentId = parentId
- classifyInfo.ChartClassifyName = chartClassifyName
- classifyInfo.ChartClassifyNameEn = chartClassifyName
- classifyInfo.HasData = 0
- classifyInfo.CreateTime = time.Now()
- classifyInfo.ModifyTime = time.Now()
- classifyInfo.SysUserId = sysUser.AdminId
- classifyInfo.SysUserRealName = sysUser.RealName
- classifyInfo.Level = level + 1
- timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
- classifyInfo.UniqueCode = utils.MD5(utils.DATA_PREFIX + "_" + timestamp)
- classifyInfo.Sort = maxSort + 1
- classifyInfo.Source = source
- classifyInfo.RootId = rootId
- newId, err := data_manage.AddChartClassify(classifyInfo)
- if err != nil {
- return
- }
- if parentId == 0 {
- classifyInfo.RootId = int(newId)
- err = classifyInfo.Update([]string{"RootId"})
- if err != nil {
- errMsg = "更新分类失败"
- return
- }
- }
-
- if classifyInfo.Source == utils.CHART_SOURCE_DEFAULT {
- go data_manage_permission.InheritParentClassify(5, classifyInfo.Source, classifyInfo.ChartClassifyId, classifyInfo.ParentId, classifyInfo.ChartClassifyName)
- }
- return
- }
- func EditChartClassify(chartClassifyId, source int, chartClassifyName, lang string, sysUser *system.Admin) (classifyInfo *data_manage.ChartClassify, err error, errMsg string, isSendEmail bool) {
- isSendEmail = true
- errMsg = "保存失败"
-
- classifyInfo, err = data_manage.GetChartClassifyById(chartClassifyId)
- if err != nil {
- return
- }
-
- if classifyInfo.Source != source {
- errMsg = "图表分类异常"
- err = errors.New(fmt.Sprintf("图表分类来源异常,修改来源:%d,分类来源:%d", source, classifyInfo.Source))
- isSendEmail = false
- return
- }
-
- updateCols := make([]string, 0)
-
- switch lang {
- case utils.EnLangVersion:
- if classifyInfo.ChartClassifyNameEn != chartClassifyName {
- count, tmpErr := data_manage.GetChartClassifyEnCount(chartClassifyName, classifyInfo.ParentId, source)
- if tmpErr != nil {
- errMsg = "判断名称是否已存在失败"
- err = errors.New("判断名称是否已存在失败,Err:" + tmpErr.Error())
- return
- }
- if count > 0 {
- errMsg = "分类名称已存在,请重新输入"
- err = errors.New(errMsg)
- isSendEmail = false
- return
- }
- classifyInfo.ChartClassifyNameEn = chartClassifyName
- classifyInfo.ModifyTime = time.Now()
- updateCols = append(updateCols, "ChartClassifyNameEn", "ModifyTime")
- }
- default:
- if classifyInfo.ChartClassifyName != chartClassifyName {
- count, tmpErr := data_manage.GetChartClassifyCount(chartClassifyName, classifyInfo.ParentId, source)
- if tmpErr != nil {
- errMsg = "判断名称是否已存在失败"
- err = errors.New("判断名称是否已存在失败,Err:" + tmpErr.Error())
- return
- }
- if count > 0 {
- errMsg = "分类名称已存在,请重新输入"
- err = errors.New(errMsg)
- isSendEmail = false
- return
- }
- classifyInfo.ChartClassifyName = chartClassifyName
- classifyInfo.ModifyTime = time.Now()
- updateCols = append(updateCols, "ChartClassifyName", "ModifyTime")
- }
- }
- if len(updateCols) > 0 {
- err = classifyInfo.Update(updateCols)
- }
- return
- }
- func MoveChartClassify(req data_manage.MoveChartClassifyReq, sysUser *system.Admin, source int) (err error, errMsg string) {
- classifyId := req.ClassifyId
- parentClassifyId := req.ParentClassifyId
- prevClassifyId := req.PrevClassifyId
- nextClassifyId := req.NextClassifyId
- chartInfoId := req.ChartInfoId
- prevChartInfoId := req.PrevChartInfoId
- nextChartInfoId := req.NextChartInfoId
-
-
-
-
-
- var parentChartClassifyInfo *data_manage.ChartClassify
- if parentClassifyId > 0 {
- parentChartClassifyInfo, err = data_manage.GetChartClassifyById(parentClassifyId)
- if err != nil {
- errMsg = "移动失败"
- err = errors.New("获取上级分类信息失败,Err:" + err.Error())
- return
- }
- }
-
- var (
- chartClassifyInfo *data_manage.ChartClassify
- prevClassify *data_manage.ChartClassify
- nextClassify *data_manage.ChartClassify
- chartInfo *data_manage.ChartInfo
- prevChartInfo *data_manage.ChartInfo
- nextChartInfo *data_manage.ChartInfo
- prevSort int
- nextSort int
- )
-
- if chartInfoId == 0 {
- chartClassifyInfo, err = data_manage.GetChartClassifyById(classifyId)
- if err != nil {
- if utils.IsErrNoRow(err) {
- errMsg = "当前分类不存在"
- err = errors.New("获取分类信息失败,Err:" + err.Error())
- return
- }
- errMsg = "移动失败"
- err = errors.New("获取分类信息失败,Err:" + err.Error())
- return
- }
- if parentClassifyId > 0 && parentChartClassifyInfo.Level == 6 {
- errMsg = "最高只支持添加6级分类"
- err = errors.New(errMsg)
- return
- }
-
- exists, e := data_manage.GetChartClassifyByParentIdAndName(source, parentClassifyId, chartClassifyInfo.ChartClassifyName, classifyId)
- if e != nil && !utils.IsErrNoRow(e) {
- errMsg = "移动失败"
- err = fmt.Errorf("获取父级分类下的同名分类失败, Err: %s", e.Error())
- return
- }
- if exists != nil && exists.ChartClassifyId > 0 {
- errMsg = "移动失败,分类名称已存在"
- return
- }
-
- {
-
- permissionClassifyIdList, tmpErr := data_manage_permission.GetUserChartClassifyPermissionList(sysUser.AdminId, classifyId)
- if tmpErr != nil {
- errMsg = "移动失败"
- err = errors.New("获取已授权分类id数据失败,Err:" + tmpErr.Error())
- return
- }
-
- haveOperaAuth := data_manage_permission.CheckChartClassifyPermissionByPermissionIdList(chartClassifyInfo.IsJoinPermission, chartClassifyInfo.ChartClassifyId, permissionClassifyIdList)
- button := GetChartClassifyOpButton(sysUser, chartClassifyInfo.SysUserId, haveOperaAuth)
- if !button.MoveButton {
- errMsg = "无操作权限"
- err = errors.New(errMsg)
- return
- }
- }
- } else {
- chartInfo, err = data_manage.GetChartInfoById(req.ChartInfoId)
- if err != nil {
- if utils.IsErrNoRow(err) {
- errMsg = "当前图表不存在"
- err = errors.New("获取分类信息失败,Err:" + err.Error())
- return
- }
- errMsg = "移动失败"
- err = errors.New("获取分类信息失败,Err:" + err.Error())
- return
- }
- if parentClassifyId == 0 {
- errMsg = "移动失败,图表必须挂在分类下"
- err = errors.New(errMsg)
- return
- }
- var haveOperaAuth bool
-
- {
- haveOperaAuth, err = data_manage_permission.CheckChartPermissionByChartInfoId(chartInfo.ChartInfoId, chartInfo.ChartClassifyId, chartInfo.IsJoinPermission, sysUser.AdminId)
- if err != nil {
- errMsg = "移动失败"
- err = errors.New("获取图表权限信息失败,Err:" + err.Error())
- return
- }
- }
-
- button := GetChartOpButton(sysUser, chartInfo.SysUserId, haveOperaAuth)
- if !button.MoveButton {
- errMsg = "无操作权限"
- err = errors.New(errMsg)
- return
- }
- }
- if prevClassifyId > 0 {
- prevClassify, err = data_manage.GetChartClassifyById(prevClassifyId)
- if err != nil {
- errMsg = "移动失败"
- err = errors.New("获取上一个兄弟节点分类信息失败,Err:" + err.Error())
- return
- }
- prevSort = prevClassify.Sort
- } else if prevChartInfoId > 0 {
- prevChartInfo, err = data_manage.GetChartInfoById(prevChartInfoId)
- if err != nil {
- errMsg = "移动失败"
- err = errors.New("获取上一个兄弟节点分类信息失败,Err:" + err.Error())
- return
- }
- prevSort = prevChartInfo.Sort
- }
- if nextClassifyId > 0 {
-
- nextClassify, err = data_manage.GetChartClassifyById(nextClassifyId)
- if err != nil {
- errMsg = "移动失败"
- err = errors.New("获取下一个兄弟节点分类信息失败,Err:" + err.Error())
- return
- }
- nextSort = nextClassify.Sort
- } else if nextChartInfoId > 0 {
-
- nextChartInfo, err = data_manage.GetChartInfoById(nextChartInfoId)
- if err != nil {
- errMsg = "移动失败"
- err = errors.New("获取下一个兄弟节点分类信息失败,Err:" + err.Error())
- return
- }
- nextSort = nextChartInfo.Sort
- }
- err, errMsg = moveChartClassify(parentChartClassifyInfo, chartClassifyInfo, prevClassify, nextClassify, chartInfo, prevChartInfo, nextChartInfo, parentClassifyId, prevSort, nextSort, source)
- return
- }
- func moveChartClassify(parentChartClassifyInfo, chartClassifyInfo, prevClassify, nextClassify *data_manage.ChartClassify, chartInfo, prevChartInfo, nextChartInfo *data_manage.ChartInfo, parentClassifyId, prevSort, nextSort, source int) (err error, errMsg string) {
- updateCol := make([]string, 0)
-
- if chartClassifyInfo != nil {
- oldParentId := chartClassifyInfo.ParentId
- oldLevel := chartClassifyInfo.Level
- var classifyIds []int
- if oldParentId != parentClassifyId {
-
- childList, e, m := GetChildChartClassifyByClassifyId(chartClassifyInfo.ChartClassifyId)
- if e != nil {
- errMsg = "移动失败"
- err = errors.New("查询子分类失败,Err:" + e.Error() + m)
- return
- }
- if len(childList) > 0 {
- for _, v := range childList {
- if v.ChartClassifyId == chartClassifyInfo.ChartClassifyId {
- continue
- }
- classifyIds = append(classifyIds, v.ChartClassifyId)
- }
- }
- }
-
- if chartClassifyInfo.ParentId != parentClassifyId && parentClassifyId != 0 {
- if chartClassifyInfo.Level != parentChartClassifyInfo.Level+1 {
- errMsg = "移动失败"
- err = errors.New("不支持目录层级变更")
- return
- }
- chartClassifyInfo.ParentId = parentChartClassifyInfo.ChartClassifyId
- chartClassifyInfo.RootId = parentChartClassifyInfo.RootId
- chartClassifyInfo.Level = parentChartClassifyInfo.Level + 1
- chartClassifyInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "ParentId", "RootId", "Level", "ModifyTime")
- } else if chartClassifyInfo.ParentId != parentClassifyId && parentClassifyId == 0 {
- errMsg = "移动失败"
- err = errors.New("不支持目录层级变更")
- return
- }
- if prevSort > 0 {
-
- if nextSort > 0 {
-
-
- if prevSort == nextSort || prevSort == chartClassifyInfo.Sort {
-
- updateSortStr := `sort + 2`
-
- if prevClassify != nil {
- _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, prevClassify.ChartClassifyId, prevClassify.Sort, updateSortStr, source)
- } else {
- _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, 0, prevSort, updateSortStr, source)
- }
-
- if prevChartInfo != nil {
-
- _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, prevChartInfo.ChartInfoId, updateSortStr)
- } else {
- _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, 0, updateSortStr)
- }
- } else {
-
- if nextSort-prevSort == 1 {
-
- updateSortStr := `sort + 1`
-
- if prevClassify != nil {
- _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, prevClassify.ChartClassifyId, prevSort, updateSortStr, source)
- } else {
- _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, 0, prevSort, updateSortStr, source)
- }
-
- if prevChartInfo != nil {
-
- _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, prevChartInfo.ChartInfoId, updateSortStr)
- } else {
- _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, 0, updateSortStr)
- }
- }
- }
- }
- chartClassifyInfo.Sort = prevSort + 1
- chartClassifyInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- } else if prevClassify == nil && nextClassify == nil && prevChartInfo == nil && nextChartInfo == nil && parentClassifyId > 0 {
-
- var maxSort int
- maxSort, err = GetChartClassifyMaxSort(parentClassifyId, source)
- if err != nil {
- errMsg = "移动失败"
- err = errors.New("查询组内排序信息失败,Err:" + err.Error())
- return
- }
- chartClassifyInfo.Sort = maxSort + 1
- chartClassifyInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- } else {
-
- firstClassify, tmpErr := data_manage.GetFirstChartClassifyByParentId(parentClassifyId)
- if tmpErr != nil && !utils.IsErrNoRow(tmpErr) {
- errMsg = "移动失败"
- err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error())
- return
- }
-
- if firstClassify != nil && firstClassify.ChartClassifyId > 0 && firstClassify.Sort == 0 {
- updateSortStr := ` sort + 1 `
- _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, firstClassify.ChartClassifyId-1, 0, updateSortStr, source)
-
- _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, 0, 0, updateSortStr)
- } else {
-
- firstEdb, tErr := data_manage.GetFirstChartInfoByClassifyId(parentClassifyId)
- if tErr != nil && !utils.IsErrNoRow(tErr) {
- errMsg = "移动失败"
- err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tErr.Error())
- return
- }
-
- if firstEdb != nil && firstEdb.ChartClassifyId > 0 && firstEdb.Sort == 0 {
- updateSortStr := ` sort + 1 `
- _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, 0, firstEdb.ChartInfoId-1, updateSortStr)
- _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, 0, 0, updateSortStr, source)
- }
- }
- chartClassifyInfo.Sort = 0
- chartClassifyInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- }
-
- if len(updateCol) > 0 {
- err = chartClassifyInfo.Update(updateCol)
- if err != nil {
- errMsg = "移动失败"
- err = errors.New("修改失败,Err:" + err.Error())
- return
- }
-
- if oldParentId != parentClassifyId {
- if len(classifyIds) > 0 {
- levelStep := chartClassifyInfo.Level - oldLevel
- err = data_manage.UpdateEdbClassifyChildByParentClassifyId(classifyIds, chartClassifyInfo.RootId, levelStep)
- if err != nil {
- errMsg = "移动失败"
- err = errors.New("更新子分类失败,Err:" + err.Error())
- return
- }
- }
- }
- }
- } else {
- if chartInfo == nil {
- errMsg = "当前图表不存在"
- err = errors.New(errMsg)
- return
- }
-
- if chartInfo.ChartClassifyId != parentClassifyId {
- chartInfo.ChartClassifyId = parentClassifyId
- chartInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "ChartClassifyId", "ModifyTime")
- }
- if prevSort > 0 {
-
- if nextSort > 0 {
-
-
- if prevSort == nextSort || prevSort == chartInfo.Sort {
-
- updateSortStr := `sort + 2`
-
- if prevClassify != nil {
- _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, prevClassify.ChartClassifyId, prevClassify.Sort, updateSortStr, source)
- } else {
- _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, 0, prevSort, updateSortStr, source)
- }
-
- if prevChartInfo != nil {
-
- _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, prevChartInfo.ChartInfoId, updateSortStr)
- } else {
- _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, 0, updateSortStr)
- }
- } else {
-
- if nextSort-prevSort == 1 {
-
- updateSortStr := `sort + 1`
-
- if prevClassify != nil {
- _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, prevClassify.ChartClassifyId, prevSort, updateSortStr, source)
- } else {
- _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, 0, prevSort, updateSortStr, source)
- }
-
- if prevChartInfo != nil {
-
- _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, prevChartInfo.ChartInfoId, updateSortStr)
- } else {
- _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, prevSort, 0, updateSortStr)
- }
- }
- }
- }
- chartInfo.Sort = prevSort + 1
- chartInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- } else if prevClassify == nil && nextClassify == nil && prevChartInfo == nil && nextChartInfo == nil && parentClassifyId > 0 {
-
- var maxSort int
- maxSort, err = GetChartClassifyMaxSort(parentClassifyId, source)
- if err != nil {
- errMsg = "移动失败"
- err = errors.New("查询组内排序信息失败,Err:" + err.Error())
- return
- }
- chartInfo.Sort = maxSort + 1
- chartInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- } else {
-
- firstClassify, tmpErr := data_manage.GetFirstChartClassifyByParentId(parentClassifyId)
- if tmpErr != nil && !utils.IsErrNoRow(tmpErr) {
- errMsg = "移动失败"
- err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error())
- return
- }
-
- if firstClassify != nil && firstClassify.ChartClassifyId > 0 && firstClassify.Sort == 0 {
- updateSortStr := ` sort + 1 `
- _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, firstClassify.ChartClassifyId-1, 0, updateSortStr, source)
-
- _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, 0, 0, updateSortStr)
- } else {
-
- firstEdb, tErr := data_manage.GetFirstChartInfoByClassifyId(parentClassifyId)
- if tErr != nil && !utils.IsErrNoRow(tErr) {
- errMsg = "移动失败"
- err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tErr.Error())
- return
- }
-
- if firstEdb != nil && firstEdb.ChartClassifyId > 0 && firstEdb.Sort == 0 {
- updateSortStr := ` sort + 1 `
- _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, 0, firstEdb.ChartInfoId-1, updateSortStr)
- _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, 0, 0, updateSortStr, source)
- }
- }
- chartInfo.Sort = 0
- chartInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- }
-
- if len(updateCol) > 0 {
- err = chartInfo.Update(updateCol)
- if err != nil {
- errMsg = "移动失败"
- err = errors.New("修改失败,Err:" + err.Error())
- return
- }
- }
- }
- return
- }
- func GetChildChartClassifyByClassifyId(targetClassifyId int) (targetList []*data_manage.ChartClassifyIdItems, err error, errMsg string) {
-
- targetClassify, err := data_manage.GetChartClassifyById(targetClassifyId)
- if err != nil {
- if utils.IsErrNoRow(err) {
- errMsg = "当前分类不存在"
- err = errors.New(errMsg)
- return
- }
- errMsg = "获取失败"
- err = errors.New("获取分类信息失败,Err:" + err.Error())
- return
- }
- orderStr := ` order by level asc, sort asc, chart_classify_id asc`
- tmpList, err := data_manage.GetChartClassifyByRootIdLevel(targetClassify.RootId, targetClassify.Source, orderStr)
- if err != nil && !utils.IsErrNoRow(err) {
- errMsg = "获取失败"
- err = errors.New("获取数据失败,Err:" + err.Error())
- return
- }
- idMap := make(map[int]struct{})
- if len(tmpList) > 0 {
- for _, v := range tmpList {
- if v.ChartClassifyId == targetClassify.ChartClassifyId {
- idMap[v.ChartClassifyId] = struct{}{}
- }
- }
- for _, v := range tmpList {
- if _, ok := idMap[v.ParentId]; ok {
- idMap[v.ChartClassifyId] = struct{}{}
- }
- }
- for _, v := range tmpList {
- if _, ok := idMap[v.ChartClassifyId]; ok {
- targetItem := new(data_manage.ChartClassifyIdItems)
- targetItem.ChartClassifyId = v.ChartClassifyId
- targetItem.ParentId = v.ParentId
- targetItem.RootId = v.RootId
- targetItem.UniqueCode = v.UniqueCode
- targetItem.Level = v.Level
- targetItem.ChartClassifyName = v.ChartClassifyName
- targetItem.IsJoinPermission = v.IsJoinPermission
- targetList = append(targetList, targetItem)
- }
- }
- }
- return
- }
- func GetChartClassifyMaxSort(parentId, source int) (maxSort int, err error) {
-
- classifyMaxSort, err := data_manage.GetChartClassifyMaxSort(parentId, source)
- if err != nil {
- return
- }
- maxSort = classifyMaxSort
- edbMaxSort, err := data_manage.GetChartInfoMaxSortByClassifyId(parentId)
- if err != nil {
- return
- }
- if maxSort < edbMaxSort {
- maxSort = edbMaxSort
- }
- return
- }
- func GetChartClassifyTreeRecursive(list []*data_manage.ChartClassifyItems, parentId int) []*data_manage.ChartClassifyItems {
- res := make([]*data_manage.ChartClassifyItems, 0)
- for _, v := range list {
- if v.ParentId == parentId {
- v.Children = GetChartClassifyTreeRecursive(list, v.ChartClassifyId)
- res = append(res, v)
- }
- }
- return res
- }
- func GetChartClassifyParentRecursive(list []*data_manage.ChartClassifyItems, classifyId int) []*data_manage.ChartClassifyItems {
- res := make([]*data_manage.ChartClassifyItems, 0)
- for _, v := range list {
- if v.ChartClassifyId == classifyId {
- if v.ParentId > 0 {
- res = GetChartClassifyParentRecursive(list, v.ParentId)
- }
- res = append(res, v)
- }
- }
- return res
- }
- func GetChartClassifyChildIds(classifyId int, classifymap map[int]*data_manage.ChartClassifyItems, childIds *[]int) {
- for _, item := range classifymap {
- if item.ParentId == classifyId {
- *childIds = append(*childIds, item.ChartClassifyId)
- GetChartClassifyChildIds(item.ChartClassifyId, classifymap, childIds)
- }
- }
- }
|