feat(fleet): add internal capacity pool and warehouse fulfillment bridge
This commit is contained in:
+3
@@ -18,6 +18,7 @@ import java.util.*;
|
||||
|
||||
@Component
|
||||
public class FleetIncomingAdapter implements FleetBookingIncomingGateway {
|
||||
@jakarta.annotation.Resource private com.baiyue.lastleg.fleet.business.FleetPoolOrderBridge fleetPool;
|
||||
private final WarehouseTransferService service;
|
||||
private final WarehouseTransferOrderMapper orders;
|
||||
private final ObjectMapper json;
|
||||
@@ -36,6 +37,8 @@ public class FleetIncomingAdapter implements FleetBookingIncomingGateway {
|
||||
List.of(new WarehouseTransferRequests.Item(null,input.cargo().cargoName(),input.cargo().packageCount(),null)),null);
|
||||
var created=service.createAndSubmit(input.customerId(),operator,request);
|
||||
var approved=service.review(input.customerId(),created.transferNo(),operator,new WarehouseTransferRequests.Review("APPROVE","外接承运已确认,按实际来货收货"));
|
||||
fleetPool.bindIncoming(input.bookingNo(),input.customerId(),approved.transferNo(),approved.lastlegOrderId(),
|
||||
approved.operatingWarehouseId(),key,operator);
|
||||
return evidence(approved);
|
||||
}
|
||||
@Override @Transactional(propagation=Propagation.MANDATORY)
|
||||
|
||||
+14
@@ -88,6 +88,8 @@ import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class WarehouseTransferService {
|
||||
@Resource private com.baiyue.lastleg.fleet.business.FleetPoolOrderBridge fleetPool;
|
||||
@Resource private com.baiyue.lastleg.fleet.business.FleetPoolOrderQueries fleetPoolQueries;
|
||||
public static final String ORDER_TYPE = "WAREHOUSE_TRANSFER";
|
||||
public static final String DRAFT = "DRAFT";
|
||||
public static final String PENDING_REVIEW = "PENDING_REVIEW";
|
||||
@@ -273,6 +275,7 @@ public class WarehouseTransferService {
|
||||
WarehouseTransferRequests.Create request) {
|
||||
WarehouseTransferOrder transfer = transfers.lockNo(customerId, transferNo);
|
||||
if (transfer == null) throw notFound("Warehouse transfer order not found");
|
||||
fleetPoolQueries.requireIndependentIncoming(customerId, transferNo);
|
||||
if (!DRAFT.equals(transfer.getStatus())) {
|
||||
throw conflict("Only a draft warehouse transfer order can be edited");
|
||||
}
|
||||
@@ -642,6 +645,7 @@ public class WarehouseTransferService {
|
||||
}
|
||||
WarehouseTransferOrder transfer = transfers.lockNo(customerId, transferNo);
|
||||
if (transfer == null) throw notFound("Warehouse transfer order not found");
|
||||
if (Set.of("REJECT", REJECTED).contains(decision)) fleetPoolQueries.requireIndependentIncoming(customerId, transferNo);
|
||||
if (!PENDING_REVIEW.equals(transfer.getStatus())) {
|
||||
if (next.equals(transfer.getStatus()) || APPROVED.equals(next)
|
||||
&& Set.of(WAIT_PDA_RECEIVING, WAIT_CUSTOMER_CONFIRMATION, READY_FOR_DISPATCH,
|
||||
@@ -712,6 +716,7 @@ public class WarehouseTransferService {
|
||||
pallet.setVolumeCbm(request.volumeCbm()); pallet.setGrossWeightKg(request.grossWeightKg());
|
||||
pallet.setDraftIdempotencyKey(request.idempotencyKey()); pallet.setDraftRequestHash(requestHash);
|
||||
pallet.setUpdatedAt(LocalDateTime.now()); transferPallets.insertOrUpdate(pallet);
|
||||
fleetPool.receiving(customerId, transferNo, pdaOperatorId());
|
||||
return detail(customerId, transferNo);
|
||||
}
|
||||
|
||||
@@ -869,6 +874,7 @@ public class WarehouseTransferService {
|
||||
order.setSubOrderStatus("WAREHOUSE_TRANSFER:" + WAIT_CUSTOMER_CONFIRMATION); order.setUpdatedAt(now); orders.updateById(order);
|
||||
insertOrderHistory(customerId, order.getId(), before, order.getCurrentStatus(), transferNo,
|
||||
"PDA receiving measurement and palletization completed", now);
|
||||
fleetPool.receiving(customerId, transferNo, operatorId);
|
||||
return detail(customerId, transferNo);
|
||||
}
|
||||
|
||||
@@ -1037,6 +1043,7 @@ public class WarehouseTransferService {
|
||||
WarehouseTransferRequests.Allocate request) {
|
||||
WarehouseTransferOrder transfer = transfers.lockNo(customerId, transferNo);
|
||||
if (transfer == null) throw notFound("Warehouse transfer order not found");
|
||||
fleetPoolQueries.requireIndependentIncoming(customerId, transferNo);
|
||||
String key = request.idempotencyKey().trim();
|
||||
String requestHash = hash(request);
|
||||
if (key.equals(transfer.getAllocationIdempotencyKey())) {
|
||||
@@ -1146,6 +1153,7 @@ public class WarehouseTransferService {
|
||||
WarehouseTransferRequests.Outbound request) {
|
||||
WarehouseTransferOrder transfer = transfers.lockNo(customerId, transferNo);
|
||||
if (transfer == null) throw notFound("Warehouse transfer order not found");
|
||||
fleetPoolQueries.requireIndependentIncoming(customerId, transferNo);
|
||||
String key = request.idempotencyKey().trim();
|
||||
String requestHash = hash(request);
|
||||
if (Set.of(OUTBOUNDED, PARTIALLY_RECEIVED, RECEIVED).contains(transfer.getStatus())
|
||||
@@ -1927,6 +1935,12 @@ public class WarehouseTransferService {
|
||||
throw new IllegalStateException(exception);
|
||||
}
|
||||
}
|
||||
private static String pdaOperatorId() {
|
||||
var auth = org.springframework.security.core.context.SecurityContextHolder.getContext().getAuthentication();
|
||||
if (auth != null && auth.getPrincipal() instanceof com.baiyue.common.security.AuthenticatedUser user)
|
||||
return user.userId() == null ? user.username() : user.userId().toString();
|
||||
return auth == null ? null : auth.getName();
|
||||
}
|
||||
private static String trim(String value) { return StringUtils.hasText(value) ? value.trim() : null; }
|
||||
private static String firstText(String first, String second) { return StringUtils.hasText(first) ? first.trim() : trim(second); }
|
||||
private static long packages(Long value) { return value == null ? 0L : value; }
|
||||
|
||||
Reference in New Issue
Block a user