fix(phase4): enforce customer and pallet versions

This commit is contained in:
2026-08-24 15:14:18 +08:00
parent e773816c98
commit 95b72afdcc
12 changed files with 82 additions and 31 deletions
@@ -23,11 +23,19 @@ public final class PalletRequests {
@NotBlank String status,
Long locationId,
@Size(max = 500) String remark,
@Size(max = 128) String fbaWarehouseCode
@Size(max = 128) String fbaWarehouseCode,
@Min(0) Integer version
) {
public SaveRequest(String palletCode, String palletType, BigDecimal capacityCbm,
BigDecimal unitPrice, String status, Long locationId, String remark) {
this(palletCode, palletType, capacityCbm, unitPrice, status, locationId, remark, null);
this(palletCode, palletType, capacityCbm, unitPrice, status, locationId, remark, null, null);
}
public SaveRequest(String palletCode, String palletType, BigDecimal capacityCbm,
BigDecimal unitPrice, String status, Long locationId, String remark,
String fbaWarehouseCode) {
this(palletCode, palletType, capacityCbm, unitPrice, status, locationId, remark,
fbaWarehouseCode, null);
}
public SaveRequest {
@@ -124,8 +124,8 @@ public class WarehouseResourceRepository {
pallets.insert(entity);
}
public void updatePallet(WarehousePalletEntity entity) {
pallets.updateById(entity);
public int updatePallet(WarehousePalletEntity entity) {
return pallets.updateById(entity);
}
public WarehousePalletEntity findPallet(long customerId, long warehouseId, long id) {
@@ -152,6 +152,9 @@ public class WarehouseResourceService {
@Transactional
public void updatePallet(long customerId, long warehouseId, long id, PalletRequests.SaveRequest request) {
WarehousePalletEntity existing = requirePallet(customerId, warehouseId, id);
if (request.version() == null || !request.version().equals(existing.getVersion())) {
throw new BizException(ResultCode.CONFLICT, "托盘版本已变化,请刷新后重试");
}
if ("SCRAPPED".equals(existing.getStatus()) && !"SCRAPPED".equals(request.status())) {
throw new BizException(ResultCode.CONFLICT, "SCRAPPED pallet cannot be reused");
}
@@ -161,7 +164,10 @@ public class WarehouseResourceService {
validatePallet(request, palletCode, locationId, customerId, warehouseId, id);
WarehousePalletEntity entity = palletEntity(customerId, warehouseId, request, palletCode, locationId);
entity.setId(existing.getId());
repository.updatePallet(entity);
entity.setVersion(request.version());
if (repository.updatePallet(entity) != 1) {
throw new BizException(ResultCode.CONFLICT, "托盘版本已变化,请刷新后重试");
}
}
public WarehousePalletEntity pallet(long customerId, long warehouseId, long id) {