修复手工预约作品日历空指针

This commit is contained in:
2026-07-23 10:12:30 +08:00
parent 3c6261f180
commit 0a4db094b0
2 changed files with 52 additions and 7 deletions
@@ -831,13 +831,13 @@ public class PlanningServiceImpl implements PlanningService {
List<PlanningAppointmentVO> result = new ArrayList<>();
Set<Long> reservationItemIds = new HashSet<>();
for (AppointmentReservationDO reservation : safeList(reservations)) {
OrderItemDO item = itemMap.get(reservation.getOrderItemId());
OrderDO order = orderMap.get(reservation.getOrderId());
OrderItemDO item = getByNullableId(itemMap, reservation.getOrderItemId());
OrderDO order = getByNullableId(orderMap, reservation.getOrderId());
if (!isVisibleOrder(order, shopId)) {
continue;
}
ProductDO product = item == null ? null : productMap.get(item.getProductId());
UserDO customer = customerMap.get(order.getUserId());
ProductDO product = item == null ? null : getByNullableId(productMap, item.getProductId());
UserDO customer = getByNullableId(customerMap, order.getUserId());
result.add(toAppointmentVO(reservation, item, order, product, customer, artistMap));
if (reservation.getOrderItemId() != null) {
reservationItemIds.add(reservation.getOrderItemId());
@@ -847,12 +847,12 @@ public class PlanningServiceImpl implements PlanningService {
if (item.getId() != null && reservationItemIds.contains(item.getId())) {
continue;
}
OrderDO order = orderMap.get(item.getOrderId());
OrderDO order = getByNullableId(orderMap, item.getOrderId());
if (!isVisibleOrder(order, shopId)) {
continue;
}
ProductDO product = productMap.get(item.getProductId());
UserDO customer = customerMap.get(order.getUserId());
ProductDO product = getByNullableId(productMap, item.getProductId());
UserDO customer = getByNullableId(customerMap, order.getUserId());
result.add(toAppointmentVO(null, item, order, product, customer, artistMap));
}
result.sort(Comparator.comparing(PlanningAppointmentVO::getStartTime, Comparator.nullsLast(String::compareTo))
@@ -1415,6 +1415,10 @@ public class PlanningServiceImpl implements PlanningService {
.collect(Collectors.toMap(UserDO::getId, Function.identity(), (a, b) -> a));
}
private <T> T getByNullableId(Map<Long, T> source, Long id) {
return id == null ? null : source.get(id);
}
private record AppointmentTimeSegment(LocalDate workDate, LocalTime startTime, LocalTime endTime) {
}
@@ -753,6 +753,47 @@ class PlanningServiceImplTest {
assertThat(calendar.getAppointments().get(0).getCustomerName()).isEqualTo("预约王女士");
}
@Test
void calendarDisplaysManualProductAppointmentWithoutProductId() {
UserDO manager = user(2, 8L);
UserDO artist = user(3, 8L);
artist.setId(20L);
artist.setNickname("小王");
LocalDate date = LocalDate.of(2026, 7, 23);
ShopDO shop = new ShopDO();
shop.setBusinessHours("09:00-18:00");
ArtistScheduleDO schedule = schedule(20L, date, LocalTime.of(9, 0), LocalTime.of(18, 0));
AppointmentReservationDO reservation = reservation(20L, 200L, 300L, date.atTime(10, 0), date.atTime(11, 0));
reservation.setProductTitle(null);
OrderDO order = order(200L, 8L, 30L);
order.setCustomerName("预约王女士");
OrderItemDO item = orderItem(300L, 200L, null, 20L, date.atTime(10, 0));
item.setAppointmentProductTitle("手工猫眼");
UserDO customer = user(0, 8L);
customer.setId(30L);
customer.setNickname("王女士");
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(schedule));
when(artistScheduleRuleMapper.selectList(any())).thenReturn(List.of());
when(appointmentReservationMapper.selectList(any())).thenReturn(List.of(reservation));
when(orderItemMapper.selectList(any())).thenReturn(List.of());
when(orderItemMapper.selectBatchIds(any())).thenReturn(List.of(item));
when(orderMapper.selectBatchIds(any())).thenReturn(List.of(order));
when(userMapper.selectBatchIds(any())).thenReturn(List.of(customer));
var calendar = planningService.getCalendar(manager, date, date, null);
assertThat(calendar.getAppointments()).hasSize(1);
assertThat(calendar.getAppointments().get(0).getProductTitle()).isEqualTo("手工猫眼");
assertThat(calendar.getAppointments().get(0).getCustomerName()).isEqualTo("预约王女士");
org.mockito.Mockito.verify(productMapper, org.mockito.Mockito.never()).selectBatchIds(any());
}
@Test
void calendarUsesShopStatusWhenNoEmployeeScheduleInShopView() {
UserDO manager = user(2, 8L);