This commit is contained in:
2026-08-25 17:55:27 +08:00
2 changed files with 28 additions and 4 deletions
@@ -41,9 +41,15 @@ public final class InboundMeasurementRequests {
@NotBlank @Size(max = 32) String itemNo,
@NotBlank @Size(max = 64) String boxSpecification,
@NotNull @Positive @Max(1000000) Integer packageCount,
@NotNull @DecimalMin("0.001") @Digits(integer = 9, fraction = 3) BigDecimal lengthCm,
@NotNull @DecimalMin("0.001") @Digits(integer = 9, fraction = 3) BigDecimal widthCm,
@NotNull @DecimalMin("0.001") @Digits(integer = 9, fraction = 3) BigDecimal heightCm,
@NotNull @DecimalMin(value = "0.001", message = "箱规长度必须大于等于 0.001 cm")
@DecimalMax(value = "999999999.999", message = "箱规长度不能超过 999,999,999.999 cm")
@Digits(integer = 9, fraction = 3, message = "箱规长度最多 9 位整数、3 位小数") BigDecimal lengthCm,
@NotNull @DecimalMin(value = "0.001", message = "箱规宽度必须大于等于 0.001 cm")
@DecimalMax(value = "999999999.999", message = "箱规宽度不能超过 999,999,999.999 cm")
@Digits(integer = 9, fraction = 3, message = "箱规宽度最多 9 位整数、3 位小数") BigDecimal widthCm,
@NotNull @DecimalMin(value = "0.001", message = "箱规高度必须大于等于 0.001 cm")
@DecimalMax(value = "999999999.999", message = "箱规高度不能超过 999,999,999.999 cm")
@Digits(integer = 9, fraction = 3, message = "箱规高度最多 9 位整数、3 位小数") BigDecimal heightCm,
@Positive Long intelligentImageFileId,
@Size(max = 500) String overLimitWarning,
@DecimalMin("0.000") @Digits(integer = 9, fraction = 3) BigDecimal outerLengthCm,
@@ -35,6 +35,8 @@ public class MeasurementBatchService {
/** 已接收第三方测量数据,待平台提交审核。 */
static final String STATUS_RECEIVED = "RECEIVED";
static final BigDecimal VOLUME_WEIGHT_FACTOR = new BigDecimal("167");
private static final BigDecimal MAX_RAW_VOLUME_CBM = new BigDecimal("999999999999.999999");
private static final BigDecimal MAX_TOTAL_VOLUME_CBM = new BigDecimal("99999999999999.9999");
@Resource
private InboundMeasurementRepository repository;
@Resource
@@ -140,7 +142,16 @@ public class MeasurementBatchService {
BigDecimal unitVolume = weighted.unitVolumeCbm();
BigDecimal packageCount = BigDecimal.valueOf(source.packageCount());
BigDecimal totalVolumeRaw = unitVolumeRaw.multiply(packageCount).setScale(6, RoundingMode.HALF_UP);
BigDecimal totalVolume = unitVolume.multiply(packageCount).setScale(4, RoundingMode.UNNECESSARY);
BigDecimal totalVolume;
try {
totalVolume = unitVolume.multiply(packageCount).setScale(4, RoundingMode.UNNECESSARY);
} catch (ArithmeticException exception) {
throw measurementRangeExceeded(source);
}
if (totalVolumeRaw.compareTo(MAX_RAW_VOLUME_CBM) > 0
|| totalVolume.compareTo(MAX_TOTAL_VOLUME_CBM) > 0) {
throw measurementRangeExceeded(source);
}
InboundMeasurementItemEntity item = new InboundMeasurementItemEntity();
item.setInboundDetailId(source.inboundDetailId());
@@ -169,6 +180,13 @@ public class MeasurementBatchService {
}).toList();
}
private static BizException measurementRangeExceeded(MeasurementBatchCommand.Item source) {
return new BizException(ResultCode.VALIDATION_FAILED,
"箱规尺寸或箱数超出系统允许范围,明细 " + source.itemNo() + ":"
+ source.lengthCm() + " × " + source.widthCm() + " × " + source.heightCm()
+ " cm,箱数 " + source.packageCount());
}
private void applyTotals(InboundMeasurementEntity measurement,
List<InboundMeasurementItemEntity> items) {
long packages = items.stream().mapToLong(InboundMeasurementItemEntity::getPackageCount).sum();