瀏覽代碼

标签字典

wujiefeng 1 年之前
父節點
當前提交
878b6d2980

+ 1 - 1
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/dictionary/extend/DictionaryItemDaoExtend.java

@@ -12,5 +12,5 @@ public interface DictionaryItemDaoExtend {
 
     Page<DictionaryItem> page(Pageable pageable, String dictionaryId, String name, String parentId);
 
-    List<DItemChildrenResult> deepAggregate(String dictionaryId, List<String> keys);
+    List<DictionaryItemModel> deepAggregate(String dictionaryId, List<String> keys);
 }

+ 4 - 3
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/dictionary/impl/DictionaryItemDaoImpl.java

@@ -2,6 +2,7 @@ package com.zhongshu.card.server.core.dao.dictionary.impl;
 
 import com.github.microservice.components.data.mongo.mongo.helper.DBHelper;
 import com.mongodb.client.MongoCollection;
+import com.zhongshu.card.client.model.dictionary.DictionaryItemModel;
 import com.zhongshu.card.server.core.dao.dictionary.extend.DictionaryItemDaoExtend;
 import com.zhongshu.card.server.core.domain.dictionary.DictionaryItem;
 import com.zhongshu.card.server.core.model.dictionary.DItemChildrenResult;
@@ -55,7 +56,7 @@ public class DictionaryItemDaoImpl implements DictionaryItemDaoExtend {
     }
 
     @Override
-    public List<DItemChildrenResult> deepAggregate(String dictionaryId, List<String> keys) {
+    public List<DictionaryItemModel> deepAggregate(String dictionaryId, List<String> keys) {
 
         List<Document> pipeline =  new ArrayList<>() {{
                 add(new Document()
@@ -82,12 +83,12 @@ public class DictionaryItemDaoImpl implements DictionaryItemDaoExtend {
                 ));
         final MongoCollection<Document> collection = this.mongoTemplate.getCollection(this.mongoTemplate.getCollectionName(DictionaryItem.class));
 
-        List<DItemChildrenResult> ret = new ArrayList<>();
+        List<DictionaryItemModel> ret = new ArrayList<>();
 
 
         collection.aggregate(pipeline).allowDiskUse(false).forEach((document)->{
             Optional.ofNullable(document).ifPresent((it) -> {
-                ret.add(this.mongoTemplate.getConverter().read(DItemChildrenResult.class, it));
+                ret.add(this.mongoTemplate.getConverter().read(DictionaryItemModel.class, it));
             });
         });
         return ret;

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

@@ -195,7 +195,17 @@ public class DictionaryService extends SuperService {
             return toItemModel(it);
         });
 
-        List<DictionaryItemModel> modelList = buildTree(pageModel.getContent(), null);
+        List<DictionaryItemModel> dItemChildrenResults = dictionaryItemDao.deepAggregate(param.getDictionaryId(), pageModel.getContent().stream().map(DictionaryItemModel::getKey).toList());
+        List<DictionaryItemModel> ret = new ArrayList<>();
+        dItemChildrenResults.forEach(it->{
+            if (it.getChildren()!=null && it.getChildren().size() > 0){
+                ret.addAll(it.getChildren());
+            }
+            it.setChildren(new ArrayList<>());
+            ret.add(it);
+        });
+
+        List<DictionaryItemModel> modelList = buildTree(ret, null);
         return ResultContent.buildContent(PageEntityUtil.buildPage(modelList, pageable, page.getTotalElements()));
     }