fix(lastleg): align receiving warehouse checks
This commit is contained in:
+25
-8
@@ -163,18 +163,19 @@ public class ReceivingContainerService {
|
||||
String activeOperatorKey = activeOperatorKey(operatorKey);
|
||||
ReceivingContainerSession active = sessions.lockActiveByOperator(activeOperatorKey);
|
||||
requireSessionWarehouse(active, overseasWarehouseId);
|
||||
if (active != null) {
|
||||
if (!containerNo.equals(active.getContainerNo())) throw conflict("Finish the current container before selecting another one");
|
||||
WarehouseResourceGateway.WarehouseReference receivingWarehouse =
|
||||
warehouse.requireActiveSharedWarehouse(overseasWarehouseId);
|
||||
ReceivingContainerResponses.Session result = snapshot(active, containerPlans);
|
||||
save(active, "PREPARE", request.idempotencyKey(), command, result); return result;
|
||||
if (active != null && !containerNo.equals(active.getContainerNo())) {
|
||||
throw conflict("Finish the current container before selecting another one");
|
||||
}
|
||||
if (sessions.lockActiveByContainer(activeContainerKey(containerNo)) != null) {
|
||||
if (active == null && sessions.lockActiveByContainer(activeContainerKey(containerNo)) != null) {
|
||||
throw conflict("Container is already signed or prepared by another account");
|
||||
}
|
||||
WarehouseResourceGateway.WarehouseReference receivingWarehouse =
|
||||
warehouse.requireActiveSharedWarehouse(overseasWarehouseId);
|
||||
bindReceivingWarehouse(containerPlans, receivingWarehouse.warehouseId());
|
||||
if (active != null) {
|
||||
ReceivingContainerResponses.Session result = snapshot(active, containerPlans);
|
||||
save(active, "PREPARE", request.idempotencyKey(), command, result); return result;
|
||||
}
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
ReceivingContainerSession session = new ReceivingContainerSession();
|
||||
session.setId(IdWorker.getId()); session.setCustomerId(customerId); session.setContainerNo(containerNo);
|
||||
@@ -890,7 +891,23 @@ public class ReceivingContainerService {
|
||||
if (assigned.size() > 1) {
|
||||
throw conflict("Container plans have inconsistent receiving warehouse assignments");
|
||||
}
|
||||
return assigned.size() == 1 && assigned.contains(overseasWarehouseId);
|
||||
return assigned.isEmpty() || assigned.size() == 1 && assigned.contains(overseasWarehouseId);
|
||||
}
|
||||
|
||||
private void bindReceivingWarehouse(List<InboundPlan> containerPlans, long overseasWarehouseId) {
|
||||
for (InboundPlan plan : containerPlans) {
|
||||
if (plan.getOverseasWarehouseId() != null) {
|
||||
if (!Objects.equals(plan.getOverseasWarehouseId(), overseasWarehouseId)) {
|
||||
throw conflict("当前柜已分配至其他海外接柜仓,无法在本仓操作");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
plan.setOverseasWarehouseId(overseasWarehouseId);
|
||||
plan.setUpdatedAt(LocalDateTime.now());
|
||||
if (plans.updateById(plan) != 1) {
|
||||
throw conflict("Receiving warehouse assignment changed concurrently");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void requireReceivingAvailable(String customerId, String containerNo) {
|
||||
|
||||
Reference in New Issue
Block a user