|
@ -1,25 +1,33 @@ |
|
|
package com.epmet.service.impl; |
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
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.security.dto.TokenDto; |
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
import com.epmet.constant.TagConstant; |
|
|
import com.epmet.constant.TagConstant; |
|
|
import com.epmet.dao.ArticleDao; |
|
|
import com.epmet.dao.*; |
|
|
import com.epmet.dao.TagCustomerDao; |
|
|
|
|
|
import com.epmet.dao.TagDefaultDao; |
|
|
|
|
|
import com.epmet.dto.form.*; |
|
|
import com.epmet.dto.form.*; |
|
|
import com.epmet.dto.result.CorrelationTagListResultDTO; |
|
|
import com.epmet.dto.result.CorrelationTagListResultDTO; |
|
|
import com.epmet.dto.result.TagInfoResultDTO; |
|
|
import com.epmet.dto.result.TagInfoResultDTO; |
|
|
import com.epmet.dto.result.UpdateTagUseCountsResultDTO; |
|
|
import com.epmet.dto.result.UpdateTagUseCountsResultDTO; |
|
|
|
|
|
import com.epmet.entity.ArticlePublishRangeEntity; |
|
|
|
|
|
import com.epmet.entity.ArticleTagsEntity; |
|
|
|
|
|
import com.epmet.entity.TagCustomerEntity; |
|
|
|
|
|
import com.epmet.entity.TagGridEntity; |
|
|
import com.epmet.redis.TagRedis; |
|
|
import com.epmet.redis.TagRedis; |
|
|
import com.epmet.service.TagService; |
|
|
import com.epmet.service.TagService; |
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
import org.springframework.data.redis.core.DefaultTypedTuple; |
|
|
|
|
|
import org.springframework.data.redis.core.ZSetOperations; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.*; |
|
|
import java.util.List; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Slf4j |
|
|
@Service |
|
|
@Service |
|
|
public class TagServiceImpl implements TagService { |
|
|
public class TagServiceImpl implements TagService { |
|
|
|
|
|
|
|
@ -31,6 +39,12 @@ public class TagServiceImpl implements TagService { |
|
|
private TagDefaultDao tagDefaultDao; |
|
|
private TagDefaultDao tagDefaultDao; |
|
|
@Autowired |
|
|
@Autowired |
|
|
private TagCustomerDao tagCustomerDao; |
|
|
private TagCustomerDao tagCustomerDao; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private ArticleTagsDao articleTagsDao; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private TagGridDao tagGridDao; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private ArticlePublishRangeDao articlePublishRangeDao; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @Description 已发布列表页的标签——政府端 |
|
|
* @Description 已发布列表页的标签——政府端 |
|
@ -118,4 +132,114 @@ public class TagServiceImpl implements TagService { |
|
|
} |
|
|
} |
|
|
return tagRedis.getResiTag(formDto); |
|
|
return tagRedis.getResiTag(formDto); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public Boolean initTag(InitTagFormDTO formDto) { |
|
|
|
|
|
List<TagCustomerEntity> customerTagList = tagCustomerDao.selectInitData(formDto.getCustomerIdList()); |
|
|
|
|
|
if (CollectionUtils.isEmpty(customerTagList)) { |
|
|
|
|
|
throw new RenException("客户标签数为空"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Set<ZSetOperations.TypedTuple<UpdateTagUseCountsResultDTO>>> customerTag = new HashMap<>(); |
|
|
|
|
|
customerTagList.stream().forEach(tag -> { |
|
|
|
|
|
buildZset(customerTag, tag.getCustomerId(), tag.getId(), tag.getTagName(), tag.getUseCount()); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (customerTag.size() > 0) { |
|
|
|
|
|
customerTag.forEach((customerId, tagSet) -> tagRedis.zAddCustomerTag(customerId, tagSet)); |
|
|
|
|
|
} |
|
|
|
|
|
//key customerId:tagId
|
|
|
|
|
|
Map<String, Set<UpdateTagUseCountsResultDTO>> reCustomerTagMap = new HashMap<>(); |
|
|
|
|
|
List<ArticleTagsEntity> articleTagList = articleTagsDao.selectInitData(formDto.getCustomerIdList()); |
|
|
|
|
|
Map<String, List<ArticleTagsEntity>> articleReTagMap = new HashMap<>(); |
|
|
|
|
|
if (!CollectionUtils.isEmpty(articleTagList)) { |
|
|
|
|
|
articleReTagMap = articleTagList.stream().collect(Collectors.groupingBy(ArticleTagsEntity::getArticleId)); |
|
|
|
|
|
articleReTagMap.forEach((articleId, articleReTagList) -> { |
|
|
|
|
|
buildReTag(reCustomerTagMap, articleReTagList); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
if (reCustomerTagMap.size() > 0) { |
|
|
|
|
|
reCustomerTagMap.forEach((customerAndTagId, tagSet) -> tagRedis.updateMoreTag(TagConstant.GOV_RETAG_KEY.concat(customerAndTagId), tagSet)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//初始化 网格级标签
|
|
|
|
|
|
List<TagGridEntity> gridTagList = tagGridDao.selectInitData(formDto.getCustomerIdList()); |
|
|
|
|
|
if (CollectionUtils.isEmpty(gridTagList)) { |
|
|
|
|
|
throw new RenException("网格标签数为空"); |
|
|
|
|
|
} |
|
|
|
|
|
customerTag.clear(); |
|
|
|
|
|
gridTagList.stream().forEach(tag -> buildZset(customerTag, tag.getGridId(), tag.getTagId(), tag.getTagName(), tag.getUseCount())); |
|
|
|
|
|
if (customerTag.size() > 0) { |
|
|
|
|
|
customerTag.forEach((gridId, tagSet) -> tagRedis.zAddGridTag(gridId, tagSet)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//获取网格发布的文章 按网格排序
|
|
|
|
|
|
List<ArticlePublishRangeEntity> publishRangeTagList = articlePublishRangeDao.selectInitData(formDto.getCustomerIdList()); |
|
|
|
|
|
if (CollectionUtils.isEmpty(publishRangeTagList)){ |
|
|
|
|
|
log.error("publishRangeTagList return empty"); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
//网格关联标签结果 key:gridId:tagId
|
|
|
|
|
|
Map<String, Set<UpdateTagUseCountsResultDTO>> resultMap = new HashMap<>(); |
|
|
|
|
|
Map<String, List<ArticlePublishRangeEntity>> gridArticleListMap = publishRangeTagList.stream().collect(Collectors.groupingBy(ArticlePublishRangeEntity::getGridId)); |
|
|
|
|
|
for (Map.Entry<String, List<ArticlePublishRangeEntity>> entry : gridArticleListMap.entrySet()) { |
|
|
|
|
|
String gridId = entry.getKey(); |
|
|
|
|
|
List<ArticlePublishRangeEntity> articleIdList = entry.getValue(); |
|
|
|
|
|
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)); |
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void buildReTag(Map<String, Set<UpdateTagUseCountsResultDTO>> reCustomerTagMap, List<ArticleTagsEntity> articleReTagList) { |
|
|
|
|
|
articleReTagList.forEach(articleTag -> { |
|
|
|
|
|
|
|
|
|
|
|
String key = articleTag.getCustomerId().concat(StrConstant.COLON).concat(articleTag.getTagId()); |
|
|
|
|
|
Set<UpdateTagUseCountsResultDTO> reTagSet = reCustomerTagMap.get(key); |
|
|
|
|
|
if (reTagSet == null) { |
|
|
|
|
|
reTagSet = new HashSet<>(); |
|
|
|
|
|
reCustomerTagMap.put(key, reTagSet); |
|
|
|
|
|
} |
|
|
|
|
|
Set<UpdateTagUseCountsResultDTO> newReTagSet = articleReTagList.stream().filter(o -> !o.getTagId().equals(articleTag.getTagId())) |
|
|
|
|
|
.map(tag -> new UpdateTagUseCountsResultDTO(tag.getTagId(), tag.getTagName())).collect(Collectors.toSet()); |
|
|
|
|
|
reTagSet.addAll(newReTagSet); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void buildGridReTag(Map<String, Set<UpdateTagUseCountsResultDTO>> resultMap,String gridId, List<ArticleTagsEntity> articleReTagList) { |
|
|
|
|
|
articleReTagList.forEach(articleTag -> { |
|
|
|
|
|
String key = gridId.concat(StrConstant.COLON).concat(articleTag.getTagId()); |
|
|
|
|
|
Set<UpdateTagUseCountsResultDTO> reTagSet = resultMap.get(key); |
|
|
|
|
|
if (reTagSet == null) { |
|
|
|
|
|
reTagSet = new HashSet<>(); |
|
|
|
|
|
resultMap.put(key, reTagSet); |
|
|
|
|
|
} |
|
|
|
|
|
Set<UpdateTagUseCountsResultDTO> newReTagSet = articleReTagList.stream().filter(o -> !o.getTagId().equals(articleTag.getTagId())) |
|
|
|
|
|
.map(tag -> new UpdateTagUseCountsResultDTO(tag.getTagId(), tag.getTagName())).collect(Collectors.toSet()); |
|
|
|
|
|
reTagSet.addAll(newReTagSet); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void buildZset(Map<String, Set<ZSetOperations.TypedTuple<UpdateTagUseCountsResultDTO>>> customerTag, String customerId, String id, String tagName, Integer useCount) { |
|
|
|
|
|
Set<ZSetOperations.TypedTuple<UpdateTagUseCountsResultDTO>> typedTupleSet = customerTag.get(customerId); |
|
|
|
|
|
if (typedTupleSet == null) { |
|
|
|
|
|
typedTupleSet = new HashSet<>(); |
|
|
|
|
|
customerTag.put(customerId, typedTupleSet); |
|
|
|
|
|
} |
|
|
|
|
|
UpdateTagUseCountsResultDTO initTag = new UpdateTagUseCountsResultDTO(); |
|
|
|
|
|
initTag.setTagId(id); |
|
|
|
|
|
initTag.setTagName(tagName); |
|
|
|
|
|
ZSetOperations.TypedTuple<UpdateTagUseCountsResultDTO> typedTuple1 = new DefaultTypedTuple<>(initTag, Double.valueOf(useCount)); |
|
|
|
|
|
typedTupleSet.add(typedTuple1); |
|
|
|
|
|
} |
|
|
} |
|
|
} |