feat: 零部件树接口
This commit is contained in:
+44
@@ -0,0 +1,44 @@
|
|||||||
|
package com.jero.modules.laws.standard.controller;
|
||||||
|
|
||||||
|
import com.jero.common.api.vo.Result;
|
||||||
|
import com.jero.common.aspect.annotation.AutoLog;
|
||||||
|
import com.jero.modules.laws.enterprise.entity.vo.LawsTreeNodeModel;
|
||||||
|
import com.jero.modules.laws.standard.entity.LawsTreeNode;
|
||||||
|
import com.jero.modules.laws.standard.entity.PartName;
|
||||||
|
import com.jero.modules.laws.standard.service.PartNameService;
|
||||||
|
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;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: Mzaxd
|
||||||
|
* @Date: 2024/1/19 10:42
|
||||||
|
*/
|
||||||
|
@Api(tags = "零部件")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/laws/standard/partName")
|
||||||
|
@Slf4j
|
||||||
|
public class LawsPartNameController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private PartNameService partNameService;
|
||||||
|
|
||||||
|
@AutoLog(value = "企业标准-零部件树")
|
||||||
|
@ApiOperation(value = "企业标准-零部件树", notes = "企业标准-零部件树")
|
||||||
|
@GetMapping("/")
|
||||||
|
public Result<List<LawsTreeNodeModel>> queryENTreeList(
|
||||||
|
@RequestParam(required = false, defaultValue = "") @ApiParam("一级节点名称") String nodeName) {
|
||||||
|
List<LawsTreeNodeModel> list = partNameService.queryTreeList(nodeName);
|
||||||
|
return Result.OK(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
package com.jero.modules.laws.standard.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @TableName laws_part_name
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName(value = "laws_part_name")
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@ApiModel(value = "laws_part_name对象", description = "零部件")
|
||||||
|
public class PartName implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键ID
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.ASSIGN_ID)
|
||||||
|
@ApiModelProperty(value = "主键ID")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建人
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "创建人")
|
||||||
|
private String createBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "创建时间")
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新人
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "更新人")
|
||||||
|
private String updateBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "更新时间")
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所属部门
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "所属部门")
|
||||||
|
private String orgCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0表示未删除,1表示删除
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "0表示未删除,1表示删除")
|
||||||
|
private Integer delFlag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 零部件码
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "零部件码")
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 零部件名称
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "零部件名称")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父级零件id
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "父级零件id")
|
||||||
|
private String parentId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子零部件
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
@ApiModelProperty(value = "子零部件")
|
||||||
|
private List<PartName> childPartNameList;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.jero.modules.laws.standard.mapper;
|
||||||
|
|
||||||
|
import com.jero.modules.laws.standard.entity.PartName;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ThinkBook
|
||||||
|
* @description 针对表【laws_part_name】的数据库操作Mapper
|
||||||
|
* @createDate 2024-01-19 10:37:39
|
||||||
|
* @Entity com.jero.modules.laws.standard.entity.PartName
|
||||||
|
*/
|
||||||
|
public interface PartNameMapper extends BaseMapper<PartName> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
package com.jero.modules.laws.standard.service;
|
||||||
|
|
||||||
|
import com.jero.modules.laws.enterprise.entity.vo.LawsTreeNodeModel;
|
||||||
|
import com.jero.modules.laws.standard.entity.LawsTreeNode;
|
||||||
|
import com.jero.modules.laws.standard.entity.PartName;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ThinkBook
|
||||||
|
* @description 针对表【laws_part_name】的数据库操作Service
|
||||||
|
* @createDate 2024-01-19 10:37:39
|
||||||
|
*/
|
||||||
|
public interface PartNameService extends IService<PartName> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询零部件树
|
||||||
|
* @param nodeName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<LawsTreeNodeModel> queryTreeList(String nodeName);
|
||||||
|
}
|
||||||
+2
-2
@@ -103,7 +103,7 @@ public class LawsTreeNodeServiceImpl extends ServiceImpl<LawsTreeNodeMapper, Law
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<LawsTreeNode> findPathToRoot(List<LawsTreeNode> allNodes, LawsTreeNode node) {
|
public static Set<LawsTreeNode> findPathToRoot(List<LawsTreeNode> allNodes, LawsTreeNode node) {
|
||||||
Set<LawsTreeNode> pathNodes = new HashSet<>();
|
Set<LawsTreeNode> pathNodes = new HashSet<>();
|
||||||
LawsTreeNode[] currentHolder = new LawsTreeNode[1];
|
LawsTreeNode[] currentHolder = new LawsTreeNode[1];
|
||||||
currentHolder[0] = node;
|
currentHolder[0] = node;
|
||||||
@@ -116,7 +116,7 @@ public class LawsTreeNodeServiceImpl extends ServiceImpl<LawsTreeNodeMapper, Law
|
|||||||
return pathNodes;
|
return pathNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<LawsTreeNode> findAllChildren(List<LawsTreeNode> allNodes, LawsTreeNode node) {
|
public Set<LawsTreeNode> findAllChildren(List<LawsTreeNode> allNodes, LawsTreeNode node) {
|
||||||
Set<LawsTreeNode> childrenSet = new HashSet<>();
|
Set<LawsTreeNode> childrenSet = new HashSet<>();
|
||||||
List<LawsTreeNode> directChildren = allNodes.stream()
|
List<LawsTreeNode> directChildren = allNodes.stream()
|
||||||
.filter(n -> n.getParentId().equals(node.getId()))
|
.filter(n -> n.getParentId().equals(node.getId()))
|
||||||
|
|||||||
+84
@@ -0,0 +1,84 @@
|
|||||||
|
package com.jero.modules.laws.standard.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.jero.common.constant.CommonConstant;
|
||||||
|
import com.jero.common.exception.JeroBootException;
|
||||||
|
import com.jero.modules.laws.enterprise.EnterpriseConstants;
|
||||||
|
import com.jero.modules.laws.enterprise.entity.vo.LawsTreeNodeModel;
|
||||||
|
import com.jero.modules.laws.enterprise.util.FindsTreeNodeChildrenUtil;
|
||||||
|
import com.jero.modules.laws.standard.entity.LawsTreeNode;
|
||||||
|
import com.jero.modules.laws.standard.entity.PartName;
|
||||||
|
import com.jero.modules.laws.standard.service.PartNameService;
|
||||||
|
import com.jero.modules.laws.standard.mapper.PartNameMapper;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ThinkBook
|
||||||
|
* @description 针对表【laws_part_name】的数据库操作Service实现
|
||||||
|
* @createDate 2024-01-19 10:37:39
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Transactional(rollbackFor = JeroBootException.class)
|
||||||
|
public class PartNameServiceImpl extends ServiceImpl<PartNameMapper, PartName>
|
||||||
|
implements PartNameService{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<LawsTreeNodeModel> queryTreeList(String nodeName) {
|
||||||
|
LambdaQueryWrapper<PartName> query = new LambdaQueryWrapper<>();
|
||||||
|
query.eq(PartName::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
|
||||||
|
List<PartName> allNodesPartName = this.list(query);
|
||||||
|
|
||||||
|
// 将PartName转换为LawsTreeNode
|
||||||
|
List<LawsTreeNode> allNodes = this.convertPartNameToLawsTreeNode(allNodesPartName);
|
||||||
|
|
||||||
|
Set<LawsTreeNode> nodesSet = new HashSet<>();
|
||||||
|
|
||||||
|
List<LawsTreeNode> matchedNodes = allNodes.stream()
|
||||||
|
.filter(node -> node.getNodeName().contains(nodeName))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
for (LawsTreeNode matchedNode : matchedNodes) {
|
||||||
|
nodesSet.addAll(LawsTreeNodeServiceImpl.findPathToRoot(allNodes, matchedNode));
|
||||||
|
// 需求调整 只带上级不带下级
|
||||||
|
// nodesSet.addAll(findAllChildren(allNodes, matchedNode));
|
||||||
|
}
|
||||||
|
// 如果没有任何匹配或者只匹配到了跟节点,则只返回根节点
|
||||||
|
List<LawsTreeNode> lawsTreeNodes = new ArrayList<>();
|
||||||
|
if (nodesSet.size() <= 1) {
|
||||||
|
LawsTreeNode parentNode = allNodes.stream().filter(node -> node.getParentCode() == null).collect(Collectors.toList()).get(0);
|
||||||
|
lawsTreeNodes.add(parentNode);
|
||||||
|
} else {
|
||||||
|
lawsTreeNodes = new ArrayList<>(nodesSet);
|
||||||
|
}
|
||||||
|
// 调用wrapTreeDataToTreeList方法生成树状数据
|
||||||
|
return FindsTreeNodeChildrenUtil.wrapTreeDataToTreeList(lawsTreeNodes);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<LawsTreeNode> convertPartNameToLawsTreeNode(List<PartName> allNodesPartName) {
|
||||||
|
List<LawsTreeNode> allNodes = new ArrayList<>();
|
||||||
|
for (PartName partName : allNodesPartName) {
|
||||||
|
LawsTreeNode lawsTreeNode = new LawsTreeNode();
|
||||||
|
lawsTreeNode.setId(partName.getId());
|
||||||
|
lawsTreeNode.setNodeCode(partName.getCode());
|
||||||
|
lawsTreeNode.setNodeName(partName.getName());
|
||||||
|
lawsTreeNode.setParentId(partName.getParentId());
|
||||||
|
lawsTreeNode.setDelFlag(partName.getDelFlag());
|
||||||
|
allNodes.add(lawsTreeNode);
|
||||||
|
}
|
||||||
|
return allNodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user