完善财务全量验收链路
This commit is contained in:
+9
-2
@@ -14,10 +14,17 @@ public class FinanceCostSnapshotService {
|
||||
public FinanceCostSnapshotService(SmartLoadingRepository repository) { this.repository = repository; }
|
||||
|
||||
public ContainerSnapshot container(long customerId, long loadingPlanId) {
|
||||
if (customerId <= 0 || loadingPlanId <= 0 || repository.plan(loadingPlanId) == null) {
|
||||
if (customerId <= 0 || loadingPlanId <= 0) {
|
||||
throw new BizException(ResultCode.NOT_FOUND, "柜次不存在");
|
||||
}
|
||||
List<OrderVolume> orders = repository.items(loadingPlanId).stream()
|
||||
// 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()
|
||||
.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)
|
||||
|
||||
+15
@@ -57,6 +57,21 @@ class FinanceCostSnapshotServiceTest {
|
||||
.hasMessageContaining("柜次不存在");
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolvesLegacyContainerBookingIdToLoadingPlan() {
|
||||
var plan = new LoadingPlanEntity();
|
||||
plan.setId(88L);
|
||||
plan.setContainerBookingId(99L);
|
||||
when(repository.plan(99L)).thenReturn(null);
|
||||
when(repository.planByBooking(99L)).thenReturn(plan);
|
||||
when(repository.items(88L)).thenReturn(List.of(item(10L, 101L, 1001L, "1.25")));
|
||||
|
||||
var snapshot = service.container(10L, 99L);
|
||||
|
||||
assertThat(snapshot.containerId()).isEqualTo(99L);
|
||||
assertThat(snapshot.orders()).hasSize(1);
|
||||
}
|
||||
|
||||
private LoadingPlanItemEntity item(long customerId, long orderId, long inboundId, String volume) {
|
||||
var item = new LoadingPlanItemEntity();
|
||||
item.setAccountId(customerId);
|
||||
|
||||
Reference in New Issue
Block a user