| | |
| | | import java.time.LocalDate; |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.LinkedHashSet; |
| | |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.toSet()); |
| | | Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(deptIds); |
| | | // 解析岗位ID(post_ids 存的是 JSON 数组字符串,如 [38]),并批量加载岗位名称 |
| | | Map<Long, List<Long>> empPostIdsMap = new LinkedHashMap<>(); |
| | | Set<Long> allPostIds = new LinkedHashSet<>(); |
| | | for (HrmEmployeeDO emp : list) { |
| | | List<Long> postIdList = parseEmployeePostIds(emp.getPostIds()); |
| | | empPostIdsMap.put(emp.getId(), postIdList); |
| | | allPostIds.addAll(postIdList); |
| | | } |
| | | Map<Long, PostRespDTO> postMap = CollUtil.isEmpty(allPostIds) |
| | | ? Collections.emptyMap() : postApi.getPostMap(allPostIds); |
| | | return list.stream().map(emp -> { |
| | | HrmEmployeeSimpleRespVO vo = new HrmEmployeeSimpleRespVO(); |
| | | vo.setId(emp.getId()); |
| | | vo.setEmployeeNo(emp.getEmployeeNo()); |
| | | vo.setName(emp.getName()); |
| | | vo.setEmployeeStatus(emp.getEmployeeStatus()); |
| | | vo.setDeptId(emp.getDeptId()); |
| | | if (emp.getDeptId() != null && deptMap.containsKey(emp.getDeptId())) { |
| | | vo.setDeptName(deptMap.get(emp.getDeptId()).getName()); |
| | | } |
| | | // 岗位信息(用于调岗等场景自动带出原岗位) |
| | | List<Long> postIdList = empPostIdsMap.getOrDefault(emp.getId(), Collections.emptyList()); |
| | | vo.setPostIds(postIdList); |
| | | if (CollUtil.isNotEmpty(postIdList)) { |
| | | vo.setPostName(postIdList.stream() |
| | | .map(postMap::get) |
| | | .filter(Objects::nonNull) |
| | | .map(PostRespDTO::getName) |
| | | .collect(Collectors.joining(","))); |
| | | } |
| | | return vo; |
| | | }).collect(Collectors.toList()); |
| | | } |
| | | |
| | | /** |
| | | * 解析员工的岗位ID字符串(JSON 数组格式,如 [38] 或 [1,2]) |
| | | */ |
| | | |
| | | /** |
| | | * 解析员工岗位ID字符串(post_ids 存 JSON 数组,如 [38] 或 [1,2]) |
| | | */ |
| | | private java.util.List<Long> parseEmployeePostIds(String postIds) { |
| | | if (StrUtil.isBlank(postIds)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | // post_ids 形如 "[38]" 或 "[1,2]":去掉中括号后按逗号解析 |
| | | return Arrays.stream(postIds.replace("[", "").replace("]", "").split(",")) |
| | | .map(String::trim) |
| | | .filter(StrUtil::isNotBlank) |
| | | .map(s -> { |
| | | try { |
| | | return Long.valueOf(s); |
| | | } catch (NumberFormatException ex) { |
| | | return null; |
| | | } |
| | | }) |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public HrmEmployeeDO getEmployeeByUserId(Long userId) { |
| | | return employeeMapper.selectByUserId(userId); |