修复预约排班规则可约判断
This commit is contained in:
+10
-2
@@ -152,11 +152,11 @@ public class AppointmentCapacityServiceImpl implements AppointmentCapacityServic
|
|||||||
startTime.toLocalTime(),
|
startTime.toLocalTime(),
|
||||||
endTime.toLocalTime()
|
endTime.toLocalTime()
|
||||||
);
|
);
|
||||||
if (schedule != null) {
|
if (schedule != null && isManualScheduleOverride(schedule)) {
|
||||||
return resolveExplicitScheduleCapacity(schedule);
|
return resolveExplicitScheduleCapacity(schedule);
|
||||||
}
|
}
|
||||||
ArtistScheduleDO daySchedule = scheduleMapper.selectDayScheduleForUpdate(shopId, artistId, startTime.toLocalDate());
|
ArtistScheduleDO daySchedule = scheduleMapper.selectDayScheduleForUpdate(shopId, artistId, startTime.toLocalDate());
|
||||||
if (daySchedule != null) {
|
if (daySchedule != null && isManualScheduleOverride(daySchedule)) {
|
||||||
throw new RuntimeException(UNAVAILABLE_MESSAGE);
|
throw new RuntimeException(UNAVAILABLE_MESSAGE);
|
||||||
}
|
}
|
||||||
return resolveRuleCapacity(shopId, artistId, startTime, endTime);
|
return resolveRuleCapacity(shopId, artistId, startTime, endTime);
|
||||||
@@ -206,4 +206,12 @@ public class AppointmentCapacityServiceImpl implements AppointmentCapacityServic
|
|||||||
}
|
}
|
||||||
return !appointmentStartTime.isBefore(scheduleStartTime) && !appointmentEndTime.isAfter(scheduleEndTime);
|
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("例外排班:");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-2
@@ -380,10 +380,13 @@ public class PlanningServiceImpl implements PlanningService {
|
|||||||
}
|
}
|
||||||
Map<String, ArtistScheduleExceptionDO> exceptionByArtistDate = loadArtistScheduleExceptions(shopId, artistIds, start, end);
|
Map<String, ArtistScheduleExceptionDO> exceptionByArtistDate = loadArtistScheduleExceptions(shopId, artistIds, start, end);
|
||||||
Set<String> explicitDayKeys = explicitSchedules.stream()
|
Set<String> explicitDayKeys = explicitSchedules.stream()
|
||||||
|
.filter(this::isManualScheduleOverride)
|
||||||
.filter(schedule -> schedule.getArtistId() != null && schedule.getWorkDate() != null)
|
.filter(schedule -> schedule.getArtistId() != null && schedule.getWorkDate() != null)
|
||||||
.map(this::scheduleKey)
|
.map(this::scheduleKey)
|
||||||
.collect(Collectors.toCollection(HashSet::new));
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
List<ArtistScheduleDO> schedules = new ArrayList<>(explicitSchedules);
|
List<ArtistScheduleDO> schedules = explicitSchedules.stream()
|
||||||
|
.filter(this::isManualScheduleOverride)
|
||||||
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
LocalDate cursor = start;
|
LocalDate cursor = start;
|
||||||
while (!cursor.isAfter(end)) {
|
while (!cursor.isAfter(end)) {
|
||||||
for (PlanningArtistVO artist : artists) {
|
for (PlanningArtistVO artist : artists) {
|
||||||
@@ -448,6 +451,14 @@ public class PlanningServiceImpl implements PlanningService {
|
|||||||
return artistId + ":" + workDate;
|
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<PlanningArtistVO> artists) {
|
private PlanningScheduleVO toScheduleVO(ArtistScheduleDO schedule, List<PlanningArtistVO> artists) {
|
||||||
Map<Long, String> artistNames = artists.stream()
|
Map<Long, String> artistNames = artists.stream()
|
||||||
.collect(Collectors.toMap(PlanningArtistVO::getId, PlanningArtistVO::getName, (a, b) -> a));
|
.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())) {
|
if (schedule != null && !Integer.valueOf(1).equals(schedule.getStatus())) {
|
||||||
return "rest";
|
return "rest";
|
||||||
}
|
}
|
||||||
if (schedule == null || Integer.valueOf(0).equals(artist.getStatus())) {
|
if (schedule == null) {
|
||||||
return "rest";
|
return "rest";
|
||||||
}
|
}
|
||||||
if (hasContinuousFreeWindow(schedule, appointments, MONTH_AVAILABLE_MINUTES)) {
|
if (hasContinuousFreeWindow(schedule, appointments, MONTH_AVAILABLE_MINUTES)) {
|
||||||
|
|||||||
+21
@@ -138,6 +138,26 @@ class AppointmentCapacityServiceImplTest {
|
|||||||
verify(reservationMapper).insert(any(AppointmentReservationDO.class));
|
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
|
@Test
|
||||||
void reserveRejectsWeekendByRuleWhenDailyScheduleMissing() {
|
void reserveRejectsWeekendByRuleWhenDailyScheduleMissing() {
|
||||||
LocalDateTime start = LocalDateTime.of(2026, 7, 4, 9, 0);
|
LocalDateTime start = LocalDateTime.of(2026, 7, 4, 9, 0);
|
||||||
@@ -228,6 +248,7 @@ class AppointmentCapacityServiceImplTest {
|
|||||||
schedule.setEndTime(LocalTime.of(20, 0));
|
schedule.setEndTime(LocalTime.of(20, 0));
|
||||||
schedule.setCapacity(capacity);
|
schedule.setCapacity(capacity);
|
||||||
schedule.setStatus(1);
|
schedule.setStatus(1);
|
||||||
|
schedule.setRemark("手动排班");
|
||||||
schedule.setIsDelete(0);
|
schedule.setIsDelete(0);
|
||||||
return schedule;
|
return schedule;
|
||||||
}
|
}
|
||||||
|
|||||||
+65
@@ -320,6 +320,71 @@ class PlanningServiceImplTest {
|
|||||||
.containsExactly("20:free");
|
.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) {
|
private UserDO user(Integer type, Long shopId) {
|
||||||
UserDO user = new UserDO();
|
UserDO user = new UserDO();
|
||||||
user.setId(10L + type);
|
user.setId(10L + type);
|
||||||
|
|||||||
Reference in New Issue
Block a user