Browse Source

标签key统一到redisKeys中

dev_shibei_match
jianjun 5 years ago
parent
commit
d698569ce4
  1. 22
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/constant/TagConstant.java
  2. 34
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/redis/TagRedis.java
  3. 9
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java
  4. 18
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/TagServiceImpl.java

22
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/constant/TagConstant.java

@ -15,34 +15,34 @@ package com.epmet.constant;
*/
public interface TagConstant {
/**
/* *//**
* 客户维度政府端 热度标签 key的前缀 zset
* 完整keyGRID_TAG_KEY:客户ID
*/
*//*
String GOV_TAG_KEY = "epmet:tags:customer:rankingTag:";
/**
*//**
* 客户维度政府端 关联标签 key的前缀 set
* 完整keyGRID_TAG_KEY:标签ID
*/
*//*
String GOV_RETAG_KEY = "epmet:tags:customer:relationTag:";
/**
*//**
* 网格热度标签居民端 key的前缀 zset
* 完整keyGRID_TAG_KEY:网格ID
*/
*//*
String GRID_TAG_KEY = "epmet:tags:grid:rankingTag:";
/**
*//**
* 网格关联标签居民端 key的前缀 set
* 完整keyGRID_RETAG_KEY:网格ID:标签ID
*/
*//*
String GRID_RETAG_KEY ="epmet:tags:grid:relationTag:";
/**
*//**
* 冒号
*/
String COLON = ":";
*//*
String COLON = ":";*/
String BEGIN_UPDATE = "开始更新标签缓存... ...";
String SUCCESS_UPDATE = "更新标签缓存成功... ...";

34
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/redis/TagRedis.java

@ -88,14 +88,14 @@ public class TagRedis {
if (tagIdList.size() > 1){
for (int i = NumConstant.ONE; i < tagIdList.size(); i++) {
String tagId = tagIdList.get(i);
tagId = TagConstant.GOV_RETAG_KEY+customerId+TagConstant.COLON+tagId;
tagId = RedisKeys.getCustomerReTagKey(customerId,tagId);
keys.add(tagId);
}
String key = TagConstant.GOV_RETAG_KEY+customerId+TagConstant.COLON+tagIdList.get(0);
String key = RedisKeys.getCustomerReTagKey(customerId,tagIdList.get(0));
objects = redisUtils.intersect(key, keys);
}else {
// 查询关联标签数量 等于1条时
String key = TagConstant.GOV_RETAG_KEY+customerId+TagConstant.COLON+tagIdList.get(0);
String key = RedisKeys.getCustomerReTagKey(customerId,tagIdList.get(0));
objects = redisUtils.sMembers(key);
}
List<CorrelationTagListResultDTO> resultList = new ArrayList<>();
@ -113,7 +113,7 @@ public class TagRedis {
if (resultList.size() > NumConstant.ZERO) {
long start = 0;
long end = -1;
String customerKey = TagConstant.GOV_TAG_KEY + customerId;
String customerKey = RedisKeys.getCustomerTagKey(customerId);
Set<ZSetOperations.TypedTuple<Object>> typedTuples = redisUtils.zReverseRangeWithScores(customerKey, start, end);
for (CorrelationTagListResultDTO correlationTagList : resultList) {
for (ZSetOperations.TypedTuple<Object> typedTuple : typedTuples) {
@ -145,7 +145,7 @@ public class TagRedis {
public List<TagInfoResultDTO> zRevRange(String key){
long start = 0;
long end = -1;
String tagKey = TagConstant.GOV_TAG_KEY+key;
String tagKey = RedisKeys.getCustomerTagKey(key);
Set<Object> objects = redisUtils.zRevRange(tagKey, start, end);
if (objects.size()== NumConstant.ZERO){
return new ArrayList<>();
@ -166,7 +166,7 @@ public class TagRedis {
public List<TagInfoResultDTO> zGridRevRange(String key){
long start = 0;
long end = -1;
String tagKey = TagConstant.GRID_TAG_KEY+key;
String tagKey = RedisKeys.getGridTagKey(key);
Set<Object> objects = redisUtils.zRevRange(tagKey, start, end);
if (objects.size()== NumConstant.ZERO){
return new ArrayList<>();
@ -192,14 +192,14 @@ public class TagRedis {
if (tagIdList.size() > 1){
for (int i = NumConstant.ONE; i < tagIdList.size(); i++) {
String tagId = tagIdList.get(i);
tagId = TagConstant.GRID_RETAG_KEY+gridId+TagConstant.COLON+tagId;
tagId = RedisKeys.getGridReTagKey(gridId,tagId);
keys.add(tagId);
}
String key = TagConstant.GRID_RETAG_KEY+gridId+TagConstant.COLON+tagIdList.get(0);
String key = RedisKeys.getGridReTagKey(gridId,tagIdList.get(0));
objects = redisUtils.intersect(key, keys);
}else {
//当级联标签为一条时
String key = TagConstant.GRID_RETAG_KEY+gridId+TagConstant.COLON+tagIdList.get(0);
String key = RedisKeys.getGridReTagKey(gridId,tagIdList.get(0));
objects = redisUtils.sMembers(key);
}
List<TagInfoResultDTO> resultList = new ArrayList<>();
@ -216,8 +216,9 @@ public class TagRedis {
if (resultList.size() > NumConstant.ZERO) {
long start = 0;
long end = -1;
String customerKey = TagConstant.GRID_TAG_KEY+formDto.getGridId();
Set<ZSetOperations.TypedTuple<Object>> typedTuples = redisUtils.zReverseRangeWithScores(customerKey, start, end);
String gridTagKey =RedisKeys.getGridTagKey(formDto.getGridId());
Set<ZSetOperations.TypedTuple<Object>> typedTuples = redisUtils.zReverseRangeWithScores(gridTagKey, start, end);
for (TagInfoResultDTO tagInfo : resultList) {
for (ZSetOperations.TypedTuple<Object> typedTuple : typedTuples) {
TagRankResultDTO tagRank = objectToDTO(typedTuple.getValue(), TagRankResultDTO.class);
@ -291,14 +292,11 @@ public class TagRedis {
public void updateMoreTag(String key, Set<UpdateTagUseCountsResultDTO> value) {
try {
log.info(TagConstant.BEGIN_UPDATE);
redisTemplate.executePipelined(new RedisCallback<Set<UpdateTagUseCountsResultDTO>>() {
@Override
public Set doInRedis(RedisConnection connection) throws DataAccessException {
for (UpdateTagUseCountsResultDTO tag : value) {
connection.sAdd(redisTemplate.getKeySerializer().serialize(key),redisTemplate.getValueSerializer().serialize(tag));
}
return null;
redisTemplate.executePipelined((RedisCallback<Set<UpdateTagUseCountsResultDTO>>) connection -> {
for (UpdateTagUseCountsResultDTO tag : value) {
connection.sAdd(redisTemplate.getKeySerializer().serialize(key),redisTemplate.getValueSerializer().serialize(tag));
}
return null;
});
log.info(TagConstant.SUCCESS_UPDATE);
}catch (Exception e){

9
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java

@ -26,6 +26,7 @@ import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.redis.RedisKeys;
import com.epmet.commons.tools.scan.param.ImgScanParamDTO;
import com.epmet.commons.tools.scan.param.ImgTaskDTO;
import com.epmet.commons.tools.scan.param.TextScanParamDTO;
@ -1196,14 +1197,14 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
String customerId = formDto.getCustomerId();
//更新缓存标签使用数量
tagsInfo.forEach(resultDTO -> {
String customerKey = TagConstant.GOV_TAG_KEY + customerId;
String customerKey = RedisKeys.getCustomerTagKey(customerId);
tagRedis.updateTagUseCounts(customerKey, resultDTO);
});
//政府端更新redis的级联标签(set)
List<UpdateTagUseCountsResultDTO> tagsInfoCopy = new ArrayList<>();
for (int i = 0; i < tagsInfo.size(); i++) {
tagsInfoCopy.addAll(tagsInfo);
String key = TagConstant.GOV_RETAG_KEY + customerId + TagConstant.COLON + tagsInfo.get(i).getTagId();
String key = RedisKeys.getCustomerReTagKey(customerId, tagsInfo.get(i).getTagId());
tagsInfoCopy.remove(tagsInfo.get(i));
Set<UpdateTagUseCountsResultDTO> setTag = new HashSet<>(tagsInfoCopy);
tagRedis.updateMoreTag(key, setTag);
@ -1259,7 +1260,7 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
List<UpdateTagUseCountsResultDTO> gridTagCacheCopy = new ArrayList<>();
gridTagCache.forEach(cacheDTO -> {
String gridId = cacheDTO.getGridId();
String key = TagConstant.GRID_TAG_KEY + gridId;
String key = RedisKeys.getGridTagKey(gridId);
List<UpdateTagUseCountsResultDTO> tagsInfo = cacheDTO.getTagsInfo();
tagsInfo.forEach(resultDTO -> {
tagRedis.updateTagUseCounts(key, resultDTO);
@ -1267,7 +1268,7 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
//级联
for (int i = 0; i < tagsInfo.size(); i++) {
gridTagCacheCopy.addAll(tagsInfo);
String moreKey = TagConstant.GRID_RETAG_KEY + gridId + TagConstant.COLON + tagsInfo.get(i).getTagId();
String moreKey = RedisKeys.getGridReTagKey(gridId, tagsInfo.get(i).getTagId());
gridTagCacheCopy.remove(tagsInfo.get(i));
Set<UpdateTagUseCountsResultDTO> setTag = new HashSet<>(gridTagCacheCopy);
tagRedis.updateMoreTag(moreKey, setTag);

18
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/TagServiceImpl.java

@ -3,8 +3,8 @@ package com.epmet.service.impl;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.redis.RedisKeys;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.constant.TagConstant;
import com.epmet.dao.*;
import com.epmet.dto.form.*;
import com.epmet.dto.result.CorrelationTagListResultDTO;
@ -90,7 +90,7 @@ public class TagServiceImpl implements TagService {
InitTagsFormDTO tagInfo = new InitTagsFormDTO();
UpdateTagUseCountsResultDTO initTag = new UpdateTagUseCountsResultDTO();
UUID uuid = UUID.randomUUID();
String replaceUuid = uuid.toString().replace("-", "");
String replaceUuid = uuid.toString().replace(StrConstant.HYPHEN, "");
tagInfo.setId(replaceUuid);
initTag.setTagId(replaceUuid);
tagInfo.setTagName(tagName);
@ -100,7 +100,7 @@ public class TagServiceImpl implements TagService {
initCacheTags.add(initTag);
});
tagCustomerDao.initTags(tags);
String key = TagConstant.GOV_TAG_KEY+customerId;
String key = RedisKeys.getCustomerTagKey(customerId);
tagRedis.initCacheTags(key,initCacheTags);
return tagRedis.zRevRange(customerId);
}
@ -159,7 +159,10 @@ public class TagServiceImpl implements TagService {
});
}
if (reCustomerTagMap.size() > 0) {
reCustomerTagMap.forEach((customerAndTagId, tagSet) -> tagRedis.updateMoreTag(TagConstant.GOV_RETAG_KEY.concat(customerAndTagId), tagSet));
reCustomerTagMap.forEach((customerAndTagId, tagSet) -> {
String[] customerIdAndTagIdArr = customerAndTagId.split(StrConstant.COLON);
tagRedis.updateMoreTag(RedisKeys.getCustomerReTagKey(customerIdAndTagIdArr[0], customerIdAndTagIdArr[1]), tagSet);
});
}
@ -189,14 +192,17 @@ public class TagServiceImpl implements TagService {
for (ArticlePublishRangeEntity publishRange : articleIdList) {
List<ArticleTagsEntity> articleTagsEntities = articleReTagMap.get(publishRange.getArticleId());
if (CollectionUtils.isEmpty(articleTagsEntities)){
//该文章诶呦标签
//该文章没有标签
continue;
}
buildGridReTag(resultMap,gridId,articleTagsEntities);
}
}
if (resultMap.size() > 0) {
resultMap.forEach((gridIdAndTagId, tagSet) -> tagRedis.updateMoreTag(TagConstant.GRID_RETAG_KEY.concat(gridIdAndTagId), tagSet));
resultMap.forEach((gridIdAndTagId, tagSet) -> {
String[] gridIdAndTagIdArr = gridIdAndTagId.split(StrConstant.COLON);
tagRedis.updateMoreTag(RedisKeys.getGridReTagKey(gridIdAndTagIdArr[0],gridIdAndTagIdArr[1]), tagSet);
});
}
return true;
}

Loading…
Cancel
Save