| | |
| | | import com.ycl.common.base.Result; |
| | | import com.ycl.common.core.domain.StringTreeSelect; |
| | | import com.ycl.system.domain.base.BaseSelect; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.ycl.common.annotation.DataScope; |
| | |
| | | * @author ycl |
| | | */ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class SysDeptServiceImpl implements ISysDeptService |
| | | { |
| | | @Autowired |
| | | private SysDeptMapper deptMapper; |
| | | |
| | | @Autowired |
| | | private SysRoleMapper roleMapper; |
| | | private final SysDeptMapper deptMapper; |
| | | private final SysRoleMapper roleMapper; |
| | | |
| | | /** |
| | | * 查询部门管理数据 |
| | |
| | | public List<SysDept> selectDeptList(SysDept dept) |
| | | { |
| | | return deptMapper.selectDeptList(dept); |
| | | } |
| | | |
| | | @Override |
| | | public List<SysDept> selectDeptListNoAuth(SysDept dept) { |
| | | return deptMapper.selectDeptListNoAuth(dept); |
| | | } |
| | | |
| | | /** |
| | |
| | | return deptMapper.selectDeptById(deptId); |
| | | } |
| | | |
| | | @Override |
| | | public List<SysDept> selectDeptByIds(List<Long> deptIds) { |
| | | return deptMapper.selectDeptByIds(deptIds); |
| | | } |
| | | |
| | | /** |
| | | * 根据ID查询所有子部门(正常状态) |
| | | * |
| | |
| | | @Override |
| | | public int insertDept(SysDept dept) |
| | | { |
| | | SysDept info = deptMapper.selectDeptById(dept.getParentId()); |
| | | // 如果父节点不为正常状态,则不允许新增子节点 |
| | | if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) |
| | | { |
| | | throw new ServiceException("部门停用,不允许新增"); |
| | | if (Objects.nonNull(dept.getParentId())) { |
| | | SysDept info = deptMapper.selectDeptById(dept.getParentId()); |
| | | // 如果父节点不为正常状态,则不允许新增子节点 |
| | | if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) |
| | | { |
| | | throw new ServiceException("上级部门已停用,不允许新增下级部门"); |
| | | } |
| | | dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); |
| | | } else { |
| | | dept.setParentId(0L); |
| | | dept.setAncestors(""); |
| | | } |
| | | dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); |
| | | return deptMapper.insertDept(dept); |
| | | } |
| | | |
| | |
| | | @Override |
| | | public int updateDept(SysDept dept) |
| | | { |
| | | SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId()); |
| | | SysDept oldDept = deptMapper.selectDeptById(dept.getDeptId()); |
| | | if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept)) |
| | | { |
| | | String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId(); |
| | | String oldAncestors = oldDept.getAncestors(); |
| | | dept.setAncestors(newAncestors); |
| | | updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors); |
| | | if (Objects.isNull(oldDept)) { |
| | | throw new RuntimeException("修改部门被删除或不存在"); |
| | | } |
| | | if (Objects.nonNull(dept.getParentId())) { |
| | | SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId()); |
| | | if (Objects.nonNull(newParentDept)) { |
| | | String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId(); |
| | | String oldAncestors = oldDept.getAncestors(); |
| | | dept.setAncestors(newAncestors); |
| | | updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors); |
| | | } |
| | | } else { |
| | | dept.setParentId(0L); |
| | | dept.setAncestors(""); |
| | | } |
| | | int result = deptMapper.updateDept(dept); |
| | | if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors()) |
| | | && !StringUtils.equals("0", dept.getAncestors())) |
| | | { |
| | | // 如果该部门是启用状态,则启用该部门的所有上级部门 |
| | | updateParentDeptStatusNormal(dept); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | |
| | | }).collect(Collectors.toList()); |
| | | return list; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<Long> getChildIds(Long deptId) { |
| | | return deptMapper.getChildIds(deptId); |
| | | } |
| | | } |