|
|
@ -37,6 +37,7 @@ import com.epmet.commons.tools.validator.group.DefaultGroup; |
|
|
|
import com.epmet.constant.ArticleConstant; |
|
|
|
import com.epmet.constant.DraftConstant; |
|
|
|
import com.epmet.constant.RoleKeyConstants; |
|
|
|
import com.epmet.constant.TagConstant; |
|
|
|
import com.epmet.dao.*; |
|
|
|
import com.epmet.dto.*; |
|
|
|
import com.epmet.dto.form.*; |
|
|
@ -46,12 +47,14 @@ import com.epmet.feign.EpmetUserOpenFeignClient; |
|
|
|
import com.epmet.feign.GovOrgOpenFeignClient; |
|
|
|
import com.epmet.redis.ArticleRedis; |
|
|
|
import com.epmet.service.*; |
|
|
|
import com.epmet.redis.TagRedis; |
|
|
|
import com.epmet.utils.ModuleConstant; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.jsoup.helper.StringUtil; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
@ -98,6 +101,14 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit |
|
|
|
private ArticleContentDao articleContentDao; |
|
|
|
@Autowired |
|
|
|
private ArticleCoverDao articleCoverDao; |
|
|
|
@Autowired |
|
|
|
private DraftService draftService; |
|
|
|
@Autowired |
|
|
|
private TagCustomerService tagCustomerService; |
|
|
|
@Autowired |
|
|
|
private TagRedis tagRedis; |
|
|
|
@Autowired |
|
|
|
private TagGridDao tagGridDao; |
|
|
|
|
|
|
|
private static final String AGENCY = "agency"; |
|
|
|
private static final String GRID = "grid"; |
|
|
@ -884,4 +895,117 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit |
|
|
|
throw new RenException(String.format(ModuleConstant.SPECIFIED_DRAFT_NOT_FOUNT_EXCEPTION_TEMPLATE,draftId)); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 更新DB的标签使用次数 |
|
|
|
* @param draftId |
|
|
|
* @author zxc |
|
|
|
*/ |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public UpdateCustomerTagCacheDTO updateCustomerTag(TokenDto tokenDto, String draftId){ |
|
|
|
//获取草稿基本信息
|
|
|
|
DraftDTO draft = draftService.get(draftId); |
|
|
|
String tags = draft.getTags(); |
|
|
|
String customerId = draft.getCustomerId(); |
|
|
|
String userId = tokenDto.getUserId(); |
|
|
|
List<String> tagsList = Arrays.asList(tags.split("\\|")); |
|
|
|
List<UpdateTagUseCountsResultDTO> tagsInfo = new ArrayList<>(); |
|
|
|
//政府端的 标签使用次数 DB和redis更新(zSet)
|
|
|
|
for (String tag : tagsList) { |
|
|
|
UpdateTagUseCountsResultDTO updateTagUseCount = tagCustomerService.checkTagInfo(tag, customerId, userId); |
|
|
|
tagsInfo.add(updateTagUseCount); |
|
|
|
} |
|
|
|
UpdateCustomerTagCacheDTO result = new UpdateCustomerTagCacheDTO(); |
|
|
|
result.setCustomerId(customerId); |
|
|
|
result.setTagsInfo(tagsInfo); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 更新redis 标签使用数量 和 标签级联 |
|
|
|
* @param formDto |
|
|
|
* @author zxc |
|
|
|
*/ |
|
|
|
public void updateCacheCustomerTag(UpdateCustomerTagCacheDTO formDto){ |
|
|
|
List<UpdateTagUseCountsResultDTO> tagsInfo = formDto.getTagsInfo(); |
|
|
|
String customerId = formDto.getCustomerId(); |
|
|
|
//更新缓存标签使用数量
|
|
|
|
for (UpdateTagUseCountsResultDTO resultDTO : tagsInfo) { |
|
|
|
String customerKey = TagConstant.GOV_TAG_KEY+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(); |
|
|
|
tagsInfoCopy.remove(tagsInfo.get(i)); |
|
|
|
Set<UpdateTagUseCountsResultDTO> setTag = new HashSet<>(tagsInfoCopy); |
|
|
|
tagRedis.updateMoreTag(key,setTag); |
|
|
|
tagsInfoCopy.clear(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 更新数据库 网格下的标签使用数量 |
|
|
|
* @param draftId |
|
|
|
* @param formDto |
|
|
|
* @author zxc |
|
|
|
*/ |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public List<UpdateGridTagCacheDTO> updateGridTag(TokenDto tokenDto,String draftId,UpdateCustomerTagCacheDTO formDto){ |
|
|
|
//获取草稿基本信息
|
|
|
|
DraftDTO draft = draftService.get(draftId); |
|
|
|
String customerId = draft.getCustomerId(); |
|
|
|
List<UpdateTagUseCountsResultDTO> tagsInfo = formDto.getTagsInfo(); |
|
|
|
String userId = tokenDto.getUserId(); |
|
|
|
List<String> gridIds = articlePublishRangeDao.selectGridIdByDraftId(draftId); |
|
|
|
List<UpdateGridTagsFormDTO> gridTags = new ArrayList<>(); |
|
|
|
List<UpdateGridTagCacheDTO> gridTagCache = new ArrayList<>(); |
|
|
|
for (String gridId : gridIds) { |
|
|
|
UpdateGridTagCacheDTO cache = new UpdateGridTagCacheDTO(); |
|
|
|
cache.setGridId(gridId); |
|
|
|
cache.setTagsInfo(tagsInfo); |
|
|
|
gridTagCache.add(cache); |
|
|
|
for (UpdateTagUseCountsResultDTO resultDTO : tagsInfo) { |
|
|
|
UpdateGridTagsFormDTO tag = new UpdateGridTagsFormDTO(); |
|
|
|
BeanUtils.copyProperties(resultDTO,tag); |
|
|
|
tag.setCreatedBy(userId); |
|
|
|
tag.setUpdatedBy(userId); |
|
|
|
tag.setCustomerId(customerId); |
|
|
|
tag.setGridId(gridId); |
|
|
|
gridTags.add(tag); |
|
|
|
} |
|
|
|
} |
|
|
|
tagGridDao.updateGridTag(gridTags,userId); |
|
|
|
return gridTagCache; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 更新redis 网格下的 标签使用数量 和 级联标签 |
|
|
|
* @param gridTagCache |
|
|
|
* @author zxc |
|
|
|
*/ |
|
|
|
public void updateCacheGridTag(List<UpdateGridTagCacheDTO> gridTagCache){ |
|
|
|
//更新 网格下 标签使用数量
|
|
|
|
List<UpdateTagUseCountsResultDTO> gridTagCacheCopy = new ArrayList<>(); |
|
|
|
for (UpdateGridTagCacheDTO cacheDTO : gridTagCache) { |
|
|
|
String gridId = cacheDTO.getGridId(); |
|
|
|
String key = TagConstant.GRID_TAG_KEY+gridId; |
|
|
|
List<UpdateTagUseCountsResultDTO> tagsInfo = cacheDTO.getTagsInfo(); |
|
|
|
for (UpdateTagUseCountsResultDTO resultDTO : tagsInfo) { |
|
|
|
tagRedis.updateTagUseCounts(key,resultDTO); |
|
|
|
} |
|
|
|
//级联
|
|
|
|
for (int i = 0; i < tagsInfo.size(); i++) { |
|
|
|
gridTagCacheCopy.addAll(tagsInfo); |
|
|
|
String moreKey = TagConstant.GRID_RETAG_KEY+gridId+TagConstant.COLON+tagsInfo.get(i).getTagId(); |
|
|
|
gridTagCacheCopy.remove(tagsInfo.get(i)); |
|
|
|
Set<UpdateTagUseCountsResultDTO> setTag = new HashSet<>(gridTagCacheCopy); |
|
|
|
tagRedis.updateMoreTag(moreKey,setTag); |
|
|
|
gridTagCacheCopy.clear(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |