This commit is contained in:
2026-09-09 20:53:24 +08:00
parent 4cc3e5372b
commit 6737c4c327
23 changed files with 525 additions and 120 deletions
@@ -788,7 +788,7 @@ class FbaPricingServiceTest {
InboundFeeEntity first = savedFee("CALCULATED");
first.setActualWeightKg(new BigDecimal("90.000")); first.setActualVolumeCbm(new BigDecimal("0.1000"));
first.setMeasurementId(301L); first.setMeasurementSource("OUTER");
InboundFeeEntity second = savedFee("CONFIRMED");
InboundFeeEntity second = savedFee("CALCULATED");
second.setId(502L); second.setInboundId(30002L); second.setActualWeightKg(new BigDecimal("110.000"));
second.setActualVolumeCbm(new BigDecimal("0.1000")); second.setMeasurementId(302L);
second.setMeasurementSource("ACTUAL");
@@ -834,20 +834,61 @@ class FbaPricingServiceTest {
}
@Test
@DisplayName("柜内任一已发送或客户确认费用阻断整组重算")
void rejectsContainerRecalculationWhenAnyFeeIsImmutable() {
@DisplayName("柜内已发送费用保持锁定且不阻断其他未锁定费用重算")
void keepsImmutableContainerFeeAndRecalculatesOnlyUnlockedMembers() {
readyRepository();
InboundPricingEntity inbound = inbound("100", "0.1");
InboundPricingEntity lockedInbound = inbound("100", "0.1");
InboundPricingEntity unlockedInbound = inbound("80", "0.1");
unlockedInbound.setId(30002L); unlockedInbound.setInboundCode("RK-002");
InboundFeeEntity sent = savedFee("SENT");
sent.setActualWeightKg(new BigDecimal("100")); sent.setActualVolumeCbm(new BigDecimal("0.1"));
InboundFeeEntity calculated = savedFee("CALCULATED");
calculated.setId(502L); calculated.setInboundId(30002L);
calculated.setActualWeightKg(new BigDecimal("80")); calculated.setActualVolumeCbm(new BigDecimal("0.1"));
when(repository.containerTierMembersForUpdate(901L, TENANT)).thenReturn(List.of(
memberRow(901L, INBOUND, "100", "0.1"), memberRow(901L, 30002L, "80", "0.1")
));
when(repository.findInbound(TENANT, INBOUND)).thenReturn(lockedInbound);
when(repository.findInbound(TENANT, 30002L)).thenReturn(unlockedInbound);
when(repository.findLatestFeeForUpdate(TENANT, INBOUND)).thenReturn(sent);
when(repository.findLatestFeeForUpdate(TENANT, 30002L)).thenReturn(calculated);
when(repository.nextFeeVersion(TENANT, 30002L)).thenReturn(2);
when(repository.completeIdempotency(any(), eq(901L), eq(NOW))).thenReturn(1);
when(repository.supersedeCurrent(TENANT, 502L, "CALCULATED")).thenReturn(1);
when(repository.markInboundContainerFeeRecalculated(eq(TENANT), eq(30002L), anyString(), anyString(), any()))
.thenReturn(1);
when(priceBookEstimator.estimate(eq(TENANT), any())).thenReturn(regionEstimate("180", "8", "1440"));
when(containerTierAllocator.allocate(any(), eq(new BigDecimal("8")))).thenReturn(
new ContainerTierAmountAllocator.Allocation(new BigDecimal("180"), new BigDecimal("1440"),
Map.of(INBOUND, new BigDecimal("800.00"), 30002L, new BigDecimal("640.00"))));
var result = service.recalculateUnlockedContainerCustomerFees(901L, TENANT, "loading-change-2");
assertThat(result.status()).isEqualTo(FbaPricingService.ContainerFeeRecalculationStatus.RECALCULATED);
assertThat(result.recalculatedCount()).isEqualTo(1);
ArgumentCaptor<InboundFeeEntity> fee = ArgumentCaptor.forClass(InboundFeeEntity.class);
verify(repository).insertFee(fee.capture());
assertThat(fee.getValue().getInboundId()).isEqualTo(30002L);
assertThat(fee.getValue().getSubtotalAmount()).isEqualByComparingTo("640.00");
verify(repository, never()).supersedeCurrent(TENANT, 501L, "SENT");
verify(priceBookEstimator).estimate(eq(TENANT), any());
}
@Test
@DisplayName("柜内费用全部锁定时关系变更无需重算且不报错")
void skipsContainerRecalculationWhenEveryFeeIsImmutable() {
InboundPricingEntity inbound = inbound("100", "0.1");
InboundFeeEntity confirmed = savedFee("CONFIRMED");
when(repository.containerTierMembersForUpdate(901L, TENANT)).thenReturn(List.of(
memberRow(901L, INBOUND, "100", "0.1")
));
when(repository.findInbound(TENANT, INBOUND)).thenReturn(inbound);
when(repository.findLatestFeeForUpdate(TENANT, INBOUND)).thenReturn(sent);
when(repository.findLatestFeeForUpdate(TENANT, INBOUND)).thenReturn(confirmed);
assertThatThrownBy(() -> service.recalculateUnlockedContainerCustomerFees(901L, TENANT, "loading-change-2"))
.isInstanceOf(BizException.class).hasMessageContaining("已发送或客户已确认");
var result = service.recalculateUnlockedContainerCustomerFees(901L, TENANT, "loading-change-locked");
assertThat(result.status()).isEqualTo(FbaPricingService.ContainerFeeRecalculationStatus.NOT_APPLICABLE);
assertThat(result.recalculatedCount()).isZero();
verify(repository, never()).supersedeCurrent(anyLong(), anyLong(), anyString());
verify(repository, never()).insertFee(any());
verify(priceBookEstimator, never()).estimate(anyLong(), any());