fix(firstleg): align measurement package validation
This commit is contained in:
@@ -264,7 +264,8 @@ public class InboundMeasurementService {
|
||||
"即使只有一箱,也必须上传并确认至少一张称重图片后再提交测量审核");
|
||||
}
|
||||
|
||||
requireConfirmedPackageTotal(inbound, items);
|
||||
int latestDeclaredPackageCount = loadLatestDeclaration(inbound).snapshot().totalPackageCount();
|
||||
requireConfirmedPackageTotal(latestDeclaredPackageCount, items);
|
||||
measurement.setStatus(STATUS_SUBMITTED);
|
||||
if (!repository.updateMeasurement(measurement)) {
|
||||
throw concurrentModification();
|
||||
@@ -275,6 +276,9 @@ public class InboundMeasurementService {
|
||||
inbound.setMeasureCompletedAt(LocalDateTime.now());
|
||||
inbound.setActualGrossWeightKg(confirmedTotals.grossWeightKg());
|
||||
inbound.setActualNetWeightKg(confirmedTotals.netWeightKg());
|
||||
// Once the warehouse confirms every carton, downstream split/loading must use the
|
||||
// same package total that was just validated against the live Order declaration.
|
||||
inbound.setTotalPackageCount(latestDeclaredPackageCount);
|
||||
if ("ONE_CLICK_DROPSHIP".equals(inbound.getFulfillmentType())) {
|
||||
if (inbound.getPalletCount() == null || inbound.getPalletCount() < 1) {
|
||||
throw new BizException(ResultCode.VALIDATION_FAILED, "请先录入预计托数并保存,再提交测量审核");
|
||||
@@ -566,7 +570,7 @@ public class InboundMeasurementService {
|
||||
LatestDeclaration latestDeclaration) {
|
||||
InboundMeasurementResponses.DeclarationSnapshot declaration = latestDeclaration.snapshot();
|
||||
return new InboundMeasurementResponses.Detail(
|
||||
inbound.getId(), inbound.getInboundCode(), inbound.getCompanyName(), inbound.getChannelCode(),
|
||||
inbound.getId(), inbound.getInboundCode(), customerDisplayName(inbound), inbound.getChannelCode(),
|
||||
inbound.getChannelName(), inbound.getFulfillmentType(), inbound.getPalletCount(),
|
||||
inbound.getProcessStatus(), inbound.getMeasureReviewStatus(),
|
||||
RECOMMENDED_PALLET_TYPE,
|
||||
@@ -740,23 +744,28 @@ public class InboundMeasurementService {
|
||||
) {
|
||||
}
|
||||
|
||||
private void requireConfirmedPackageTotal(InboundOrderEntity inbound,
|
||||
private void requireConfirmedPackageTotal(int latestDeclaredPackageCount,
|
||||
List<InboundMeasurementItemEntity> items) {
|
||||
if (inbound.getTotalPackageCount() == null || inbound.getTotalPackageCount() < 1) {
|
||||
throw new BizException(ResultCode.VALIDATION_FAILED, "入库单原始总箱数无效,不能提交测量");
|
||||
if (latestDeclaredPackageCount < 1) {
|
||||
throw new BizException(ResultCode.VALIDATION_FAILED, "客户最新申报总箱数无效,不能提交测量");
|
||||
}
|
||||
long confirmed = items.stream()
|
||||
.map(InboundMeasurementItemEntity::getPackageCount)
|
||||
.filter(java.util.Objects::nonNull)
|
||||
.mapToLong(Integer::longValue)
|
||||
.sum();
|
||||
if (confirmed != inbound.getTotalPackageCount()) {
|
||||
if (confirmed != latestDeclaredPackageCount) {
|
||||
throw new BizException(ResultCode.VALIDATION_FAILED,
|
||||
"人工确认箱数合计" + confirmed + "箱,与入库单总箱数"
|
||||
+ inbound.getTotalPackageCount() + "箱不一致");
|
||||
"人工确认箱数合计" + confirmed + "箱,与客户最新申报总箱数"
|
||||
+ latestDeclaredPackageCount + "箱不一致");
|
||||
}
|
||||
}
|
||||
|
||||
private static String customerDisplayName(InboundOrderEntity inbound) {
|
||||
if (StringUtils.hasText(inbound.getCompanyName())) return inbound.getCompanyName();
|
||||
return StringUtils.hasText(inbound.getCustomerName()) ? inbound.getCustomerName() : null;
|
||||
}
|
||||
|
||||
private InboundMeasurementResponses.WeightResult toWeight(InboundWeightResultEntity weight) {
|
||||
return toWeight(weight, weight.getId() == null ? null
|
||||
: palletAllocations.findByWeightResult(weight.getTenantId(), weight.getInboundId(), weight.getId()));
|
||||
|
||||
Reference in New Issue
Block a user