|
@@ -27,30 +27,37 @@ func SaveEdbMonitorClassify(req request.EdbMonitorClassifySaveReq) (msg string,
|
|
|
err = fmt.Errorf("get parent classify err:%w", er)
|
|
|
return
|
|
|
}
|
|
|
+ var parentClassify *edbmonitor.EdbMonitorClassify
|
|
|
+ if req.ParentId > 0 {
|
|
|
+ parentClassify, er = edbmonitor.GetEdbMonitorClassifyById(req.ParentId)
|
|
|
+ if er != nil {
|
|
|
+ if er.Error() == utils.ErrNoRow() {
|
|
|
+ msg = "父级分类不存在"
|
|
|
+ err = errors.New("parent classify not exist")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ msg = "分类信息保存失败"
|
|
|
+ err = fmt.Errorf("get parent classify err:%w", er)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var rootId int
|
|
|
+ if parentClassify != nil {
|
|
|
+ rootId = parentClassify.RootId
|
|
|
+ }
|
|
|
var parentId []int
|
|
|
- if req.ParentId != req.RootId {
|
|
|
+ if req.ParentId != rootId {
|
|
|
if req.ParentId > 0 {
|
|
|
parentId = append(parentId, req.ParentId)
|
|
|
}
|
|
|
- if req.RootId > 0 {
|
|
|
- parentId = append(parentId, req.RootId)
|
|
|
+ if rootId > 0 {
|
|
|
+ parentId = append(parentId, rootId)
|
|
|
}
|
|
|
} else {
|
|
|
if req.ParentId > 0 {
|
|
|
parentId = append(parentId, req.ParentId)
|
|
|
}
|
|
|
}
|
|
|
- count, er := edbmonitor.GetEdbMonitorClassifyCountByIdList(parentId)
|
|
|
- if er != nil {
|
|
|
- msg = "分类信息保存失败"
|
|
|
- err = fmt.Errorf("get classify count err:%w", er)
|
|
|
- return
|
|
|
- }
|
|
|
- if len(parentId) != count {
|
|
|
- msg = "父级分类不存在"
|
|
|
- err = errors.New("parent classify not exist")
|
|
|
- return
|
|
|
- }
|
|
|
|
|
|
if req.ClassifyId > 0 {
|
|
|
classifyInfo, er := edbmonitor.GetEdbMonitorClassifyById(req.ClassifyId)
|
|
@@ -96,8 +103,8 @@ func SaveEdbMonitorClassify(req request.EdbMonitorClassifySaveReq) (msg string,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if classifyInfo.RootId != req.RootId {
|
|
|
- classifyInfo.RootId = req.RootId
|
|
|
+ if classifyInfo.RootId != rootId {
|
|
|
+ classifyInfo.RootId = rootId
|
|
|
updateCols = append(updateCols, "root_id")
|
|
|
|
|
|
}
|
|
@@ -125,7 +132,7 @@ func SaveEdbMonitorClassify(req request.EdbMonitorClassifySaveReq) (msg string,
|
|
|
tmp := new(edbmonitor.EdbMonitorClassify)
|
|
|
tmp.ClassifyName = req.ClassifyName
|
|
|
tmp.ParentId = req.ParentId
|
|
|
- tmp.RootId = req.RootId
|
|
|
+ tmp.RootId = rootId
|
|
|
tmp.Level = req.Level
|
|
|
tmp.Sort = maxSort + 1
|
|
|
tmp.CreateTime = time.Now()
|