|
@@ -244,6 +244,7 @@ func AddChartClassify(chartClassifyName string, parentId, level, source int, lan
|
|
|
}
|
|
|
//查询顶级rootId
|
|
|
rootId := 0
|
|
|
+ var classifyNamePath, classifyIdPath string
|
|
|
if parentId > 0 {
|
|
|
parentClassify, tErr := data_manage.GetChartClassifyById(parentId)
|
|
|
if tErr != nil {
|
|
@@ -257,6 +258,10 @@ func AddChartClassify(chartClassifyName string, parentId, level, source int, lan
|
|
|
return
|
|
|
}
|
|
|
rootId = parentClassify.RootId
|
|
|
+ classifyNamePath = fmt.Sprint(parentClassify.ChartClassifyNamePath, "|", chartClassifyName)
|
|
|
+ classifyIdPath = fmt.Sprint(parentClassify.ChartClassifyIdPath, ",")
|
|
|
+ } else {
|
|
|
+ classifyNamePath = chartClassifyName
|
|
|
}
|
|
|
|
|
|
classifyInfo = new(data_manage.ChartClassify)
|
|
@@ -274,18 +279,24 @@ func AddChartClassify(chartClassifyName string, parentId, level, source int, lan
|
|
|
classifyInfo.Sort = maxSort + 1
|
|
|
classifyInfo.Source = source
|
|
|
classifyInfo.RootId = rootId
|
|
|
+ classifyInfo.ChartClassifyNamePath = classifyNamePath
|
|
|
|
|
|
- newId, err := data_manage.AddChartClassify(classifyInfo)
|
|
|
+ err = data_manage.AddChartClassify(classifyInfo)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+ // 更改分类id完整路径path
|
|
|
+ updateCols := []string{"ClassifyIdPath"}
|
|
|
+ classifyInfo.ChartClassifyIdPath = fmt.Sprint(classifyIdPath, classifyInfo.ChartClassifyId)
|
|
|
if parentId == 0 { //一级目录的rootId等于自己本身
|
|
|
- classifyInfo.RootId = int(newId)
|
|
|
- err = classifyInfo.Update([]string{"RootId"})
|
|
|
- if err != nil {
|
|
|
- errMsg = "更新分类失败"
|
|
|
- return
|
|
|
- }
|
|
|
+ classifyInfo.RootId = classifyInfo.ChartClassifyId
|
|
|
+ updateCols = append(updateCols, "RootId")
|
|
|
+ }
|
|
|
+ err = classifyInfo.Update(updateCols)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "更新分类失败"
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
//// 目前只有ETA图库需要继承分类权限
|
|
@@ -329,6 +340,8 @@ func EditChartClassify(chartClassifyId, source int, chartClassifyName, lang stri
|
|
|
|
|
|
// 需要变更的字段
|
|
|
updateCols := make([]string, 0)
|
|
|
+ // 旧完整路径 , 新的完整路径
|
|
|
+ var oldClassifyNamePath, newClassifyNamePath string
|
|
|
|
|
|
// 语言版本校验
|
|
|
switch lang {
|
|
@@ -353,27 +366,41 @@ func EditChartClassify(chartClassifyId, source int, chartClassifyName, lang stri
|
|
|
}
|
|
|
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
|
|
|
+ //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
|
|
|
+ //}
|
|
|
+ // 旧完整路径
|
|
|
+ oldClassifyNamePath = classifyInfo.ChartClassifyNamePath
|
|
|
+
|
|
|
+ if classifyInfo.ParentId > 0 {
|
|
|
+ parentItem, tmpErr := data_manage.GetChartClassifyById(classifyInfo.ParentId)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ newClassifyNamePath = fmt.Sprint(parentItem.ChartClassifyNamePath, "|", chartClassifyName)
|
|
|
+ } else {
|
|
|
+ newClassifyNamePath = chartClassifyName
|
|
|
}
|
|
|
|
|
|
classifyInfo.ChartClassifyName = chartClassifyName
|
|
|
classifyInfo.ModifyTime = time.Now()
|
|
|
- updateCols = append(updateCols, "ChartClassifyName", "ModifyTime")
|
|
|
+ classifyInfo.ChartClassifyNamePath = newClassifyNamePath
|
|
|
+ updateCols = append(updateCols, "ChartClassifyName", "ModifyTime", "ChartClassifyNamePath")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if len(updateCols) > 0 {
|
|
|
- err = classifyInfo.Update(updateCols)
|
|
|
+ err = classifyInfo.UpdateClassifyNameAndNamePath(updateCols, oldClassifyNamePath, newClassifyNamePath)
|
|
|
}
|
|
|
|
|
|
return
|
|
@@ -546,12 +573,298 @@ func MoveChartClassify(req data_manage.MoveChartClassifyReq, sysUser *system.Adm
|
|
|
nextSort = nextChartInfo.Sort
|
|
|
}
|
|
|
|
|
|
- err, errMsg = moveChartClassify(parentChartClassifyInfo, chartClassifyInfo, prevClassify, nextClassify, chartInfo, prevChartInfo, nextChartInfo, parentClassifyId, prevSort, nextSort, source)
|
|
|
+ err, errMsg = moveChartOrClassify(parentChartClassifyInfo, chartClassifyInfo, prevClassify, nextClassify, chartInfo, prevChartInfo, nextChartInfo, parentClassifyId, prevSort, nextSort, source)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// moveChartClassify 移动图表分类
|
|
|
-func moveChartClassify(parentChartClassifyInfo, chartClassifyInfo, prevClassify, nextClassify *data_manage.ChartClassify, chartInfo, prevChartInfo, nextChartInfo *data_manage.ChartInfo, parentClassifyId, prevSort, nextSort, source int) (err error, errMsg string) {
|
|
|
+func moveChartOrClassify(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 {
|
|
|
+ //更新子分类对应的level
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
|
|
|
+ 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 {
|
|
|
+ //下一个兄弟节点
|
|
|
+ //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
|
|
|
+ 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
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
|
|
|
+ if firstClassify != nil && firstClassify.ChartClassifyId > 0 && firstClassify.Sort == 0 {
|
|
|
+ updateSortStr := ` sort + 1 `
|
|
|
+ _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, firstClassify.ChartClassifyId-1, 0, updateSortStr, source)
|
|
|
+ //该分类下的所有图表也需要+1
|
|
|
+ _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, 0, 0, updateSortStr)
|
|
|
+ } else {
|
|
|
+ //如果该分类下存在图表,且第一个图表的排序等于0,那么需要调整排序
|
|
|
+ firstEdb, tErr := data_manage.GetFirstChartInfoByClassifyId(parentClassifyId)
|
|
|
+ if tErr != nil && !utils.IsErrNoRow(tErr) {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tErr.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ //更新对应分类的root_id和层级
|
|
|
+ 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 {
|
|
|
+ //下一个兄弟节点
|
|
|
+ //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
|
|
|
+ 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
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
|
|
|
+ if firstClassify != nil && firstClassify.ChartClassifyId > 0 && firstClassify.Sort == 0 {
|
|
|
+ updateSortStr := ` sort + 1 `
|
|
|
+ _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, firstClassify.ChartClassifyId-1, 0, updateSortStr, source)
|
|
|
+ //该分类下的所有图表也需要+1
|
|
|
+ _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, 0, 0, updateSortStr)
|
|
|
+ } else {
|
|
|
+ //如果该分类下存在图表,且第一个图表的排序等于0,那么需要调整排序
|
|
|
+ firstEdb, tErr := data_manage.GetFirstChartInfoByClassifyId(parentClassifyId)
|
|
|
+ if tErr != nil && !utils.IsErrNoRow(tErr) {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tErr.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
|
|
|
+ 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 moveChart(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)
|
|
|
|
|
|
// 移动对象为分类, 判断分类是否存在
|
|
@@ -839,6 +1152,185 @@ func moveChartClassify(parentChartClassifyInfo, chartClassifyInfo, prevClassify,
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+// moveChartClassify 移动图表分类
|
|
|
+func moveChartClassify(parentChartClassifyInfo, chartClassifyInfo, prevClassify, nextClassify *data_manage.ChartClassify, prevChartInfo, nextChartInfo *data_manage.ChartInfo, parentClassifyId, prevSort, nextSort, source int) (err error, errMsg string) {
|
|
|
+ updateCol := make([]string, 0)
|
|
|
+
|
|
|
+ oldParentId := chartClassifyInfo.ParentId
|
|
|
+ oldLevel := chartClassifyInfo.Level
|
|
|
+ var classifyIds []int
|
|
|
+ if oldParentId != parentClassifyId {
|
|
|
+ //更新子分类对应的level
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
|
|
|
+ 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 {
|
|
|
+ //下一个兄弟节点
|
|
|
+ //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
|
|
|
+ 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
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
|
|
|
+ if firstClassify != nil && firstClassify.ChartClassifyId > 0 && firstClassify.Sort == 0 {
|
|
|
+ updateSortStr := ` sort + 1 `
|
|
|
+ _ = data_manage.UpdateChartClassifySortByParentIdAndSource(parentClassifyId, firstClassify.ChartClassifyId-1, 0, updateSortStr, source)
|
|
|
+ //该分类下的所有图表也需要+1
|
|
|
+ _ = data_manage.UpdateChartInfoSortByClassifyIdV2(parentClassifyId, 0, 0, updateSortStr)
|
|
|
+ } else {
|
|
|
+ //如果该分类下存在图表,且第一个图表的排序等于0,那么需要调整排序
|
|
|
+ firstEdb, tErr := data_manage.GetFirstChartInfoByClassifyId(parentClassifyId)
|
|
|
+ if tErr != nil && !utils.IsErrNoRow(tErr) {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tErr.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
|
|
|
+ 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")
|
|
|
+ }
|
|
|
+
|
|
|
+ oldClassifyIdPath := chartClassifyInfo.ChartClassifyIdPath
|
|
|
+ oldClassifyNamePath := chartClassifyInfo.ChartClassifyNamePath
|
|
|
+ newClassifyNamePath := fmt.Sprint(chartClassifyInfo.ChartClassifyNamePath, `|`, chartClassifyInfo.ChartClassifyName)
|
|
|
+ newClassifyIdPath := fmt.Sprint(chartClassifyInfo.ChartClassifyIdPath, `,`, chartClassifyInfo.ChartClassifyId)
|
|
|
+
|
|
|
+ //更新
|
|
|
+ if len(updateCol) > 0 {
|
|
|
+ err = chartClassifyInfo.Update(updateCol)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("修改失败,Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //更新对应分类的root_id和层级
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更改了上级分类,那么需要同步去更改自己的分类全路径
|
|
|
+ tmpErr := data_manage.UpdateChartClassifyNameAndNamePathByOldClassifyIdPath(oldClassifyIdPath, newClassifyIdPath, oldClassifyNamePath, newClassifyNamePath)
|
|
|
+ if tmpErr != nil {
|
|
|
+ utils.FileLog.Error(fmt.Sprintf("更新图表分类全路径失败,分类id:%d;失败原因Err:%s", chartClassifyInfo.ChartClassifyId, tmpErr.Error()))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
func GetChildChartClassifyByClassifyId(targetClassifyId int) (targetList []*data_manage.ChartClassifyIdItems, err error, errMsg string) {
|
|
|
//判断是否是挂在顶级目录下
|
|
|
targetClassify, err := data_manage.GetChartClassifyById(targetClassifyId)
|