优化提交
This commit is contained in:
+32
-8
@@ -45,16 +45,17 @@ public class WarehousePalletTransitionService {
|
||||
if (version != request.expectedVersion()) {
|
||||
throw new BizException(ResultCode.CONFLICT, "托盘版本已变化,请重新扫码");
|
||||
}
|
||||
if (pallet.getLocationId() == null) {
|
||||
throw new BizException(ResultCode.CONFLICT, "托盘没有有效库位,不能执行库内作业");
|
||||
}
|
||||
transition(pallet, status, request.targetLocationId(), version);
|
||||
// 当前海外尾程按托盘作业,不要求业务端选择库位。未传目标库位时保留托盘现有
|
||||
// 技术库位;历史无库位托盘则只流转托盘状态,不能因此阻断 PDA 作业。
|
||||
Long targetLocationId = request.targetLocationId() == null
|
||||
? pallet.getLocationId() : request.targetLocationId();
|
||||
transition(pallet, status, targetLocationId, version);
|
||||
WarehousePalletOperationEntity operation = new WarehousePalletOperationEntity();
|
||||
operation.setId(IdWorker.getId()); operation.setOperationKey(key); operation.setRequestHash(requestHash);
|
||||
operation.setWarehouseId(request.warehouseId()); operation.setPalletId(palletId);
|
||||
operation.setPalletCode(pallet.getPalletCode()); operation.setBeforeStatus(pallet.getStatus());
|
||||
operation.setAfterStatus(status); operation.setBeforeLocationId(pallet.getLocationId());
|
||||
operation.setAfterLocationId(request.targetLocationId()); operation.setBeforeVersion(version);
|
||||
operation.setAfterLocationId(targetLocationId); operation.setBeforeVersion(version);
|
||||
operation.setAfterVersion(version + 1); operation.setOperationStatus("APPLIED");
|
||||
operation.setReason(trim(request.reason())); operation.setCreatedAt(LocalDateTime.now());
|
||||
operation.setUpdatedAt(operation.getCreatedAt()); mapper.insert(operation);
|
||||
@@ -75,7 +76,7 @@ public class WarehousePalletTransitionService {
|
||||
}
|
||||
WarehousePalletEntity pallet = mapper.lockPublicPallet(request.warehouseId(), palletId);
|
||||
if (pallet == null || !operation.getAfterStatus().equals(pallet.getStatus())
|
||||
|| !Long.valueOf(operation.getAfterLocationId()).equals(pallet.getLocationId())) {
|
||||
|| !java.util.Objects.equals(operation.getAfterLocationId(), pallet.getLocationId())) {
|
||||
throw new BizException(ResultCode.CONFLICT, "托盘已被后续作业修改,自动补偿失败");
|
||||
}
|
||||
transition(pallet, operation.getBeforeStatus(), operation.getBeforeLocationId(),
|
||||
@@ -85,14 +86,18 @@ public class WarehousePalletTransitionService {
|
||||
return response(operation, false);
|
||||
}
|
||||
|
||||
private void transition(WarehousePalletEntity pallet, String targetStatus, long targetLocationId,
|
||||
private void transition(WarehousePalletEntity pallet, String targetStatus, Long targetLocationId,
|
||||
int expectedVersion) {
|
||||
int currentVersion = pallet.getVersion() == null ? 0 : pallet.getVersion();
|
||||
if (currentVersion != expectedVersion || !MUTABLE_STATUSES.contains(pallet.getStatus())) {
|
||||
throw new BizException(ResultCode.CONFLICT, "托盘版本或状态已变化,请重新扫码");
|
||||
}
|
||||
long warehouseId = pallet.getWarehouseId();
|
||||
long sourceLocationId = pallet.getLocationId();
|
||||
Long sourceLocationId = pallet.getLocationId();
|
||||
if (sourceLocationId == null || targetLocationId == null) {
|
||||
transitionWithOptionalLocation(pallet, sourceLocationId, targetLocationId, targetStatus, expectedVersion);
|
||||
return;
|
||||
}
|
||||
WarehouseLocationEntity source;
|
||||
WarehouseLocationEntity target;
|
||||
if (sourceLocationId <= targetLocationId) {
|
||||
@@ -116,6 +121,25 @@ public class WarehousePalletTransitionService {
|
||||
}
|
||||
}
|
||||
|
||||
private void transitionWithOptionalLocation(WarehousePalletEntity pallet, Long sourceLocationId,
|
||||
Long targetLocationId, String targetStatus,
|
||||
int expectedVersion) {
|
||||
long warehouseId = pallet.getWarehouseId();
|
||||
if (sourceLocationId != null) {
|
||||
WarehouseLocationEntity source = requireLocation(warehouseId, sourceLocationId);
|
||||
requireLocationMatchesPallet(source, pallet.getStatus());
|
||||
releaseSourceLocation(warehouseId, source, pallet.getStatus());
|
||||
}
|
||||
if (targetLocationId != null) {
|
||||
WarehouseLocationEntity target = requireLocation(warehouseId, targetLocationId);
|
||||
requireAvailableTarget(target, targetStatus);
|
||||
occupyTargetLocation(warehouseId, target, targetStatus);
|
||||
}
|
||||
if (mapper.transition(warehouseId, pallet.getId(), targetStatus, targetLocationId, expectedVersion) != 1) {
|
||||
throw new BizException(ResultCode.CONFLICT, "托盘版本已变化,请重新扫码");
|
||||
}
|
||||
}
|
||||
|
||||
private WarehouseLocationEntity requireLocation(long warehouseId, long locationId) {
|
||||
WarehouseLocationEntity location = mapper.lockPublicLocation(warehouseId, locationId);
|
||||
if (location == null || "INACTIVE".equals(location.getStatus())) {
|
||||
|
||||
+27
-5
@@ -116,6 +116,30 @@ public class WarehouseResourceService {
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public WarehousePalletResolveResponse ensureRelabelPallet(long warehouseId, String businessId) {
|
||||
String normalizedBusinessId = businessId == null ? null : businessId.trim();
|
||||
WarehousePalletBindingEntity existing = repository.findPalletBinding(PUBLIC_RESOURCE_SCOPE, warehouseId,
|
||||
"RELABEL_PDA_NEW", normalizedBusinessId);
|
||||
if (existing != null) return resolvePublicPallet(existing.getPalletId());
|
||||
Long palletId = createPallet(PUBLIC_RESOURCE_SCOPE, warehouseId,
|
||||
new PalletRequests.SaveRequest(null, "STANDARD", null, java.math.BigDecimal.ZERO, "IDLE", null,
|
||||
"PDA换标拆托新托盘"));
|
||||
WarehousePalletBindingEntity binding = new WarehousePalletBindingEntity();
|
||||
binding.setId(IdWorker.getId()); binding.setCustomerId(PUBLIC_RESOURCE_SCOPE); binding.setWarehouseId(warehouseId);
|
||||
binding.setBusinessType("RELABEL_PDA_NEW"); binding.setBusinessId(normalizedBusinessId); binding.setPalletId(palletId);
|
||||
binding.setCreatedAt(java.time.LocalDateTime.now());
|
||||
try {
|
||||
repository.insertPalletBinding(binding);
|
||||
return resolvePublicPallet(palletId);
|
||||
} catch (org.springframework.dao.DuplicateKeyException duplicate) {
|
||||
WarehousePalletBindingEntity winner = repository.findPalletBinding(PUBLIC_RESOURCE_SCOPE, warehouseId,
|
||||
"RELABEL_PDA_NEW", normalizedBusinessId);
|
||||
if (winner == null) throw duplicate;
|
||||
return resolvePublicPallet(winner.getPalletId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the warehouse-scoped virtual location used only as a pallet/inventory reference.
|
||||
* It is deliberately never made IDLE/OCCUPIED by resource locking.
|
||||
@@ -186,7 +210,6 @@ public class WarehouseResourceService {
|
||||
if (matches.isEmpty()) throw new BizException(ResultCode.NOT_FOUND, "托盘码不存在");
|
||||
if (matches.size() != 1) throw new BizException(ResultCode.CONFLICT, "托盘码在多个仓库重复,无法解析");
|
||||
WarehousePalletEntity pallet = matches.get(0);
|
||||
if (pallet.getLocationId() == null) throw new BizException(ResultCode.CONFLICT, "托盘未绑定库位");
|
||||
if ("SCRAPPED".equals(pallet.getStatus())) throw new BizException(ResultCode.CONFLICT, "托盘已报废");
|
||||
return palletReference(pallet);
|
||||
}
|
||||
@@ -194,7 +217,6 @@ public class WarehouseResourceService {
|
||||
public WarehousePalletResolveResponse resolvePublicPallet(long palletId) {
|
||||
WarehousePalletEntity pallet = repository.findPublicPallet(palletId);
|
||||
if (pallet == null) throw new BizException(ResultCode.NOT_FOUND, "托盘不存在");
|
||||
if (pallet.getLocationId() == null) throw new BizException(ResultCode.CONFLICT, "托盘未绑定库位");
|
||||
return palletReference(pallet);
|
||||
}
|
||||
|
||||
@@ -218,8 +240,8 @@ public class WarehouseResourceService {
|
||||
}
|
||||
|
||||
private WarehousePalletResolveResponse palletReference(WarehousePalletEntity pallet) {
|
||||
WarehouseLocationEntity location = repository.findLocation(PUBLIC_RESOURCE_SCOPE,
|
||||
pallet.getWarehouseId(), pallet.getLocationId());
|
||||
WarehouseLocationEntity location = pallet.getLocationId() == null ? null
|
||||
: repository.findLocation(PUBLIC_RESOURCE_SCOPE, pallet.getWarehouseId(), pallet.getLocationId());
|
||||
String blockReason = reservationBlockReason(pallet, location);
|
||||
return new WarehousePalletResolveResponse(pallet.getId(), pallet.getPalletCode(), pallet.getWarehouseId(),
|
||||
pallet.getLocationId(), pallet.getStatus(), pallet.getFbaWarehouseCode(), pallet.getUnitPrice(),
|
||||
@@ -230,7 +252,7 @@ public class WarehouseResourceService {
|
||||
|
||||
private static String reservationBlockReason(WarehousePalletEntity pallet, WarehouseLocationEntity location) {
|
||||
if (!"IDLE".equals(pallet.getStatus())) return "PALLET_NOT_IDLE";
|
||||
if (location == null) return "LOCATION_NOT_FOUND";
|
||||
if (location == null) return pallet.getLocationId() == null ? "LOCATION_NOT_REQUIRED" : "LOCATION_NOT_FOUND";
|
||||
if ("VIRTUAL".equals(location.getLocationType())) {
|
||||
return "ACTIVE".equals(location.getStatus()) ? null : "VIRTUAL_LOCATION_NOT_ACTIVE";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user