优化x
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
package com.baiyue.firstleg.loading.coload;
|
||||
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
import com.baiyue.common.core.api.ApiResponse;
|
||||
import com.baiyue.firstleg.client.OrderCargoClient;
|
||||
import com.baiyue.firstleg.client.PendingReviewOrderClient;
|
||||
import com.baiyue.firstleg.dto.OrderApprovedInboundCommand;
|
||||
import com.baiyue.firstleg.service.InboundOrderCreationService;
|
||||
import com.baiyue.firstleg.loading.coload.persistence.ColoadGroupMapper;
|
||||
import com.baiyue.firstleg.loading.coload.persistence.ColoadPersistenceRows.GroupRow;
|
||||
import com.baiyue.firstleg.loading.coload.persistence.ColoadPersistenceRows.CommandRow;
|
||||
@@ -12,6 +17,7 @@ import com.baiyue.firstleg.loading.coload.persistence.ColoadPersistenceRows.Orde
|
||||
import com.baiyue.firstleg.loading.coload.service.ColoadGroupService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
@@ -35,9 +41,19 @@ import static org.mockito.Mockito.when;
|
||||
class ColoadGroupServiceTest {
|
||||
@MockBean
|
||||
private ColoadGroupMapper mapper;
|
||||
@MockBean private PendingReviewOrderClient pendingReviewOrders;
|
||||
@MockBean private OrderCargoClient orderCargoClient;
|
||||
@MockBean private InboundOrderCreationService inboundOrderCreationService;
|
||||
@Resource
|
||||
private ColoadGroupService service;
|
||||
|
||||
@BeforeEach
|
||||
void allowNoPendingReviewProjectionByDefault() {
|
||||
when(mapper.existingOrderIds(any())).thenAnswer(invocation -> invocation.getArgument(0));
|
||||
when(pendingReviewOrders.batch(anyString(), any(PendingReviewOrderClient.BatchRequest.class)))
|
||||
.thenReturn(ApiResponse.success(List.of()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void readsCrossCustomerTwoMemberGroupByEitherInboundCodeWithoutInternalIdentifiers() {
|
||||
when(mapper.groupsByInboundCode("IN-A")).thenReturn(List.of(lookup(500L, "ACTIVE")));
|
||||
@@ -154,6 +170,31 @@ class ColoadGroupServiceTest {
|
||||
verify(mapper).insertMember(anyLong(), eq(groupId.getValue()), eq(202L), eq(12L), eq(1002L), eq(50));
|
||||
}
|
||||
|
||||
@Test
|
||||
void provisionsSelectedPendingReviewOrderBeforeResolvingColoadCandidates() {
|
||||
PendingReviewOrderClient.Row pending = new PendingReviewOrderClient.Row(
|
||||
11L, "FO-11", "IN-1001", 101L, "客户", 9L, "CH", "美森海卡",
|
||||
30, LocalDateTime.now(), null, "PENDING_REVIEW");
|
||||
OrderApprovedInboundCommand snapshot = new OrderApprovedInboundCommand(
|
||||
101L, 11L, "FO-11", "IN-1001", 101L, "客户", 9L, "义乌仓",
|
||||
null, null, null, "FIRST_LEG", "CH", "美森海卡", null, null,
|
||||
null, null, null, false, "FBA", null, null, null, null, null, null, 30);
|
||||
when(pendingReviewOrders.batch(anyString(), any(PendingReviewOrderClient.BatchRequest.class)))
|
||||
.thenReturn(ApiResponse.success(List.of(pending)));
|
||||
when(mapper.existingOrderIds(List.of(11L, 12L))).thenReturn(List.of(12L));
|
||||
when(orderCargoClient.inboundSnapshot(anyString(), eq(101L), eq(11L)))
|
||||
.thenReturn(ApiResponse.success(snapshot));
|
||||
when(inboundOrderCreationService.prepareFromDraft(snapshot)).thenReturn(1001L);
|
||||
stubSuccessfulCreate("pending-review", List.of(
|
||||
candidate(101L, 11L, 1001L, 30), candidate(202L, 12L, 1002L, 50)), "ACTIVE", null);
|
||||
|
||||
var result = service.create(List.of(11L, 12L), "pending-review", 7L, "operator");
|
||||
|
||||
assertThat(result.status()).isEqualTo("ACTIVE");
|
||||
verify(inboundOrderCreationService).prepareFromDraft(snapshot);
|
||||
verify(pendingReviewOrders).batch(anyString(), eq(new PendingReviewOrderClient.BatchRequest(List.of(11L))));
|
||||
}
|
||||
|
||||
@org.junit.jupiter.params.ParameterizedTest
|
||||
@org.junit.jupiter.params.provider.ValueSource(strings = {
|
||||
"PREPARING", "WAIT_MEASURE", "MEASURING", "MEASURE_PENDING", "MEASURE_REJECTED",
|
||||
|
||||
+12
@@ -49,6 +49,9 @@ class ColoadGroupSqlContractTest {
|
||||
.contains("FROM fl_inbound_order o")
|
||||
.contains("o.order_no orderNo", "o.inbound_code inboundCode")
|
||||
.contains("o.warehouse_name warehouseName", "o.channel_name channelName")
|
||||
.contains("activeAllocationPlanCount", "activeAllocationPlanId", "activeAllocatedPackageCount")
|
||||
.contains("COUNT(DISTINCT item.loading_plan_id)", "MIN(item.loading_plan_id)")
|
||||
.contains("COALESCE(SUM(item.package_count),0)")
|
||||
.contains("FROM fl_loading_plan_item item")
|
||||
.contains("item.deleted=0")
|
||||
.contains("member.active_flag=1")
|
||||
@@ -63,6 +66,15 @@ class ColoadGroupSqlContractTest {
|
||||
.doesNotContain("destination_code");
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapperDetectsExistingFirstlegProjectionsBeforeCallingThePendingReviewOwner() throws Exception {
|
||||
Method method = ColoadGroupMapper.class.getDeclaredMethod("existingOrderIds", java.util.List.class);
|
||||
String sql = String.join(" ", method.getAnnotation(Select.class).value());
|
||||
assertThat(sql).contains("SELECT DISTINCT order_id FROM fl_inbound_order")
|
||||
.contains("deleted=0", "order_id IN")
|
||||
.doesNotContain("FOR UPDATE");
|
||||
}
|
||||
|
||||
@Test
|
||||
void inboundCodeReadKeepsConsumedGroupsAndAllFrozenEffectiveFragments() throws Exception {
|
||||
Method lookup = ColoadGroupMapper.class.getDeclaredMethod("groupsByInboundCode", String.class);
|
||||
|
||||
Reference in New Issue
Block a user