liding
17 小时以前 17a7a0c0df3dbc3e6225dddb55f6332deccdb201
src/main/java/com/ruoyi/project/system/service/impl/SysDeptServiceImpl.java
@@ -1,11 +1,5 @@
package com.ruoyi.project.system.service.impl;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.exception.ServiceException;
@@ -20,24 +14,29 @@
import com.ruoyi.project.system.mapper.SysDeptMapper;
import com.ruoyi.project.system.mapper.SysRoleMapper;
import com.ruoyi.project.system.service.ISysDeptService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
/**
 * 部门管理 服务实现
 *
 *
 * @author ruoyi
 */
@Service
@RequiredArgsConstructor
public class SysDeptServiceImpl implements ISysDeptService
{
    @Autowired
    private SysDeptMapper deptMapper;
    @Autowired
    private SysRoleMapper roleMapper;
    private final SysDeptMapper deptMapper;
    private final SysRoleMapper roleMapper;
    /**
     * 查询部门管理数据
     *
     *
     * @param dept 部门信息
     * @return 部门信息集合
     */
@@ -49,8 +48,21 @@
    }
    /**
     * 查询部门树结构信息
     *
     * @param dept 部门信息
     * @return 部门树信息集合
     */
    @Override
    public List<TreeSelect> selectDeptTreeList(SysDept dept)
    {
        List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept);
        return buildDeptTreeSelect(depts);
    }
    /**
     * 构建前端所需要树结构
     *
     *
     * @param depts 部门列表
     * @return 树结构列表
     */
@@ -58,14 +70,9 @@
    public List<SysDept> buildDeptTree(List<SysDept> depts)
    {
        List<SysDept> returnList = new ArrayList<SysDept>();
        List<Long> tempList = new ArrayList<Long>();
        List<Long> tempList = depts.stream().map(SysDept::getDeptId).collect(Collectors.toList());
        for (SysDept dept : depts)
        {
            tempList.add(dept.getDeptId());
        }
        for (Iterator<SysDept> iterator = depts.iterator(); iterator.hasNext();)
        {
            SysDept dept = (SysDept) iterator.next();
            // 如果是顶级节点, 遍历该父节点的所有子节点
            if (!tempList.contains(dept.getParentId()))
            {
@@ -82,7 +89,7 @@
    /**
     * 构建前端所需要下拉树结构
     *
     *
     * @param depts 部门列表
     * @return 下拉树结构列表
     */
@@ -95,7 +102,7 @@
    /**
     * 根据角色ID查询部门树信息
     *
     *
     * @param roleId 角色ID
     * @return 选中部门列表
     */
@@ -108,7 +115,7 @@
    /**
     * 根据部门ID查询信息
     *
     *
     * @param deptId 部门ID
     * @return 部门信息
     */
@@ -120,7 +127,7 @@
    /**
     * 根据ID查询所有子部门(正常状态)
     *
     *
     * @param deptId 部门ID
     * @return 子部门数
     */
@@ -132,7 +139,7 @@
    /**
     * 是否存在子节点
     *
     *
     * @param deptId 部门ID
     * @return 结果
     */
@@ -140,12 +147,12 @@
    public boolean hasChildByDeptId(Long deptId)
    {
        int result = deptMapper.hasChildByDeptId(deptId);
        return result > 0 ? true : false;
        return result > 0;
    }
    /**
     * 查询部门是否存在用户
     *
     *
     * @param deptId 部门ID
     * @return 结果 true 存在 false 不存在
     */
@@ -153,17 +160,17 @@
    public boolean checkDeptExistUser(Long deptId)
    {
        int result = deptMapper.checkDeptExistUser(deptId);
        return result > 0 ? true : false;
        return result > 0;
    }
    /**
     * 校验部门名称是否唯一
     *
     *
     * @param dept 部门信息
     * @return 结果
     */
    @Override
    public String checkDeptNameUnique(SysDept dept)
    public boolean checkDeptNameUnique(SysDept dept)
    {
        Long deptId = StringUtils.isNull(dept.getDeptId()) ? -1L : dept.getDeptId();
        SysDept info = deptMapper.checkDeptNameUnique(dept.getDeptName(), dept.getParentId());
@@ -176,13 +183,13 @@
    /**
     * 校验部门是否有数据权限
     *
     *
     * @param deptId 部门id
     */
    @Override
    public void checkDeptDataScope(Long deptId)
    {
        if (!SysUser.isAdmin(SecurityUtils.getUserId()))
        if (!SysUser.isAdmin(SecurityUtils.getUserId()) && StringUtils.isNotNull(deptId))
        {
            SysDept dept = new SysDept();
            dept.setDeptId(deptId);
@@ -196,7 +203,7 @@
    /**
     * 新增保存部门信息
     *
     *
     * @param dept 部门信息
     * @return 结果
     */
@@ -215,7 +222,7 @@
    /**
     * 修改保存部门信息
     *
     *
     * @param dept 部门信息
     * @return 结果
     */
@@ -243,7 +250,7 @@
    /**
     * 修改该部门的父级部门状态
     *
     *
     * @param dept 当前部门
     */
    private void updateParentDeptStatusNormal(SysDept dept)
@@ -255,7 +262,7 @@
    /**
     * 修改子元素关系
     *
     *
     * @param deptId 被修改的部门ID
     * @param newAncestors 新的父ID集合
     * @param oldAncestors 旧的父ID集合
@@ -275,7 +282,7 @@
    /**
     * 删除部门管理信息
     *
     *
     * @param deptId 部门ID
     * @return 结果
     */
@@ -283,6 +290,16 @@
    public int deleteDeptById(Long deptId)
    {
        return deptMapper.deleteDeptById(deptId);
    }
    /**
     * 查询顶层部门id
     * @param deptId
     * @return
     */
    @Override
    public Long maxLevelDeptId(Long deptId) {
        return deptMapper.maxLevelDeptId(deptId);
    }
    /**
@@ -302,6 +319,11 @@
        }
    }
    @Override
    public SysDept selectDeptByDeptName(String deptName) {
        return deptMapper.selectDeptByDeptName(deptName);
    }
    /**
     * 得到子节点列表
     */