功能:支持待分配预约与首次排班引导
This commit is contained in:
+43
-17
@@ -67,6 +67,8 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
private static final int MONTH_AVAILABLE_MINUTES = 90;
|
||||
private static final String RESERVATION_PENDING_QUOTE = "PENDING_QUOTE";
|
||||
private static final String RESERVATION_CONFIRMED = "CONFIRMED";
|
||||
private static final String RESERVATION_UNASSIGNED = "UNASSIGNED";
|
||||
private static final String ASSIGNMENT_ASSIGNED = "ASSIGNED";
|
||||
private static final String PRODUCT_SOURCE_TYPE_MANAGER_APPOINTMENT = "MANAGER_APPOINTMENT";
|
||||
private static final String ENCODED_UNSET_PASSWORD = "$2a$10$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW";
|
||||
private static final List<String> ACTIVE_RESERVATION_STATUS = List.of("LOCKED", RESERVATION_PENDING_QUOTE, RESERVATION_CONFIRMED);
|
||||
@@ -169,7 +171,7 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
Long shopId = requirePlanningShopId(currentUser);
|
||||
requireAppointmentDuration(dto.getDurationMinutes());
|
||||
ProductDO product = resolveAppointmentProduct(dto, shopId);
|
||||
UserDO artist = requireActiveArtist(dto.getArtistId(), shopId);
|
||||
UserDO artist = dto.getArtistId() == null ? null : requireActiveArtist(dto.getArtistId(), shopId);
|
||||
UserDO customer = resolveCustomer(shopId, dto);
|
||||
|
||||
int quantity = dto.getQuantity() == null || dto.getQuantity() <= 0 ? 1 : dto.getQuantity();
|
||||
@@ -204,21 +206,23 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
item.setProductId(product.getId());
|
||||
item.setQuantity(quantity);
|
||||
item.setPrice(unitPrice);
|
||||
item.setArtistId(artist.getId());
|
||||
item.setArtistId(artist == null ? null : artist.getId());
|
||||
item.setAppointmentTime(startTime);
|
||||
item.setIsDelete(0);
|
||||
orderItemMapper.insert(item);
|
||||
|
||||
appointmentCapacityService.reserveConfirmedOrThrow(
|
||||
order.getId(),
|
||||
item.getId(),
|
||||
shopId,
|
||||
artist.getId(),
|
||||
product.getTitle(),
|
||||
startTime,
|
||||
endTime,
|
||||
trimToNull(dto.getClientRequestId())
|
||||
);
|
||||
if (artist != null) {
|
||||
appointmentCapacityService.reserveConfirmedOrThrow(
|
||||
order.getId(),
|
||||
item.getId(),
|
||||
shopId,
|
||||
artist.getId(),
|
||||
product.getTitle(),
|
||||
startTime,
|
||||
endTime,
|
||||
trimToNull(dto.getClientRequestId())
|
||||
);
|
||||
}
|
||||
|
||||
return getAppointment(currentUser, item.getId());
|
||||
}
|
||||
@@ -291,6 +295,9 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
}
|
||||
OrderDO order = requireAccessibleOrder(currentUser, orderId);
|
||||
int targetStatus = dto.getStatus();
|
||||
if (targetStatus != OrderStatus.CANCELLED.getCode() && hasUnassignedOrderItem(orderId)) {
|
||||
throw new RuntimeException("请先分配员工");
|
||||
}
|
||||
if (targetStatus == OrderStatus.PENDING_SERVICE.getCode()) {
|
||||
if (!Integer.valueOf(OrderStatus.PENDING_SERVICE.getCode()).equals(order.getStatus())) {
|
||||
orderMapper.updateStatusIfCurrent(order.getId(), order.getStatus(), OrderStatus.PENDING_SERVICE.getCode());
|
||||
@@ -508,8 +515,10 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
? reservation.getProductTitle()
|
||||
: product == null ? "预约作品" : product.getTitle());
|
||||
vo.setArtistId(artistId);
|
||||
vo.setArtistName(artist == null ? "未分配" : artist.getName());
|
||||
vo.setArtistColor(artist == null ? ARTIST_COLORS.get(0) : artist.getColor());
|
||||
boolean unassigned = artistId == null;
|
||||
vo.setArtistName(unassigned ? "待分配" : artist.getName());
|
||||
vo.setArtistColor(unassigned ? "#D59A52" : artist.getColor());
|
||||
vo.setAssignmentStatus(unassigned ? RESERVATION_UNASSIGNED : ASSIGNMENT_ASSIGNED);
|
||||
vo.setDate(start == null ? null : start.toLocalDate().toString());
|
||||
vo.setStartTime(start == null ? null : DATE_TIME_FORMATTER.format(start));
|
||||
vo.setEndTime(end == null ? null : DATE_TIME_FORMATTER.format(end));
|
||||
@@ -517,7 +526,7 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
vo.setDurationMinutes(start == null || end == null ? durationMinutes : Math.toIntExact(Duration.between(start, end).toMinutes()));
|
||||
vo.setStatus(order == null ? null : order.getStatus());
|
||||
vo.setStatusText(statusText(order == null ? null : order.getStatus()));
|
||||
String occupancyStatus = resolveOccupancyStatus(reservation, order);
|
||||
String occupancyStatus = unassigned ? RESERVATION_UNASSIGNED : resolveOccupancyStatus(reservation, order);
|
||||
vo.setOccupancyStatus(occupancyStatus);
|
||||
vo.setCanEdit(canEditAppointment(order, occupancyStatus));
|
||||
vo.setCanCancel(canCancelAppointment(order, occupancyStatus));
|
||||
@@ -575,12 +584,16 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
artistCounts.add(countVO);
|
||||
}
|
||||
int total = dayAppointments.size();
|
||||
int unassignedCount = Math.toIntExact(dayAppointments.stream()
|
||||
.filter(appointment -> appointment.getArtistId() == null)
|
||||
.count());
|
||||
boolean hasWorkingSchedule = workingArtistCount > 0;
|
||||
boolean allFull = workingArtistCount > 0 && fullWorkingArtistCount == workingArtistCount;
|
||||
|
||||
PlanningDaySummaryVO summary = new PlanningDaySummaryVO();
|
||||
summary.setDate(date);
|
||||
summary.setTotalCount(total);
|
||||
summary.setUnassignedCount(unassignedCount);
|
||||
summary.setArtistCounts(artistCounts);
|
||||
summary.setDayStatus(PlanningCalendarSupport.resolveDayStatus(total, hasWorkingSchedule, allFull));
|
||||
summaries.add(summary);
|
||||
@@ -883,14 +896,18 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
|
||||
private Boolean canEditAppointment(OrderDO order, String occupancyStatus) {
|
||||
return order != null
|
||||
&& (RESERVATION_PENDING_QUOTE.equals(occupancyStatus) || RESERVATION_CONFIRMED.equals(occupancyStatus))
|
||||
&& (RESERVATION_PENDING_QUOTE.equals(occupancyStatus)
|
||||
|| RESERVATION_CONFIRMED.equals(occupancyStatus)
|
||||
|| RESERVATION_UNASSIGNED.equals(occupancyStatus))
|
||||
&& !Integer.valueOf(OrderStatus.COMPLETED.getCode()).equals(order.getStatus())
|
||||
&& !Integer.valueOf(OrderStatus.CANCELLED.getCode()).equals(order.getStatus());
|
||||
}
|
||||
|
||||
private Boolean canCancelAppointment(OrderDO order, String occupancyStatus) {
|
||||
return order != null
|
||||
&& (RESERVATION_PENDING_QUOTE.equals(occupancyStatus) || RESERVATION_CONFIRMED.equals(occupancyStatus))
|
||||
&& (RESERVATION_PENDING_QUOTE.equals(occupancyStatus)
|
||||
|| RESERVATION_CONFIRMED.equals(occupancyStatus)
|
||||
|| RESERVATION_UNASSIGNED.equals(occupancyStatus))
|
||||
&& !Integer.valueOf(OrderStatus.COMPLETED.getCode()).equals(order.getStatus())
|
||||
&& !Integer.valueOf(OrderStatus.CANCELLED.getCode()).equals(order.getStatus());
|
||||
}
|
||||
@@ -905,6 +922,15 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean hasUnassignedOrderItem(Long orderId) {
|
||||
QueryWrapper<OrderItemDO> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("order_id", orderId)
|
||||
.eq("is_delete", 0)
|
||||
.isNull("artist_id")
|
||||
.last("LIMIT 1");
|
||||
return orderItemMapper.selectCount(wrapper) > 0;
|
||||
}
|
||||
|
||||
private <T> List<T> safeList(List<T> list) {
|
||||
return list == null ? List.of() : list;
|
||||
}
|
||||
|
||||
+1
@@ -17,6 +17,7 @@ public class PlanningAppointmentVO {
|
||||
private Long artistId;
|
||||
private String artistName;
|
||||
private String artistColor;
|
||||
private String assignmentStatus;
|
||||
private String date;
|
||||
private String startTime;
|
||||
private String endTime;
|
||||
|
||||
+1
@@ -8,6 +8,7 @@ import java.util.List;
|
||||
public class PlanningDaySummaryVO {
|
||||
private String date;
|
||||
private Integer totalCount;
|
||||
private Integer unassignedCount;
|
||||
private List<PlanningArtistCountVO> artistCounts;
|
||||
private String dayStatus;
|
||||
}
|
||||
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
package com.xiaowang.jacyucloudsalon.core.modules.planning.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.artist.mapper.ArtistScheduleExceptionMapper;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.artist.mapper.ArtistScheduleMapper;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.artist.mapper.NailArtistInfoMapper;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.order.entity.OrderDO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.order.entity.OrderItemDO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.order.mapper.OrderItemMapper;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.order.mapper.OrderMapper;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.order.service.OrderService;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.order.support.OrderStatus;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.planning.dto.PlanningAppointmentStatusDTO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.planning.dto.PlanningAppointmentCreateDTO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.planning.mapper.AppointmentReservationMapper;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.planning.service.AppointmentCapacityService;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.product.mapper.ProductMapper;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.product.entity.ProductDO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.security.support.AdminScopeHelper;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.shop.mapper.ShopMapper;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.shop.entity.ShopDO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.user.entity.UserDO;
|
||||
import com.xiaowang.jacyucloudsalon.core.modules.user.mapper.UserMapper;
|
||||
import com.xiaowang.jacyucloudsalon.core.support.id.TimeOrderedSnowflakeIdGenerator;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class PlanningServiceImplTest {
|
||||
|
||||
@Mock private AdminScopeHelper adminScopeHelper;
|
||||
@Mock private UserMapper userMapper;
|
||||
@Mock private NailArtistInfoMapper nailArtistInfoMapper;
|
||||
@Mock private ArtistScheduleMapper artistScheduleMapper;
|
||||
@Mock private ArtistScheduleExceptionMapper artistScheduleExceptionMapper;
|
||||
@Mock private AppointmentReservationMapper appointmentReservationMapper;
|
||||
@Mock private OrderMapper orderMapper;
|
||||
@Mock private OrderItemMapper orderItemMapper;
|
||||
@Mock private ProductMapper productMapper;
|
||||
@Mock private ShopMapper shopMapper;
|
||||
@Mock private AppointmentCapacityService appointmentCapacityService;
|
||||
@Mock private OrderService orderService;
|
||||
@Mock private TimeOrderedSnowflakeIdGenerator snowflakeIdGenerator;
|
||||
|
||||
private PlanningServiceImpl service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new PlanningServiceImpl(adminScopeHelper, userMapper, nailArtistInfoMapper, artistScheduleMapper,
|
||||
artistScheduleExceptionMapper, appointmentReservationMapper, orderMapper, orderItemMapper,
|
||||
productMapper, shopMapper, appointmentCapacityService, orderService, snowflakeIdGenerator);
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsCompletingUnassignedAppointment() {
|
||||
UserDO operator = new UserDO();
|
||||
OrderDO order = order(11L, OrderStatus.PENDING_SERVICE.getCode());
|
||||
when(orderMapper.selectById(11L)).thenReturn(order);
|
||||
when(orderItemMapper.selectCount(any(Wrapper.class))).thenReturn(1L);
|
||||
PlanningAppointmentStatusDTO dto = new PlanningAppointmentStatusDTO();
|
||||
dto.setStatus(OrderStatus.COMPLETED.getCode());
|
||||
|
||||
RuntimeException error = assertThrows(RuntimeException.class, () -> service.updateStatus(operator, 11L, dto));
|
||||
|
||||
assertEquals("请先分配员工", error.getMessage());
|
||||
verify(orderService, never()).processOrder(11L, OrderStatus.COMPLETED.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void allowsCancellingUnassignedAppointment() {
|
||||
UserDO operator = new UserDO();
|
||||
OrderDO order = order(12L, OrderStatus.PENDING_SERVICE.getCode());
|
||||
when(orderMapper.selectById(12L)).thenReturn(order);
|
||||
PlanningAppointmentStatusDTO dto = new PlanningAppointmentStatusDTO();
|
||||
dto.setStatus(OrderStatus.CANCELLED.getCode());
|
||||
|
||||
service.updateStatus(operator, 12L, dto);
|
||||
|
||||
verify(orderService).processOrder(12L, OrderStatus.CANCELLED.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createsUnassignedAppointmentWithoutReservation() {
|
||||
service = spy(service);
|
||||
UserDO operator = new UserDO();
|
||||
operator.setType(2);
|
||||
UserDO customer = new UserDO();
|
||||
customer.setId(31L);
|
||||
ProductDO product = new ProductDO();
|
||||
product.setId(41L);
|
||||
product.setShopId(21L);
|
||||
product.setTitle("纯色美甲");
|
||||
product.setPrice(java.math.BigDecimal.valueOf(99));
|
||||
product.setIsDelete(0);
|
||||
ShopDO shop = new ShopDO();
|
||||
shop.setId(21L);
|
||||
shop.setBusinessHours("10:00-22:00");
|
||||
when(adminScopeHelper.resolveShopScope(operator, null)).thenReturn(21L);
|
||||
when(productMapper.selectById(41L)).thenReturn(product);
|
||||
when(userMapper.selectById(31L)).thenReturn(customer);
|
||||
when(shopMapper.selectById(21L)).thenReturn(shop);
|
||||
when(snowflakeIdGenerator.nextIdString()).thenReturn("10001");
|
||||
doAnswer(invocation -> {
|
||||
OrderDO value = invocation.getArgument(0);
|
||||
value.setId(51L);
|
||||
return 1;
|
||||
}).when(orderMapper).insert(any(OrderDO.class));
|
||||
doAnswer(invocation -> {
|
||||
OrderItemDO value = invocation.getArgument(0);
|
||||
value.setId(61L);
|
||||
return 1;
|
||||
}).when(orderItemMapper).insert(any(OrderItemDO.class));
|
||||
doReturn(new com.xiaowang.jacyucloudsalon.core.modules.planning.vo.PlanningAppointmentVO())
|
||||
.when(service).getAppointment(operator, 61L);
|
||||
PlanningAppointmentCreateDTO dto = new PlanningAppointmentCreateDTO();
|
||||
dto.setCustomerUserId(31L);
|
||||
dto.setProductId(41L);
|
||||
dto.setAppointmentDate("2026-10-13");
|
||||
dto.setAppointmentTime("14:00");
|
||||
dto.setDurationMinutes(60);
|
||||
|
||||
service.createAppointment(operator, dto);
|
||||
|
||||
ArgumentCaptor<OrderItemDO> itemCaptor = ArgumentCaptor.forClass(OrderItemDO.class);
|
||||
verify(orderItemMapper).insert(itemCaptor.capture());
|
||||
assertEquals(null, itemCaptor.getValue().getArtistId());
|
||||
verify(appointmentCapacityService, never()).reserveConfirmedOrThrow(
|
||||
any(), any(), any(), any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
private OrderDO order(Long id, int status) {
|
||||
OrderDO order = new OrderDO();
|
||||
order.setId(id);
|
||||
order.setShopId(21L);
|
||||
order.setStatus(status);
|
||||
order.setIsDelete(0);
|
||||
return order;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user