xiangpei
2025-05-14 47cd9ecc0eff38ffe6b3b794b2bf197e958f4403
src/main/java/com/mindskip/xzs/service/impl/DepartmentServiceImpl.java
@@ -58,15 +58,19 @@
        if (Objects.isNull(entity)) {
            throw new RuntimeException("该部门不存在");
        }
        // 先清除之前的管理员标识
        List<BaseSelect> deptUserList = userDepartmentMapper.getDeptUserList(entity.getId());
        List<Integer> userIds = deptUserList.stream().map(BaseSelect::getId).collect(Collectors.toList());
        if (! CollectionUtils.isEmpty(userIds)) {
            userMapper.clearDeptAdmin(userIds, entity.getId());
            userMapper.cancelUserDeptAdmin(userIds);
        }
        // 设置部门管理员
        if (! CollectionUtils.isEmpty(department.getAdminId())) {
            List<BaseSelect> deptUserList = userDepartmentMapper.getDeptUserList(entity.getId());
            List<Integer> userIds = deptUserList.stream().map(BaseSelect::getId).collect(Collectors.toList());
            if (! CollectionUtils.isEmpty(userIds)) {
                // 先清除之前的管理员标识
                userMapper.clearDeptAdmin(userIds, entity.getId());
            }
            // 标识部门管理员
            userMapper.updateDeptAdmin(department.getAdminId(), DeptAdminEnum.YES.getValue(), entity.getId());
            UpdateDeptAdminVO updateDeptAdminVO = new UpdateDeptAdminVO();
            updateDeptAdminVO.setAdminIds(department.getAdminId());
            userMapper.updateUserDeptAdmin(updateDeptAdminVO);
        }
        if (Objects.nonNull(department.getParentId())) {
            // 查出父级的层级
@@ -133,6 +137,7 @@
            Collections.reverse(fatherList);
            vo.setParentIds(fatherList);
        }
        vo.setAdminId(userDepartmentMapper.selectDeptAdmin(id));
        return vo;
    }
@@ -163,20 +168,20 @@
        if (Objects.isNull(entity)) {
            throw new RuntimeException("该部门不存在");
        }
        List<BaseSelect> deptUserList = userDepartmentMapper.getDeptUserList(entity.getId());
        List<Integer> userIds = deptUserList.stream().map(BaseSelect::getId).collect(Collectors.toList());
        if (! CollectionUtils.isEmpty(userIds)) {
            // 先清除之前的管理员标识
            userMapper.clearDeptAdmin(userIds, entity.getId());
            // 修改没被选择的用户并且不是别的部门管理员的用户角色为1
            userMapper.cancelUserDeptAdmin(userIds);
        }
        if (! CollectionUtils.isEmpty(form.getAdminIds())) {
            List<BaseSelect> deptUserList = userDepartmentMapper.getDeptUserList(entity.getId());
            List<Integer> userIds = deptUserList.stream().map(BaseSelect::getId).collect(Collectors.toList());
            if (! CollectionUtils.isEmpty(userIds)) {
                // 先清除之前的管理员标识
                userMapper.clearDeptAdmin(userIds, entity.getId());
            }
            // 标识部门管理员
            userMapper.updateDeptAdmin(form.getAdminIds(), DeptAdminEnum.YES.getValue(), entity.getId());
            // 修改被选择的用户为部门管理员
            userMapper.updateUserDeptAdmin(form);
        }
        // 修改被选择的用户为部门管理员
        userMapper.updateUserDeptAdmin(form);
        // 修改没被选择的用户并且不是别的部门管理员的用户角色为1
        userMapper.cancelUserDeptAdmin(form);
    }
    @Override