fix(firstleg): allow fee confirmation while awaiting palletization

This commit is contained in:
2026-10-26 11:38:51 +08:00
parent 2ae8e7ce94
commit 50687c851d
4 changed files with 147 additions and 16 deletions
@@ -22,6 +22,9 @@ import com.baiyue.firstleg.pricebookquery.application.model.PriceBookQueryRows.R
import jakarta.annotation.Resource;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.ArgumentCaptor;
import org.apache.ibatis.annotations.Select;
import org.springframework.boot.test.mock.mockito.MockBean;
@@ -223,11 +226,13 @@ class FbaPricingServiceTest {
verify(financeOutbox, never()).publishInbound(any(), anyLong(), anyLong(), anyLong(), anyInt(), any());
}
@Test
@DisplayName("待分柜边界确认费用后仍保持主流程状态")
void confirmsAtWaitSplitWithoutRollingBackProcessStatus() {
/** 待组托、待分柜确认费用均不推进物流主流程。 */
@ParameterizedTest
@ValueSource(strings = {"WAIT_PALLETIZE", "WAIT_SPLIT"})
@DisplayName("待组托或待分柜确认费用后仍保持主流程状态")
void confirmsWithoutRollingBackProcessStatus(String processStatus) {
InboundPricingEntity inbound = inbound("10.000", "1.0000");
inbound.setProcessStatus("WAIT_SPLIT");
inbound.setProcessStatus(processStatus);
inbound.setFeeStatus("CALCULATED");
InboundFeeEntity fee = savedFee("CALCULATED");
when(repository.findLatestFee(TENANT, INBOUND)).thenReturn(fee);
@@ -244,7 +249,7 @@ class FbaPricingServiceTest {
FeeSnapshotResponse response = service.confirm(
TENANT, OPERATOR, INBOUND, "confirm-wait-split");
assertThat(response.nextProcessStatus()).isEqualTo("WAIT_SPLIT");
assertThat(response.nextProcessStatus()).isEqualTo(processStatus);
verify(repository).markInboundConfirmed(TENANT, INBOUND);
}
@@ -436,11 +441,13 @@ class FbaPricingServiceTest {
verify(repository, never()).insertFee(any());
}
@Test
/** 待组托发送费用保留主状态,重复请求不重复生成费用事件。 */
@ParameterizedTest
@CsvSource({"FEE_CONFIRMING,WAIT_PALLET", "WAIT_PALLETIZE,WAIT_PALLETIZE"})
@DisplayName("重复发送只返回首次结果且不会重复写Outbox")
void sendIsIdempotentAndDoesNotDuplicateOutbox() {
void sendIsIdempotentAndDoesNotDuplicateOutbox(String processStatus, String expectedStatus) {
InboundPricingEntity inbound = inbound("10", "1");
inbound.setProcessStatus("FEE_CONFIRMING");
inbound.setProcessStatus(processStatus);
inbound.setFeeStatus("CONFIRMED");
InboundFeeEntity confirmed = savedFee("CONFIRMED");
when(repository.findInbound(TENANT, INBOUND)).thenReturn(inbound);
@@ -448,7 +455,7 @@ class FbaPricingServiceTest {
when(repository.findIdempotency(TENANT, OPERATOR, "FEE_SEND", "send-once"))
.thenReturn(null, completed("FEE_SEND", 501L));
when(repository.sendFee(TENANT, 501L, OPERATOR, NOW)).thenReturn(1);
when(repository.markInboundFeeSent(TENANT, INBOUND, "FEE_CONFIRMING")).thenReturn(1);
when(repository.markInboundFeeSent(TENANT, INBOUND, processStatus)).thenReturn(1);
when(repository.completeIdempotency(any(), eq(501L), eq(NOW))).thenReturn(1);
when(repository.findFee(TENANT, 501L)).thenReturn(confirmed);
InboundFeeItemEntity item = new InboundFeeItemEntity(); item.setUnitPrice(new BigDecimal("2.00"));
@@ -459,8 +466,8 @@ class FbaPricingServiceTest {
FeeSnapshotResponse first = service.send(TENANT, OPERATOR, INBOUND, "send-once");
FeeSnapshotResponse repeated = service.send(TENANT, OPERATOR, INBOUND, "send-once");
assertThat(first.nextProcessStatus()).isEqualTo("WAIT_PALLET");
assertThat(repeated.nextProcessStatus()).isEqualTo("WAIT_PALLET");
assertThat(first.nextProcessStatus()).isEqualTo(expectedStatus);
assertThat(repeated.nextProcessStatus()).isEqualTo(expectedStatus);
verify(financeOutbox, times(1)).publishInbound(
eq(FinanceFeeSourceOutboxService.PUBLISHED), eq(TENANT), eq(INBOUND),
eq(501L), eq(1), eq(NOW));