package com.ruoyi.system.service.impl;
|
|
import java.util.ArrayList;
|
import java.util.Iterator;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.ruoyi.system.domain.vo.TreeSelect;
|
import com.ruoyi.system.mapper.SysDeptMapper;
|
import com.ruoyi.system.mapper.SysRoleMapper;
|
import com.ruoyi.system.service.ISysDeptService;
|
import com.ruoyi.system.service.ISysRoleService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import com.ruoyi.common.core.constant.UserConstants;
|
import com.ruoyi.common.core.exception.ServiceException;
|
import com.ruoyi.common.core.text.Convert;
|
import com.ruoyi.common.core.utils.SpringUtils;
|
import com.ruoyi.common.core.utils.StringUtils;
|
import com.ruoyi.common.datascope.annotation.DataScope;
|
import com.ruoyi.common.security.utils.SecurityUtils;
|
import com.ruoyi.system.api.domain.SysDept;
|
import com.ruoyi.system.api.domain.SysRole;
|
import com.ruoyi.system.api.domain.SysUser;
|
|
/**
|
* 部门管理 服务实现
|
*
|
* @author ruoyi
|
*/
|
@Service
|
public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> implements ISysDeptService
|
{
|
@Autowired
|
private SysDeptMapper deptMapper;
|
|
@Autowired
|
private SysRoleMapper roleMapper;
|
|
/**
|
* 查询部门管理数据
|
*
|
* @param dept 部门信息
|
* @return 部门信息集合
|
*/
|
@Override
|
@DataScope(deptAlias = "d")
|
public List<SysDept> selectDeptList(SysDept dept)
|
{
|
return deptMapper.selectDeptList(dept);
|
}
|
|
/**
|
* 查询部门树结构信息
|
*
|
* @param dept 部门信息
|
* @return 部门树信息集合
|
*/
|
@Override
|
public List<TreeSelect> selectDeptTreeList(SysDept dept)
|
{
|
List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept);
|
return buildDeptTreeSelect(depts);
|
}
|
|
@Override
|
public List<SysDept> buildDeptTree(List<SysDept> depts) {
|
return null;
|
}
|
|
@Override
|
public List<TreeSelect> buildDeptTreeSelect(List<SysDept> depts) {
|
return null;
|
}
|
|
/**
|
* 构建前端所需要树结构
|
*
|
* @param depts 部门列表
|
* @return 树结构列表
|
*/
|
|
|
/**
|
* 构建前端所需要下拉树结构
|
*
|
* @param depts 部门列表
|
* @return 下拉树结构列表
|
*/
|
|
/**
|
* 根据角色ID查询部门树信息
|
*
|
* @param roleId 角色ID
|
* @return 选中部门列表
|
*/
|
@Override
|
public List<Long> selectDeptListByRoleId(Long roleId)
|
{
|
SysRole role = roleMapper.selectRoleById(roleId);
|
return deptMapper.selectDeptListByRoleId(roleId, role.isDeptCheckStrictly());
|
}
|
|
/**
|
* 根据部门ID查询信息
|
*
|
* @param deptId 部门ID
|
* @return 部门信息
|
*/
|
@Override
|
public SysDept selectDeptById(Long deptId)
|
{
|
return deptMapper.selectDeptById(deptId);
|
}
|
|
/**
|
* 根据ID查询所有子部门(正常状态)
|
*
|
* @param deptId 部门ID
|
* @return 子部门数
|
*/
|
@Override
|
public int selectNormalChildrenDeptById(Long deptId)
|
{
|
return deptMapper.selectNormalChildrenDeptById(deptId);
|
}
|
|
/**
|
* 是否存在子节点
|
*
|
* @param deptId 部门ID
|
* @return 结果
|
*/
|
@Override
|
public boolean hasChildByDeptId(Long deptId)
|
{
|
int result = deptMapper.hasChildByDeptId(deptId);
|
return result > 0;
|
}
|
|
/**
|
* 查询部门是否存在用户
|
*
|
* @param deptId 部门ID
|
* @return 结果 true 存在 false 不存在
|
*/
|
@Override
|
public boolean checkDeptExistUser(Long deptId)
|
{
|
int result = deptMapper.checkDeptExistUser(deptId);
|
return result > 0;
|
}
|
|
/**
|
* 校验部门名称是否唯一
|
*
|
* @param dept 部门信息
|
* @return 结果
|
*/
|
@Override
|
public boolean checkDeptNameUnique(SysDept dept)
|
{
|
Long deptId = StringUtils.isNull(dept.getDeptId()) ? -1L : dept.getDeptId();
|
SysDept info = deptMapper.checkDeptNameUnique(dept.getDeptName());
|
if (StringUtils.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue())
|
{
|
return UserConstants.NOT_UNIQUE;
|
}
|
return UserConstants.UNIQUE;
|
}
|
|
/**
|
* 校验部门是否有数据权限
|
*
|
* @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("没有权限访问部门数据!");
|
}
|
}
|
}
|
|
@Override
|
public int insertDept(SysDept dept) {
|
int i = deptMapper.insertDept(dept);
|
return i;
|
}
|
|
/**
|
* 新增保存部门信息
|
*
|
* @param dept 部门信息
|
* @return 结果
|
*/
|
|
|
/**
|
* 修改保存部门信息
|
*
|
* @param dept 部门信息
|
* @return 结果
|
*/
|
@Override
|
public int updateDept(SysDept dept)
|
{
|
|
// 果该部门是启用状态,则启用该部门的所有上级部门
|
int i = deptMapper.updateDept(dept);
|
|
return i;
|
}
|
|
|
|
/**
|
* 删除部门管理信息
|
*
|
* @param deptId 部门ID
|
* @return 结果
|
*/
|
@Override
|
public int deleteDeptById(Long deptId)
|
{
|
return deptMapper.deleteDeptById(deptId);
|
}
|
|
|
|
}
|