fix: keep location guidance non-blocking

This commit is contained in:
2026-09-04 15:15:12 +08:00
parent e23c5dcb7b
commit 2c21d27f61
6 changed files with 122 additions and 9 deletions
@@ -25,6 +25,8 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import feign.FeignException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.math.BigDecimal;
import java.math.RoundingMode;
@@ -37,6 +39,7 @@ import java.util.Set;
/** 平台端入库测量、OCR 修正、重量确认和提交审核应用服务。 */
@Service
public class InboundMeasurementService {
private static final Logger LOGGER = LoggerFactory.getLogger(InboundMeasurementService.class);
/** 测量批次已提交,等待测量审核。 */
private static final String STATUS_SUBMITTED = "SUBMITTED";
/** OCR 或人工修正的重量已确认,可参与计费。 */
@@ -298,8 +301,7 @@ public class InboundMeasurementService {
request.adjustedWeightValue(), request.adjustedWeightUnit(),
request.adjustmentReason(), operatorId, operatorName);
} else if (WEIGHT_CONFIRMED.equals(weight.getRecognitionStatus())) {
locationOccupation.ensureForConfirmedWeight(
tenantId, inboundId, operatorId, weight.getId(), weight.getVersion());
ensureLocationWithoutBlocking(tenantId, inboundId, operatorId, weight.getId(), weight.getVersion());
return toWeight(weight);
}
BigDecimal value = effectiveValue(weight);
@@ -329,11 +331,21 @@ public class InboundMeasurementService {
insertRevision(weight, confirmedVersion, "CONFIRM", value, unit, value, unit,
grossWeightKg, netWeightKg, null, operatorId, operatorName);
recalculateConfirmedWeight(inbound, operatorId);
locationOccupation.ensureForConfirmedWeight(
tenantId, inboundId, operatorId, weight.getId(), confirmedVersion);
ensureLocationWithoutBlocking(tenantId, inboundId, operatorId, weight.getId(), confirmedVersion);
return toWeight(weight);
}
private void ensureLocationWithoutBlocking(long tenantId, long inboundId, long operatorId,
long weightResultId, int weightVersion) {
try {
locationOccupation.ensureForConfirmedWeight(
tenantId, inboundId, operatorId, weightResultId, weightVersion);
} catch (RuntimeException exception) {
LOGGER.warn("称重确认已完成,但库位指引暂未生成,不阻断测量主流程: tenantId={}, inboundId={}, weightResultId={}",
tenantId, inboundId, weightResultId, exception);
}
}
@Transactional
public void deleteWeightResult(long tenantId, long inboundId, long resultId,
int version, long operatorId) {
@@ -94,7 +94,16 @@ public class MeasurementLocationOccupationService {
}
}
public void requireOccupied(long tenantId, long inboundId) {
public void ensureForSubmission(long tenantId, long inboundId, long operatorId) {
var weights = confirmedWeights(tenantId, inboundId);
InboundWeightResultEntity latest = weights.stream()
.max(java.util.Comparator.comparing(InboundWeightResultEntity::getConfirmedAt)
.thenComparing(InboundWeightResultEntity::getId))
.orElseThrow(() -> new BizException(ResultCode.CONFLICT,
"至少需要一张已确认的称重图片才能提交测量"));
ensureForConfirmedWeight(tenantId, inboundId, operatorId, latest.getId(),
latest.getVersion() == null ? 0 : latest.getVersion());
InboundOrderEntity order = requireOrder(tenantId, inboundId);
long warehouseId = requireWarehouse(order);
var confirmedWeights = confirmedWeights(tenantId, inboundId);
@@ -6,9 +6,12 @@ import com.baiyue.firstleg.dto.InboundMeasurementRequests;
import com.baiyue.firstleg.dto.InboundMeasurementResponses;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Service
public class MeasurementSubmissionService {
private static final Logger LOGGER = LoggerFactory.getLogger(MeasurementSubmissionService.class);
@Resource
private InboundMeasurementService measurements;
@Resource
@@ -19,7 +22,12 @@ public class MeasurementSubmissionService {
long tenantId, long inboundId, long operatorId,
InboundMeasurementRequests.SubmitRequest request) {
var result = measurements.submit(tenantId, inboundId, operatorId, request);
locations.requireOccupied(tenantId, inboundId);
try {
locations.ensureForSubmission(tenantId, inboundId, operatorId);
} catch (RuntimeException exception) {
LOGGER.warn("测量已提交,但库位指引暂未补齐,不阻断提交审核主流程: tenantId={}, inboundId={}",
tenantId, inboundId, exception);
}
return result;
}
}