公司人员树

This commit is contained in:
mashuai 2024-08-15 17:25:36 +08:00
parent 0d2940081e
commit e53e7e09d0
8 changed files with 227 additions and 9 deletions

View File

@ -32,16 +32,28 @@ public class BmCustomer extends BaseEntity implements Serializable {
* 往来单位类型
*/
@ApiModelProperty(value = "往来单位类型")
@Excel(name = "单位类型")
private Integer typeId;
/**
* 往来单位类型
*/
@ApiModelProperty(value = "往来单位类型名称")
@Excel(name = "单位类型")
private String typeName;
/**
* 所属分公司
*/
@ApiModelProperty(value = "所属分公司")
@Excel(name = "所属分公司")
private Integer companyId;
/**
* 所属分公司
*/
@ApiModelProperty(value = "所属分公司名称")
@Excel(name = "所属分公司")
private String companyName;
/**
* 材料员
*/

View File

@ -0,0 +1,82 @@
package com.bonus.base.api.domain;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import java.util.ArrayList;
import java.util.Date;
import java.io.Serializable;
import java.util.List;
/**
* 部门表(SysDept)实体类
*
* @author makejava
* @since 2024-08-15 13:44:56
*/
@Data
public class SysDeptTree implements Serializable {
private static final long serialVersionUID = 991828482042492876L;
/**
* 更新时间
*/
private Date updateTime;
/**
* 更新者
*/
private String updateBy;
/**
* 创建时间
*/
private Date createTime;
/**
* 创建者
*/
private String createBy;
/**
* 删除标志0代表存在 2代表删除
*/
private String delFlag;
/**
* 部门状态0正常 1停用
*/
private String status;
/**
* 邮箱
*/
private String email;
/**
* 联系电话
*/
private String phone;
/**
* 负责人
*/
private String leader;
/**
* 显示顺序
*/
private Integer orderNum;
/**
* 部门名称
*/
private String deptName;
/**
* 祖级列表
*/
private String ancestors;
/**
* 父部门id
*/
private Integer parentId;
/**
* 部门id
*/
private Integer deptId;
/** 子节点 */
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<SysDeptTree> children = new ArrayList<>();
}

View File

@ -1,5 +1,6 @@
package com.bonus.base.api.domain;
import com.bonus.system.api.domain.SysDept;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.io.Serializable;
@ -36,6 +37,14 @@ public class TreeSelect implements Serializable
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<TreeSelect> children;
public TreeSelect(SysDeptTree dept)
{
this.id = dept.getDeptId();
this.parentId = dept.getParentId();
this.label = dept.getDeptName();
this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
}
public TreeSelect(MaType maType)
{
this.parentId = maType.getParentId();

View File

@ -1,6 +1,8 @@
package com.bonus.base.controller;
import com.bonus.base.api.domain.BmCustomer;
import com.bonus.base.api.domain.SysDeptTree;
import com.bonus.base.api.domain.TreeSelect;
import com.bonus.base.service.IBmCustomerService;
import com.bonus.common.core.utils.poi.ExcelUtil;
import com.bonus.common.core.web.controller.BaseController;
@ -51,6 +53,19 @@ public class BmCustomerController extends BaseController {
return getDataTableError(new ArrayList<>());
}
/**
* 查询部门树
*
* @return 查询结果
*/
@ApiOperation(value = "查询部门树")
@RequiresPermissions("material:maType:query")
@GetMapping("/deptTree")
public AjaxResult selectDeptTree(SysDeptTree sysDept) {
List<TreeSelect> deptList = customerService.selectDeptTree(sysDept);
return AjaxResult.success(deptList);
}
/**
* 获取往来单位下拉选
*/

View File

@ -1,6 +1,7 @@
package com.bonus.base.mapper;
import com.bonus.base.api.domain.BmCustomer;
import com.bonus.base.api.domain.SysDeptTree;
import java.util.List;
@ -56,4 +57,11 @@ public interface BmCustomerMapper {
* @return 结果
*/
int deleteCustomerByIds(Long[] customerIds);
/**
*
* @return
*/
List<SysDeptTree> selectDeptTree(SysDeptTree sysDept);
}

View File

@ -1,6 +1,8 @@
package com.bonus.base.service;
import com.bonus.base.api.domain.BmCustomer;
import com.bonus.base.api.domain.SysDeptTree;
import com.bonus.base.api.domain.TreeSelect;
import java.util.List;
@ -58,4 +60,11 @@ public interface IBmCustomerService
* @return 结果
*/
public int deleteCustomerByIds(Long[] customerIds);
/**
* 查询部门下拉树结构
* @return
*/
List<TreeSelect> selectDeptTree(SysDeptTree sysDept);
}

View File

@ -1,12 +1,18 @@
package com.bonus.base.service.impl;
import com.bonus.base.api.domain.BmCustomer;
import com.bonus.base.api.domain.SysDeptTree;
import com.bonus.base.api.domain.TreeSelect;
import com.bonus.base.mapper.BmCustomerMapper;
import com.bonus.base.service.IBmCustomerService;
import com.bonus.common.core.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
/**
* 往来单位 服务层实现
@ -49,4 +55,71 @@ public class BmCustomerServiceImpl implements IBmCustomerService
public int deleteCustomerByIds(Long[] customerIds) {
return bmCustomerMapper.deleteCustomerByIds(customerIds);
}
/**
* 查询部门树结构信息
* @return
*/
@Override
public List<TreeSelect> selectDeptTree(SysDeptTree sysDept) {
List<SysDeptTree> deptList = bmCustomerMapper.selectDeptTree(sysDept);
return buildDeptTreeSelect(deptList);
}
private List<TreeSelect> buildDeptTreeSelect(List<SysDeptTree> deptList) {
List<SysDeptTree> deptTrees = buildDeptTree(deptList);
return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
}
private List<SysDeptTree> buildDeptTree(List<SysDeptTree> deptList) {
List<SysDeptTree> returnList = new ArrayList<>();
List<Integer> tempList = deptList.stream().map(SysDeptTree::getDeptId).collect(Collectors.toList());
for (SysDeptTree sysDept : deptList) {
// 如果是顶级节点, 遍历该父节点的所有子节点
if (!tempList.contains(sysDept.getParentId())) {
recursionFn(deptList, sysDept);
returnList.add(sysDept);
}
}
if (returnList.isEmpty()) {
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().longValue() == t.getDeptId().longValue()) {
tlist.add(n);
}
}
return tlist;
}
/**
* 判断是否有子节点
*/
private boolean hasChild(List<SysDeptTree> list, SysDeptTree t) {
return getChildList(list, t).size() > 0 ? true : false;
}
}

View File

@ -20,21 +20,23 @@
</resultMap>
<sql id="Base_Column_List">
<!--@mbg.generated-->
id, type_id, company_id, `name`, material_clerk, manager, phone, is_active, `time`,
legal_representative, legal_phone, sort_num, company
bc.id, bc.type_id, bct.NAME as typeName, bc.company_id, sd.dept_name as companyName, bc.`name`, bc.material_clerk, bc.manager, bc.phone, bc.is_active, bc.`time`,
bc.legal_representative, bc.legal_phone, bc.sort_num, bc.company
</sql>
<select id="selectCustomerList" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from bm_customer
from bm_customer bc
left join bm_customer_type bct on bct.id = bc.type_id
left join sys_dept sd on sd.dept_id = bc.company_id
where
is_active = 1
bc.is_active = 1
<if test="name != null and name != ''">
AND name like concat('%', #{name}, '%')
AND bc.name like concat('%', #{name}, '%')
</if>
<if test="dataCondition != null and dataCondition.size()>0">
AND id in
AND bc.id in
<foreach collection="dataCondition" item="proId" index="index" open="(" separator="," close=")">
#{proId}
</foreach>
@ -46,7 +48,15 @@
select
<include refid="Base_Column_List" />
from bm_customer
where id = #{id,jdbcType=INTEGER}
left join bm_customer_type bct on bct.id = bc.type_id
left join sys_dept sd on sd.dept_id = bc.company_id
where bc.is_active = '1' and bc.id = #{id,jdbcType=INTEGER}
</select>
<select id="selectDeptTree" resultType="com.bonus.base.api.domain.SysDeptTree">
select d.dept_id as deptId, d.parent_id as parentId, d.ancestors, d.dept_name as deptName, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time
from sys_dept d
where d.del_flag = '0' and d.status = '0'
</select>
<delete id="deleteCustomerById" parameterType="java.lang.Integer">