feat: new api /tags/hierarchical

main
itao 1 year ago
parent f0e2313b0d
commit f493bf5b99

@ -84,4 +84,10 @@ public class TagInfoController {
public Result<List<UserInfo>> queryCreator() {
return Result.success(tagService.queryCreator());
}
@ApiOperation(value = "查询(层级)标签列表", notes = "查询(层级)标签列表")
@GetMapping("/hierarchical")
public Result<List<TagHierarchicalDTO>> queryHierarchicalTagList() {
return Result.success(tagService.queryHierarchicalTagList());
}
}

@ -0,0 +1,26 @@
package com.luoo.tag.pojo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
@ApiModel(value = "标签层级对象DTO")
public class TagHierarchicalDTO implements Serializable {
private static final long serialVersionUID = -1198060864891902188L;
@ApiModelProperty(value = "标签ID")
private String id;
@ApiModelProperty(value = "标签中文名称")
private String nameCh;
@ApiModelProperty(value = "标签英文名称")
private String nameEn;
@ApiModelProperty(value = "子标签集合")
private List<TagHierarchicalDTO> children;
}

@ -27,8 +27,7 @@ import java.time.LocalDateTime;
import java.util.*;
import java.util.function.Function;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;
import static java.util.stream.Collectors.*;
/**
*
@ -342,4 +341,32 @@ public class TagService {
return criteriaBuilder.and(predicateList.toArray(predicates));
};
}
/**
*
* @return
*/
public List<TagHierarchicalDTO> queryHierarchicalTagList() {
List<Tag> tagList = tagDao.findAll();
Map<String, List<Tag>> tagMap = tagList.stream().collect(groupingBy(Tag::getParentId));
List<Tag> rootTagList = tagMap.get(StringUtils.EMPTY);
List<TagHierarchicalDTO> tagHierarchicalDTOList = Lists.newArrayList();
rootTagList.forEach(tag -> {
TagHierarchicalDTO tagHierarchicalDTO = new TagHierarchicalDTO();
BeanUtils.copyProperties(tag, tagHierarchicalDTO);
tagHierarchicalDTOList.add(tagHierarchicalDTO);
List<Tag> childTagList = tagMap.get(tag.getId());
if(CollectionUtils.isEmpty(childTagList)){
return;
}
List<TagHierarchicalDTO> childTagHierarchicalDTOList = childTagList.stream().map(childTag -> {
TagHierarchicalDTO childTagHierarchicalDTO = new TagHierarchicalDTO();
BeanUtils.copyProperties(childTag, childTagHierarchicalDTO);
return childTagHierarchicalDTO;
}).collect(toList());
tagHierarchicalDTO.setChildren(childTagHierarchicalDTOList);
});
return tagHierarchicalDTOList;
}
}

Loading…
Cancel
Save