|
@@ -659,8 +659,30 @@ func MoveEdbClassify(req data_manage.MoveEdbClassifyReq, sysUser *system.Admin,
|
|
|
// moveEdbClassify 移动指标分类
|
|
|
func moveEdbClassify(parentEdbClassifyInfo, edbClassifyInfo, prevClassify, nextClassify *data_manage.EdbClassify, edbInfo, prevEdbInfo, nextEdbInfo *data_manage.EdbInfo, parentClassifyId int, prevSort, nextSort int, classifyType uint8) (err error, errMsg string) {
|
|
|
updateCol := make([]string, 0)
|
|
|
+
|
|
|
// 移动对象为分类, 判断分类是否存在
|
|
|
if edbClassifyInfo != nil {
|
|
|
+ oldParentId := edbClassifyInfo.ParentId
|
|
|
+ oldLevel := edbClassifyInfo.Level
|
|
|
+ var classifyIds []int
|
|
|
+ if oldParentId != parentClassifyId {
|
|
|
+ //更新子分类对应的level
|
|
|
+ childList, e, m := GetChildClassifyByClassifyId(edbClassifyInfo.ClassifyId)
|
|
|
+ if e != nil {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("查询子分类失败,Err:" + e.Error() + m)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(childList) > 0 {
|
|
|
+ for _, v := range childList {
|
|
|
+ if v.ClassifyId == edbClassifyInfo.ClassifyId {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ classifyIds = append(classifyIds, v.ClassifyId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
//判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
|
|
|
if edbClassifyInfo.ParentId != parentClassifyId && parentClassifyId != 0 {
|
|
|
edbClassifyInfo.ParentId = parentEdbClassifyInfo.ClassifyId
|
|
@@ -668,6 +690,12 @@ func moveEdbClassify(parentEdbClassifyInfo, edbClassifyInfo, prevClassify, nextC
|
|
|
edbClassifyInfo.Level = parentEdbClassifyInfo.Level + 1
|
|
|
edbClassifyInfo.ModifyTime = time.Now()
|
|
|
updateCol = append(updateCol, "ParentId", "RootId", "Level", "ModifyTime")
|
|
|
+ } else if edbClassifyInfo.ParentId != parentClassifyId && parentClassifyId == 0 {
|
|
|
+ edbClassifyInfo.ParentId = 0
|
|
|
+ edbClassifyInfo.RootId = edbClassifyInfo.ClassifyId
|
|
|
+ edbClassifyInfo.Level = 1
|
|
|
+ edbClassifyInfo.ModifyTime = time.Now()
|
|
|
+ updateCol = append(updateCol, "ParentId", "RootId", "Level", "ModifyTime")
|
|
|
}
|
|
|
|
|
|
if prevSort > 0 {
|
|
@@ -764,6 +792,18 @@ func moveEdbClassify(parentEdbClassifyInfo, edbClassifyInfo, prevClassify, nextC
|
|
|
err = errors.New("修改失败,Err:" + err.Error())
|
|
|
return
|
|
|
}
|
|
|
+ //更新对应分类的root_id和层级
|
|
|
+ if oldParentId != parentClassifyId {
|
|
|
+ if len(classifyIds) > 0 {
|
|
|
+ levelStep := edbClassifyInfo.Level - oldLevel
|
|
|
+ err = data_manage.UpdateEdbClassifyChildByParentClassifyId(classifyIds, edbClassifyInfo.RootId, levelStep)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "移动失败"
|
|
|
+ err = errors.New("更新子分类失败,Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
if edbInfo == nil {
|
|
@@ -974,7 +1014,7 @@ func GetFullClassifyByClassifyId(targetClassifyId int) (targetList []*data_manag
|
|
|
targetList = append(targetList, targetItem)
|
|
|
return
|
|
|
}
|
|
|
- tmpList, err := data_manage.GetEdbClassifyByRootIdLevel(targetClassify.RootId, targetClassify.ClassifyType)
|
|
|
+ tmpList, err := data_manage.GetEdbClassifyByRootIdLevel(targetClassify.RootId, targetClassify.ClassifyType, "")
|
|
|
if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
errMsg = "获取失败"
|
|
|
err = errors.New("获取数据失败,Err:" + err.Error())
|
|
@@ -1022,15 +1062,27 @@ func GetChildClassifyByClassifyId(targetClassifyId int) (targetList []*data_mana
|
|
|
err = errors.New("获取分类信息失败,Err:" + err.Error())
|
|
|
return
|
|
|
}
|
|
|
- tmpList, err := data_manage.GetEdbClassifyByRootIdLevel(targetClassify.RootId, targetClassify.ClassifyType)
|
|
|
+ orderStr := ` order by level asc, sort asc, classify_id asc`
|
|
|
+ tmpList, err := data_manage.GetEdbClassifyByRootIdLevel(targetClassify.RootId, targetClassify.ClassifyType, orderStr)
|
|
|
if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
errMsg = "获取失败"
|
|
|
err = errors.New("获取数据失败,Err:" + err.Error())
|
|
|
return
|
|
|
}
|
|
|
+ idMap := make(map[int]struct{})
|
|
|
if len(tmpList) > 0 {
|
|
|
for _, v := range tmpList {
|
|
|
- if v.Level >= targetClassify.Level {
|
|
|
+ if v.ClassifyId == targetClassify.ClassifyId {
|
|
|
+ idMap[v.ClassifyId] = struct{}{}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for _, v := range tmpList {
|
|
|
+ if _, ok := idMap[v.ParentId]; ok {
|
|
|
+ idMap[v.ClassifyId] = struct{}{}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for _, v := range tmpList {
|
|
|
+ if _, ok := idMap[v.ClassifyId]; ok {
|
|
|
targetItem := new(data_manage.EdbClassifyIdItems)
|
|
|
targetItem.ClassifyId = v.ClassifyId
|
|
|
targetItem.ParentId = v.ParentId
|
|
@@ -1042,6 +1094,7 @@ func GetChildClassifyByClassifyId(targetClassifyId int) (targetList []*data_mana
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|