| | |
| | | package com.project.system.service.impl; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.project.common.annotation.DataScope; |
| | | import com.project.common.constant.UserConstants; |
| | | import com.project.common.core.domain.TreeSelect; |
| | |
| | | import com.project.system.mapper.SysDeptMapper; |
| | | import com.project.system.mapper.SysRoleMapper; |
| | | import com.project.system.service.ISysDeptService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 部门管理 服务实现 |
| | |
| | | * @author project |
| | | */ |
| | | @Service |
| | | public class SysDeptServiceImpl implements ISysDeptService |
| | | @RequiredArgsConstructor |
| | | public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> implements ISysDeptService |
| | | { |
| | | @Autowired |
| | | private SysDeptMapper deptMapper; |
| | | |
| | | @Autowired |
| | | private SysRoleMapper roleMapper; |
| | | private final SysDeptMapper deptMapper; |
| | | private final SysRoleMapper roleMapper; |
| | | |
| | | /** |
| | | * 查询部门管理数据 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 根据登录人部门获取审批机构id |
| | | * @param deptId 登录人部门id |
| | | * @return 审批机构id |
| | | */ |
| | | @Override |
| | | public Long getCheckDeptIdByLoginDeptId(Long deptId) |
| | | { |
| | | SysDept loginDept = selectDeptById(deptId); |
| | | if (loginDept.getDeptId()==100 || loginDept.getParentId()==100){ |
| | | return loginDept.getDeptId(); |
| | | } else { |
| | | return getCheckDeptIdByLoginDeptId(loginDept.getParentId()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据登录人id获取管辖机构ids |
| | | * @param userId 登录人id |
| | | * @return 审批机构ids |
| | | */ |
| | | @Override |
| | | public List<Long> getApplyDeptIdsByLoginUserId(Long userId) |
| | | { |
| | | return deptMapper.getApplyDeptIdsByLoginUserId(userId); |
| | | } |
| | | |
| | | @Override |
| | | public String getDeptAllName(Long deptId) |
| | | { |
| | | List<String> names = new ArrayList<>(); |
| | | names = getAncestorsNames(deptId, names); |
| | | if (CollectionUtil.isEmpty(names)){ |
| | | return ""; |
| | | } |
| | | Collections.reverse(names); |
| | | return StrUtil.join("-", names); |
| | | } |
| | | |
| | | /** |
| | | * 递归列表 |
| | | */ |
| | | private void recursionFn(List<SysDept> list, SysDept t) |
| | |
| | | { |
| | | return getChildList(list, t).size() > 0; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取祖籍names列表 |
| | | * |
| | | * @param deptId 当前部门id |
| | | * @param names 祖籍id列表 |
| | | * @return names列表 |
| | | */ |
| | | public List<String> getAncestorsNames(long deptId, List<String> names) { |
| | | SysDept dept = deptMapper.selectDeptById(deptId); |
| | | if (dept == null) { |
| | | return names; |
| | | } |
| | | if (deptId == 100) { |
| | | names.add(dept.getDeptName()); |
| | | return names; |
| | | } |
| | | if (dept.getParentId() != null && dept.getParentId() == 100) { |
| | | names.add(dept.getDeptName()); |
| | | return names; |
| | | } else { |
| | | names.add(dept.getDeptName()); |
| | | return getAncestorsNames(dept.getParentId(), names); |
| | | } |
| | | } |
| | | } |