This commit is contained in:
2026-08-13 20:00:30 +08:00
parent 50251240f4
commit 5bc62a109e
28 changed files with 602 additions and 176 deletions
@@ -30,6 +30,9 @@ public final class InboundMeasurementResponses {
Long measurementId,
String sourceType,
String measurementStatus,
@Schema(description = "入库主单乐观锁版本,用于测量审核、驳回和异常放行", example = "3")
Integer inboundVersion,
@Schema(description = "测量批次乐观锁版本,用于测量草稿和明细维护", example = "4")
Integer version,
String originalDocumentNo,
BigDecimal originalGrossWeightKg,
@@ -17,13 +17,13 @@ public class InternalFinanceCostSnapshotController {
@Value("${baiyue.security.internal-service-token}") private String expectedToken;
public InternalFinanceCostSnapshotController(FinanceCostSnapshotService service) { this.service = service; }
@GetMapping("/customers/{customerId}/containers/{containerId}")
public ApiResponse<FinanceCostSnapshotService.ContainerSnapshot> container(
@GetMapping("/customers/{customerId}/loading-plans/{loadingPlanId}")
public ApiResponse<FinanceCostSnapshotService.ContainerSnapshot> loadingPlan(
@RequestHeader(value="X-Internal-Service-Token", required=false) String token,
@PathVariable long customerId, @PathVariable long containerId) {
@PathVariable long customerId, @PathVariable long loadingPlanId) {
if (token == null || !MessageDigest.isEqual(token.getBytes(StandardCharsets.UTF_8), expectedToken.getBytes(StandardCharsets.UTF_8))) {
throw new BizException(ResultCode.FORBIDDEN, "内部服务令牌无效");
}
return ApiResponse.success(service.container(customerId, containerId));
return ApiResponse.success(service.loadingPlan(customerId, loadingPlanId));
}
}
@@ -13,27 +13,26 @@ public class FinanceCostSnapshotService {
private final SmartLoadingRepository repository;
public FinanceCostSnapshotService(SmartLoadingRepository repository) { this.repository = repository; }
public ContainerSnapshot container(long customerId, long loadingPlanId) {
public ContainerSnapshot loadingPlan(long customerId, long loadingPlanId) {
if (customerId <= 0 || loadingPlanId <= 0) {
throw new BizException(ResultCode.NOT_FOUND, "柜次不存在");
}
// Older Finance deployments called this endpoint with the physical
// container booking ID. Resolve both identities during rollout while
// preserving the caller's ID in the snapshot contract.
var plan = repository.plan(loadingPlanId);
if (plan == null) plan = repository.planByBooking(loadingPlanId);
if (plan == null) throw new BizException(ResultCode.NOT_FOUND, "柜次不存在");
long effectivePlanId = plan.getId() == null || plan.getId() <= 0 ? loadingPlanId : plan.getId();
List<OrderVolume> orders = repository.items(effectivePlanId).stream()
if (plan.getContainerBookingId() == null || plan.getContainerBookingId() <= 0) {
throw new BizException(ResultCode.BAD_REQUEST, "装柜计划未关联柜次");
}
List<OrderVolume> orders = repository.items(loadingPlanId).stream()
.filter(item -> item.getAccountId() != null && item.getAccountId() == customerId)
.filter(item -> item.getOrderId() != null && item.getOrderId() > 0)
.filter(item -> item.getVolumeCbm() != null && item.getVolumeCbm().signum() > 0)
.map(item -> new OrderVolume(item.getOrderId(), item.getInboundId(), item.getVolumeCbm()))
.toList();
if (orders.isEmpty()) throw new BizException(ResultCode.BAD_REQUEST, "柜次没有该客户的有效订单体积");
return new ContainerSnapshot(loadingPlanId, customerId, orders);
return new ContainerSnapshot(loadingPlanId, plan.getContainerBookingId(), customerId, orders);
}
public record ContainerSnapshot(long containerId, long customerId, List<OrderVolume> orders) {}
public record ContainerSnapshot(long loadingPlanId, long containerBookingId, long customerId,
List<OrderVolume> orders) {}
public record OrderVolume(long orderId, Long inboundId, BigDecimal volumeCbm) {}
}
@@ -347,6 +347,7 @@ public class InboundMeasurementService {
review == null ? null : review.getReviewerName(), measurement == null ? null : measurement.getId(),
measurement == null ? null : measurement.getSourceType(),
measurement == null ? null : measurement.getStatus(),
inbound.getVersion(),
measurement == null ? null : measurement.getVersion(),
measurement == null ? null : measurement.getOriginalDocumentNo(),
measurement == null ? null : measurement.getOriginalGrossWeightKg(),