wujiefeng 1 рік тому
батько
коміт
c0b205c8ef

+ 22 - 5
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/dictionary/DictionaryService.java

@@ -2,6 +2,7 @@ package com.zhongshu.card.server.core.service.dictionary;
 
 import com.github.microservice.auth.security.helper.AuthHelper;
 import com.github.microservice.components.data.base.util.PageEntityUtil;
+import com.github.microservice.components.data.mongo.mongo.domain.SuperEntity;
 import com.github.microservice.net.ResultContent;
 import com.zhongshu.card.client.model.dictionary.*;
 import com.zhongshu.card.client.type.DictionaryType;
@@ -20,7 +21,10 @@ import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 @Service
 public class DictionaryService extends SuperService {
@@ -138,9 +142,6 @@ public class DictionaryService extends SuperService {
         dictionaryItem.setId(id);
         dictionaryItem.setIdString(id);
         dictionaryItem.setCreateTime(System.currentTimeMillis());
-        if (StringUtils.isBlank(param.getKey())){
-            dictionaryItem.setParentId(param.getDictionaryId());
-        }
         dictionaryItemDao.save(dictionaryItem);
         return ResultContent.buildSuccess();
     }
@@ -270,12 +271,28 @@ public class DictionaryService extends SuperService {
         }
 
         List<DictionaryItem> list = dictionaryItemDao.findByDictionary_Id(dictionary.getId());
+
         return null;
     }
-
+//
 //    private List<DictionaryItemModel> buildTree(String parentId, List<DictionaryItem> list, List<DictionaryItemModel> treeList){
+//        Map<String, DictionaryItem> itemMap = new HashMap<>();
+//        itemMap = list.stream().collect(Collectors.toMap(SuperEntity::getId, it->it));
+//
+//        List<DictionaryItem> rootItems = new ArrayList<>();
 //
-//        list.for
+//        for (DictionaryItem item : list) {
+//            if (item.getParentId() == null || item.getParentId().isEmpty()) {
+//                // 没有父节点的项是根节点
+//                rootItems.add(item);
+//            } else {
+//                // 将子节点添加到父节点的 children 中
+//                DictionaryItem parentItem = itemMap.get(item.getParentId());
+//                if (parentItem != null) {
+//                    parentItem.addChild(item);
+//                }
+//            }
+//        }
 //    }
 
 //    /**