|
@ -29,6 +29,7 @@ import com.epmet.dto.result.IssueCategoryTagResultDTO; |
|
|
import com.epmet.entity.IssueProjectCategoryDictEntity; |
|
|
import com.epmet.entity.IssueProjectCategoryDictEntity; |
|
|
import com.epmet.entity.IssueProjectTagDictEntity; |
|
|
import com.epmet.entity.IssueProjectTagDictEntity; |
|
|
import com.epmet.service.IssueProjectCategoryDictService; |
|
|
import com.epmet.service.IssueProjectCategoryDictService; |
|
|
|
|
|
import com.epmet.service.IssueProjectTagDictService; |
|
|
import com.epmet.utils.ModuleConstants; |
|
|
import com.epmet.utils.ModuleConstants; |
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
@ -65,6 +66,8 @@ public class IssueProjectTagDictRedis { |
|
|
private IssueProjectCategoryDictDao categoryDictDao; |
|
|
private IssueProjectCategoryDictDao categoryDictDao; |
|
|
@Autowired |
|
|
@Autowired |
|
|
private IssueProjectCategoryDictService categoryDictService; |
|
|
private IssueProjectCategoryDictService categoryDictService; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private IssueProjectTagDictService tagDictService; |
|
|
public void delete(Object[] ids) { |
|
|
public void delete(Object[] ids) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
@ -101,12 +104,10 @@ public class IssueProjectTagDictRedis { |
|
|
boolean ifOtherOnly = 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); |
|
|
|
|
|
|
|
|
Map<String,List<IssueCategoryTagResultDTO>> result = new HashMap<>(); |
|
|
Map<String,List<IssueCategoryTagResultDTO>> result = new HashMap<>(); |
|
|
|
|
|
//传入的categories不会只包含"其他"这个分类,因为情况下ifOtherOnly为true,直接传入null
|
|
|
List<IssueProjectTagDictEntity> _default = poolDao.selectTagByCategory(ifOtherOnly || CollectionUtils.isEmpty(category) ? null : category, customerId, NumConstant.ZERO_STR);//默认
|
|
|
List<IssueCategoryTagResultDTO> _default = poolDao.selectDefault(customerId,ifOtherOnly ? null : category); |
|
|
if(!CollectionUtils.isEmpty(_default)){ |
|
|
if(!CollectionUtils.isEmpty(_default)){ |
|
|
result.put(ModuleConstants.DEFAULT_TAG_CATEGORY_NAME,_default.stream().map(o -> { |
|
|
result.put(ModuleConstants.DEFAULT_TAG_CATEGORY_NAME,_default); |
|
|
IssueCategoryTagResultDTO tag = ConvertUtils.sourceToTarget(o,IssueCategoryTagResultDTO.class); |
|
|
|
|
|
tag.setName(o.getTagName()); return tag;}).collect(Collectors.toList())); |
|
|
|
|
|
}else log.error("there is no default tag data in database , customerId : {}",customerId); |
|
|
}else log.error("there is no default tag data in database , customerId : {}",customerId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -127,16 +128,19 @@ public class IssueProjectTagDictRedis { |
|
|
result.put(ModuleConstants.CUSTOMIZED_TAG_CATEGORY_NAME,customizedResult); |
|
|
result.put(ModuleConstants.CUSTOMIZED_TAG_CATEGORY_NAME,customizedResult); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//默认、自定义标签,只要有一个是空就触发补偿
|
|
|
|
|
|
//不信任缓存数据
|
|
|
//默认、自定义标签,只要有一个是空就触发补偿
|
|
|
if(!CollectionUtils.isEmpty(result) && !CollectionUtils.isEmpty(result.get(ModuleConstants.DEFAULT_TAG_CATEGORY_NAME)) |
|
|
//不信任缓存数据
|
|
|
|
|
|
if(!CollectionUtils.isEmpty(result) && !CollectionUtils.isEmpty(result.get(ModuleConstants.DEFAULT_TAG_CATEGORY_NAME)) |
|
|
&& !CollectionUtils.isEmpty(result.get(ModuleConstants.CUSTOMIZED_TAG_CATEGORY_NAME))) |
|
|
&& !CollectionUtils.isEmpty(result.get(ModuleConstants.CUSTOMIZED_TAG_CATEGORY_NAME))) |
|
|
return result; |
|
|
return result; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.warn("fetch customer govern tag cache blankly,customerId:{},now begin compensation...", customerId); |
|
|
log.warn("fetch customer govern tag cache blankly,customerId:{},now begin compensation...", customerId); |
|
|
|
|
|
|
|
|
Map<String,List<IssueCategoryTagResultDTO>> compensate = compensate(customerId, category, ifOtherOnly); |
|
|
Map<String,List<IssueCategoryTagResultDTO>> compensate = compensate(customerId, category, ifOtherOnly,result); |
|
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(compensate)) { |
|
|
if (CollectionUtils.isEmpty(compensate)) { |
|
|
log.error("compensation failure or there is no tag data in database!!"); |
|
|
log.error("compensation failure or there is no tag data in database!!"); |
|
@ -235,7 +239,7 @@ public class IssueProjectTagDictRedis { |
|
|
|
|
|
|
|
|
log.warn("fetch customer govern tag cache blankly,customerId:{},now begin compensation...", customerId); |
|
|
log.warn("fetch customer govern tag cache blankly,customerId:{},now begin compensation...", customerId); |
|
|
|
|
|
|
|
|
Map<String,List<IssueCategoryTagResultDTO>> compensate = compensate(customerId, category, ifOtherOnly); |
|
|
Map<String,List<IssueCategoryTagResultDTO>> compensate = compensate(customerId, category, ifOtherOnly,null); |
|
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(compensate)) { |
|
|
if (CollectionUtils.isEmpty(compensate)) { |
|
|
log.error("compensation failure or there is no tag data in database!!"); |
|
|
log.error("compensation failure or there is no tag data in database!!"); |
|
@ -249,10 +253,7 @@ public class IssueProjectTagDictRedis { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @Description category为空,则补偿全部,返回默认标签和自定义标签,补偿全部 |
|
|
* @Description 如果之前查询的结果为空,说明默认与自定义都没有 |
|
|
* category仅包含"其他"这个分类的Id时,返回同上,补偿全部 |
|
|
|
|
|
* category不为空且不只有"其他"这个分类的Id时,则返回并补偿集合中的类别标签以及自定义标签 |
|
|
|
|
|
* 默认标签不按照热度排序,自定义标签按照热度排序 |
|
|
|
|
|
* |
|
|
* |
|
|
* |
|
|
* |
|
|
* @param customerId |
|
|
* @param customerId |
|
@ -261,17 +262,38 @@ public class IssueProjectTagDictRedis { |
|
|
* @author wangc |
|
|
* @author wangc |
|
|
* @date 2020.12.10 09:34 |
|
|
* @date 2020.12.10 09:34 |
|
|
*/ |
|
|
*/ |
|
|
public Map<String,List<IssueCategoryTagResultDTO>> compensate(String customerId,List<String> category,boolean ifOtherOnly){ |
|
|
public Map<String,List<IssueCategoryTagResultDTO>> compensate(String customerId,List<String> category,boolean ifOtherOnly,Map<String,List<IssueCategoryTagResultDTO>> preResult){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<IssueProjectTagDictEntity> db = poolDao.selectTagByCategory(ifOtherOnly || CollectionUtils.isEmpty(category) ? null : category, customerId, null); |
|
|
List<IssueProjectTagDictEntity> db = new LinkedList<>(); |
|
|
|
|
|
|
|
|
if(CollectionUtils.isEmpty(db) && (ifOtherOnly || CollectionUtils.isEmpty(category))){ |
|
|
if(CollectionUtils.isEmpty(preResult) || CollectionUtils.isEmpty(preResult.get(ModuleConstants.DEFAULT_TAG_CATEGORY_NAME))){ |
|
|
CategoryTagInitFormDTO customerIdParam = new CategoryTagInitFormDTO(); customerIdParam.setCustomerId(customerId); |
|
|
CategoryTagInitFormDTO customerIdParam = new CategoryTagInitFormDTO(); customerIdParam.setCustomerId(customerId); |
|
|
categoryDictService.init(customerIdParam); |
|
|
if(ifOtherOnly || CollectionUtils.isEmpty(category)) { |
|
|
db = poolDao.selectTagByCategory(ifOtherOnly || CollectionUtils.isEmpty(category) ? null : category, customerId, null); |
|
|
//补偿全部默认标签
|
|
|
|
|
|
categoryDictService.init(customerIdParam); |
|
|
|
|
|
db.addAll(poolDao.selectTagListByCustomer(customerId)); |
|
|
|
|
|
}else{ |
|
|
|
|
|
if(NumConstant.ZERO <= poolDao.selectCountByCustomerId(customerId)){ |
|
|
|
|
|
categoryDictService.init(customerIdParam); |
|
|
|
|
|
}else{ |
|
|
|
|
|
//只插入category中的标签
|
|
|
|
|
|
tagDictService.insertBatch(poolDao.selectTagByCategory(category,"default",customerId)); |
|
|
|
|
|
db.addAll(poolDao.selectTagsByCustomerIdAndTagIds(customerId,category)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(CollectionUtils.isEmpty(preResult) || CollectionUtils.isEmpty(preResult.get(ModuleConstants.CUSTOMIZED_TAG_CATEGORY_NAME))){ |
|
|
|
|
|
//先去数据库查询自定义,为空则是最终结果,不为空则补偿
|
|
|
|
|
|
List<IssueProjectTagDictEntity> customizedTags = poolDao.selectCustomizedByCustomerId(customerId); |
|
|
|
|
|
if(!CollectionUtils.isEmpty(customizedTags)){ |
|
|
|
|
|
db.addAll(customizedTags); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// key -> redisKey
|
|
|
// key -> redisKey
|
|
|
// value -> [key : score ; value : object]
|
|
|
// value -> [key : score ; value : object]
|
|
|
Map<String,Map<Integer,List<IssueCategoryTagResultDTO>>> fulfilled = new HashMap<>(); |
|
|
Map<String,Map<Integer,List<IssueCategoryTagResultDTO>>> fulfilled = new HashMap<>(); |
|
@ -310,9 +332,12 @@ public class IssueProjectTagDictRedis { |
|
|
|
|
|
|
|
|
Map<String,List<IssueCategoryTagResultDTO>> result = new HashMap<>(); |
|
|
Map<String,List<IssueCategoryTagResultDTO>> result = new HashMap<>(); |
|
|
//默认标签:按照分类排序 Mapper返回的查询结果是有序的
|
|
|
//默认标签:按照分类排序 Mapper返回的查询结果是有序的
|
|
|
result.put(ModuleConstants.DEFAULT_TAG_CATEGORY_NAME,CollectionUtils.isEmpty(db) ? null : db.stream().filter(o -> !StringUtils.equals(ModuleConstants.CUSTOMIZED_TAG_CATEGORY_NAME,o.getCategoryId())).map(entity -> { |
|
|
//result.put(ModuleConstants.DEFAULT_TAG_CATEGORY_NAME,CollectionUtils.isEmpty(db) ? null : db.stream().filter(o -> !StringUtils.equals(ModuleConstants.CUSTOMIZED_TAG_CATEGORY_NAME,o.getCategoryId())).map(entity -> {
|
|
|
IssueCategoryTagResultDTO tag = ConvertUtils.sourceToTarget(entity,IssueCategoryTagResultDTO.class); |
|
|
// IssueCategoryTagResultDTO tag = ConvertUtils.sourceToTarget(entity,IssueCategoryTagResultDTO.class);
|
|
|
tag.setName(entity.getTagName()); return tag;}).collect(Collectors.toList())); |
|
|
// tag.setName(entity.getTagName()); return tag;}).collect(Collectors.toList()));
|
|
|
|
|
|
result.put(ModuleConstants.DEFAULT_TAG_CATEGORY_NAME,poolDao.selectDefault(customerId,ifOtherOnly ? null : category)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//自定义标签:按照热度排序 sorted(Comparator.comparing(IssueProjectTagDictEntity :: getIssueUseCount).reversed())
|
|
|
//自定义标签:按照热度排序 sorted(Comparator.comparing(IssueProjectTagDictEntity :: getIssueUseCount).reversed())
|
|
|
result.put(ModuleConstants.CUSTOMIZED_TAG_CATEGORY_NAME,CollectionUtils.isEmpty(db) ? null : db.stream().filter(o -> StringUtils.equals(ModuleConstants.CUSTOMIZED_TAG_CATEGORY_NAME,o.getCategoryId())).sorted(Comparator.comparing(IssueProjectTagDictEntity :: getIssueUseCount).reversed()).map(entity -> { |
|
|
result.put(ModuleConstants.CUSTOMIZED_TAG_CATEGORY_NAME,CollectionUtils.isEmpty(db) ? null : db.stream().filter(o -> StringUtils.equals(ModuleConstants.CUSTOMIZED_TAG_CATEGORY_NAME,o.getCategoryId())).sorted(Comparator.comparing(IssueProjectTagDictEntity :: getIssueUseCount).reversed()).map(entity -> { |
|
|
IssueCategoryTagResultDTO tag = ConvertUtils.sourceToTarget(entity,IssueCategoryTagResultDTO.class); |
|
|
IssueCategoryTagResultDTO tag = ConvertUtils.sourceToTarget(entity,IssueCategoryTagResultDTO.class); |
|
@ -388,7 +413,42 @@ public class IssueProjectTagDictRedis { |
|
|
* @date 2021.03.22 16:20 |
|
|
* @date 2021.03.22 16:20 |
|
|
*/ |
|
|
*/ |
|
|
public void updateTagAvailabilityBySecondCategoryIds(String customerId,List<String>secondCategoryIds,String availableFlag){ |
|
|
public void updateTagAvailabilityBySecondCategoryIds(String customerId,List<String>secondCategoryIds,String availableFlag){ |
|
|
|
|
|
if(CollectionUtils.isEmpty(secondCategoryIds)) return; |
|
|
|
|
|
secondCategoryIds.forEach(cid -> { |
|
|
|
|
|
String key = GovIssueRedisKeys.getGovernmentTagKey(customerId, cid); |
|
|
|
|
|
|
|
|
|
|
|
Set<ZSetOperations.TypedTuple<Object>> tagTuples = |
|
|
|
|
|
redisUtils.zReverseRangeWithScores(key, NumConstant.ZERO_L, (long) (NumConstant.ONE_NEG)); |
|
|
|
|
|
|
|
|
|
|
|
if(!CollectionUtils.isEmpty(tagTuples)){ |
|
|
|
|
|
Map<Double, Set<IssueCategoryTagResultDTO>> heatMap = new HashMap<>(); |
|
|
|
|
|
tagTuples.forEach(tuple -> { |
|
|
|
|
|
Set<IssueCategoryTagResultDTO> queue = heatMap.get(tuple.getValue()); |
|
|
|
|
|
if((CollectionUtils.isEmpty(queue))) queue = new HashSet<>(); |
|
|
|
|
|
IssueCategoryTagResultDTO ele = parseObject(tuple.getValue(), IssueCategoryTagResultDTO.class); |
|
|
|
|
|
ele.setIsDisable(availableFlag); |
|
|
|
|
|
queue.add(ele); |
|
|
|
|
|
heatMap.put((Double) tuple.getValue(),queue); |
|
|
|
|
|
}); |
|
|
|
|
|
List<IssueCategoryTagResultDTO> customizedResult = new LinkedList<>(); |
|
|
|
|
|
heatMap.keySet().stream().sorted(Comparator.reverseOrder()).collect(Collectors.toList()).forEach(count -> { |
|
|
|
|
|
customizedResult.addAll(heatMap.get(count)); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
redisUtils.delete(key); |
|
|
|
|
|
|
|
|
|
|
|
redisTemplate.executePipelined((RedisCallback) connection -> { |
|
|
|
|
|
heatMap.forEach((score,set) -> { |
|
|
|
|
|
set.forEach(o -> { |
|
|
|
|
|
connection.zSetCommands().zIncrBy(redisTemplate.getKeySerializer().serialize(key), |
|
|
|
|
|
score , |
|
|
|
|
|
redisTemplate.getValueSerializer().serialize(o)); |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
return null; |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public <T> T parseObject(Object o,Class<T> clazz){ |
|
|
public <T> T parseObject(Object o,Class<T> clazz){ |
|
|