浏览代码

移动分类调整

xyxie 1 年之前
父节点
当前提交
5ca101f204
共有 2 个文件被更改,包括 34 次插入6 次删除
  1. 4 2
      models/data_manage/edb_info.go
  2. 30 4
      services/data/edb_classify.go

+ 4 - 2
models/data_manage/edb_info.go

@@ -732,9 +732,11 @@ func GetFirstEdbInfoByClassifyId(classifyId int) (item *EdbInfo, err error) {
 // UpdateEdbInfoSortByClassifyId 根据分类id更新排序
 func UpdateEdbInfoSortByClassifyId(classifyId, nowSort int, prevEdbInfoId int, updateSort string) (err error) {
 	o := orm.NewOrmUsingDB("data")
-	sql := ` update edb_info set sort = ` + updateSort + ` WHERE classify_id=? AND `
+	sql := ` update edb_info set sort = ` + updateSort + ` WHERE classify_id=?`
 	if prevEdbInfoId > 0 {
-		sql += ` ( sort > ? or ( edb_info_id > ` + fmt.Sprint(prevEdbInfoId) + ` and sort=` + fmt.Sprint(nowSort) + ` )) `
+		sql += ` AND ( sort > ? or ( edb_info_id > ` + fmt.Sprint(prevEdbInfoId) + ` and sort=` + fmt.Sprint(nowSort) + ` )) `
+	} else {
+		sql += ` AND ( sort > ? )`
 	}
 	_, err = o.Raw(sql, classifyId, nowSort).Exec()
 	return

+ 30 - 4
services/data/edb_classify.go

@@ -863,8 +863,22 @@ func moveEdbClassify(parentEdbClassifyInfo, edbClassifyInfo, prevClassify, nextC
 					if nextSort-prevSort == 1 {
 						//变更兄弟节点的排序
 						updateSortStr := `sort + 1`
-						_ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, prevSort, updateSortStr, classifyType)
-						_ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, 0, updateSortStr)
+
+						//变更分类
+						if prevClassify != nil {
+							_ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, prevClassify.ClassifyId, prevSort, updateSortStr, classifyType)
+						} else {
+							_ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, prevSort, updateSortStr, classifyType)
+						}
+
+						//变更指标
+						if prevEdbInfo != nil {
+							//变更兄弟节点的排序
+							_ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, prevEdbInfo.EdbInfoId, updateSortStr)
+						} else {
+							_ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, 0, updateSortStr)
+						}
+
 					}
 				}
 			}
@@ -982,8 +996,20 @@ func moveEdbClassify(parentEdbClassifyInfo, edbClassifyInfo, prevClassify, nextC
 					if nextSort-prevSort == 1 {
 						//变更兄弟节点的排序
 						updateSortStr := `sort + 1`
-						_ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, prevSort, updateSortStr, classifyType)
-						_ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, 0, updateSortStr)
+						//变更分类
+						if prevClassify != nil {
+							_ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, prevClassify.ClassifyId, prevSort, updateSortStr, classifyType)
+						} else {
+							_ = data_manage.UpdateEdbClassifySortByParentId(parentClassifyId, 0, prevSort, updateSortStr, classifyType)
+						}
+
+						//变更指标
+						if prevEdbInfo != nil {
+							//变更兄弟节点的排序
+							_ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, prevEdbInfo.EdbInfoId, updateSortStr)
+						} else {
+							_ = data_manage.UpdateEdbInfoSortByClassifyId(parentClassifyId, prevSort, 0, updateSortStr)
+						}
 					}
 				}
 			}