Browse Source

恢复字典表及 标签表字段校验,及初始化缓存

tags/24080901
niohe·erbao 1 year ago
parent
commit
60e6cba04e
2 changed files with 26 additions and 27 deletions
  1. +8
    -8
      pmapi/src/main/java/com/ningdatech/pmapi/meta/helper/basic/AbstractDictionaryCache.java
  2. +18
    -19
      pmapi/src/main/java/com/ningdatech/pmapi/meta/helper/basic/AbstractTagsCache.java

+ 8
- 8
pmapi/src/main/java/com/ningdatech/pmapi/meta/helper/basic/AbstractDictionaryCache.java View File

@@ -29,14 +29,14 @@ public abstract class AbstractDictionaryCache implements InitializingBean, Dicti

@Override
public void afterPropertiesSet() {
// dictionaryCacheHelper = Caffeine.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES)
// .refreshAfterWrite(5, TimeUnit.MINUTES).build(key -> {
// List<DictionaryDTO> dictionaryDTOList = iMetaDictionaryService.queryAll();
// dictionaryMap = buildCateMap(dictionaryDTOList);
// Map<String, List<DictionaryDTO>> dictionaryTypeListMap = dictionaryDTOList.stream().collect(Collectors.groupingBy(DictionaryDTO::getDictionaryType));
// return dictionaryTypeListMap.get(key);
// });
// warmUp();
dictionaryCacheHelper = Caffeine.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES)
.refreshAfterWrite(5, TimeUnit.MINUTES).build(key -> {
List<DictionaryDTO> dictionaryDTOList = iMetaDictionaryService.queryAll();
dictionaryMap = buildCateMap(dictionaryDTOList);
Map<String, List<DictionaryDTO>> dictionaryTypeListMap = dictionaryDTOList.stream().collect(Collectors.groupingBy(DictionaryDTO::getDictionaryType));
return dictionaryTypeListMap.get(key);
});
warmUp();
}

private Map<String, DictionaryDTO> buildCateMap(List<DictionaryDTO> dictionaryDTOList) {


+ 18
- 19
pmapi/src/main/java/com/ningdatech/pmapi/meta/helper/basic/AbstractTagsCache.java View File

@@ -34,25 +34,24 @@ public abstract class AbstractTagsCache implements InitializingBean, TagCache {

@Override
public void afterPropertiesSet() {
// tagsCache = Caffeine.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES)
// .refreshAfterWrite(5, TimeUnit.MINUTES)
// .build(key -> {
// // 查询全部
// List<TagDTO> tagDTOList = iMetaTagService.queryAll();
// // TODO 临时关闭校验
//// Assert.isTrue(CollectionUtils.isNotEmpty(tagDTOList), "MetaTags queryAll is Empty");
// tagDtoMap = buildCateMap(tagDTOList);
// List<TagDTO> tagInLevel = tagDTOList.stream().filter(tagDto -> {
// // 只过滤出小于等于level的tag
// if (Objects.isNull(tagDto.getTagLevel())) {
// return false;
// }
// return Integer.parseInt(key) >= tagDto.getTagLevel();
// }).collect(Collectors.toList());
// List<TagTreeDTO> treeDtos = MetaTagAssembler.toTagTreeDTOList(tagInLevel);
// return toTreeStructure(treeDtos);
// });
// warmUp();
tagsCache = Caffeine.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES)
.refreshAfterWrite(5, TimeUnit.MINUTES)
.build(key -> {
// 查询全部
List<TagDTO> tagDTOList = iMetaTagService.queryAll();
Assert.isTrue(CollectionUtils.isNotEmpty(tagDTOList), "MetaTags queryAll is Empty");
tagDtoMap = buildCateMap(tagDTOList);
List<TagDTO> tagInLevel = tagDTOList.stream().filter(tagDto -> {
// 只过滤出小于等于level的tag
if (Objects.isNull(tagDto.getTagLevel())) {
return false;
}
return Integer.parseInt(key) >= tagDto.getTagLevel();
}).collect(Collectors.toList());
List<TagTreeDTO> treeDtos = MetaTagAssembler.toTagTreeDTOList(tagInLevel);
return toTreeStructure(treeDtos);
});
warmUp();
}

private Map<String, TagDTO> buildCateMap(List<TagDTO> tagDTOList) {


Loading…
Cancel
Save