diff --git a/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/redis/IssueProjectTagDictRedis.java b/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/redis/IssueProjectTagDictRedis.java index 18ebfdd206..9e0cd829cb 100644 --- a/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/redis/IssueProjectTagDictRedis.java +++ b/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/redis/IssueProjectTagDictRedis.java @@ -90,9 +90,9 @@ public class IssueProjectTagDictRedis { } IssueProjectCategoryDictEntity otherCategory = categoryDictDao.selectSingleByCustomerIdAndCategoryNameAndCategoryType(customerId, ModuleConstants.CATEGORY_NAME_OTHERS, null); - boolean ifOther = null == otherCategory ? false : (!CollectionUtils.isEmpty(category) && category.size() == NumConstant.ONE && category.contains(otherCategory.getId()) ? true : false); + boolean ifOtherOnly = null == otherCategory ? false : (!CollectionUtils.isEmpty(category) && category.size() == NumConstant.ONE && category.contains(otherCategory.getId()) ? true : false); Set keys; - if (CollectionUtils.isEmpty(category) || ifOther) + if (CollectionUtils.isEmpty(category) || ifOtherOnly) keys = redisUtils.keys(GovIssueRedisKeys.getGovernmentTagKey(customerId, null)); else keys = category.stream().map(key -> { return GovIssueRedisKeys.getGovernmentTagKey(customerId, key); @@ -111,32 +111,35 @@ public class IssueProjectTagDictRedis { return null; } }, redisTemplate.getValueSerializer()); - //热度Map 分数为key - Map> heatMap = new HashMap<>(); + + Map> result = new HashMap<>(); if (!CollectionUtils.isEmpty(heatTuple)) { + //热度Map 分数为key + Map> heatMap = new HashMap<>(); heatTuple.forEach(tupleSet -> { tupleSet.forEach(tuple -> { Double heatScore = tuple.getScore(); List queue = heatMap.get(heatScore); if (CollectionUtils.isEmpty(queue)) queue = new LinkedList<>(); queue.add(parseObject(tuple.getValue(), IssueCategoryTagResultDTO.class)); - heatMap.put(heatScore,queue); + heatMap.put(heatScore, queue); }); }); List defaultResult = new LinkedList<>(); heatMap.keySet().stream().sorted(Comparator.reverseOrder()).collect(Collectors.toList()).forEach(count -> { defaultResult.addAll(heatMap.get(count)); }); - Map> result = new HashMap<>(); - result.put(ModuleConstants.DEFAULT_TAG_CATEGORY_NAME,defaultResult); - Set> customizedTuples = redisUtils.zReverseRangeWithScores(GovIssueRedisKeys.getGovernmentTagKey(customerId, null), NumConstant.ZERO_L, (long) (NumConstant.ONE_NEG)); - if(!CollectionUtils.isEmpty(customizedTuples)){ + + result.put(ModuleConstants.DEFAULT_TAG_CATEGORY_NAME, defaultResult); + } + Set> customizedTuples = redisUtils.zReverseRangeWithScores(GovIssueRedisKeys.getGovernmentTagKey(customerId, null), NumConstant.ZERO_L, (long) (NumConstant.ONE_NEG)); + if(!CollectionUtils.isEmpty(customizedTuples)){ Map> customizedHeatMap = new HashMap<>(); customizedTuples.forEach(tuple -> { List queue = customizedHeatMap.get(tuple.getValue()); if((CollectionUtils.isEmpty(queue))) queue = new LinkedList<>(); queue.add(parseObject(tuple.getValue(), IssueCategoryTagResultDTO.class)); - heatMap.put((Double) tuple.getValue(),queue); + customizedHeatMap.put((Double) tuple.getValue(),queue); }); List customizedResult = new LinkedList<>(); customizedHeatMap.keySet().stream().sorted(Comparator.reverseOrder()).collect(Collectors.toList()).forEach(count -> { @@ -144,14 +147,14 @@ public class IssueProjectTagDictRedis { }); result.put(ModuleConstants.CUSTOMIZED_TAG_CATEGORY_NAME,customizedResult); } - return result; + return result; } - } + log.warn("fetch customer govern tag cache blankly,customerId:{},now begin compensation...", customerId); - Map> compensate = compensate(customerId, category, ifOther); + Map> compensate = compensate(customerId, category, ifOtherOnly); if (CollectionUtils.isEmpty(compensate)) { log.error("compensation failure or there is no default tag data in database!!"); @@ -173,14 +176,16 @@ public class IssueProjectTagDictRedis { * @author wangc * @date 2020.12.10 09:34 */ - public Map> compensate(String customerId,List category,boolean ifOther){ - //TODO 补偿机制 + public Map> compensate(String customerId,List category,boolean ifOtherOnly){ + - List _default = poolDao.selectTagByCategory(ifOther || CollectionUtils.isEmpty(category) ? null : category, NumConstant.ZERO_STR, customerId);//默认 + List _default = poolDao.selectTagByCategory(ifOtherOnly || CollectionUtils.isEmpty(category) ? null : category, NumConstant.ZERO_STR, customerId);//默认 List _customized = poolDao.selectTagByCategory(null,NumConstant.ONE_STR,customerId);//自定义 + Map>> fulfilled = new HashMap<>(); + Map> result = new HashMap<>(); - return null; + return result; } /**