|
|
|
@ -2,13 +2,11 @@ package com.luoo.tag.service;
|
|
|
|
|
|
|
|
|
|
import api.PageResult;
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
import com.luoo.tag.client.UserClient;
|
|
|
|
|
import com.luoo.tag.config.RequestContext;
|
|
|
|
|
import com.luoo.tag.dao.TagDao;
|
|
|
|
|
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.*;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
@ -17,6 +15,9 @@ import org.springframework.data.domain.Page;
|
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
import util.AssertUtil;
|
|
|
|
|
import util.IdWorker;
|
|
|
|
|
|
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
|
@ -35,6 +36,7 @@ import static java.util.stream.Collectors.toMap;
|
|
|
|
|
public class TagService {
|
|
|
|
|
private final TagDao tagDao;
|
|
|
|
|
private final IdWorker idWorker;
|
|
|
|
|
private final UserClient userClient;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分页查询标签
|
|
|
|
@ -56,7 +58,7 @@ public class TagService {
|
|
|
|
|
BeanUtils.copyProperties(tag, tagDTO);
|
|
|
|
|
TagStatistic tagStatistic = tagStatisticMap.get(tag.getId());
|
|
|
|
|
tagDTO.setChildTagCount(tagStatistic.getChildTagCount());
|
|
|
|
|
tagDTO.setArticleRefCount(tagStatistic.getColumnRefCount());
|
|
|
|
|
tagDTO.setColumnRefCount(tagStatistic.getColumnRefCount());
|
|
|
|
|
tagDTO.setSongRefCount(tagStatistic.getSongRefCount());
|
|
|
|
|
Tag parentTag = parentTagMap.get(tagDTO.getParentId());
|
|
|
|
|
if (Objects.nonNull(parentTag)) {
|
|
|
|
@ -112,6 +114,14 @@ public class TagService {
|
|
|
|
|
AssertUtil.mustTrue(nameDuplicateCheck, "标签中英文名称不允许重复");
|
|
|
|
|
|
|
|
|
|
Tag tag = tagOptional.get();
|
|
|
|
|
String parentId = updateReq.getParentId();
|
|
|
|
|
if (StringUtils.isNotBlank(parentId) && !parentId.equals(tag.getParentId())){
|
|
|
|
|
Optional<Tag> parentTagOptional = tagDao.findById(parentId);
|
|
|
|
|
AssertUtil.mustTrue(parentTagOptional.isPresent(), "父标签记录不存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tag.setParentId(parentId);
|
|
|
|
|
tag.setLevel(StringUtils.isBlank(parentId) ? TagLevelEnum.L1.getCode() : TagLevelEnum.L2.getCode());
|
|
|
|
|
tag.setNameCh(updateReq.getNameCh());
|
|
|
|
|
tag.setNameEn(updateReq.getNameEn());
|
|
|
|
|
tag.setUpdateTime(LocalDateTime.now());
|
|
|
|
@ -133,7 +143,7 @@ public class TagService {
|
|
|
|
|
|
|
|
|
|
TagStatistic tagStatistic = queryTagStatistic(tag.getId());
|
|
|
|
|
tagDTO.setChildTagCount(tagStatistic.getChildTagCount());
|
|
|
|
|
tagDTO.setArticleRefCount(tagStatistic.getColumnRefCount());
|
|
|
|
|
tagDTO.setColumnRefCount(tagStatistic.getColumnRefCount());
|
|
|
|
|
tagDTO.setSongRefCount(tagStatistic.getSongRefCount());
|
|
|
|
|
return tagDTO;
|
|
|
|
|
}
|
|
|
|
@ -156,7 +166,7 @@ public class TagService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除标签
|
|
|
|
|
* 删除标签(支持幂等)
|
|
|
|
|
* @param id 标签ID
|
|
|
|
|
*/
|
|
|
|
|
public void delete(String id){
|
|
|
|
@ -172,6 +182,22 @@ public class TagService {
|
|
|
|
|
tagDao.deleteById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询标签创建人
|
|
|
|
|
* @return 标签创建人列表
|
|
|
|
|
*/
|
|
|
|
|
public List<UserInfo> queryCreator(){
|
|
|
|
|
/*List<String> creatorIdList = tagDao.queryCreator();
|
|
|
|
|
Result<List<UserInfo>> userInfoResult = userClient.queryAdminList(creatorIdList);
|
|
|
|
|
long resultCode = userInfoResult.getCode();
|
|
|
|
|
if(resultCode == 0){
|
|
|
|
|
return userInfoResult.getData();
|
|
|
|
|
}*/
|
|
|
|
|
UserInfo foo = UserInfo.builder().id("1627863701048659968").name("foo").build();
|
|
|
|
|
UserInfo other = UserInfo.builder().id("1627863701048659969").name("老左").build();
|
|
|
|
|
return Lists.newArrayList(foo, other);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 通过标签ID查询标签信息
|
|
|
|
|
* @param idList 标签ID集合
|
|
|
|
|