From 60e6cba04ea2db7f86e70daf22397b7566dab862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?niohe=C2=B7erbao?= Date: Tue, 7 Mar 2023 15:48:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=81=A2=E5=A4=8D=E5=AD=97=E5=85=B8=E8=A1=A8?= =?UTF-8?q?=E5=8F=8A=20=E6=A0=87=E7=AD=BE=E8=A1=A8=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=EF=BC=8C=E5=8F=8A=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meta/helper/basic/AbstractDictionaryCache.java | 16 +++++----- .../pmapi/meta/helper/basic/AbstractTagsCache.java | 37 +++++++++++----------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/meta/helper/basic/AbstractDictionaryCache.java b/pmapi/src/main/java/com/ningdatech/pmapi/meta/helper/basic/AbstractDictionaryCache.java index 16a8b84..bd4773e 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/meta/helper/basic/AbstractDictionaryCache.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/meta/helper/basic/AbstractDictionaryCache.java @@ -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 dictionaryDTOList = iMetaDictionaryService.queryAll(); -// dictionaryMap = buildCateMap(dictionaryDTOList); -// Map> 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 dictionaryDTOList = iMetaDictionaryService.queryAll(); + dictionaryMap = buildCateMap(dictionaryDTOList); + Map> dictionaryTypeListMap = dictionaryDTOList.stream().collect(Collectors.groupingBy(DictionaryDTO::getDictionaryType)); + return dictionaryTypeListMap.get(key); + }); + warmUp(); } private Map buildCateMap(List dictionaryDTOList) { diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/meta/helper/basic/AbstractTagsCache.java b/pmapi/src/main/java/com/ningdatech/pmapi/meta/helper/basic/AbstractTagsCache.java index c20fc7b..413e410 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/meta/helper/basic/AbstractTagsCache.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/meta/helper/basic/AbstractTagsCache.java @@ -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 tagDTOList = iMetaTagService.queryAll(); -// // TODO 临时关闭校验 -//// Assert.isTrue(CollectionUtils.isNotEmpty(tagDTOList), "MetaTags queryAll is Empty"); -// tagDtoMap = buildCateMap(tagDTOList); -// List tagInLevel = tagDTOList.stream().filter(tagDto -> { -// // 只过滤出小于等于level的tag -// if (Objects.isNull(tagDto.getTagLevel())) { -// return false; -// } -// return Integer.parseInt(key) >= tagDto.getTagLevel(); -// }).collect(Collectors.toList()); -// List treeDtos = MetaTagAssembler.toTagTreeDTOList(tagInLevel); -// return toTreeStructure(treeDtos); -// }); -// warmUp(); + tagsCache = Caffeine.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES) + .refreshAfterWrite(5, TimeUnit.MINUTES) + .build(key -> { + // 查询全部 + List tagDTOList = iMetaTagService.queryAll(); + Assert.isTrue(CollectionUtils.isNotEmpty(tagDTOList), "MetaTags queryAll is Empty"); + tagDtoMap = buildCateMap(tagDTOList); + List tagInLevel = tagDTOList.stream().filter(tagDto -> { + // 只过滤出小于等于level的tag + if (Objects.isNull(tagDto.getTagLevel())) { + return false; + } + return Integer.parseInt(key) >= tagDto.getTagLevel(); + }).collect(Collectors.toList()); + List treeDtos = MetaTagAssembler.toTagTreeDTOList(tagInLevel); + return toTreeStructure(treeDtos); + }); + warmUp(); } private Map buildCateMap(List tagDTOList) {