feat: add api /tag/name

main
itao 1 year ago
parent cf419fbe92
commit d43c622020

@ -1,16 +0,0 @@
package com.luoo.tag.controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Web
*/
@RestController
@CrossOrigin
@RequestMapping("/tag/creator")
public class TagCreatorController {
}

@ -15,19 +15,19 @@ import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* Web
* Web
*/
@RestController
@CrossOrigin
@Api(tags = "标签API")
@RequestMapping("/tag")
@RequiredArgsConstructor
public class TagController {
public class TagInfoController {
private final TagService tagService;
@ApiOperation(value = "查询标签列表", notes = "查询标签列表")
@GetMapping("/list")
public Result<PageResult<TagDTO>> list(@Validated TagQueryReq queryReq) {
public Result<PageResult<TagDTO>> page(@Validated TagQueryReq queryReq) {
return Result.success(tagService.queryPage(queryReq));
}
@ -39,7 +39,6 @@ public class TagController {
}
@ApiOperation(value = "新增标签信息", notes = "新增标签信息")
@ApiImplicitParams({ @ApiImplicitParam(name = "createReq", value = "创建参数", required = true) })
@PostMapping
public Result<Void> create(@Validated @RequestBody TagCreateReq createReq) {
tagService.create(createReq);
@ -47,8 +46,7 @@ public class TagController {
}
@ApiOperation(value = "更新标签信息", notes = "更新标签信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "updateReq", value = "更新参数", required = true),
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "标签ID", required = true) })
@PutMapping("/{id}")
public Result<Void> update(@Validated @RequestBody TagUpdateReq updateReq, @PathVariable String id) {
@ -75,6 +73,12 @@ public class TagController {
return Result.success();
}
@ApiOperation(value = "查询标签名称", notes = "查询标签名称")
@GetMapping("/name")
public Result<List<TagNameDTO>> queryTagNameList(TagNameQueryReq queryReq) {
return Result.success(tagService.queryTagNameList(queryReq));
}
@ApiOperation(value = "查询标签创建人", notes = "查询标签创建人")
@GetMapping("/creator/list")
public Result<List<UserInfo>> queryCreator() {

@ -0,0 +1,31 @@
package com.luoo.tag.pojo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
@Data
@ApiModel(value = "标签名称DTO")
public class TagNameDTO implements Serializable {
private static final long serialVersionUID = -1198060864891902188L;
@ApiModelProperty(value = "标签层级 1=一级2=二级")
private Integer level;
@ApiModelProperty(value = "标签ID")
private String id;
@ApiModelProperty(value = "父标签ID(空字符串表示)")
private String parentId = "";
@ApiModelProperty(value = "标签中文名称")
private String nameCh;
@ApiModelProperty(value = "标签英文名称")
private String nameEn;
@ApiModelProperty(value = "标签状态 0=禁用1=启用")
private Integer state;
}

@ -0,0 +1,25 @@
package com.luoo.tag.pojo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
*
*/
@Data
@ApiModel(value = "标签名称列表查询请求")
public class TagNameQueryReq implements Serializable {
private static final long serialVersionUID = -2488176417248177119L;
@ApiModelProperty(value = "标签层级 1=一级2=二级")
private Integer level;
@ApiModelProperty(value = "父标签ID")
private String parentId;
@ApiModelProperty(value = "标签状态 0=禁用1=启用")
private Integer state;
}

@ -39,11 +39,11 @@ public class TagService {
private final UserClient userClient;
/**
*
*
* @return PageResult<TagDTO>
*/
public PageResult<TagDTO> queryPage(TagQueryReq queryReq){
Specification<Tag> specification = createSpecification(queryReq);
Specification<Tag> specification = createTagInfoSpecification(queryReq);
PageRequest pageRequest = PageRequest.of(queryReq.getPageNum()-1, queryReq.getPageSize());
Page<Tag> tagPage = tagDao.findAll(specification, pageRequest);
@ -182,6 +182,26 @@ public class TagService {
tagDao.deleteById(id);
}
/**
*
* @param queryReq
* @return
*/
public List<TagNameDTO> queryTagNameList(TagNameQueryReq queryReq) {
Specification<Tag> tagNameSpecification = createTagNameSpecification(queryReq);
List<Tag> tagList = tagDao.findAll(tagNameSpecification);
return tagList.stream().map(tag -> {
TagNameDTO tagNameDTO = new TagNameDTO();
tagNameDTO.setLevel(tag.getLevel());
tagNameDTO.setId(tag.getId());
tagNameDTO.setParentId(tag.getParentId());
tagNameDTO.setNameCh(tag.getNameCh());
tagNameDTO.setNameEn(tag.getNameEn());
tagNameDTO.setState(tag.getState());
return tagNameDTO;
}).collect(toList());
}
/**
*
* @return
@ -254,11 +274,11 @@ public class TagService {
}
/**
*
*
* @param queryReq
* @return
*/
private Specification<Tag> createSpecification(TagQueryReq queryReq) {
private Specification<Tag> createTagInfoSpecification(TagQueryReq queryReq) {
return (root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> predicateList = new ArrayList<>();
String tagName = queryReq.getName();
@ -267,22 +287,21 @@ public class TagService {
Predicate tagNameEnPredicate = criteriaBuilder.like(root.get("nameEn"), '%'+tagName+'%');
predicateList.add(criteriaBuilder.or(tagNameChPredicate, tagNameEnPredicate));
}
if(Objects.nonNull(queryReq.getLevel())){
predicateList.add(criteriaBuilder.equal(root.get("level").as(Integer.class), queryReq.getLevel()));
}
if(Objects.nonNull(queryReq.getState())){
predicateList.add(criteriaBuilder.equal(root.get("state").as(Integer.class), queryReq.getState()));
}
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(Objects.nonNull(level)){
predicateList.add(criteriaBuilder.equal(root.get("level"), level));
}
if(StringUtils.isNotBlank(queryReq.getParentId())){
predicateList.add(criteriaBuilder.equal(root.get("parentId"), queryReq.getParentId()));
}
if(StringUtils.isNotBlank(queryReq.getCreatorId())){
predicateList.add(criteriaBuilder.equal(root.get("creatorId"), queryReq.getCreatorId()));
}
if(Objects.nonNull(queryReq.getCreateTimeStart())){
predicateList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("createTime").as(LocalDateTime.class),
queryReq.getCreateTimeStart()));
@ -295,4 +314,27 @@ public class TagService {
return criteriaBuilder.and(predicateList.toArray(predicates));
};
}
/**
*
* @param queryReq
* @return
*/
private Specification<Tag> createTagNameSpecification(TagNameQueryReq queryReq) {
return (root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> predicateList = new ArrayList<>();
Integer level = queryReq.getLevel();
if(Objects.nonNull(level)){
predicateList.add(criteriaBuilder.equal(root.get("level").as(Integer.class), level));
}
if(StringUtils.isNotBlank(queryReq.getParentId())){
predicateList.add(criteriaBuilder.equal(root.get("parentId"), queryReq.getParentId()));
}
if(Objects.nonNull(queryReq.getState())){
predicateList.add(criteriaBuilder.equal(root.get("state").as(Integer.class), queryReq.getState()));
}
Predicate[] predicates = new Predicate[predicateList.size()];
return criteriaBuilder.and(predicateList.toArray(predicates));
};
}
}

Loading…
Cancel
Save