mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-06-01 18:35:37 +08:00
优化字典
This commit is contained in:
@@ -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<DictDefine> getAllDefine() {
|
||||
List<DictDefine> all = dictionaryService.select()
|
||||
//查询所有的字典项并按字典ID分组
|
||||
Map<String, List<DictionaryItemEntity>> items = QueryParamEntity.newQuery()
|
||||
.where(DictionaryItemEntity::getStatus, DataStatus.STATUS_ENABLED)
|
||||
.noPaging()
|
||||
.execute(itemService::select)
|
||||
.stream().collect(Collectors.groupingBy(DictionaryItemEntity::getDictId));
|
||||
|
||||
//转换为字段
|
||||
List<DictDefine> 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user