fix(firstleg): keep loading evidence replacement transactional

This commit is contained in:
2026-10-02 19:50:47 +08:00
parent c9a1e93299
commit d0df738bba
3 changed files with 259 additions and 3 deletions
@@ -84,13 +84,14 @@ public class CabinetLoadingEvidenceService {
value.setCreatedBy(operatorId); value.setCreatedByName(operatorName);
value.setUpdatedBy(operatorId); value.setUpdatedByName(operatorName);
try { mapper.insert(value); } catch (DuplicateKeyException exception) {
CabinetLoadingEvidenceEntity concurrent = mapper.byOperation(taskId, key);
if (concurrent != null && Objects.equals(concurrent.getRequestHash(), requestHash)) return view(scope);
// A replacement may already have voided the old row in this transaction.
// Roll it back; a subsequent same-key request can read the committed winner.
throw conflict("装柜证据发生并发变更,请刷新后重试");
}
return view(scope);
}
@Transactional
public EvidenceList upload(long taskId, long warehouseId, String key, int expectedVersion,
String evidenceType, String sealNo, String remark, MultipartFile multipart,
long operatorId, String operatorName) {
@@ -167,7 +168,7 @@ public class CabinetLoadingEvidenceService {
}
private Scope scope(long taskId, long warehouseId, long operatorId, boolean mutable) {
LoadingPickTaskEntity task = loadingPicks.task(taskId);
LoadingPickTaskEntity task = mutable ? loadingPicks.taskForUpdate(taskId) : loadingPicks.task(taskId);
var booking = task == null ? null : loadingPicks.activeBookingByTask(taskId);
if (task == null || task.getContainerBookingId() == null || booking == null
|| !Objects.equals(task.getContainerBookingId(), booking.getId())) {