fix: limit dispatch vehicles to 15 and 30 pallets
This commit is contained in:
@@ -23,7 +23,7 @@ public final class DeliveryRequests {
|
|||||||
@NotBlank @Size(max = 64) String pickupMethod,
|
@NotBlank @Size(max = 64) String pickupMethod,
|
||||||
@NotBlank @Size(max = 64) String loadingType,
|
@NotBlank @Size(max = 64) String loadingType,
|
||||||
@Size(max = 64) String vehicleType,
|
@Size(max = 64) String vehicleType,
|
||||||
@Size(max = 64) String vehicleSize,
|
@jakarta.validation.constraints.Pattern(regexp = "15托|30托") String vehicleSize,
|
||||||
@Size(max = 128) String driverName,
|
@Size(max = 128) String driverName,
|
||||||
@Size(max = 64) String driverPhone,
|
@Size(max = 64) String driverPhone,
|
||||||
@Size(max = 64) String vehiclePlate,
|
@Size(max = 64) String vehiclePlate,
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public final class DispatchRequests {
|
|||||||
public DraftPallet(Long planPalletId, String draftToken) { this(planPalletId, draftToken, null); }
|
public DraftPallet(Long planPalletId, String draftToken) { this(planPalletId, draftToken, null); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public record DraftContainer(@NotBlank @Size(max = 64) String draftToken, @NotNull @Min(1) @Max(500) Integer capacity) {}
|
public record DraftContainer(@NotBlank @Size(max = 64) String draftToken, @NotNull Integer capacity) {}
|
||||||
|
|
||||||
public record DraftRelease(@NotBlank @Size(max = 64) String draftToken) {
|
public record DraftRelease(@NotBlank @Size(max = 64) String draftToken) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,6 +123,9 @@ public class DispatchService {
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public DispatchContainerResponse createDraftContainer(String operatorId, DispatchRequests.DraftContainer request) {
|
public DispatchContainerResponse createDraftContainer(String operatorId, DispatchRequests.DraftContainer request) {
|
||||||
|
if (!Set.of(15, 30).contains(request.capacity())) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.CONFLICT, "车辆大小仅支持15托或30托");
|
||||||
|
}
|
||||||
DispatchDraft draft = ensureDraft(operatorId, request.draftToken());
|
DispatchDraft draft = ensureDraft(operatorId, request.draftToken());
|
||||||
int next = draftContainers.findByToken(request.draftToken()).stream().mapToInt(DispatchDraftContainer::getSequenceNo).max().orElse(0) + 1;
|
int next = draftContainers.findByToken(request.draftToken()).stream().mapToInt(DispatchDraftContainer::getSequenceNo).max().orElse(0) + 1;
|
||||||
DispatchDraftContainer c = new DispatchDraftContainer(); c.setId(IdWorker.getId()); c.setDraftId(draft.getId()); c.setDraftToken(request.draftToken()); c.setSequenceNo(next); c.setCapacity(request.capacity()); c.setCreatedAt(LocalDateTime.now()); c.setUpdatedAt(LocalDateTime.now()); draftContainers.insert(c);
|
DispatchDraftContainer c = new DispatchDraftContainer(); c.setId(IdWorker.getId()); c.setDraftId(draft.getId()); c.setDraftToken(request.draftToken()); c.setSequenceNo(next); c.setCapacity(request.capacity()); c.setCreatedAt(LocalDateTime.now()); c.setUpdatedAt(LocalDateTime.now()); draftContainers.insert(c);
|
||||||
|
|||||||
@@ -2118,7 +2118,7 @@ components:
|
|||||||
required: [draftToken, capacity]
|
required: [draftToken, capacity]
|
||||||
properties:
|
properties:
|
||||||
draftToken: { type: string, minLength: 1, maxLength: 64 }
|
draftToken: { type: string, minLength: 1, maxLength: 64 }
|
||||||
capacity: { type: integer, minimum: 1, maximum: 500 }
|
capacity: { type: integer, enum: [15, 30] }
|
||||||
SmartDispatchDraft:
|
SmartDispatchDraft:
|
||||||
type: object
|
type: object
|
||||||
required: [draftToken, containers]
|
required: [draftToken, containers]
|
||||||
@@ -2159,7 +2159,7 @@ components:
|
|||||||
pickupMethod: { type: string, maxLength: 64 }
|
pickupMethod: { type: string, maxLength: 64 }
|
||||||
loadingType: { type: string, maxLength: 64 }
|
loadingType: { type: string, maxLength: 64 }
|
||||||
vehicleType: { type: string, nullable: true, maxLength: 64 }
|
vehicleType: { type: string, nullable: true, maxLength: 64 }
|
||||||
vehicleSize: { type: string, nullable: true, maxLength: 64 }
|
vehicleSize: { type: string, nullable: true, enum: [15托, 30托] }
|
||||||
driverName: { type: string, nullable: true, maxLength: 128 }
|
driverName: { type: string, nullable: true, maxLength: 128 }
|
||||||
driverPhone: { type: string, nullable: true, maxLength: 64 }
|
driverPhone: { type: string, nullable: true, maxLength: 64 }
|
||||||
vehiclePlate: { type: string, nullable: true, maxLength: 64 }
|
vehiclePlate: { type: string, nullable: true, maxLength: 64 }
|
||||||
|
|||||||
+1
@@ -181,6 +181,7 @@ class PlatformDispatchOutboundContractTest {
|
|||||||
assertTrue(yaml.contains("platform:overseas-warehouse:outbound:list"));
|
assertTrue(yaml.contains("platform:overseas-warehouse:outbound:list"));
|
||||||
assertTrue(yaml.contains("platform:overseas-warehouse:outbound:create"));
|
assertTrue(yaml.contains("platform:overseas-warehouse:outbound:create"));
|
||||||
assertTrue(yaml.contains("platform:overseas-warehouse:outbound:cancel"));
|
assertTrue(yaml.contains("platform:overseas-warehouse:outbound:cancel"));
|
||||||
|
assertTrue(yaml.contains("vehicleSize: { type: string, nullable: true, enum: [15托, 30托] }"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertPermission(Method method, String permission) {
|
private static void assertPermission(Method method, String permission) {
|
||||||
|
|||||||
+1
@@ -25,6 +25,7 @@ class SmartDispatchOpenApiContractTest {
|
|||||||
assertTrue(yaml.contains("/api/platform/v1/last-leg/dispatches/drafts/{draftToken}/containers/{containerId}:"));
|
assertTrue(yaml.contains("/api/platform/v1/last-leg/dispatches/drafts/{draftToken}/containers/{containerId}:"));
|
||||||
assertTrue(yaml.contains("draftContainerId:"));
|
assertTrue(yaml.contains("draftContainerId:"));
|
||||||
assertTrue(yaml.contains("SmartDispatchDraftContainer:"));
|
assertTrue(yaml.contains("SmartDispatchDraftContainer:"));
|
||||||
|
assertTrue(yaml.contains("capacity: { type: integer, enum: [15, 30] }"));
|
||||||
assertTrue(yaml.contains("SmartDispatchDraft:"));
|
assertTrue(yaml.contains("SmartDispatchDraft:"));
|
||||||
assertTrue(yaml.contains("platform:overseas-warehouse:inbound-order:list"));
|
assertTrue(yaml.contains("platform:overseas-warehouse:inbound-order:list"));
|
||||||
assertTrue(yaml.contains("platform:overseas-warehouse:inbound-order:smart-dispatch"));
|
assertTrue(yaml.contains("platform:overseas-warehouse:inbound-order:smart-dispatch"));
|
||||||
|
|||||||
+11
@@ -252,6 +252,17 @@ class DispatchServiceTest {
|
|||||||
verify(locks).findActiveByDraftContainer("draft-1", 21L);
|
verify(locks).findActiveByDraftContainer("draft-1", 21L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void draftContainerOnlyAcceptsFifteenOrThirtyPalletVehicles() {
|
||||||
|
ResponseStatusException exception = assertThrows(ResponseStatusException.class,
|
||||||
|
() -> service.createDraftContainer("7", new DispatchRequests.DraftContainer("draft-1", 14)));
|
||||||
|
|
||||||
|
assertEquals(409, exception.getStatusCode().value());
|
||||||
|
assertEquals("车辆大小仅支持15托或30托", exception.getReason());
|
||||||
|
verify(drafts, never()).lockActive(any(), any());
|
||||||
|
verify(draftContainers, never()).insert(any(DispatchDraftContainer.class));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void rejectsPalletAlreadyLockedByAnotherDispatch() {
|
void rejectsPalletAlreadyLockedByAnotherDispatch() {
|
||||||
when(candidates.lockSelected("100", List.of(10L))).thenReturn(List.of(candidate(10L, null, "ONT8")));
|
when(candidates.lockSelected("100", List.of(10L))).thenReturn(List.of(candidate(10L, null, "ONT8")));
|
||||||
|
|||||||
Reference in New Issue
Block a user