fuliqi
2025-02-19 8fec9579ae4adb4f7f53440933908c90eea33b20
Merge remote-tracking branch 'origin/master'
3个文件已修改
59 ■■■■■ 已修改文件
start/src/main/java/com/ycl/web/controller/system/SysDeptController.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
system/src/main/java/com/ycl/system/service/impl/SysDeptServiceImpl.java 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
system/src/main/resources/mapper/system/SysDeptMapper.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
start/src/main/java/com/ycl/web/controller/system/SysDeptController.java
@@ -1,6 +1,7 @@
package com.ycl.web.controller.system;
import java.util.List;
import java.util.Objects;
import com.ycl.common.base.Result;
import com.ycl.common.core.domain.StringTreeSelect;
@@ -113,7 +114,7 @@
        {
            return error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");
        }
        else if (dept.getParentId().equals(deptId))
        else if (Objects.nonNull(dept.getParentId()) && dept.getParentId().equals(deptId))
        {
            return error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己");
        }
system/src/main/java/com/ycl/system/service/impl/SysDeptServiceImpl.java
@@ -6,6 +6,7 @@
import com.ycl.common.base.Result;
import com.ycl.common.core.domain.StringTreeSelect;
import com.ycl.system.domain.base.BaseSelect;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ycl.common.annotation.DataScope;
@@ -29,13 +30,12 @@
 * @author ycl
 */
@Service
@RequiredArgsConstructor
public class SysDeptServiceImpl implements ISysDeptService
{
    @Autowired
    private SysDeptMapper deptMapper;
    @Autowired
    private SysRoleMapper roleMapper;
    private final SysDeptMapper deptMapper;
    private final SysRoleMapper roleMapper;
    /**
     * 查询部门管理数据
@@ -262,13 +262,18 @@
    @Override
    public int insertDept(SysDept dept)
    {
        SysDept info = deptMapper.selectDeptById(dept.getParentId());
        // 如果父节点不为正常状态,则不允许新增子节点
        if (!UserConstants.DEPT_NORMAL.equals(info.getStatus()))
        {
            throw new ServiceException("部门停用,不允许新增");
        if (Objects.nonNull(dept.getParentId())) {
            SysDept info = deptMapper.selectDeptById(dept.getParentId());
            // 如果父节点不为正常状态,则不允许新增子节点
            if (!UserConstants.DEPT_NORMAL.equals(info.getStatus()))
            {
                throw new ServiceException("上级部门已停用,不允许新增下级部门");
            }
            dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
        } else {
            dept.setParentId(0L);
            dept.setAncestors("");
        }
        dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
        return deptMapper.insertDept(dept);
    }
@@ -281,22 +286,23 @@
    @Override
    public int updateDept(SysDept dept)
    {
        SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId());
        SysDept oldDept = deptMapper.selectDeptById(dept.getDeptId());
        if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept))
        {
            String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId();
            String oldAncestors = oldDept.getAncestors();
            dept.setAncestors(newAncestors);
            updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors);
        if (Objects.isNull(oldDept)) {
            throw new RuntimeException("修改部门被删除或不存在");
        }
        if (Objects.nonNull(dept.getParentId())) {
            SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId());
            if (Objects.nonNull(newParentDept)) {
                String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId();
                String oldAncestors = oldDept.getAncestors();
                dept.setAncestors(newAncestors);
                updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors);
            }
        } else {
            dept.setParentId(0L);
            dept.setAncestors("");
        }
        int result = deptMapper.updateDept(dept);
        if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors())
                && !StringUtils.equals("0", dept.getAncestors()))
        {
            // 如果该部门是启用状态,则启用该部门的所有上级部门
            updateParentDeptStatusNormal(dept);
        }
        return result;
    }
system/src/main/resources/mapper/system/SysDeptMapper.xml
@@ -135,9 +135,9 @@
    <update id="updateDept" parameterType="SysDept">
         update sys_dept
         <set>
             <if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
             <if test="parentId != null">parent_id = #{parentId},</if>
             <if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
             <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
             <if test="ancestors != null">ancestors = #{ancestors},</if>
             <if test="orderNum != null">order_num = #{orderNum},</if>
             <if test="leader != null">leader = #{leader},</if>
             <if test="phone != null">phone = #{phone},</if>