|
|
@ -24,14 +24,17 @@ import com.epmet.dto.form.CorrelationTagListFormDTO; |
|
|
|
import com.epmet.dto.form.TagCascadeListFormDTO; |
|
|
|
import com.epmet.dto.result.CorrelationTagListResultDTO; |
|
|
|
import com.epmet.dto.result.TagInfoResultDTO; |
|
|
|
import com.epmet.dto.result.TagRankResultDTO; |
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import org.apache.poi.ss.formula.functions.T; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.data.redis.core.ZSetOperations; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Stream; |
|
|
|
|
|
|
|
@Component |
|
|
|
public class TagRedis { |
|
|
@ -56,6 +59,7 @@ public class TagRedis { |
|
|
|
List<String> tagIdList = formDto.getTagIdList(); |
|
|
|
Set<Object> objects ; |
|
|
|
Collection<String> keys = new ArrayList<>(); |
|
|
|
//当查询关联标签数量大于1条时
|
|
|
|
if (tagIdList.size() > 1){ |
|
|
|
for (int i = NumConstant.ONE; i < tagIdList.size(); i++) { |
|
|
|
String tagId = tagIdList.get(i); |
|
|
@ -63,8 +67,9 @@ public class TagRedis { |
|
|
|
keys.add(tagId); |
|
|
|
} |
|
|
|
String key = TagConstant.GOV_RETAG_KEY+customerId+TagConstant.COLON+tagIdList.get(0); |
|
|
|
objects = redisUtils.sUnion(key, keys); |
|
|
|
objects = redisUtils.intersect(key, keys); |
|
|
|
}else { |
|
|
|
// 查询关联标签数量 等于1条时
|
|
|
|
String key = TagConstant.GOV_RETAG_KEY+customerId+TagConstant.COLON+tagIdList.get(0); |
|
|
|
objects = redisUtils.sMembers(key); |
|
|
|
} |
|
|
@ -72,12 +77,37 @@ public class TagRedis { |
|
|
|
if (objects.size()==NumConstant.ZERO){ |
|
|
|
return resultList; |
|
|
|
} |
|
|
|
ObjectMapper objectMapper = new ObjectMapper(); |
|
|
|
//转换DTO
|
|
|
|
for (Object object : objects) { |
|
|
|
CorrelationTagListResultDTO correlationTag = objectMapper.convertValue(object, CorrelationTagListResultDTO.class); |
|
|
|
resultList.add(correlationTag); |
|
|
|
resultList.add(objectToDTO(object,CorrelationTagListResultDTO.class)); |
|
|
|
} |
|
|
|
//级联标签排序
|
|
|
|
//1.取出 zset 中的有序标签,根据级联标签,筛选有序标签
|
|
|
|
List<TagRankResultDTO> resultEquals = new ArrayList<>(); |
|
|
|
if (resultList.size() > NumConstant.ZERO) { |
|
|
|
long start = 0; |
|
|
|
long end = -1; |
|
|
|
String customerKey = TagConstant.GOV_TAG_KEY + customerId; |
|
|
|
Set<ZSetOperations.TypedTuple<Object>> typedTuples = redisUtils.zReverseRangeWithScores(customerKey, start, end); |
|
|
|
for (CorrelationTagListResultDTO correlationTagList : resultList) { |
|
|
|
for (ZSetOperations.TypedTuple<Object> typedTuple : typedTuples) { |
|
|
|
TagRankResultDTO tagRank = objectToDTO(typedTuple.getValue(), TagRankResultDTO.class); |
|
|
|
tagRank.setScore(typedTuple.getScore()); |
|
|
|
if (correlationTagList.getTagId().equals(tagRank.getTagId())){ |
|
|
|
resultEquals.add(tagRank); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// 根据标签使用顺序倒叙
|
|
|
|
List<TagRankResultDTO> collect = resultEquals.stream().sorted(Comparator.comparing(TagRankResultDTO::getScore).reversed()).collect(Collectors.toList()); |
|
|
|
List<CorrelationTagListResultDTO> realResult = new ArrayList<>(); |
|
|
|
for (TagRankResultDTO tagRankResultDTO : collect) { |
|
|
|
CorrelationTagListResultDTO correlation = new CorrelationTagListResultDTO(); |
|
|
|
BeanUtils.copyProperties(tagRankResultDTO,correlation); |
|
|
|
realResult.add(correlation); |
|
|
|
} |
|
|
|
return resultList; |
|
|
|
return realResult; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -95,10 +125,8 @@ public class TagRedis { |
|
|
|
return new ArrayList<>(); |
|
|
|
} |
|
|
|
List<TagInfoResultDTO> result = new ArrayList<TagInfoResultDTO>(); |
|
|
|
ObjectMapper objectMapper = new ObjectMapper(); |
|
|
|
for (Object object : objects) { |
|
|
|
TagInfoResultDTO tagInfoResultDto = objectMapper.convertValue(object, TagInfoResultDTO.class); |
|
|
|
result.add(tagInfoResultDto); |
|
|
|
result.add(objectToDTO(object,TagInfoResultDTO.class)); |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
@ -117,16 +145,14 @@ public class TagRedis { |
|
|
|
return new ArrayList<>(); |
|
|
|
} |
|
|
|
List<TagInfoResultDTO> result = new ArrayList<TagInfoResultDTO>(); |
|
|
|
ObjectMapper objectMapper = new ObjectMapper(); |
|
|
|
for (Object object : objects) { |
|
|
|
TagInfoResultDTO tagInfoResultDto = objectMapper.convertValue(object, TagInfoResultDTO.class); |
|
|
|
result.add(tagInfoResultDto); |
|
|
|
result.add(objectToDTO(object,TagInfoResultDTO.class)); |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description |
|
|
|
* @Description 获取居民端级联标签——按照使用次数倒序 |
|
|
|
* @param formDto |
|
|
|
* @author zxc |
|
|
|
*/ |
|
|
@ -135,6 +161,7 @@ public class TagRedis { |
|
|
|
String gridId = formDto.getGridId(); |
|
|
|
Set<Object> objects ; |
|
|
|
Collection<String> keys = new ArrayList<>(); |
|
|
|
//当 级联标签大于1条的时候
|
|
|
|
if (tagIdList.size() > 1){ |
|
|
|
for (int i = NumConstant.ONE; i < tagIdList.size(); i++) { |
|
|
|
String tagId = tagIdList.get(i); |
|
|
@ -142,8 +169,9 @@ public class TagRedis { |
|
|
|
keys.add(tagId); |
|
|
|
} |
|
|
|
String key = TagConstant.GRID_RETAG_KEY+gridId+TagConstant.COLON+tagIdList.get(0); |
|
|
|
objects = redisUtils.sUnion(key, keys); |
|
|
|
objects = redisUtils.intersect(key, keys); |
|
|
|
}else { |
|
|
|
//当级联标签为一条时
|
|
|
|
String key = TagConstant.GRID_RETAG_KEY+gridId+TagConstant.COLON+tagIdList.get(0); |
|
|
|
objects = redisUtils.sMembers(key); |
|
|
|
} |
|
|
@ -151,12 +179,49 @@ public class TagRedis { |
|
|
|
if (objects.size()==NumConstant.ZERO){ |
|
|
|
return resultList; |
|
|
|
} |
|
|
|
ObjectMapper objectMapper = new ObjectMapper(); |
|
|
|
//转换DTO
|
|
|
|
for (Object object : objects) { |
|
|
|
TagInfoResultDTO tagInfo = objectMapper.convertValue(object, TagInfoResultDTO.class); |
|
|
|
resultList.add(tagInfo); |
|
|
|
resultList.add(objectToDTO(object, TagInfoResultDTO.class)); |
|
|
|
} |
|
|
|
//级联标签排序
|
|
|
|
//1.取出 zset 中的有序标签,根据级联标签,筛选有序标签
|
|
|
|
List<TagRankResultDTO> resultEquals = new ArrayList<>(); |
|
|
|
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); |
|
|
|
for (TagInfoResultDTO tagInfo : resultList) { |
|
|
|
for (ZSetOperations.TypedTuple<Object> typedTuple : typedTuples) { |
|
|
|
TagRankResultDTO tagRank = objectToDTO(typedTuple.getValue(), TagRankResultDTO.class); |
|
|
|
tagRank.setScore(typedTuple.getScore()); |
|
|
|
if (tagInfo.getTagId().equals(tagRank.getTagId())){ |
|
|
|
resultEquals.add(tagRank); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// 根据标签使用顺序倒叙
|
|
|
|
List<TagRankResultDTO> collect = resultEquals.stream().sorted(Comparator.comparing(TagRankResultDTO::getScore).reversed()).collect(Collectors.toList()); |
|
|
|
List<TagInfoResultDTO> tagInfoResultList = new ArrayList<>(); |
|
|
|
for (TagRankResultDTO tagRankResultDTO : collect) { |
|
|
|
TagInfoResultDTO tagInfoResult = new TagInfoResultDTO(); |
|
|
|
BeanUtils.copyProperties(tagRankResultDTO,tagInfoResult); |
|
|
|
tagInfoResultList.add(tagInfoResult); |
|
|
|
} |
|
|
|
return resultList; |
|
|
|
return tagInfoResultList; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description Object 转换 DTO |
|
|
|
* @param o |
|
|
|
* @param tClass |
|
|
|
* @author zxc |
|
|
|
*/ |
|
|
|
public <T> T objectToDTO(Object o,Class<T> tClass){ |
|
|
|
ObjectMapper objectMapper = new ObjectMapper(); |
|
|
|
T t = objectMapper.convertValue(o, tClass); |
|
|
|
return t; |
|
|
|
} |
|
|
|
|
|
|
|
} |