工程管理
This commit is contained in:
parent
565b7097e5
commit
c73c988bdb
|
|
@ -0,0 +1,77 @@
|
||||||
|
package com.bonus.common.biz.domain;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ma_sh
|
||||||
|
* @create 2024/10/16 10:17
|
||||||
|
*/
|
||||||
|
public class TreeBuild {
|
||||||
|
|
||||||
|
public List<TreeNode> nodeList = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造方法
|
||||||
|
* @param nodeList 将数据集合赋值给nodeList,即所有数据作为所有节点。
|
||||||
|
*/
|
||||||
|
public TreeBuild(List<TreeNode> nodeList){
|
||||||
|
this.nodeList = nodeList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取需构建的所有根节点(顶级节点) "0"
|
||||||
|
* @return 所有根节点List集合
|
||||||
|
*/
|
||||||
|
public List<TreeNode> getRootNode(){
|
||||||
|
// 保存所有根节点(所有根节点的数据)
|
||||||
|
List<TreeNode> rootNodeList = new ArrayList<>();
|
||||||
|
// treeNode:查询出的每一条数据(节点)
|
||||||
|
for (TreeNode treeNode : nodeList){
|
||||||
|
// 判断当前节点是否为根节点,此处注意:若parentId类型是String,则要采用equals()方法判断。
|
||||||
|
if (0 == treeNode.getParentId()) {
|
||||||
|
// 是,添加
|
||||||
|
rootNodeList.add(treeNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rootNodeList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据每一个顶级节点(根节点)进行构建树形结构
|
||||||
|
* @return 构建整棵树
|
||||||
|
*/
|
||||||
|
public List<TreeNode> buildTree(){
|
||||||
|
// treeNodes:保存一个顶级节点所构建出来的完整树形
|
||||||
|
List<TreeNode> treeNodes = new ArrayList<TreeNode>();
|
||||||
|
// getRootNode():获取所有的根节点
|
||||||
|
for (TreeNode treeRootNode : getRootNode()) {
|
||||||
|
// 将顶级节点进行构建子树
|
||||||
|
treeRootNode = buildChildTree(treeRootNode);
|
||||||
|
// 完成一个顶级节点所构建的树形,增加进来
|
||||||
|
treeNodes.add(treeRootNode);
|
||||||
|
}
|
||||||
|
return treeNodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 递归-----构建子树形结构
|
||||||
|
* @param pNode 根节点(顶级节点)
|
||||||
|
* @return 整棵树
|
||||||
|
*/
|
||||||
|
public TreeNode buildChildTree(TreeNode pNode){
|
||||||
|
List<TreeNode> childTree = new ArrayList<TreeNode>();
|
||||||
|
// nodeList:所有节点集合(所有数据)
|
||||||
|
for (TreeNode treeNode : nodeList) {
|
||||||
|
// 判断当前节点的父节点ID是否等于根节点的ID,即当前节点为其下的子节点
|
||||||
|
if (treeNode.getParentId() == pNode.getId()) {
|
||||||
|
// 再递归进行判断当前节点的情况,调用自身方法
|
||||||
|
childTree.add(buildChildTree(treeNode));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// for循环结束,即节点下没有任何节点,树形构建结束,设置树结果
|
||||||
|
pNode.setChildren(childTree);
|
||||||
|
return pNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.bonus.common.biz.domain;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ma_sh
|
||||||
|
* @create 2024/10/16 10:16
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class TreeNode {
|
||||||
|
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
private String label;
|
||||||
|
|
||||||
|
private long parentId;
|
||||||
|
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||||
|
private String level;
|
||||||
|
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||||
|
private String unitName;
|
||||||
|
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||||
|
private String companyId;
|
||||||
|
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
private float num;
|
||||||
|
|
||||||
|
private String modelCode;
|
||||||
|
|
||||||
|
private String manageType;
|
||||||
|
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||||
|
private List<TreeNode> children = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
package com.bonus.material.basic.controller;
|
package com.bonus.material.basic.controller;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.bonus.common.biz.domain.SysDeptTree;
|
|
||||||
import com.bonus.common.biz.domain.TreeSelect;
|
|
||||||
import com.bonus.common.log.enums.OperaType;
|
import com.bonus.common.log.enums.OperaType;
|
||||||
import com.bonus.material.common.annotation.PreventRepeatSubmit;
|
import com.bonus.material.common.annotation.PreventRepeatSubmit;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
|
|
@ -42,9 +39,8 @@ public class BmUnitPersonController extends BaseController
|
||||||
*/
|
*/
|
||||||
@ApiOperation(value = "查询部门用户下拉树")
|
@ApiOperation(value = "查询部门用户下拉树")
|
||||||
@GetMapping("/getDeptUserTree")
|
@GetMapping("/getDeptUserTree")
|
||||||
public AjaxResult selectDeptTree(SysDeptTree sysDept) {
|
public AjaxResult selectDeptTree(BmUnitPerson unitPerson) {
|
||||||
List<TreeSelect> deptList = bmUnitPersonService.selectDeptTree(sysDept);
|
return bmUnitPersonService.selectDeptTree(unitPerson);
|
||||||
return AjaxResult.success(deptList);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -41,5 +41,8 @@ public class BmUnitPerson extends BaseEntity
|
||||||
@ApiModelProperty(value = "数据所属组织")
|
@ApiModelProperty(value = "数据所属组织")
|
||||||
private String companyId;
|
private String companyId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 二级树标识 1代表查询二级树
|
||||||
|
*/
|
||||||
|
private Integer isTree;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.bonus.material.basic.mapper;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.bonus.common.biz.domain.SysDeptTree;
|
import com.bonus.common.biz.domain.SysDeptTree;
|
||||||
|
import com.bonus.common.biz.domain.TreeNode;
|
||||||
import com.bonus.material.basic.domain.BmUnitPerson;
|
import com.bonus.material.basic.domain.BmUnitPerson;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -32,8 +33,8 @@ public interface BmUnitPersonMapper
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询部门树
|
* 查询部门树
|
||||||
* @param sysDept
|
* @param unitPerson
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<SysDeptTree> selectDeptTree(SysDeptTree sysDept);
|
List<TreeNode> selectDeptTree(BmUnitPerson unitPerson);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,5 @@
|
||||||
package com.bonus.material.basic.service;
|
package com.bonus.material.basic.service;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.bonus.common.biz.domain.SysDeptTree;
|
|
||||||
import com.bonus.common.biz.domain.TreeSelect;
|
|
||||||
import com.bonus.common.core.web.domain.AjaxResult;
|
import com.bonus.common.core.web.domain.AjaxResult;
|
||||||
import com.bonus.material.basic.domain.BmUnitPerson;
|
import com.bonus.material.basic.domain.BmUnitPerson;
|
||||||
|
|
||||||
|
|
@ -34,9 +30,9 @@ public interface IBmUnitPersonService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询部门下拉树结构
|
* 查询部门下拉树结构
|
||||||
* @param sysDept
|
* @param unitPerson
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<TreeSelect> selectDeptTree(SysDeptTree sysDept);
|
AjaxResult selectDeptTree(BmUnitPerson unitPerson);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,12 @@
|
||||||
package com.bonus.material.basic.service.impl;
|
package com.bonus.material.basic.service.impl;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import com.alibaba.nacos.common.utils.CollectionUtils;
|
import com.alibaba.nacos.common.utils.CollectionUtils;
|
||||||
import com.bonus.common.biz.domain.SysDeptTree;
|
import com.bonus.common.biz.domain.TreeBuild;
|
||||||
import com.bonus.common.biz.domain.TreeSelect;
|
import com.bonus.common.biz.domain.TreeNode;
|
||||||
import com.bonus.common.biz.enums.HttpCodeEnum;
|
import com.bonus.common.biz.enums.HttpCodeEnum;
|
||||||
import com.bonus.common.core.utils.DateUtils;
|
import com.bonus.common.core.utils.DateUtils;
|
||||||
import com.bonus.common.core.utils.StringUtils;
|
|
||||||
import com.bonus.common.core.web.domain.AjaxResult;
|
import com.bonus.common.core.web.domain.AjaxResult;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
@ -69,71 +67,24 @@ public class BmUnitPersonServiceImpl implements IBmUnitPersonService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询部门下拉树结构
|
* 查询部门下拉树结构
|
||||||
* @param sysDept
|
* @param unitPerson
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<TreeSelect> selectDeptTree(SysDeptTree sysDept) {
|
public AjaxResult selectDeptTree(BmUnitPerson unitPerson) {
|
||||||
List<SysDeptTree> deptList = bmUnitPersonMapper.selectDeptTree(sysDept);
|
List<TreeNode> groupList = new ArrayList<>();
|
||||||
return buildDeptTreeSelect(deptList);
|
List<TreeNode> list = new ArrayList<>();
|
||||||
}
|
try {
|
||||||
|
list = bmUnitPersonMapper.selectDeptTree(unitPerson);
|
||||||
private List<TreeSelect> buildDeptTreeSelect(List<SysDeptTree> deptList) {
|
if (CollectionUtils.isNotEmpty(list)) {
|
||||||
List<SysDeptTree> deptTrees = buildDeptTree(deptList);
|
// 创建树形结构(数据集合作为参数)
|
||||||
return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
|
TreeBuild treeBuild = new TreeBuild(list);
|
||||||
}
|
// 原查询结果转换树形结构
|
||||||
|
groupList = treeBuild.buildTree();
|
||||||
private List<SysDeptTree> buildDeptTree(List<SysDeptTree> deptList) {
|
|
||||||
List<SysDeptTree> returnList = new ArrayList<>();
|
|
||||||
List<String> tempList = deptList.stream().map(SysDeptTree::getDeptId).collect(Collectors.toList());
|
|
||||||
for (SysDeptTree sysDept : deptList) {
|
|
||||||
// 如果是顶级节点, 遍历该父节点的所有子节点
|
|
||||||
if (!tempList.contains(sysDept.getParentId())) {
|
|
||||||
recursionFn(deptList, sysDept);
|
|
||||||
returnList.add(sysDept);
|
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
if (returnList.isEmpty()) {
|
return AjaxResult.success(groupList);
|
||||||
returnList = deptList;
|
|
||||||
}
|
|
||||||
return returnList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 递归列表
|
|
||||||
*/
|
|
||||||
private void recursionFn(List<SysDeptTree> list, SysDeptTree t) {
|
|
||||||
// 得到子节点列表
|
|
||||||
List<SysDeptTree> childList = getChildList(list, t);
|
|
||||||
t.setChildren(childList);
|
|
||||||
for (SysDeptTree tChild : childList) {
|
|
||||||
if (hasChild(list, tChild)) {
|
|
||||||
recursionFn(list, tChild);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 得到子节点列表
|
|
||||||
*/
|
|
||||||
private List<SysDeptTree> getChildList(List<SysDeptTree> list, SysDeptTree t) {
|
|
||||||
List<SysDeptTree> tlist = new ArrayList<>();
|
|
||||||
Iterator<SysDeptTree> it = list.iterator();
|
|
||||||
while (it.hasNext()) {
|
|
||||||
SysDeptTree n = (SysDeptTree) it.next();
|
|
||||||
if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().equals(t.getDeptId())) {
|
|
||||||
tlist.add(n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tlist;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断是否有子节点
|
|
||||||
*/
|
|
||||||
private boolean hasChild(List<SysDeptTree> list, SysDeptTree t) {
|
|
||||||
return getChildList(list, t).size() > 0 ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.bonus.material.basic.mapper.BmUnitPersonMapper">
|
<mapper namespace="com.bonus.material.basic.mapper.BmUnitPersonMapper">
|
||||||
|
|
||||||
<select id="selectDeptTree" resultType="com.bonus.common.biz.domain.SysDeptTree">
|
<select id="selectDeptTree" resultType="com.bonus.common.biz.domain.TreeNode">
|
||||||
<choose>
|
<choose>
|
||||||
<!-- 当 isTree 为 1 时执行 -->
|
<!-- 当 isTree 为 1 时执行 -->
|
||||||
<when test="isTree != null and isTree == 1">
|
<when test="isTree != null and isTree == 1">
|
||||||
SELECT
|
SELECT
|
||||||
d.dept_id AS deptId,
|
d.dept_id AS id,
|
||||||
d.parent_id AS parentId,
|
d.parent_id AS parentId,
|
||||||
d.ancestors,
|
d.ancestors,
|
||||||
d.dept_name AS deptName,
|
d.dept_name AS label,
|
||||||
d.order_num,
|
d.order_num,
|
||||||
d.leader,
|
d.leader,
|
||||||
d.phone,
|
d.phone,
|
||||||
|
|
@ -33,17 +33,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
SELECT
|
SELECT
|
||||||
d.dept_id AS deptId,
|
d.dept_id AS id,
|
||||||
d.parent_id AS parentId,
|
d.parent_id AS parentId,
|
||||||
d.dept_name AS deptName
|
d.dept_name AS label
|
||||||
FROM sys_dept d
|
FROM sys_dept d
|
||||||
WHERE d.del_flag = '0'
|
WHERE d.del_flag = '0'
|
||||||
AND d.STATUS = '0'
|
AND d.STATUS = '0'
|
||||||
UNION
|
UNION
|
||||||
SELECT
|
SELECT
|
||||||
su.user_id AS deptId,
|
su.user_id AS id,
|
||||||
su.dept_id AS parentId,
|
su.dept_id AS parentId,
|
||||||
su.user_name AS deptName
|
su.user_name AS label
|
||||||
FROM sys_user su
|
FROM sys_user su
|
||||||
LEFT JOIN sys_dept sd ON su.dept_id = sd.dept_id
|
LEFT JOIN sys_dept sd ON su.dept_id = sd.dept_id
|
||||||
) AS combined_results
|
) AS combined_results
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue