| | |
| | | package cn.iocoder.yudao.module.hrm.service.attendance; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| | | import cn.iocoder.yudao.module.hrm.controller.admin.attendance.vo.HrmAttendanceSummaryPageReqVO; |
| | |
| | | if (pageReqVO.getStartDate() != null) { |
| | | return getAttendanceSummaryByDateRange(pageReqVO); |
| | | } |
| | | // 员工姓名模糊搜索:先按姓名查出员工ID,再按 ID 集合过滤(汇总表的 user_id 存的是员工ID) |
| | | Set<Long> nameMatchedIds = resolveEmployeeIdsByName(pageReqVO.getUserName()); |
| | | if (nameMatchedIds != null && nameMatchedIds.isEmpty()) { |
| | | // 姓名搜不到任何员工时直接返回空,避免退化成查全部 |
| | | return PageResult.empty(); |
| | | } |
| | | return attendanceSummaryMapper.selectPage(pageReqVO, new LambdaQueryWrapperX<HrmAttendanceSummaryDO>() |
| | | .eqIfPresent(HrmAttendanceSummaryDO::getUserId, pageReqVO.getUserId()) |
| | | .inIfPresent(HrmAttendanceSummaryDO::getUserId, nameMatchedIds) |
| | | .eqIfPresent(HrmAttendanceSummaryDO::getDeptId, pageReqVO.getDeptId()) |
| | | .eqIfPresent(HrmAttendanceSummaryDO::getYearMonth, pageReqVO.getYearMonth()) |
| | | .orderByDesc(HrmAttendanceSummaryDO::getYearMonth) |
| | | .orderByAsc(HrmAttendanceSummaryDO::getDeptId)); |
| | | } |
| | | |
| | | /** |
| | | * 按员工姓名模糊匹配,返回员工ID集合 |
| | | * |
| | | * @return null 表示未传姓名(不参与过滤);空集合表示传了姓名但没有任何员工匹配 |
| | | */ |
| | | private Set<Long> resolveEmployeeIdsByName(String userName) { |
| | | if (StrUtil.isBlank(userName)) { |
| | | return null; |
| | | } |
| | | List<HrmEmployeeDO> matched = employeeService.getEmployeeListByNameLike(userName.trim()); |
| | | if (CollUtil.isEmpty(matched)) { |
| | | return Collections.emptySet(); |
| | | } |
| | | return matched.stream().map(HrmEmployeeDO::getId).collect(Collectors.toSet()); |
| | | } |
| | | |
| | | /** |
| | |
| | | .filter(e -> reqVO.getUserId().equals(e.getId())) |
| | | .toList(); |
| | | } |
| | | // 员工姓名模糊过滤 |
| | | if (StrUtil.isNotBlank(reqVO.getUserName())) { |
| | | String keyword = reqVO.getUserName().trim(); |
| | | employees = employees.stream() |
| | | .filter(e -> e.getName() != null && e.getName().contains(keyword)) |
| | | .toList(); |
| | | } |
| | | if (CollUtil.isEmpty(employees)) { |
| | | return PageResult.empty(); |
| | | } |