feat(标签库): 基础功能
This commit is contained in:
+52
@@ -0,0 +1,52 @@
|
|||||||
|
package com.jero.modules.laws.labeldatabase.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.jero.common.api.vo.Result;
|
||||||
|
import com.jero.common.aspect.annotation.AutoLog;
|
||||||
|
import com.jero.modules.laws.labeldatabase.entity.LawsLabelDatabase;
|
||||||
|
import com.jero.modules.laws.labeldatabase.service.ILawsLabelDatabaseService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import io.swagger.annotations.ApiParam;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName: LawsLabelDatabaseController
|
||||||
|
* @Description:
|
||||||
|
* @Author: yjz
|
||||||
|
* @Date: 2024-01-26 10:21
|
||||||
|
* @Version: 1.0
|
||||||
|
**/
|
||||||
|
|
||||||
|
@Api(tags = "标签库")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/laws/lawsLabelDatabase")
|
||||||
|
@Slf4j
|
||||||
|
public class LawsLabelDatabaseController {
|
||||||
|
private final ILawsLabelDatabaseService lawsLabelDatabaseService;
|
||||||
|
|
||||||
|
public LawsLabelDatabaseController(ILawsLabelDatabaseService lawsLabelDatabaseService) {
|
||||||
|
this.lawsLabelDatabaseService = lawsLabelDatabaseService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标准化活动-树结构查询
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@AutoLog(value = "标签库-树结构查询")
|
||||||
|
@ApiOperation(value="标签库-树结构查询", notes="标签库-树结构查询")
|
||||||
|
@GetMapping(value = "/queryTreeList")
|
||||||
|
public Result<IPage<LawsLabelDatabase>> queryTreeList(@ApiParam("一级节点名称") String firstNodeName,
|
||||||
|
@ApiParam("当前页")
|
||||||
|
@RequestParam(name="pageNo", defaultValue="1")
|
||||||
|
Integer pageNo,
|
||||||
|
@ApiParam("每页条数")
|
||||||
|
@RequestParam(name="pageSize", defaultValue="10")
|
||||||
|
Integer pageSize) {
|
||||||
|
return Result.OK(lawsLabelDatabaseService.queryTreeList(firstNodeName, pageNo, pageSize));
|
||||||
|
}
|
||||||
|
}
|
||||||
+49
@@ -0,0 +1,49 @@
|
|||||||
|
package com.jero.modules.laws.labeldatabase.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.jero.modules.laws.documenttool.entity.BaseEntity;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author yjz
|
||||||
|
* @TableName laws_label_database
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName(value = "laws_label_database")
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@ApiModel(value = "laws_label_database对象", description = "标签库")
|
||||||
|
public class LawsLabelDatabase extends BaseEntity {
|
||||||
|
/** 标签码 */
|
||||||
|
@ApiModelProperty(value = "标签码")
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/** 标签名称 */
|
||||||
|
@ApiModelProperty(value = "标签名称")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/** 父id */
|
||||||
|
@ApiModelProperty(value = "父id")
|
||||||
|
private String parentId;
|
||||||
|
|
||||||
|
/** 一级节点 */
|
||||||
|
@ApiModelProperty(value = "一级节点")
|
||||||
|
private String firstNode;
|
||||||
|
|
||||||
|
/** 层级 */
|
||||||
|
@TableField(exist = false)
|
||||||
|
@ApiModelProperty(value = "层级")
|
||||||
|
private Integer level;
|
||||||
|
|
||||||
|
/** 子零部件 */
|
||||||
|
@TableField(exist = false)
|
||||||
|
@ApiModelProperty(value = "子集")
|
||||||
|
private List<LawsLabelDatabase> childrenList;
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
package com.jero.modules.laws.labeldatabase.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.jero.modules.laws.labeldatabase.entity.LawsLabelDatabase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @InterfaceName: LawsLabelDatabaseMapper
|
||||||
|
* @Description:
|
||||||
|
* @Author: yjz
|
||||||
|
* @Date: 2024-01-26 10:23
|
||||||
|
* @Version: 1.0
|
||||||
|
**/
|
||||||
|
public interface LawsLabelDatabaseMapper extends BaseMapper<LawsLabelDatabase> {
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.jero.modules.laws.labeldatabase.mapper.LawsLabelDatabaseMapper">
|
||||||
|
|
||||||
|
</mapper>
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
package com.jero.modules.laws.labeldatabase.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.jero.modules.laws.labeldatabase.entity.LawsLabelDatabase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @InterfaceName: ILawsLabelDatabaseService
|
||||||
|
* @Description:
|
||||||
|
* @Author: yjz
|
||||||
|
* @Date: 2024-01-26 10:23
|
||||||
|
* @Version: 1.0
|
||||||
|
**/
|
||||||
|
public interface ILawsLabelDatabaseService extends IService<LawsLabelDatabase> {
|
||||||
|
/**
|
||||||
|
* 树结构查询
|
||||||
|
*
|
||||||
|
* @param firstNodeName
|
||||||
|
* @param pageNo
|
||||||
|
* @param pageSize
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
IPage<LawsLabelDatabase> queryTreeList(String firstNodeName, Integer pageNo, Integer pageSize);
|
||||||
|
}
|
||||||
+87
@@ -0,0 +1,87 @@
|
|||||||
|
package com.jero.modules.laws.labeldatabase.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.jero.modules.laws.labeldatabase.entity.LawsLabelDatabase;
|
||||||
|
import com.jero.modules.laws.labeldatabase.mapper.LawsLabelDatabaseMapper;
|
||||||
|
import com.jero.modules.laws.labeldatabase.service.ILawsLabelDatabaseService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName: ILawsLabelDatabaseServiceImpl
|
||||||
|
* @Description:
|
||||||
|
* @Author: yjz
|
||||||
|
* @Date: 2024-01-26 10:22
|
||||||
|
* @Version: 1.0
|
||||||
|
**/
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class LawsLabelDatabaseServiceImpl
|
||||||
|
extends ServiceImpl<LawsLabelDatabaseMapper, LawsLabelDatabase>
|
||||||
|
implements ILawsLabelDatabaseService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPage<LawsLabelDatabase> queryTreeList(String firstNodeName, Integer pageNo, Integer pageSize) {
|
||||||
|
// 查询所有数据
|
||||||
|
List<LawsLabelDatabase> list = list((new LambdaQueryWrapper<LawsLabelDatabase>()
|
||||||
|
.orderByDesc(LawsLabelDatabase::getCreateTime)));
|
||||||
|
// 根节点
|
||||||
|
List<LawsLabelDatabase> rootNodeList = list.stream()
|
||||||
|
.filter(v -> StringUtils.isBlank(v.getParentId()))
|
||||||
|
.map(v -> v.setLevel(1))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
// 搜索条件
|
||||||
|
if (StringUtils.isNotBlank(firstNodeName)){
|
||||||
|
rootNodeList = rootNodeList.stream()
|
||||||
|
.filter(v -> v.getName().contains(firstNodeName))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
// 构建树结构
|
||||||
|
rootNodeList.stream()
|
||||||
|
.map(v -> {
|
||||||
|
v.setChildrenList(createChildren(v, list, 1));
|
||||||
|
return v;
|
||||||
|
}).forEach(v -> log.info(v.getId()));
|
||||||
|
|
||||||
|
// 手动分页
|
||||||
|
IPage<LawsLabelDatabase> page = new Page<>(pageNo, pageSize);
|
||||||
|
page.setTotal(rootNodeList.size());
|
||||||
|
page.setRecords(rootNodeList.stream()
|
||||||
|
.skip((long) (Math.max(1, pageNo) - 1) * pageSize)
|
||||||
|
.limit(pageSize)
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 递归构建子节点
|
||||||
|
* @param tree
|
||||||
|
* @param treeList
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private List<LawsLabelDatabase> createChildren(LawsLabelDatabase tree, List<LawsLabelDatabase> treeList, Integer level) {
|
||||||
|
List<LawsLabelDatabase> collect = treeList.stream().filter(v -> Objects.equals(tree.getId(), v.getParentId())).collect(Collectors.toList());
|
||||||
|
// 计算层级
|
||||||
|
if (!collect.isEmpty()){
|
||||||
|
level += 1 ;
|
||||||
|
}else {
|
||||||
|
level -= 1;
|
||||||
|
}
|
||||||
|
Integer finalLevel = level;
|
||||||
|
return collect.stream()
|
||||||
|
.map(v -> {
|
||||||
|
// 层级
|
||||||
|
v.setLevel(finalLevel);
|
||||||
|
v.setChildrenList(createChildren(v, treeList, finalLevel));
|
||||||
|
return v;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user