|
@@ -366,8 +366,9 @@ func MoveSciHqClassify(classifyId, parentClassifyId, prevClassifyId, nextClassif
|
|
|
classifyInfo.Level = parentClassifyInfo.Level + 1
|
|
|
updateCol = append(updateCol, "ParentId", "Level")
|
|
|
}
|
|
|
- var currentSort, prevSort, nextSort int
|
|
|
- currentSort = classifyInfo.Sort
|
|
|
+ var prevSort, nextSort int
|
|
|
+ //var currentSort, prevSort, nextSort int
|
|
|
+ //currentSort = classifyInfo.Sort
|
|
|
|
|
|
var prevClassify *data_manage.BaseFromSciHqClassify
|
|
|
var nextClassify *data_manage.BaseFromSciHqClassify
|
|
@@ -425,25 +426,97 @@ func MoveSciHqClassify(classifyId, parentClassifyId, prevClassifyId, nextClassif
|
|
|
}
|
|
|
}
|
|
|
//移到两个排序值中间操作
|
|
|
- if prevSort >= currentSort {
|
|
|
- //往下移动
|
|
|
- err = data_manage.MoveDownSciHqIndexClassifyBySort(parentClassifyId, prevSort, currentSort)
|
|
|
+ //if prevSort >= currentSort {
|
|
|
+ // //往下移动
|
|
|
+ // err = data_manage.MoveDownSciHqIndexClassifyBySort(parentClassifyId, prevSort, currentSort)
|
|
|
+ // if err != nil {
|
|
|
+ // err = errors.New("向下移动出错:" + err.Error())
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ // classifyInfo.Sort = prevSort
|
|
|
+ //} else if nextSort <= currentSort && nextSort != 0 {
|
|
|
+ // //往上移动
|
|
|
+ // err = data_manage.MoveUpSciHqIndexClassifyBySort(parentClassifyId, nextSort, currentSort)
|
|
|
+ // if err != nil {
|
|
|
+ // err = errors.New("向上移动出错:" + err.Error())
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ // classifyInfo.Sort = nextSort
|
|
|
+ //}
|
|
|
+ //classifyInfo.ModifyTime = time.Now()
|
|
|
+ //updateCol = append(updateCol, "Sort", "ModifyTime")
|
|
|
+ //err = classifyInfo.Update(updateCol)
|
|
|
+ //if err != nil {
|
|
|
+ // errMsg = "移动失败"
|
|
|
+ // err = errors.New("修改失败,Err:" + err.Error())
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+
|
|
|
+ if prevSort > 0 {
|
|
|
+ //如果是移动在两个兄弟节点之间
|
|
|
+ if nextSort > 0 {
|
|
|
+ //下一个兄弟节点
|
|
|
+ //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
|
|
|
+ if prevSort == nextSort || prevSort == classifyInfo.Sort {
|
|
|
+ //变更兄弟节点的排序
|
|
|
+ updateSortStr := `sort + 2`
|
|
|
+
|
|
|
+ //变更分类
|
|
|
+ if prevClassify != nil {
|
|
|
+ _ = data_manage.UpdateSciHqClassifySortByParentId(parentClassifyId, prevClassify.ClassifyId, prevClassify.Sort, updateSortStr)
|
|
|
+ } else {
|
|
|
+ _ = data_manage.UpdateSciHqClassifySortByParentId(parentClassifyId, 0, prevSort, updateSortStr)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
|
|
|
+ if nextSort-prevSort == 1 {
|
|
|
+ //变更兄弟节点的排序
|
|
|
+ updateSortStr := `sort + 1`
|
|
|
+
|
|
|
+ //变更分类
|
|
|
+ if prevClassify != nil {
|
|
|
+ _ = data_manage.UpdateSciHqClassifySortByParentId(parentClassifyId, prevClassify.ClassifyId, prevSort, updateSortStr)
|
|
|
+ } else {
|
|
|
+ _ = data_manage.UpdateSciHqClassifySortByParentId(parentClassifyId, 0, prevSort, updateSortStr)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ classifyInfo.Sort = prevSort + 1
|
|
|
+ classifyInfo.ModifyTime = time.Now()
|
|
|
+ updateCol = append(updateCol, "Sort", "ModifyTime")
|
|
|
+ } else if prevClassify == nil && nextClassify == nil && parentClassifyId > 0 {
|
|
|
+ //处理只拖动到目录里,默认放到目录底部的情况
|
|
|
+ var maxSort int
|
|
|
+ maxSort, err = data_manage.GetSciHqClassifySortMaxByParentId(parentClassifyId)
|
|
|
if err != nil {
|
|
|
- err = errors.New("向下移动出错:" + err.Error())
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("查询组内排序信息失败,Err:" + err.Error())
|
|
|
return
|
|
|
}
|
|
|
- classifyInfo.Sort = prevSort
|
|
|
- } else if nextSort <= currentSort && nextSort != 0 {
|
|
|
- //往上移动
|
|
|
- err = data_manage.MoveUpSciHqIndexClassifyBySort(parentClassifyId, nextSort, currentSort)
|
|
|
- if err != nil {
|
|
|
- err = errors.New("向上移动出错:" + err.Error())
|
|
|
+ classifyInfo.Sort = maxSort + 1 //那就是排在组内最后一位
|
|
|
+ classifyInfo.ModifyTime = time.Now()
|
|
|
+ updateCol = append(updateCol, "Sort", "ModifyTime")
|
|
|
+ } else {
|
|
|
+ // 拖动到父级分类的第一位
|
|
|
+ firstClassify, tmpErr := data_manage.GetFirstSciHqClassifyByParentId(parentClassifyId)
|
|
|
+ if tmpErr != nil && !utils.IsErrNoRow(tmpErr) {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + tmpErr.Error())
|
|
|
return
|
|
|
}
|
|
|
- classifyInfo.Sort = nextSort
|
|
|
+
|
|
|
+ //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
|
|
|
+ if firstClassify != nil && firstClassify.Sort == 0 {
|
|
|
+ updateSortStr := ` sort + 1 `
|
|
|
+ _ = data_manage.UpdateSciHqClassifySortByParentId(parentClassifyId, firstClassify.ClassifyId-1, 0, updateSortStr)
|
|
|
+ }
|
|
|
+ classifyInfo.Sort = 0 //那就是排在第一位
|
|
|
+ classifyInfo.ModifyTime = time.Now()
|
|
|
+ updateCol = append(updateCol, "Sort", "ModifyTime")
|
|
|
}
|
|
|
- classifyInfo.ModifyTime = time.Now()
|
|
|
- updateCol = append(updateCol, "Sort", "ModifyTime")
|
|
|
+
|
|
|
err = classifyInfo.Update(updateCol)
|
|
|
if err != nil {
|
|
|
errMsg = "移动失败"
|