From cf56370e57a3462d7c4069de3f61bdaa39800e2b Mon Sep 17 00:00:00 2001 From: sxu <602087911@qq.com> Date: Wed, 26 Mar 2025 16:42:45 +0800 Subject: [PATCH] dept_full_name --- .../com/bonus/system/api/domain/SysDept.java | 14 ++++++++++++++ .../bonus/system/mapper/SysDeptMapper.java | 2 ++ .../service/impl/SysDeptServiceImpl.java | 19 +++++++++++++++++++ .../resources/mapper/system/SysDeptMapper.xml | 19 +++++++++++++++++++ 4 files changed, 54 insertions(+) diff --git a/bonus-api/bonus-api-system/src/main/java/com/bonus/system/api/domain/SysDept.java b/bonus-api/bonus-api-system/src/main/java/com/bonus/system/api/domain/SysDept.java index 4de9694..518439e 100644 --- a/bonus-api/bonus-api-system/src/main/java/com/bonus/system/api/domain/SysDept.java +++ b/bonus-api/bonus-api-system/src/main/java/com/bonus/system/api/domain/SysDept.java @@ -42,6 +42,12 @@ public class SysDept extends BaseEntity { */ private String deptName; + /** + * 全路径部门名称 + */ + private String deptFullName; + + /** * 显示顺序 */ @@ -312,6 +318,14 @@ public class SysDept extends BaseEntity { this.deptName = deptName; } + public String getDeptFullName() { + return deptFullName; + } + + public void setDeptFullName(String deptFullName) { + this.deptFullName = deptFullName; + } + @NotNull(message = "显示顺序不能为空") public Integer getOrderNum() { return orderNum; diff --git a/bonus-modules/bonus-system/src/main/java/com/bonus/system/mapper/SysDeptMapper.java b/bonus-modules/bonus-system/src/main/java/com/bonus/system/mapper/SysDeptMapper.java index 31a57f6..0649f6b 100644 --- a/bonus-modules/bonus-system/src/main/java/com/bonus/system/mapper/SysDeptMapper.java +++ b/bonus-modules/bonus-system/src/main/java/com/bonus/system/mapper/SysDeptMapper.java @@ -135,6 +135,8 @@ public interface SysDeptMapper */ public int updateDeptChildren(@Param("depts") List depts); + public int updateDeptFullName(@Param("depts") List depts); + /** * 删除部门管理信息 * diff --git a/bonus-modules/bonus-system/src/main/java/com/bonus/system/service/impl/SysDeptServiceImpl.java b/bonus-modules/bonus-system/src/main/java/com/bonus/system/service/impl/SysDeptServiceImpl.java index 8519a5f..9f0ad1c 100644 --- a/bonus-modules/bonus-system/src/main/java/com/bonus/system/service/impl/SysDeptServiceImpl.java +++ b/bonus-modules/bonus-system/src/main/java/com/bonus/system/service/impl/SysDeptServiceImpl.java @@ -311,6 +311,7 @@ public class SysDeptServiceImpl implements ISysDeptService if (dept.getParentId() == null){ dept.setParentId(0L); dept.setAncestors("0"); + dept.setDeptFullName(dept.getDeptName()); dept.setStatus("0");//默认启用 int result = deptMapper.insertDept(dept); if (SecurityUtils.isAdmin(SecurityUtils.getUserId()) && systemConfig.isAddRootCompany() && result > 0) { @@ -328,6 +329,7 @@ public class SysDeptServiceImpl implements ISysDeptService throw new ServiceException("部门停用,不允许新增"); } dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); + dept.setDeptFullName(info.getDeptFullName() + "/" + dept.getDeptName()); return deptMapper.insertDept(dept); } } @@ -350,6 +352,10 @@ public class SysDeptServiceImpl implements ISysDeptService String oldAncestors = oldDept.getAncestors(); dept.setAncestors(newAncestors); updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors); + String newDeptFullNames = newParentDept.getDeptFullName() + "/" + dept.getDeptName(); + String oldDeptFullNames = oldDept.getDeptFullName(); + dept.setDeptFullName(newDeptFullNames); + updateDeptFullName(dept.getDeptId(), newDeptFullNames, oldDeptFullNames); } int result = deptMapper.updateDept(dept); if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors()) @@ -404,6 +410,19 @@ public class SysDeptServiceImpl implements ISysDeptService } } + public void updateDeptFullName(Long deptId, String newFullNames, String oldFullNames) + { + List children = deptMapper.selectChildrenDeptById(deptId); + for (SysDept child : children) + { + child.setDeptFullName(child.getDeptFullName().replaceFirst(oldFullNames, newFullNames)); + } + if (children.size() > 0) + { + deptMapper.updateDeptFullName(children); + } + } + /** * 删除部门管理信息 * diff --git a/bonus-modules/bonus-system/src/main/resources/mapper/system/SysDeptMapper.xml b/bonus-modules/bonus-system/src/main/resources/mapper/system/SysDeptMapper.xml index 17e27cc..7c6598a 100644 --- a/bonus-modules/bonus-system/src/main/resources/mapper/system/SysDeptMapper.xml +++ b/bonus-modules/bonus-system/src/main/resources/mapper/system/SysDeptMapper.xml @@ -9,6 +9,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -37,6 +38,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" d.parent_id, d.ancestors, d.dept_name, + d.dept_full_name, d.order_num, d.leader, d.phone, @@ -53,6 +55,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" d.parent_id, d.ancestors, d.dept_name, + d.dept_full_name, d.order_num, d.leader, d.phone, @@ -193,6 +196,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" dept_id, parent_id, dept_name, + dept_full_name, ancestors, order_num, leader, @@ -214,6 +218,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{deptId}, #{parentId}, #{deptName}, + #{deptFullName}, #{ancestors}, #{orderNum}, #{leader}, @@ -239,6 +244,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" parent_id = #{parentId}, dept_name = #{deptName}, + dept_full_name = #{deptFullName}, ancestors = #{ancestors}, order_num = #{orderNum}, leader = #{leader}, @@ -274,6 +280,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + update sys_dept set dept_full_name = + + when #{item.deptId} then #{item.deptFullName} + + where dept_id in + + #{item.deptId} + + + update sys_dept set status = '0' where dept_id in