| | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.domain.entity.SysDept; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.helper.LoginHelper; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.TreeBuildUtils; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.common.core.constant.UserConstants; |
| | | import com.ruoyi.system.domain.SysDept; |
| | | import com.ruoyi.system.domain.SysRole; |
| | | import com.ruoyi.system.domain.SysUser; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.mybatis.helper.DataBaseHelper; |
| | | 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.mapper.SysDeptMapper; |
| | | import com.ruoyi.system.mapper.SysRoleMapper; |
| | | import com.ruoyi.system.mapper.SysUserMapper; |
| | |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public List<SysDept> selectDeptList(SysDept dept) { |
| | | return baseMapper.selectDeptList(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); |
| | | return baseMapper.selectDeptList(lqw); |
| | | } |
| | | |
| | | /** |
| | | * 查询部门树结构信息 |
| | | * |
| | | * @param dept 部门信息 |
| | | * @return 部门树信息集合 |
| | | */ |
| | | @Override |
| | | public List<Tree<Long>> selectDeptTreeList(SysDept dept) { |
| | | List<SysDept> depts = this.selectDeptList(dept); |
| | | return buildDeptTreeSelect(depts); |
| | | } |
| | | |
| | | /** |
| | |
| | | if (CollUtil.isEmpty(depts)) { |
| | | return CollUtil.newArrayList(); |
| | | } |
| | | Long parentId = depts.get(0).getParentId(); |
| | | return TreeBuildUtils.build(depts, parentId, (dept, tree) -> |
| | | return TreeBuildUtils.build(depts, (dept, tree) -> |
| | | tree.setId(dept.getDeptId()) |
| | | .setParentId(dept.getParentId()) |
| | | .setName(dept.getDeptName()) |
| | |
| | | @Override |
| | | public List<Long> selectDeptListByRoleId(Long roleId) { |
| | | SysRole role = roleMapper.selectById(roleId); |
| | | return baseMapper.selectDeptListByRoleId(roleId, role.isDeptCheckStrictly()); |
| | | return baseMapper.selectDeptListByRoleId(roleId, role.getDeptCheckStrictly()); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public SysDept selectDeptById(Long deptId) { |
| | | return baseMapper.selectById(deptId); |
| | | SysDept dept = baseMapper.selectById(deptId); |
| | | SysDept parentDept = baseMapper.selectOne(new LambdaQueryWrapper<SysDept>() |
| | | .select(SysDept::getDeptName).eq(SysDept::getDeptId, dept.getParentId())); |
| | | dept.setParentName(ObjectUtil.isNotNull(parentDept) ? parentDept.getDeptName() : null); |
| | | return dept; |
| | | } |
| | | |
| | | /** |
| | |
| | | public long selectNormalChildrenDeptById(Long deptId) { |
| | | return baseMapper.selectCount(new LambdaQueryWrapper<SysDept>() |
| | | .eq(SysDept::getStatus, UserConstants.DEPT_NORMAL) |
| | | .apply("find_in_set({0}, ancestors)", deptId)); |
| | | .apply(DataBaseHelper.findInSet(deptId, "ancestors"))); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public void checkDeptDataScope(Long deptId) { |
| | | if (!SysUser.isAdmin(LoginHelper.getUserId())) { |
| | | if (!LoginHelper.isAdmin()) { |
| | | SysDept dept = new SysDept(); |
| | | dept.setDeptId(deptId); |
| | | List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept); |
| | | List<SysDept> depts = this.selectDeptList(dept); |
| | | if (CollUtil.isEmpty(depts)) { |
| | | throw new ServiceException("没有权限访问部门数据!"); |
| | | } |
| | |
| | | */ |
| | | public void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors) { |
| | | List<SysDept> children = baseMapper.selectList(new LambdaQueryWrapper<SysDept>() |
| | | .apply("find_in_set({0},ancestors)", deptId)); |
| | | .apply(DataBaseHelper.findInSet(deptId, "ancestors"))); |
| | | List<SysDept> list = new ArrayList<>(); |
| | | for (SysDept child : children) { |
| | | child.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors)); |
| | | SysDept dept = new SysDept(); |
| | | dept.setDeptId(child.getDeptId()); |
| | | dept.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors)); |
| | | list.add(dept); |
| | | } |
| | | if (children.size() > 0) { |
| | | baseMapper.updateDeptChildren(children); |
| | | if (list.size() > 0) { |
| | | baseMapper.updateBatchById(list); |
| | | } |
| | | } |
| | | |