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 a9eba92..da59c92 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 @@ -39,6 +39,11 @@ public class SysDept extends BaseEntity { */ private String deptName; + /** + * 部门名称(全称) + */ + private String deptFullName; + /** * 显示顺序 */ @@ -308,6 +313,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..d95a10a 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 updateDeptChildrenFullName(@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 8d557fc..2ce2d22 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 @@ -310,6 +310,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) { @@ -327,6 +328,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,7 @@ public class SysDeptServiceImpl implements ISysDeptService dept.setAncestors(newAncestors); updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors); } + updateDeptChildrenFullName(dept, newParentDept); int result = deptMapper.updateDept(dept); if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors()) && !StringUtils.equals("0", dept.getAncestors())) @@ -360,7 +363,7 @@ public class SysDeptServiceImpl implements ISysDeptService //判断是否需要修改公司管理员用户信息 if (SecurityUtils.isAdmin(SecurityUtils.getUserId()) && systemConfig.isAddRootCompany() && Objects.nonNull(dept.getParentId()) && dept.getParentId().equals(0L)){ SysUser companyAdminUser = dept.getSysUser(); - if (Objects.nonNull(companyAdminUser.getRoleId())) { + if (Objects.nonNull(companyAdminUser) && Objects.nonNull(companyAdminUser.getRoleId())) { companyAdminUser.setUpdateBy(SecurityUtils.getUsername()); companyAdminUser.setUpdateTime(DateUtils.getNowDate()); roleMenuMapper.deleteRoleMenuByRoleId(companyAdminUser.getRoleId()); @@ -371,6 +374,38 @@ public class SysDeptServiceImpl implements ISysDeptService return result; } + public void updateDeptChildrenFullName(SysDept dept, SysDept newParentDept) + { + if (Objects.isNull(newParentDept)) { + dept.setDeptFullName(dept.getDeptName()); + } else { + dept.setDeptFullName(newParentDept.getDeptFullName() + "/" + dept.getDeptName()); + } + List children = deptMapper.selectChildrenDeptById(dept.getDeptId()); + List fullDeptList = deptMapper.selectDeptList(new SysDept()); + for (SysDept innerDept : fullDeptList) { + if (innerDept.getDeptId().equals(dept.getDeptId())) { + innerDept.setDeptName(dept.getDeptName()); + } + } + for (SysDept child : children) { + if (child.getDeptId().equals(dept.getDeptId())) { + child.setDeptName(dept.getDeptName()); + } + } + for (SysDept child : children) { + String deptAncestors = child.getAncestors(); + deptAncestors = deptAncestors.replaceFirst("0,", "").replaceAll(",", "/"); + for (SysDept innerDept : fullDeptList) { + deptAncestors = deptAncestors.replace(String.valueOf(innerDept.getDeptId()), innerDept.getDeptName()); + } + child.setDeptFullName(deptAncestors + "/" + child.getDeptName()); + } + if (children.size() > 0) { + deptMapper.updateDeptChildrenFullName(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 bf43191..e2f7cee 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, @@ -82,6 +85,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" AND dept_id = #{deptId} +-- AND (d.dept_id = #{deptId} OR d.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId}, +-- ancestors) )) AND parent_id = #{parentId} @@ -192,6 +197,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" dept_id, parent_id, dept_name, + dept_full_name, ancestors, order_num, leader, @@ -213,6 +219,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{deptId}, #{parentId}, #{deptName}, + #{deptFullName}, #{ancestors}, #{orderNum}, #{leader}, @@ -238,6 +245,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}, @@ -273,6 +281,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 diff --git a/sql/bns_202504_patch/bns_202504_patch.sql b/sql/bns_202504_patch/bns_202504_patch.sql index 50ab45e..0272124 100644 --- a/sql/bns_202504_patch/bns_202504_patch.sql +++ b/sql/bns_202504_patch/bns_202504_patch.sql @@ -1,3 +1,11 @@ -- 照片地址 alter table sys_user - add photo_url varchar(255) null comment '照片地址'; \ No newline at end of file + add photo_url varchar(255) null comment '照片地址'; + +-- 生日 +alter table sys_user + add birthday date null comment '生日'; + +-- 生日 +alter table sys_dept + add dept_full_name date null comment '组织全称'; \ No newline at end of file