fix: add api /creator/list

main
itao 1 year ago
parent c044745bc0
commit 38bac893e2

@ -1,12 +1,18 @@
package com.luoo.tag.client;
import api.Result;
import com.luoo.tag.pojo.UserInfo;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.List;
@FeignClient("luoo-user")
public interface UserClient {
@GetMapping("/admin")
public Result findAll();
@GetMapping("/admin/list")
public Result<List<UserInfo>> queryAdminList(List<String> idList);
@GetMapping("/admin")
public Result<List<UserInfo>> findAll(List<String> idList);
}

@ -2,10 +2,7 @@ package com.luoo.tag.controller;
import api.PageResult;
import api.Result;
import com.luoo.tag.pojo.TagCreateReq;
import com.luoo.tag.pojo.TagDTO;
import com.luoo.tag.pojo.TagQueryReq;
import com.luoo.tag.pojo.TagUpdateReq;
import com.luoo.tag.pojo.*;
import com.luoo.tag.service.TagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
@ -15,6 +12,8 @@ import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* Web
*/
@ -68,11 +67,17 @@ public class TagController {
return Result.success();
}
@ApiOperation(value = "删除标签", notes = "删除标签")
@ApiOperation(value = "删除标签信息", notes = "删除标签信息")
@ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "标签ID", required = true) })
@DeleteMapping("/{id}")
public Result<Void> delete(@PathVariable String id) {
tagService.delete(id);
return Result.success();
}
@ApiOperation(value = "查询标签创建人", notes = "查询标签创建人")
@GetMapping("/creator/list")
public Result<List<UserInfo>> queryCreator() {
return Result.success(tagService.queryCreator());
}
}

@ -31,4 +31,7 @@ public interface TagDao extends JpaRepository<Tag, String>, JpaSpecificationExec
@Query(value = "select new com.luoo.tag.pojo.TagStatistic(parentId, count(*)) from Tag where parentId in :parentIds group by parentId")
List<TagStatistic> countByParentIds(List<String> parentIds);
@Query(value = "select distinct creator_id from tb_tag order by create_time desc", nativeQuery = true)
List<String> queryCreator();
}

@ -16,8 +16,8 @@ public class TagDTO implements Serializable {
@ApiModelProperty(value = "标签ID")
private String id;
@ApiModelProperty(value = "父标签ID")
private String parentId;
@ApiModelProperty(value = "父标签ID(空字符串表示)")
private String parentId = "";
@ApiModelProperty(value = "父标签名称")
private String parentNameCh = "";
@ -34,8 +34,8 @@ public class TagDTO implements Serializable {
@ApiModelProperty(value = "子标签数量")
private Long childTagCount = 0L;
@ApiModelProperty(value = "关联期刊数量TODO")
private Long articleRefCount = 0L;
@ApiModelProperty(value = "关联期刊数量")
private Long columnRefCount = 0L;
@ApiModelProperty(value = "关联歌曲数量")
private Long songRefCount = 0L;

@ -1,5 +1,6 @@
package com.luoo.tag.pojo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -14,9 +15,15 @@ import java.io.Serializable;
public class TagUpdateReq implements Serializable {
private static final long serialVersionUID = -8810544476079524714L;
@ApiModelProperty(value = "标签ID")
/**
* ID
*/
@JsonIgnore
private String id;
@ApiModelProperty(value = "父标签ID")
private String parentId;
@ApiModelProperty(value = "标签中文名")
@NotBlank(message = "标签中文名称必填")
private String nameCh;

@ -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

Loading…
Cancel
Save