龚焕茏
2024-05-07 49429bad1036c81c056faeadfa009c53ba777fad
src/main/java/com/mindskip/xzs/service/impl/DepartmentServiceImpl.java
@@ -63,13 +63,13 @@
            throw new RuntimeException("该部门不存在");
        }
        if (Objects.nonNull(department.getAdminId())) {
            Integer adminNum = departmentMapper.countByAdminId(department.getAdminId(), department.getId());
            if (adminNum > 0) {
                throw new RuntimeException("一个用户只能是一个单位的管理员");
            }
            if (! Objects.equals(entity.getAdminId(), department.getAdminId())) {
                // 取消原先的管理员标识
                List<Integer> depIds = departmentMapper.selectByAdminId(entity.getAdminId());
                depIds.remove(department.getId());
                if (depIds.size() < 1) {
                    userMapper.updateDeptAdmin(entity.getAdminId(), DeptAdminEnum.NO.getValue());
                }
                userMapper.updateDeptAdmin(entity.getAdminId(), DeptAdminEnum.NO.getValue());
            }
            // 标识部门管理员
            userMapper.updateDeptAdmin(department.getAdminId(), DeptAdminEnum.YES.getValue());
@@ -91,8 +91,11 @@
    }
    @Override
    public List<Department> gets() {
        return departmentMapper.gets();
    public List<Department> gets(Integer deptId) {
        if (deptId == null || deptId == -1) {
            deptId = null;
        }
        return departmentMapper.gets(deptId);
    }
    @Override
@@ -117,13 +120,13 @@
            throw new RuntimeException("该部门不存在");
        }
        if (Objects.nonNull(form.getAdminId())) {
            Integer adminNum = departmentMapper.countByAdminId(form.getAdminId(), form.getId());
            if (adminNum > 0) {
                throw new RuntimeException("一个用户只能是一个单位的管理员");
            }
            if (! Objects.equals(entity.getAdminId(), form.getAdminId())) {
                // 取消原先的管理员标识
                List<Integer> depIds = departmentMapper.selectByAdminId(entity.getAdminId());
                depIds.remove(form.getId());
                if (depIds.size() < 1) {
                    userMapper.updateDeptAdmin(entity.getAdminId(), DeptAdminEnum.NO.getValue());
                }
                userMapper.updateDeptAdmin(entity.getAdminId(), DeptAdminEnum.NO.getValue());
            }
            // 标识部门管理员
            userMapper.updateDeptAdmin(form.getAdminId(), DeptAdminEnum.YES.getValue());