| | |
| | | */ |
| | | @Service |
| | | public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> implements ISysDeptService { |
| | | @Autowired |
| | | private SysDeptMapper deptMapper; |
| | | |
| | | @Autowired |
| | | private SysRoleMapper roleMapper; |
| | |
| | | @Override |
| | | @DataScope(deptAlias = "d") |
| | | public List<SysDept> selectDeptList(SysDept dept) { |
| | | Object dataScope = dept.getParams().get("dataScope"); |
| | | return list(new LambdaQueryWrapper<SysDept>() |
| | | .eq(dept.getParentId() != null && dept.getParentId() != 0, |
| | | SysDept::getParentId, dept.getParentId()) |
| | | .like(StrUtil.isNotBlank(dept.getDeptName()), SysDept::getDeptName, dept.getDeptName()) |
| | | .eq(StrUtil.isNotBlank(dept.getStatus()), SysDept::getStatus, dept.getStatus()) |
| | | .apply(dataScope != null, dataScope != null ? dataScope.toString() : null) |
| | | .orderByAsc(SysDept::getParentId) |
| | | .orderByAsc(SysDept::getOrderNum)); |
| | | return baseMapper.selectDeptList(dept); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public List<Integer> selectDeptListByRoleId(Long roleId) { |
| | | SysRole role = roleMapper.selectRoleById(roleId); |
| | | return deptMapper.selectDeptListByRoleId(roleId, role.isDeptCheckStrictly()); |
| | | SysRole role = roleMapper.selectById(roleId); |
| | | return baseMapper.selectDeptListByRoleId(roleId, role.isDeptCheckStrictly()); |
| | | } |
| | | |
| | | /** |
| | |
| | | int result = baseMapper.updateById(dept); |
| | | if (UserConstants.DEPT_NORMAL.equals(dept.getStatus())) { |
| | | // 如果该部门是启用状态,则启用该部门的所有上级部门 |
| | | updateParentDeptStatus(dept); |
| | | updateParentDeptStatusNormal(dept); |
| | | } |
| | | return result; |
| | | } |
| | |
| | | /** |
| | | * 修改子元素关系 |
| | | * |
| | | * @param deptId 被修改的部门ID |
| | | * @param deptId 被修改的部门ID |
| | | * @param newAncestors 新的父ID集合 |
| | | * @param oldAncestors 旧的父ID集合 |
| | | */ |
| | |
| | | List<SysDept> children = list(new LambdaQueryWrapper<SysDept>() |
| | | .apply("find_in_set({0},ancestors)",deptId)); |
| | | for (SysDept child : children) { |
| | | child.setAncestors(child.getAncestors().replace(oldAncestors, newAncestors)); |
| | | child.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors)); |
| | | } |
| | | if (children.size() > 0) { |
| | | updateBatchById(children); |
| | | baseMapper.updateDeptChildren(children); |
| | | } |
| | | } |
| | | |