fix(dispatch): persist and reuse the resolved draft group
This commit is contained in:
+12
-3
@@ -207,7 +207,12 @@ public class DispatchService {
|
||||
DispatchDraft draft = ensureDraft(operatorId, request.draftToken());
|
||||
DispatchDraftContainer boundContainer = request.draftContainerId() == null ? null : draftContainers.selectById(request.draftContainerId());
|
||||
if (boundContainer == null && request.draftContainerId() == null) {
|
||||
boundContainer = new DispatchDraftContainer(); boundContainer.setId(IdWorker.getId()); boundContainer.setDraftId(draft.getId()); boundContainer.setDraftToken(request.draftToken()); boundContainer.setSequenceNo(1); boundContainer.setCapacity(500); boundContainer.setCreatedAt(LocalDateTime.now()); boundContainer.setUpdatedAt(LocalDateTime.now()); draftContainers.insert(boundContainer);
|
||||
var existing = draftContainers.findByToken(request.draftToken());
|
||||
if (existing.size() > 1) throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "存在多个装车分组,请明确选择目标分组");
|
||||
if (existing.size() == 1) boundContainer = existing.get(0);
|
||||
else {
|
||||
boundContainer = new DispatchDraftContainer(); boundContainer.setId(IdWorker.getId()); boundContainer.setDraftId(draft.getId()); boundContainer.setDraftToken(request.draftToken()); boundContainer.setSequenceNo(1); boundContainer.setCapacity(500); boundContainer.setCreatedAt(LocalDateTime.now()); boundContainer.setUpdatedAt(LocalDateTime.now()); draftContainers.insert(boundContainer);
|
||||
}
|
||||
}
|
||||
if (boundContainer == null || !request.draftToken().equals(boundContainer.getDraftToken()) || !Objects.equals(boundContainer.getDraftId(), draft.getId())) throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "装车托盘不存在");
|
||||
DispatchPalletCandidate candidate = requireDraftSource(customerId, request);
|
||||
@@ -219,7 +224,11 @@ public class DispatchService {
|
||||
}
|
||||
if (active != null) {
|
||||
if (request.draftToken().equals(active.getDraftToken())
|
||||
&& Objects.equals(trimToNull(operatorId), active.getOperatorId())) return;
|
||||
&& Objects.equals(trimToNull(operatorId), active.getOperatorId())) {
|
||||
if (!Objects.equals(boundContainer.getId(), active.getDraftContainerId()))
|
||||
throw new ResponseStatusException(HttpStatus.CONFLICT, "托盘已锁定到其他装车分组,请先移除后重新选择");
|
||||
return;
|
||||
}
|
||||
throw new ResponseStatusException(HttpStatus.CONFLICT,
|
||||
"Pallet is already locked by another dispatch draft: " + candidate.palletNo());
|
||||
}
|
||||
@@ -235,7 +244,7 @@ public class DispatchService {
|
||||
lock.setReturnReceiptId(candidate.returnReceiptId());
|
||||
lock.setWarehousePalletId(candidate.warehousePalletId());
|
||||
lock.setDraftToken(request.draftToken());
|
||||
lock.setDraftContainerId(request.draftContainerId());
|
||||
lock.setDraftContainerId(boundContainer.getId());
|
||||
lock.setOperatorId(trimToNull(operatorId));
|
||||
lock.setStatus("ACTIVE");
|
||||
lock.setLockedAt(now);
|
||||
|
||||
Reference in New Issue
Block a user