疯狂的狮子li
2021-09-13 2af534eea471f4adb104906c7a814bcc66d4d68d
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
@@ -11,7 +11,9 @@
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.system.mapper.SysDeptMapper;
import com.ruoyi.system.mapper.SysRoleMapper;
import com.ruoyi.system.mapper.SysUserMapper;
@@ -118,7 +120,7 @@
     * @return 子部门数
     */
    @Override
    public int selectNormalChildrenDeptById(Long deptId) {
    public long selectNormalChildrenDeptById(Long deptId) {
        return count(new LambdaQueryWrapper<SysDept>()
                .eq(SysDept::getStatus, 0)
                .apply("find_in_set({0}, ancestors)", deptId));
@@ -132,7 +134,7 @@
     */
    @Override
    public boolean hasChildByDeptId(Long deptId) {
        int result = count(new LambdaQueryWrapper<SysDept>()
        long result = count(new LambdaQueryWrapper<SysDept>()
                .eq(SysDept::getParentId, deptId)
                .last("limit 1"));
        return result > 0;
@@ -146,7 +148,7 @@
     */
    @Override
    public boolean checkDeptExistUser(Long deptId) {
        int result = userMapper.selectCount(new LambdaQueryWrapper<SysUser>()
        long result = userMapper.selectCount(new LambdaQueryWrapper<SysUser>()
                .eq(SysUser::getDeptId, deptId));
        return result > 0;
    }
@@ -171,6 +173,23 @@
    }
    /**
     * 校验部门是否有数据权限
     *
     * @param deptId 部门id
     */
    @Override
    public void checkDeptDataScope(Long deptId) {
        if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
            SysDept dept = new SysDept();
            dept.setDeptId(deptId);
            List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept);
            if (StringUtils.isEmpty(depts)) {
                throw new ServiceException("没有权限访问部门数据!");
            }
        }
    }
    /**
     * 新增保存部门信息
     *
     * @param dept 部门信息