Browse Source

查询标签列表的方法完善

master
wangchao 5 years ago
parent
commit
137d296242
  1. 39
      epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/redis/IssueProjectTagDictRedis.java

39
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<String> 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<Double, List<IssueCategoryTagResultDTO>> heatMap = new HashMap<>();
Map<String,List<IssueCategoryTagResultDTO>> result = new HashMap<>();
if (!CollectionUtils.isEmpty(heatTuple)) {
//热度Map 分数为key
Map<Double, List<IssueCategoryTagResultDTO>> heatMap = new HashMap<>();
heatTuple.forEach(tupleSet -> {
tupleSet.forEach(tuple -> {
Double heatScore = tuple.getScore();
List<IssueCategoryTagResultDTO> 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<IssueCategoryTagResultDTO> defaultResult = new LinkedList<>();
heatMap.keySet().stream().sorted(Comparator.reverseOrder()).collect(Collectors.toList()).forEach(count -> {
defaultResult.addAll(heatMap.get(count));
});
Map<String,List<IssueCategoryTagResultDTO>> result = new HashMap<>();
result.put(ModuleConstants.DEFAULT_TAG_CATEGORY_NAME,defaultResult);
Set<ZSetOperations.TypedTuple<Object>> 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<ZSetOperations.TypedTuple<Object>> customizedTuples = redisUtils.zReverseRangeWithScores(GovIssueRedisKeys.getGovernmentTagKey(customerId, null), NumConstant.ZERO_L, (long) (NumConstant.ONE_NEG));
if(!CollectionUtils.isEmpty(customizedTuples)){
Map<Double, List<IssueCategoryTagResultDTO>> customizedHeatMap = new HashMap<>();
customizedTuples.forEach(tuple -> {
List<IssueCategoryTagResultDTO> 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<IssueCategoryTagResultDTO> 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<String,List<IssueCategoryTagResultDTO>> compensate = compensate(customerId, category, ifOther);
Map<String,List<IssueCategoryTagResultDTO>> 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<String,List<IssueCategoryTagResultDTO>> compensate(String customerId,List<String> category,boolean ifOther){
//TODO 补偿机制
public Map<String,List<IssueCategoryTagResultDTO>> compensate(String customerId,List<String> category,boolean ifOtherOnly){
List<IssueProjectTagDictEntity> _default = poolDao.selectTagByCategory(ifOther || CollectionUtils.isEmpty(category) ? null : category, NumConstant.ZERO_STR, customerId);//默认
List<IssueProjectTagDictEntity> _default = poolDao.selectTagByCategory(ifOtherOnly || CollectionUtils.isEmpty(category) ? null : category, NumConstant.ZERO_STR, customerId);//默认
List<IssueProjectTagDictEntity> _customized = poolDao.selectTagByCategory(null,NumConstant.ONE_STR,customerId);//自定义
Map<String,Map<Integer,List<IssueCategoryTagResultDTO>>> fulfilled = new HashMap<>();
Map<String,List<IssueCategoryTagResultDTO>> result = new HashMap<>();
return null;
return result;
}
/**

Loading…
Cancel
Save