|
@@ -94,16 +94,67 @@ func GetFullClassifyByClassifyId(targetClassifyId int) (targetList []*data_manag
|
|
|
idMap := make(map[int]struct{})
|
|
|
if len(tmpList) > 0 {
|
|
|
for _, v := range tmpList {
|
|
|
- addFlag := false
|
|
|
if v.ClassifyId == targetClassify.ClassifyId {
|
|
|
idMap[v.ClassifyId] = struct{}{}
|
|
|
idMap[v.ParentId] = struct{}{}
|
|
|
- addFlag = true
|
|
|
- } else if _, ok := idMap[v.ClassifyId]; ok {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for _, v := range tmpList {
|
|
|
+ if _, ok := idMap[v.ClassifyId]; ok {
|
|
|
idMap[v.ParentId] = struct{}{}
|
|
|
- addFlag = true
|
|
|
}
|
|
|
- if addFlag {
|
|
|
+ }
|
|
|
+ for _, v := range tmpList {
|
|
|
+ if _, ok := idMap[v.ClassifyId]; ok {
|
|
|
+ targetItem := new(data_manage.EdbClassifyIdItems)
|
|
|
+ targetItem.ClassifyId = v.ClassifyId
|
|
|
+ targetItem.ParentId = v.ParentId
|
|
|
+ targetItem.RootId = v.RootId
|
|
|
+ targetItem.UniqueCode = v.UniqueCode
|
|
|
+ targetItem.Level = v.Level
|
|
|
+ targetItem.ClassifyName = v.ClassifyName
|
|
|
+ targetList = append(targetList, targetItem)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetChildClassifyByClassifyId(targetClassifyId int) (targetList []*data_manage.EdbClassifyIdItems, err error, errMsg string) {
|
|
|
+ //判断是否是挂在顶级目录下
|
|
|
+ targetClassify, err := data_manage.GetEdbClassifyById(targetClassifyId)
|
|
|
+ if err != nil {
|
|
|
+ if err.Error() == utils.ErrNoRow() {
|
|
|
+ errMsg = "当前分类不存在"
|
|
|
+ err = errors.New(errMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ errMsg = "获取失败"
|
|
|
+ err = errors.New("获取分类信息失败,Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ tmpList, err := data_manage.GetEdbClassifyByRootIdLevel(targetClassify.RootId, targetClassify.ClassifyType)
|
|
|
+ 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.ParentId == targetClassify.ClassifyId || v.ClassifyId == targetClassifyId {
|
|
|
+ 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
|
|
@@ -247,10 +298,20 @@ func AddEdbClassify(classifyName string, parentId, level int, classifyType uint8
|
|
|
UniqueCode: utils.MD5(utils.DATA_PREFIX + "_" + timestamp),
|
|
|
Sort: maxSort + 1,
|
|
|
}
|
|
|
- _, err = data_manage.AddEdbClassify(classifyInfo)
|
|
|
+ newId, err := data_manage.AddEdbClassify(classifyInfo)
|
|
|
if err != nil {
|
|
|
errMsg = "保存分类失败"
|
|
|
+ return
|
|
|
}
|
|
|
+ if parentId == 0 { //一级目录的rootId等于自己本身
|
|
|
+ classifyInfo.RootId = int(newId)
|
|
|
+ err = classifyInfo.Update([]string{"RootId"})
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "更新分类失败"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|