@@ -44,6 +44,8 @@ public class InterviewAssignmentServiceImpl implements IInterviewAssignmentServi
4444 private static final LocalTime MORNING_END = LocalTime .of (11 , 0 );
4545 private static final LocalTime AFTERNOON_START = LocalTime .of (13 , 0 );
4646 private static final LocalTime AFTERNOON_END = LocalTime .of (17 , 0 );
47+ private static final LocalTime EVENING_START = LocalTime .of (19 , 0 );
48+ private static final LocalTime EVENING_END = LocalTime .of (21 , 0 );
4749 private static final int INTERVIEW_DURATION = 10 ; // 面试时长10分钟
4850
4951 @ Override
@@ -79,10 +81,9 @@ public InterviewAssignmentResultDTO assignInterviews(Integer cycleId) {
7981 Map <Integer , List <String >> userPreferredTimes = getUserPreferredTimes (resumes , interviewTimeField .getFieldId ());
8082 Map <Integer , List <String >> userPreferredDepartments = getUserPreferredDepartments (resumes , expectedDepartmentsField .getFieldId ());
8183
82- // 初始化各部门面试时间槽 (将Day1设置为9月27日,Day2设置为9月28日 )
84+ // 初始化各部门面试时间槽 (将Day1设置为9月27日,仅有一天面试 )
8385 LocalDate day1 = LocalDate .of (2025 , 9 , 27 );
84- LocalDate day2 = LocalDate .of (2025 , 9 , 28 );
85- List <LocalDateTime > timeSlots = generateTimeSlotsForSpecificDays (day1 , day2 );
86+ List <LocalDateTime > timeSlots = generateTimeSlotsForSingleDay (day1 );
8687 Map <String , Map <LocalDateTime , Boolean >> departmentSlotAvailability = initializeDepartmentSlotAvailability (timeSlots , userPreferredDepartments );
8788
8889 // 使用优化的分配策略分配面试时间
@@ -402,23 +403,24 @@ private Map<Integer, List<String>> getUserPreferredDepartments(List<Resume> resu
402403 }
403404
404405 /**
405- * 为特定日期生成面试时间槽 (Day1为9月27日,Day2为9月28日 )
406+ * 为单个日期生成面试时间槽 (仅9月27日一天,包括上午、下午、晚上 )
406407 */
407- private List <LocalDateTime > generateTimeSlotsForSpecificDays (LocalDate day1 , LocalDate day2 ) {
408+ private List <LocalDateTime > generateTimeSlotsForSingleDay (LocalDate day ) {
408409 List <LocalDateTime > timeSlots = new ArrayList <>();
409410
410- // 为指定的两天生成面试时间槽
411- LocalDate [] dates = {day1 , day2 };
412- for (LocalDate date : dates ) {
413- // 生成上午时间段 (9:00-11:00)
414- for (LocalTime time = MORNING_START ; time .isBefore (MORNING_END ); time = time .plusMinutes (INTERVIEW_DURATION )) {
415- timeSlots .add (LocalDateTime .of (date , time ));
416- }
417-
418- // 生成下午时间段 (13:00-17:00)
419- for (LocalTime time = AFTERNOON_START ; time .isBefore (AFTERNOON_END ); time = time .plusMinutes (INTERVIEW_DURATION )) {
420- timeSlots .add (LocalDateTime .of (date , time ));
421- }
411+ // 生成上午时间段 (9:00-11:00)
412+ for (LocalTime time = MORNING_START ; time .isBefore (MORNING_END ); time = time .plusMinutes (INTERVIEW_DURATION )) {
413+ timeSlots .add (LocalDateTime .of (day , time ));
414+ }
415+
416+ // 生成下午时间段 (13:00-17:00)
417+ for (LocalTime time = AFTERNOON_START ; time .isBefore (AFTERNOON_END ); time = time .plusMinutes (INTERVIEW_DURATION )) {
418+ timeSlots .add (LocalDateTime .of (day , time ));
419+ }
420+
421+ // 生成晚上时间段 (19:00-21:00)
422+ for (LocalTime time = EVENING_START ; time .isBefore (EVENING_END ); time = time .plusMinutes (INTERVIEW_DURATION )) {
423+ timeSlots .add (LocalDateTime .of (day , time ));
422424 }
423425
424426 return timeSlots ;
@@ -508,7 +510,17 @@ private boolean tryAssignInterviewTime(User user, Resume resume, List<String> pr
508510 LocalDateTime assignedSlot = findAndReserveSlot (preferredTime , department , departmentSlotAvailability );
509511 if (assignedSlot != null ) {
510512 // 成功分配时间
511- String period = assignedSlot .getHour () < 12 ? "上午" : "下午" ;
513+ String period ;
514+ LocalTime timeOfDay = assignedSlot .toLocalTime ();
515+ if (!timeOfDay .isBefore (MORNING_START ) && timeOfDay .isBefore (MORNING_END )) {
516+ period = "上午" ;
517+ } else if (!timeOfDay .isBefore (AFTERNOON_START ) && timeOfDay .isBefore (AFTERNOON_END )) {
518+ period = "下午" ;
519+ } else if (!timeOfDay .isBefore (EVENING_START ) && timeOfDay .isBefore (EVENING_END )) {
520+ period = "晚上" ;
521+ } else {
522+ period = "未知" ; // 备用,不应该出现
523+ }
512524 logger .info ("成功为用户 {} 分配面试时间: {}" , user .getUsername (), assignedSlot );
513525 // 从简历中获取姓名而不是从用户表中获取
514526 String name = getResumeName (resume );
@@ -619,7 +631,7 @@ private LocalDateTime findAnyAvailableSlot(String department,
619631 * 严格按照用户选择的具体日期和时间段进行匹配
620632 */
621633 private boolean isSlotMatchPreference (LocalDateTime slotTime , String preferredTime ) {
622- // 处理格式如 "Day 1 上午" 或 " Day 1 下午 "
634+ // 处理格式如 "Day 1 上午"、"Day 1 下午"、" Day 1 晚上 "
623635 String [] parts = preferredTime .split (" " );
624636 if (parts .length < 3 || !"Day" .equals (parts [0 ])) {
625637 logger .warn ("无效的期望时间格式: {}" , preferredTime );
@@ -628,28 +640,21 @@ private boolean isSlotMatchPreference(LocalDateTime slotTime, String preferredTi
628640
629641 try {
630642 int dayNumber = Integer .parseInt (parts [1 ]);
631- String period = parts [2 ]; // "上午" 或 "下午"
643+ String period = parts [2 ]; // "上午"、 "下午"、"晚上 "
632644
633- // 根据面试时间槽的日期确定是第几天
645+ // 现在只有Day 1,对应9月27日
634646 LocalDate day1 = LocalDate .of (2025 , 9 , 27 );
635- LocalDate day2 = LocalDate .of (2025 , 9 , 28 );
636647
637- // 严格匹配具体日期和时间段
648+ // 只匹配Day 1,即9月27日
638649 if (dayNumber == 1 && slotTime .toLocalDate ().equals (day1 )) {
639650 // 检查时间段是否匹配
640651 LocalTime time = slotTime .toLocalTime ();
641652 if ("上午" .equals (period )) {
642653 return !time .isBefore (MORNING_START ) && time .isBefore (MORNING_END );
643654 } else if ("下午" .equals (period )) {
644655 return !time .isBefore (AFTERNOON_START ) && time .isBefore (AFTERNOON_END );
645- }
646- } else if (dayNumber == 2 && slotTime .toLocalDate ().equals (day2 )) {
647- // 检查时间段是否匹配
648- LocalTime time = slotTime .toLocalTime ();
649- if ("上午" .equals (period )) {
650- return !time .isBefore (MORNING_START ) && time .isBefore (MORNING_END );
651- } else if ("下午" .equals (period )) {
652- return !time .isBefore (AFTERNOON_START ) && time .isBefore (AFTERNOON_END );
656+ } else if ("晚上" .equals (period )) {
657+ return !time .isBefore (EVENING_START ) && time .isBefore (EVENING_END );
653658 }
654659 } else {
655660 logger .debug ("时间槽 {} 与期望时间 {} 不匹配: 日期不匹配" , slotTime , preferredTime );
0 commit comments