fix: restore transfer creation replay before carton validation
This commit is contained in:
+10
-10
@@ -214,6 +214,16 @@ public class WarehouseTransferService {
|
||||
@Transactional
|
||||
public WarehouseTransferResponses.Detail create(String customerId, String operatorId,
|
||||
WarehouseTransferRequests.Create request) {
|
||||
// 已成功创建的命令先恢复原业务身份;不能用后来冻结或换标后的箱状态否定重放。
|
||||
String key = request.idempotencyKey().trim();
|
||||
String requestHash = hash(request);
|
||||
WarehouseTransferOrder replay = transfers.findKey(customerId, key);
|
||||
if (replay != null) {
|
||||
if (!requestHash.equals(replay.getRequestHash())) {
|
||||
throw conflict("Idempotency key was reused with different warehouse transfer data");
|
||||
}
|
||||
return detail(customerId, replay.getTransferNo());
|
||||
}
|
||||
if (!request.isInboundModeValid()) throw badRequest("外来货物须填写入仓信息,库存转运须选择FBA仓或私人仓");
|
||||
int itemPackages = request.items().stream().mapToInt(WarehouseTransferRequests.Item::packageCount).sum();
|
||||
if (itemPackages != request.packageCount()) {
|
||||
@@ -224,16 +234,6 @@ public class WarehouseTransferService {
|
||||
validateDestination(request.destinationType(), request.destinationWarehouseCode(), request.fbaWarehouseCode(),
|
||||
request.privateDestinationAddress(), request.privateDestinationPostalCode(),
|
||||
request.privateDestinationContactName(), request.privateDestinationContactPhone());
|
||||
String key = request.idempotencyKey().trim();
|
||||
String requestHash = hash(request);
|
||||
WarehouseTransferOrder replay = transfers.findKey(customerId, key);
|
||||
if (replay != null) {
|
||||
if (!requestHash.equals(replay.getRequestHash())) {
|
||||
throw conflict("Idempotency key was reused with different warehouse transfer data");
|
||||
}
|
||||
return detail(customerId, replay.getTransferNo());
|
||||
}
|
||||
|
||||
var customer = customerDirectory.find(customerId);
|
||||
if (customer == null || !customerId.equals(customer.id()) || !StringUtils.hasText(customer.name())) {
|
||||
throw new ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE, "客户名称暂不可用,请稍后重试");
|
||||
|
||||
Reference in New Issue
Block a user