fix(firstleg): avoid phase-three reads in phase-two queries

This commit is contained in:
2026-08-08 12:25:00 +08:00
parent d30e975eed
commit 44bae99999
2 changed files with 55 additions and 7 deletions
@@ -1,8 +1,22 @@
package com.baiyue.firstleg.service;
import com.baiyue.common.core.exception.BizException;
import com.baiyue.firstleg.dto.InboundOrderDetail;
import com.baiyue.firstleg.dto.UnifiedInboundDetail;
import com.baiyue.firstleg.dto.UnifiedInboundQuery;
import com.baiyue.firstleg.entity.InboundOrderEntity;
import com.baiyue.firstleg.repository.InboundOrderRepository;
import com.baiyue.firstleg.repository.UnifiedInboundReadRepository;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.test.util.ReflectionTestUtils;
import java.util.List;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -65,6 +79,30 @@ class UnifiedInboundQueryServiceTest {
assertThat(UnifiedInboundQueryService.requiresPhaseThreeSummary("DELIVERED")).isTrue();
}
@ParameterizedTest
@ValueSource(strings = {"WAIT_MEASURE", "INBOUNDED", "WAIT_SPLIT"})
void phaseTwoDetailDoesNotQueryPhaseThreeTables(String processStatus) {
InboundOrderRepository inbounds = mock(InboundOrderRepository.class);
UnifiedInboundReadRepository operations = mock(UnifiedInboundReadRepository.class);
UnifiedInboundQueryService service = new UnifiedInboundQueryService();
ReflectionTestUtils.setField(service, "inbounds", inbounds);
ReflectionTestUtils.setField(service, "operations", operations);
InboundOrderEntity inbound = new InboundOrderEntity();
inbound.setId(88L);
inbound.setOrderId(99L);
inbound.setTenantId(10001L);
inbound.setProcessStatus(processStatus);
InboundOrderDetail detail = new InboundOrderDetail(null, null, null, null, null, List.of());
when(inbounds.findByOrderId(10001L, 99L)).thenReturn(inbound);
when(inbounds.detail(10001L, inbound)).thenReturn(detail);
UnifiedInboundDetail result = service.detail(10001L, 99L);
assertThat(result).isNotNull();
verifyNoInteractions(operations);
}
@Test
void rejectsUnknownReviewStatusBeforeRepositoryQuery() {
UnifiedInboundQuery query = new UnifiedInboundQuery(