|
|
|
@ -1,7 +1,12 @@
|
|
|
|
|
package com.luoo.tag.service;
|
|
|
|
|
|
|
|
|
|
import api.PageResult;
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
import com.luoo.tag.config.RequestContext;
|
|
|
|
|
import com.luoo.tag.enums.TagLevelEnum;
|
|
|
|
|
import com.luoo.tag.enums.TagStateEnum;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
import util.AssertUtil;
|
|
|
|
|
import com.luoo.tag.dao.TagDao;
|
|
|
|
|
import com.luoo.tag.pojo.*;
|
|
|
|
@ -33,9 +38,9 @@ public class TagService {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分页查询标签
|
|
|
|
|
* @return
|
|
|
|
|
* @return PageResult<TagDTO>
|
|
|
|
|
*/
|
|
|
|
|
public Page<TagDTO> queryPage(TagQueryReq queryReq){
|
|
|
|
|
public PageResult<TagDTO> queryPage(TagQueryReq queryReq){
|
|
|
|
|
Specification<Tag> specification = createSpecification(queryReq);
|
|
|
|
|
|
|
|
|
|
PageRequest pageRequest = PageRequest.of(queryReq.getPageNum()-1, queryReq.getPageSize());
|
|
|
|
@ -46,7 +51,7 @@ public class TagService {
|
|
|
|
|
.distinct().collect(toList());
|
|
|
|
|
Map<String, Tag> parentTagMap = queryTagMap(parentIdList);
|
|
|
|
|
Map<String, TagStatistic> tagStatisticMap = queryTagStatistic(tagIdList);
|
|
|
|
|
return tagPage.map(tag -> {
|
|
|
|
|
Page<TagDTO> pageDTOPage = tagPage.map(tag -> {
|
|
|
|
|
TagDTO tagDTO = new TagDTO();
|
|
|
|
|
BeanUtils.copyProperties(tag, tagDTO);
|
|
|
|
|
TagStatistic tagStatistic = tagStatisticMap.get(tag.getId());
|
|
|
|
@ -54,16 +59,12 @@ public class TagService {
|
|
|
|
|
tagDTO.setArticleRefCount(tagStatistic.getColumnRefCount());
|
|
|
|
|
tagDTO.setSongRefCount(tagStatistic.getSongRefCount());
|
|
|
|
|
Tag parentTag = parentTagMap.get(tagDTO.getParentId());
|
|
|
|
|
if(Objects.nonNull(parentTag)){
|
|
|
|
|
if (Objects.nonNull(parentTag)) {
|
|
|
|
|
tagDTO.setParentNameCh(parentTag.getNameCh());
|
|
|
|
|
}
|
|
|
|
|
return tagDTO;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<String, Tag> queryTagMap(List<String> idList){
|
|
|
|
|
List<Tag> tagList = tagDao.findAllById(idList);
|
|
|
|
|
return tagList.stream().collect(toMap(Tag::getId, Function.identity()));
|
|
|
|
|
return new PageResult<>(pageDTOPage.getTotalElements(), pageDTOPage.getContent());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -81,13 +82,19 @@ public class TagService {
|
|
|
|
|
}else{
|
|
|
|
|
createReq.setParentId(StringUtils.EMPTY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Tag tag = new Tag();
|
|
|
|
|
BeanUtils.copyProperties(createReq, tag);
|
|
|
|
|
tag.setId(idWorker.nextId()+"");
|
|
|
|
|
tag.setState(1);
|
|
|
|
|
tag.setLevel(StringUtils.isBlank(parentId) ? TagLevelEnum.L1.getCode() : TagLevelEnum.L2.getCode());
|
|
|
|
|
tag.setState(TagStateEnum.ENABLE.getCode());
|
|
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
tag.setCreateTime(now);
|
|
|
|
|
tag.setUpdateTime(now);
|
|
|
|
|
|
|
|
|
|
UserInfo userInfo = RequestContext.get();
|
|
|
|
|
tag.setCreatorId(userInfo.getId());
|
|
|
|
|
tag.setUpdaterId(userInfo.getId());
|
|
|
|
|
tagDao.save(tag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -108,6 +115,7 @@ public class TagService {
|
|
|
|
|
tag.setNameCh(updateReq.getNameCh());
|
|
|
|
|
tag.setNameEn(updateReq.getNameEn());
|
|
|
|
|
tag.setUpdateTime(LocalDateTime.now());
|
|
|
|
|
tag.setUpdaterId(RequestContext.get().getId());
|
|
|
|
|
tagDao.save(tag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -137,10 +145,14 @@ public class TagService {
|
|
|
|
|
*/
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void updateState(String id, Integer state){
|
|
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
tagDao.updateStateById(state, id);
|
|
|
|
|
Tag updateTag = new Tag();
|
|
|
|
|
updateTag.setId(id);
|
|
|
|
|
updateTag.setState(state);
|
|
|
|
|
updateTag.setUpdaterId(RequestContext.get().getId());
|
|
|
|
|
updateTag.setUpdateTime(LocalDateTime.now());
|
|
|
|
|
tagDao.updateStateById(updateTag);
|
|
|
|
|
// 级联更新子标签状态
|
|
|
|
|
tagDao.updateStateByParentId(state, id);
|
|
|
|
|
tagDao.updateStateByParentId(updateTag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -160,6 +172,16 @@ public class TagService {
|
|
|
|
|
tagDao.deleteById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 通过标签ID查询标签信息
|
|
|
|
|
* @param idList 标签ID集合
|
|
|
|
|
* @return 标签信息Map
|
|
|
|
|
*/
|
|
|
|
|
private Map<String, Tag> queryTagMap(List<String> idList){
|
|
|
|
|
List<Tag> tagList = tagDao.findAllById(idList);
|
|
|
|
|
return tagList.stream().collect(toMap(Tag::getId, Function.identity()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 通过标签编码查询引用统计
|
|
|
|
@ -179,7 +201,7 @@ public class TagService {
|
|
|
|
|
private Map<String, TagStatistic> queryTagStatistic(List<String> tagIdList){
|
|
|
|
|
Map<String, TagStatistic> tagStatisticMap = tagIdList.stream()
|
|
|
|
|
.collect(toMap(Function.identity(), TagStatistic::new));
|
|
|
|
|
List<TagStatistic> childTagStatisticList = tagDao.countByParentIds(tagIdList);
|
|
|
|
|
List<TagStatistic> childTagStatisticList = queryChildTagStatistic(tagIdList);
|
|
|
|
|
childTagStatisticList.forEach(childTagStatistic -> {
|
|
|
|
|
tagStatisticMap.get(childTagStatistic.getTagId()).setChildTagCount(childTagStatistic.getChildTagCount());
|
|
|
|
|
});
|
|
|
|
@ -187,6 +209,24 @@ public class TagService {
|
|
|
|
|
return tagStatisticMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<TagStatistic> queryChildTagStatistic(List<String> tagIdList){
|
|
|
|
|
if(CollectionUtils.isEmpty(tagIdList)){
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
List<TagStatistic> childTagStatisticList = tagDao.countByParentIds(tagIdList);
|
|
|
|
|
Map<String, TagStatistic> childTagStatisticMap = childTagStatisticList.stream()
|
|
|
|
|
.collect(toMap(TagStatistic::getTagId, Function.identity()));
|
|
|
|
|
return tagIdList.stream().map(tagId -> {
|
|
|
|
|
TagStatistic tagStatistic = childTagStatisticMap.get(tagId);
|
|
|
|
|
if(Objects.isNull(tagStatistic)){
|
|
|
|
|
tagStatistic = new TagStatistic();
|
|
|
|
|
tagStatistic.setTagId(tagId);
|
|
|
|
|
tagStatistic.setChildTagCount(0L);
|
|
|
|
|
}
|
|
|
|
|
return tagStatistic;
|
|
|
|
|
}).collect(toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建动态查询条件
|
|
|
|
|
* @param queryReq 列表查询参数
|
|
|
|
@ -204,17 +244,17 @@ public class TagService {
|
|
|
|
|
if(Objects.nonNull(queryReq.getState())){
|
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("state").as(Integer.class), queryReq.getState()));
|
|
|
|
|
}
|
|
|
|
|
if(Objects.nonNull(queryReq.getCreatorId())){
|
|
|
|
|
if(StringUtils.isNotBlank(queryReq.getCreatorId())){
|
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("creatorId"), queryReq.getCreatorId()));
|
|
|
|
|
}
|
|
|
|
|
if(StringUtils.isNotBlank(queryReq.getId())){
|
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("id"), queryReq.getId()));
|
|
|
|
|
}
|
|
|
|
|
Integer level = queryReq.getLevel();
|
|
|
|
|
if (level.compareTo(1) == 0){
|
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("parentId"), ""));
|
|
|
|
|
if(Objects.nonNull(level)){
|
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("level"), level));
|
|
|
|
|
}
|
|
|
|
|
if(level.compareTo(2) == 0 && StringUtils.isNotBlank(queryReq.getParentId())){
|
|
|
|
|
if(StringUtils.isNotBlank(queryReq.getParentId())){
|
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("parentId"), queryReq.getParentId()));
|
|
|
|
|
}
|
|
|
|
|
if(Objects.nonNull(queryReq.getCreateTimeStart())){
|
|
|
|
|