| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.lang.tree.Tree; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.common.core.constant.UserConstants; |
| | | import com.ruoyi.system.domain.SysDept; |
| | | import com.ruoyi.system.domain.SysRole; |
| | |
| | | import com.ruoyi.common.satoken.utils.LoginHelper; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.core.utils.TreeBuildUtils; |
| | | import com.ruoyi.system.domain.bo.SysDeptBo; |
| | | import com.ruoyi.system.domain.vo.SysDeptVo; |
| | | import com.ruoyi.system.mapper.SysDeptMapper; |
| | | import com.ruoyi.system.mapper.SysRoleMapper; |
| | | import com.ruoyi.system.mapper.SysUserMapper; |
| | |
| | | * @return 部门信息集合 |
| | | */ |
| | | @Override |
| | | public List<SysDept> selectDeptList(SysDept dept) { |
| | | LambdaQueryWrapper<SysDept> lqw = new LambdaQueryWrapper<>(); |
| | | lqw.eq(SysDept::getDelFlag, "0") |
| | | .eq(ObjectUtil.isNotNull(dept.getDeptId()), SysDept::getDeptId, dept.getDeptId()) |
| | | .eq(ObjectUtil.isNotNull(dept.getParentId()), SysDept::getParentId, dept.getParentId()) |
| | | .like(StringUtils.isNotBlank(dept.getDeptName()), SysDept::getDeptName, dept.getDeptName()) |
| | | .eq(StringUtils.isNotBlank(dept.getStatus()), SysDept::getStatus, dept.getStatus()) |
| | | .orderByAsc(SysDept::getParentId) |
| | | .orderByAsc(SysDept::getOrderNum); |
| | | public List<SysDeptVo> selectDeptList(SysDeptBo dept) { |
| | | LambdaQueryWrapper<SysDept> lqw = buildQueryWrapper(dept); |
| | | return baseMapper.selectDeptList(lqw); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public List<Tree<Long>> selectDeptTreeList(SysDept dept) { |
| | | List<SysDept> depts = this.selectDeptList(dept); |
| | | SysDeptBo bo = BeanUtil.toBean(dept, SysDeptBo.class); |
| | | LambdaQueryWrapper<SysDept> lqw = buildQueryWrapper(bo); |
| | | List<SysDept> depts = baseMapper.selectList(lqw); |
| | | return buildDeptTreeSelect(depts); |
| | | } |
| | | |
| | | private LambdaQueryWrapper<SysDept> buildQueryWrapper(SysDeptBo bo) { |
| | | LambdaQueryWrapper<SysDept> lqw = Wrappers.lambdaQuery(); |
| | | lqw.eq(SysDept::getDelFlag, "0"); |
| | | lqw.eq(ObjectUtil.isNotNull(bo.getDeptId()), SysDept::getDeptId, bo.getDeptId()); |
| | | lqw.eq(ObjectUtil.isNotNull(bo.getParentId()), SysDept::getParentId, bo.getParentId()); |
| | | lqw.like(StringUtils.isNotBlank(bo.getDeptName()), SysDept::getDeptName, bo.getDeptName()); |
| | | lqw.eq(StringUtils.isNotBlank(bo.getStatus()), SysDept::getStatus, bo.getStatus()); |
| | | lqw.orderByAsc(SysDept::getParentId); |
| | | lqw.orderByAsc(SysDept::getOrderNum); |
| | | return lqw; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return 部门信息 |
| | | */ |
| | | @Override |
| | | public SysDept selectDeptById(Long deptId) { |
| | | SysDept dept = baseMapper.selectById(deptId); |
| | | SysDept parentDept = baseMapper.selectOne(new LambdaQueryWrapper<SysDept>() |
| | | public SysDeptVo selectDeptById(Long deptId) { |
| | | SysDeptVo dept = baseMapper.selectVoById(deptId); |
| | | SysDeptVo parentDept = baseMapper.selectVoOne(new LambdaQueryWrapper<SysDept>() |
| | | .select(SysDept::getDeptName).eq(SysDept::getDeptId, dept.getParentId())); |
| | | dept.setParentName(ObjectUtil.isNotNull(parentDept) ? parentDept.getDeptName() : null); |
| | | return dept; |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public String checkDeptNameUnique(SysDept dept) { |
| | | public String checkDeptNameUnique(SysDeptBo dept) { |
| | | boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysDept>() |
| | | .eq(SysDept::getDeptName, dept.getDeptName()) |
| | | .eq(SysDept::getParentId, dept.getParentId()) |
| | |
| | | @Override |
| | | public void checkDeptDataScope(Long deptId) { |
| | | if (!LoginHelper.isAdmin()) { |
| | | SysDept dept = new SysDept(); |
| | | SysDeptBo dept = new SysDeptBo(); |
| | | dept.setDeptId(deptId); |
| | | List<SysDept> depts = this.selectDeptList(dept); |
| | | List<SysDeptVo> depts = this.selectDeptList(dept); |
| | | if (CollUtil.isEmpty(depts)) { |
| | | throw new ServiceException("没有权限访问部门数据!"); |
| | | } |
| | |
| | | /** |
| | | * 新增保存部门信息 |
| | | * |
| | | * @param dept 部门信息 |
| | | * @param bo 部门信息 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int insertDept(SysDept dept) { |
| | | SysDept info = baseMapper.selectById(dept.getParentId()); |
| | | public int insertDept(SysDeptBo bo) { |
| | | SysDept info = baseMapper.selectById(bo.getParentId()); |
| | | // 如果父节点不为正常状态,则不允许新增子节点 |
| | | if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) { |
| | | throw new ServiceException("部门停用,不允许新增"); |
| | | } |
| | | SysDept dept = BeanUtil.toBean(bo, SysDept.class); |
| | | dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); |
| | | return baseMapper.insert(dept); |
| | | } |
| | |
| | | /** |
| | | * 修改保存部门信息 |
| | | * |
| | | * @param dept 部门信息 |
| | | * @param bo 部门信息 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int updateDept(SysDept dept) { |
| | | public int updateDept(SysDeptBo bo) { |
| | | SysDept dept = BeanUtil.toBean(bo, SysDept.class); |
| | | SysDept newParentDept = baseMapper.selectById(dept.getParentId()); |
| | | SysDept oldDept = baseMapper.selectById(dept.getDeptId()); |
| | | if (ObjectUtil.isNotNull(newParentDept) && ObjectUtil.isNotNull(oldDept)) { |