|
|
@ -22,11 +22,22 @@ import com.epmet.commons.tools.redis.RedisUtils; |
|
|
|
import com.epmet.constant.GovIssueRedisKeys; |
|
|
|
import com.epmet.dto.result.IssueCategoryTagResultDTO; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.dao.DataAccessException; |
|
|
|
import org.springframework.data.redis.connection.RedisConnection; |
|
|
|
import org.springframework.data.redis.core.RedisCallback; |
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
import org.springframework.data.redis.core.ZSetOperations; |
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* 议题、项目标签字典表 |
|
|
@ -39,7 +50,8 @@ import java.util.List; |
|
|
|
public class IssueProjectTagDictRedis { |
|
|
|
@Autowired |
|
|
|
private RedisUtils redisUtils; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private RedisTemplate redisTemplate; |
|
|
|
public void delete(Object[] ids) { |
|
|
|
|
|
|
|
} |
|
|
@ -65,10 +77,40 @@ public class IssueProjectTagDictRedis { |
|
|
|
*/ |
|
|
|
public List<IssueCategoryTagResultDTO> getTagsOrderByRank(String customerId,List<String> category){ |
|
|
|
if(StringUtils.isBlank(customerId)) { |
|
|
|
log.error("customerId can not be null when obtain govern tags cache"); |
|
|
|
log.error("customerId can not be null when obtain govern tags."); |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
Set<String> keys; |
|
|
|
if(CollectionUtils.isEmpty(category)) |
|
|
|
keys = redisUtils.keys(GovIssueRedisKeys.getGovernmentTagKey(customerId,null)); |
|
|
|
else keys = category.stream().map(key -> {return GovIssueRedisKeys.getGovernmentTagKey(customerId,key);}).collect(Collectors.toSet()); |
|
|
|
|
|
|
|
List<Set<ZSetOperations.TypedTuple<Object>>> heatTuple = redisTemplate.executePipelined(new RedisCallback<Set<ZSetOperations.TypedTuple<Object>>>() { |
|
|
|
@Nullable |
|
|
|
@Override |
|
|
|
public Set<ZSetOperations.TypedTuple<Object>> doInRedis(RedisConnection connection) throws DataAccessException { |
|
|
|
connection.openPipeline(); |
|
|
|
keys.forEach(key -> { |
|
|
|
connection.zSetCommands().zRangeByScoreWithScores(redisTemplate.getKeySerializer().serialize(key), NumConstant.ZERO_L, (long) (NumConstant.ONE_NEG)); |
|
|
|
}); |
|
|
|
return null; |
|
|
|
} |
|
|
|
},redisTemplate.getValueSerializer()); |
|
|
|
//热度Map 分数为key
|
|
|
|
Map<Double,List<IssueCategoryTagResultDTO>> heatMap = new HashMap<>(); |
|
|
|
if(CollectionUtils.isEmpty(heatTuple)){ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
log.warn("fetch customer govern tag cache blankly , customerId:{} , now begin compensation...",customerId); |
|
|
|
//TODO 补偿机制
|
|
|
|
|
|
|
|
log.warn("compensation completed !!"); |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
public List<IssueCategoryTagResultDTO> compensate(String customerId,List<String> category){ |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|