From 2e41aaef70e97a2d7003cdec344cda3eda5a108a Mon Sep 17 00:00:00 2001 From: xiaowang <2161656029@qq.com> Date: Wed, 1 Jul 2026 19:54:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A2=84=E7=BA=A6=E6=8E=92?= =?UTF-8?q?=E7=8F=AD=E8=A7=84=E5=88=99=E5=8F=AF=E7=BA=A6=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/AppointmentCapacityServiceImpl.java | 12 +++- .../service/impl/PlanningServiceImpl.java | 15 ++++- .../AppointmentCapacityServiceImplTest.java | 21 ++++++ .../service/impl/PlanningServiceImplTest.java | 65 +++++++++++++++++++ 4 files changed, 109 insertions(+), 4 deletions(-) diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/AppointmentCapacityServiceImpl.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/AppointmentCapacityServiceImpl.java index 374487ad..6bd983be 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/AppointmentCapacityServiceImpl.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/AppointmentCapacityServiceImpl.java @@ -152,11 +152,11 @@ public class AppointmentCapacityServiceImpl implements AppointmentCapacityServic startTime.toLocalTime(), endTime.toLocalTime() ); - if (schedule != null) { + if (schedule != null && isManualScheduleOverride(schedule)) { return resolveExplicitScheduleCapacity(schedule); } ArtistScheduleDO daySchedule = scheduleMapper.selectDayScheduleForUpdate(shopId, artistId, startTime.toLocalDate()); - if (daySchedule != null) { + if (daySchedule != null && isManualScheduleOverride(daySchedule)) { throw new RuntimeException(UNAVAILABLE_MESSAGE); } return resolveRuleCapacity(shopId, artistId, startTime, endTime); @@ -206,4 +206,12 @@ public class AppointmentCapacityServiceImpl implements AppointmentCapacityServic } return !appointmentStartTime.isBefore(scheduleStartTime) && !appointmentEndTime.isAfter(scheduleEndTime); } + + private boolean isManualScheduleOverride(ArtistScheduleDO schedule) { + if (schedule == null || schedule.getRemark() == null || schedule.getRemark().isBlank()) { + return false; + } + String remark = schedule.getRemark().trim(); + return !"规则生成排班".equals(remark) && !remark.startsWith("例外排班:"); + } } diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImpl.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImpl.java index 378f39e8..23e1c1eb 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImpl.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImpl.java @@ -380,10 +380,13 @@ public class PlanningServiceImpl implements PlanningService { } Map exceptionByArtistDate = loadArtistScheduleExceptions(shopId, artistIds, start, end); Set explicitDayKeys = explicitSchedules.stream() + .filter(this::isManualScheduleOverride) .filter(schedule -> schedule.getArtistId() != null && schedule.getWorkDate() != null) .map(this::scheduleKey) .collect(Collectors.toCollection(HashSet::new)); - List schedules = new ArrayList<>(explicitSchedules); + List schedules = explicitSchedules.stream() + .filter(this::isManualScheduleOverride) + .collect(Collectors.toCollection(ArrayList::new)); LocalDate cursor = start; while (!cursor.isAfter(end)) { for (PlanningArtistVO artist : artists) { @@ -448,6 +451,14 @@ public class PlanningServiceImpl implements PlanningService { return artistId + ":" + workDate; } + private boolean isManualScheduleOverride(ArtistScheduleDO schedule) { + if (schedule == null || schedule.getRemark() == null || schedule.getRemark().isBlank()) { + return false; + } + String remark = schedule.getRemark().trim(); + return !"规则生成排班".equals(remark) && !remark.startsWith("例外排班:"); + } + private PlanningScheduleVO toScheduleVO(ArtistScheduleDO schedule, List artists) { Map artistNames = artists.stream() .collect(Collectors.toMap(PlanningArtistVO::getId, PlanningArtistVO::getName, (a, b) -> a)); @@ -689,7 +700,7 @@ public class PlanningServiceImpl implements PlanningService { if (schedule != null && !Integer.valueOf(1).equals(schedule.getStatus())) { return "rest"; } - if (schedule == null || Integer.valueOf(0).equals(artist.getStatus())) { + if (schedule == null) { return "rest"; } if (hasContinuousFreeWindow(schedule, appointments, MONTH_AVAILABLE_MINUTES)) { diff --git a/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/AppointmentCapacityServiceImplTest.java b/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/AppointmentCapacityServiceImplTest.java index 4e13cb85..1c23a09e 100644 --- a/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/AppointmentCapacityServiceImplTest.java +++ b/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/AppointmentCapacityServiceImplTest.java @@ -138,6 +138,26 @@ class AppointmentCapacityServiceImplTest { verify(reservationMapper).insert(any(AppointmentReservationDO.class)); } + @Test + void reserveUsesRuleWhenCachedGeneratedDayScheduleIsStale() { + LocalDateTime start = LocalDateTime.of(2026, 7, 2, 9, 0); + LocalDateTime end = start.plusHours(1); + ArtistScheduleDO staleSchedule = schedule(1); + staleSchedule.setWorkDate(start.toLocalDate()); + staleSchedule.setStatus(0); + staleSchedule.setRemark(null); + when(scheduleMapper.selectCoveringSchedule(9L, 30L, start.toLocalDate(), start.toLocalTime(), end.toLocalTime())) + .thenReturn(null); + when(scheduleMapper.selectDayScheduleForUpdate(9L, 30L, start.toLocalDate())).thenReturn(staleSchedule); + when(ruleMapper.selectOne(any())).thenReturn(rule("DOUBLE_REST", "1,2,3,4,5", LocalTime.of(9, 0), LocalTime.of(17, 0))); + when(exceptionMapper.selectOne(any())).thenReturn(null); + when(reservationMapper.countOverlappingActiveForUpdate(30L, start, end)).thenReturn(0); + + service.reserveOrThrow(1L, 10L, 9L, 30L, "French", start, end); + + verify(reservationMapper).insert(any(AppointmentReservationDO.class)); + } + @Test void reserveRejectsWeekendByRuleWhenDailyScheduleMissing() { LocalDateTime start = LocalDateTime.of(2026, 7, 4, 9, 0); @@ -228,6 +248,7 @@ class AppointmentCapacityServiceImplTest { schedule.setEndTime(LocalTime.of(20, 0)); schedule.setCapacity(capacity); schedule.setStatus(1); + schedule.setRemark("手动排班"); schedule.setIsDelete(0); return schedule; } diff --git a/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImplTest.java b/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImplTest.java index f47aef4a..92051a8a 100644 --- a/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImplTest.java +++ b/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImplTest.java @@ -320,6 +320,71 @@ class PlanningServiceImplTest { .containsExactly("20:free"); } + @Test + void calendarUsesRuleWhenCachedGeneratedScheduleIsStale() { + UserDO manager = user(2, 8L); + UserDO artist = user(3, 8L); + artist.setId(20L); + artist.setNickname("缇庣敳甯?"); + LocalDate date = LocalDate.of(2026, 7, 2); + ShopDO shop = new ShopDO(); + shop.setBusinessHours("09:00-18:00"); + ArtistScheduleDO staleSchedule = schedule(20L, date, LocalTime.of(0, 0), LocalTime.of(0, 0)); + staleSchedule.setStatus(0); + staleSchedule.setRemark(null); + + when(adminScopeHelper.resolveShopScope(manager, null)).thenReturn(8L); + when(shopMapper.selectById(8L)).thenReturn(shop); + when(shopScheduleExceptionMapper.selectList(any())).thenReturn(List.of()); + when(userMapper.selectList(any())).thenReturn(List.of(artist)); + when(nailArtistInfoMapper.selectList(any())).thenReturn(List.of()); + when(artistScheduleMapper.selectList(any())).thenReturn(List.of(staleSchedule)); + when(artistScheduleRuleMapper.selectList(any())) + .thenReturn(List.of(scheduleRule(20L, "DOUBLE_REST", "1,2,3,4,5", LocalTime.of(9, 0), LocalTime.of(17, 0)))); + when(artistScheduleExceptionMapper.selectList(any())).thenReturn(List.of()); + when(appointmentReservationMapper.selectList(any())).thenReturn(List.of()); + + var calendar = planningService.getCalendar(manager, date, date, 20L); + + assertThat(calendar.getSchedules()).hasSize(1); + var schedule = calendar.getSchedules().get(0); + assertThat(schedule.getArtistId()).isEqualTo(20L); + assertThat(schedule.getStartTime()).isEqualTo("09:00"); + assertThat(schedule.getEndTime()).isEqualTo("17:00"); + assertThat(schedule.getStatus()).isEqualTo(1); + assertThat(calendar.getDaySummaries().get(0).getDayStatus()).isEqualTo("free"); + } + + @Test + void calendarUsesScheduleWhenArtistBookingStatusIsResting() { + UserDO manager = user(2, 8L); + UserDO artist = user(3, 8L); + artist.setId(20L); + artist.setStatus(0); + artist.setNickname("缇庣敳甯?"); + LocalDate date = LocalDate.of(2026, 7, 2); + ShopDO shop = new ShopDO(); + shop.setBusinessHours("09:00-18:00"); + + when(adminScopeHelper.resolveShopScope(manager, null)).thenReturn(8L); + when(shopMapper.selectById(8L)).thenReturn(shop); + when(shopScheduleExceptionMapper.selectList(any())).thenReturn(List.of()); + when(userMapper.selectList(any())).thenReturn(List.of(artist)); + when(nailArtistInfoMapper.selectList(any())).thenReturn(List.of()); + when(artistScheduleMapper.selectList(any())).thenReturn(List.of()); + when(artistScheduleRuleMapper.selectList(any())) + .thenReturn(List.of(scheduleRule(20L, "DOUBLE_REST", "1,2,3,4,5", LocalTime.of(9, 0), LocalTime.of(17, 0)))); + when(artistScheduleExceptionMapper.selectList(any())).thenReturn(List.of()); + when(appointmentReservationMapper.selectList(any())).thenReturn(List.of()); + + var calendar = planningService.getCalendar(manager, date, date, 20L); + + assertThat(calendar.getDaySummaries().get(0).getDayStatus()).isEqualTo("free"); + assertThat(calendar.getDaySummaries().get(0).getArtistCounts()) + .extracting(count -> count.getArtistId() + ":" + count.getStatus()) + .containsExactly("20:free"); + } + private UserDO user(Integer type, Long shopId) { UserDO user = new UserDO(); user.setId(10L + type);