| 31 | import java.util.stream.Collectors; |
| 32 | |
| 33 | @Slf4j |
| 34 | @Service |
| 35 | @RequiredArgsConstructor |
| 36 | public class MatchService { |
| 37 | |
| 38 | private final HybridMatchService hybridMatchService; |
| 39 | private final ResumeRepository resumeRepository; |
| 40 | private final PositionRepository positionRepository; |
| 41 | private final MatchRecordRepository matchRecordRepository; |
| 42 | |
| 43 | /** |
| 44 | * 执行单次匹配 |
| 45 | */ |
| 46 | @Transactional |
| 47 | public MatchResultDTO match(MatchRequestDTO request, Long userId) { |
| 48 | Resume resume = resumeRepository.findById(request.getResumeId()) |
| 49 | .orElseThrow(() -> new BusinessException("简历不存在")); |
| 50 | Position position = positionRepository.findByIdAndDeletedFalse(request.getPositionId()) |
| 51 | .orElseThrow(() -> new BusinessException("岗位不存在或已删除")); |
| 52 | |
| 53 | // 执行混合匹配 |
| 54 | MatchResult result = hybridMatchService.match( |
| 55 | resume.getContent(), |
| 56 | resume.getExtractedSkills(), |
| 57 | buildPositionContent(position), |
| 58 | position.getSkills(), |
| 59 | userId |
| 60 | ); |
| 61 | |
| 62 | // 保存匹配记录 |
| 63 | MatchRecord record = saveMatchRecord(resume, position, result, userId); |
| 64 | |
| 65 | return toDTO(record, result, resume.getFileName(), position.getTitle()); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * 为简历匹配多个岗位 |
| 70 | */ |
| 71 | @Transactional |
| 72 | public List<MatchResultDTO> matchResumeToPositions(Long resumeId, Long userId) { |
| 73 | Resume resume = resumeRepository.findById(resumeId) |
| 74 | .orElseThrow(() -> new BusinessException("简历不存在")); |
| 75 | List<Position> positions = positionRepository.findByDeletedFalse(); |
| 76 | |
| 77 | List<MatchResultDTO> results = new ArrayList<>(); |
| 78 | for (Position position : positions) { |
| 79 | MatchResult result = hybridMatchService.match( |
| 80 | resume.getContent(), |
| 81 | resume.getExtractedSkills(), |
| 82 | buildPositionContent(position), |
| 83 | position.getSkills(), |
| 84 | userId |
| 85 | ); |
| 86 | MatchRecord record = saveMatchRecord(resume, position, result, userId); |
| 87 | results.add(toDTO(record, result, resume.getFileName(), position.getTitle())); |
| 88 | } |
| 89 | |
| 90 | // 按分数排序 |
nothing calls this directly
no outgoing calls
no test coverage detected