From 3fe15b1b31733677287c80e4dfc7c5e4b5688da3 Mon Sep 17 00:00:00 2001 From: zhou-hao Date: Mon, 25 Feb 2019 11:14:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AD=97=E5=85=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../simple/BoostDictDefineRepository.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/hsweb-system/hsweb-system-dictionary/hsweb-system-dictionary-local/src/main/java/org/hswebframework/web/dictionary/simple/BoostDictDefineRepository.java b/hsweb-system/hsweb-system-dictionary/hsweb-system-dictionary-local/src/main/java/org/hswebframework/web/dictionary/simple/BoostDictDefineRepository.java index e7dbc046d..fb472c00a 100644 --- a/hsweb-system/hsweb-system-dictionary/hsweb-system-dictionary-local/src/main/java/org/hswebframework/web/dictionary/simple/BoostDictDefineRepository.java +++ b/hsweb-system/hsweb-system-dictionary/hsweb-system-dictionary-local/src/main/java/org/hswebframework/web/dictionary/simple/BoostDictDefineRepository.java @@ -2,6 +2,7 @@ package org.hswebframework.web.dictionary.simple; import lombok.extern.slf4j.Slf4j; import org.hswebframework.web.commons.entity.DataStatus; +import org.hswebframework.web.commons.entity.param.QueryParamEntity; import org.hswebframework.web.dict.DictDefine; import org.hswebframework.web.dict.EnumDict; import org.hswebframework.web.dict.defaults.DefaultDictDefine; @@ -9,6 +10,7 @@ import org.hswebframework.web.dict.defaults.DefaultDictDefineRepository; import org.hswebframework.web.dictionary.api.DictionaryItemService; import org.hswebframework.web.dictionary.api.DictionaryService; import org.hswebframework.web.dictionary.api.entity.DictionaryEntity; +import org.hswebframework.web.dictionary.api.entity.DictionaryItemEntity; import org.hswebframework.web.dictionary.api.events.ClearDictionaryCacheEvent; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheConfig; @@ -20,6 +22,7 @@ import org.springframework.transaction.event.TransactionalEventListener; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; /** @@ -65,16 +68,26 @@ public class BoostDictDefineRepository extends DefaultDictDefineRepository { @Override public List getAllDefine() { - List all = dictionaryService.select() + //查询所有的字典项并按字典ID分组 + Map> items = QueryParamEntity.newQuery() + .where(DictionaryItemEntity::getStatus, DataStatus.STATUS_ENABLED) + .noPaging() + .execute(itemService::select) + .stream().collect(Collectors.groupingBy(DictionaryItemEntity::getDictId)); + + //转换为字段 + List all =QueryParamEntity.newQuery() + .where(DictionaryEntity::getStatus,DataStatus.STATUS_ENABLED) + .noPaging() + .execute(dictionaryService::select) .stream() - .filter(e -> DataStatus.STATUS_ENABLED.equals(e.getStatus())) .map(dict -> DefaultDictDefine.builder() .id(dict.getId()) .comments(dict.getDescribe()) - .items(dict.getItems() == null ? Collections.emptyList() : (List) new ArrayList<>(dict.getItems())) + .items((List) items.getOrDefault(dict.getId(),Collections.emptyList())) .build()) .collect(Collectors.toList()); - + //添加默认的字典 all.addAll(super.getAllDefine()); return all; }