fix: fall back to order declared volume
This commit is contained in:
+25
-3
@@ -5,6 +5,7 @@ import jakarta.annotation.Resource;
|
||||
import com.baiyue.common.core.api.ApiResponse;
|
||||
import com.baiyue.common.core.api.ResultCode;
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
import com.baiyue.firstleg.client.OrderCargoClient;
|
||||
import com.baiyue.firstleg.client.WarehousePalletLocationClient;
|
||||
import com.baiyue.firstleg.config.InboundProperties;
|
||||
import com.baiyue.firstleg.entity.InboundOrderEntity;
|
||||
@@ -32,6 +33,8 @@ public class MeasurementLocationOccupationService {
|
||||
@Resource
|
||||
private InboundMeasurementRepository measurements;
|
||||
@Resource
|
||||
private OrderCargoClient orderCargo;
|
||||
@Resource
|
||||
private InboundProperties properties;
|
||||
@Value("${baiyue.security.internal-service-token}")
|
||||
private String internalToken;
|
||||
@@ -167,15 +170,34 @@ public class MeasurementLocationOccupationService {
|
||||
}
|
||||
|
||||
private BigDecimal requireVolume(long tenantId, long inboundId, InboundOrderEntity order) {
|
||||
if (order.getActualVolumeCbm() != null && order.getActualVolumeCbm().signum() > 0) {
|
||||
return order.getActualVolumeCbm();
|
||||
}
|
||||
var measurement = measurements.findLatestMeasurement(tenantId, inboundId);
|
||||
if (measurement != null && measurement.getOriginalVolumeCbm() != null
|
||||
&& measurement.getOriginalVolumeCbm().signum() > 0) {
|
||||
return measurement.getOriginalVolumeCbm();
|
||||
}
|
||||
if (order.getActualVolumeCbm() == null || order.getActualVolumeCbm().signum() <= 0) {
|
||||
throw new BizException(ResultCode.CONFLICT, "入库单缺少有效客户申报体积");
|
||||
if (order.getOrderId() == null || order.getOrderId() <= 0) {
|
||||
throw new BizException(ResultCode.CONFLICT, "入库单缺少有效实测或客户申报体积");
|
||||
}
|
||||
return order.getActualVolumeCbm();
|
||||
try {
|
||||
ApiResponse<OrderCargoClient.MeasurementDeclarationSnapshot> response = orderCargo.measurementDeclaration(
|
||||
internalToken, tenantId, order.getOrderId());
|
||||
if (response == null || !response.successful() || response.data() == null) {
|
||||
String message = response == null || !org.springframework.util.StringUtils.hasText(response.message())
|
||||
? "客户订单申报体积查询失败" : response.message();
|
||||
throw new BizException(response == null ? ResultCode.SERVICE_UNAVAILABLE
|
||||
: ResultCode.of(response.code()), message);
|
||||
}
|
||||
BigDecimal declaredVolume = response.data().originalVolumeCbm();
|
||||
if (declaredVolume != null && declaredVolume.signum() > 0) {
|
||||
return declaredVolume;
|
||||
}
|
||||
} catch (FeignException exception) {
|
||||
throw new BizException(ResultCode.SERVICE_UNAVAILABLE, "订单服务暂不可用,无法读取客户申报体积");
|
||||
}
|
||||
throw new BizException(ResultCode.CONFLICT, "入库单缺少有效实测或客户申报体积");
|
||||
}
|
||||
|
||||
private static int requirePackageCount(InboundOrderEntity order) {
|
||||
|
||||
Reference in New Issue
Block a user