This commit is contained in:
2026-08-31 10:17:03 +08:00
parent aa583efa4a
commit bf1dc1f209
17 changed files with 354 additions and 142 deletions
@@ -2,8 +2,10 @@ package com.baiyue.firstleg.loading.coload;
import com.baiyue.common.security.AuthenticatedUser;
import com.baiyue.firstleg.loading.coload.controller.PlatformColoadGroupController;
import com.baiyue.firstleg.loading.coload.controller.InternalColoadGroupController;
import com.baiyue.firstleg.loading.coload.model.ColoadGroupModels.CancelRequest;
import com.baiyue.firstleg.loading.coload.model.ColoadGroupModels.CreateRequest;
import com.baiyue.firstleg.loading.coload.model.ColoadGroupModels.InternalBatchQueryRequest;
import com.baiyue.firstleg.loading.coload.port.ColoadGroupAssignmentPort;
import org.junit.jupiter.api.Test;
import org.springframework.security.access.prepost.PreAuthorize;
@@ -51,6 +53,16 @@ class ColoadGroupContractTest {
long.class, String.class)).isNotNull();
}
@Test
void orderAggregationUsesSeparateInternalServiceTokenEndpoint() throws Exception {
RequestMapping base = InternalColoadGroupController.class.getAnnotation(RequestMapping.class);
assertThat(base.value()).containsExactly("/internal/firstleg/v1/coload-groups");
Method method = InternalColoadGroupController.class.getDeclaredMethod(
"batchQuery", String.class, InternalBatchQueryRequest.class);
assertThat(method.getAnnotation(PostMapping.class).value()).containsExactly("/batch-query");
assertThat(method.getAnnotation(PreAuthorize.class)).isNull();
}
private void assertEndpoint(String methodName, String path, Class<?>... parameterTypes) throws Exception {
Method method = PlatformColoadGroupController.class.getDeclaredMethod(methodName, parameterTypes);
if (path.isEmpty()) {
@@ -7,6 +7,7 @@ import com.baiyue.firstleg.loading.coload.persistence.ColoadPersistenceRows.Inbo
import com.baiyue.firstleg.loading.coload.persistence.ColoadPersistenceRows.MemberRow;
import com.baiyue.firstleg.loading.coload.persistence.ColoadPersistenceRows.InboundGroupLookupRow;
import com.baiyue.firstleg.loading.coload.persistence.ColoadPersistenceRows.MemberCodeRow;
import com.baiyue.firstleg.loading.coload.persistence.ColoadPersistenceRows.OrderGroupLinkRow;
import com.baiyue.firstleg.loading.coload.service.ColoadGroupService;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
@@ -83,6 +84,23 @@ class ColoadGroupServiceTest {
.isInstanceOf(BizException.class).hasMessageContaining("多个有效");
}
@Test
void internalOrderAggregationKeepsTechnicalGroupSnapshotOffPlatformContract() {
when(mapper.linksByOrderIds(List.of(11L, 12L))).thenReturn(List.of(
link(11L, 500L), link(12L, 500L)));
when(mapper.group(500L)).thenReturn(group(500L, "LOCKED", 700L, 1));
when(mapper.members(500L)).thenReturn(List.of(
member(101L, 11L, 1001L, 30), member(202L, 12L, 1002L, 50)));
var result = service.queryInternalByOrderIds(List.of(12L, 11L));
assertThat(result).extracting("orderId").containsExactly(11L, 12L);
assertThat(result).allSatisfy(info -> {
assertThat(info.group().groupId()).isEqualTo(500L);
assertThat(info.group().status()).isEqualTo("LOCKED");
});
}
@Test
void createsCrossCustomerGroupAndFreezesAllAvailableFragmentsForEveryOrder() {
when(mapper.lockCandidates(List.of(11L, 12L))).thenReturn(List.of(
@@ -272,6 +290,13 @@ class ColoadGroupServiceTest {
return value;
}
private static OrderGroupLinkRow link(long orderId, long groupId) {
OrderGroupLinkRow value = new OrderGroupLinkRow();
value.setOrderId(orderId);
value.setGroupId(groupId);
return value;
}
private static org.assertj.core.groups.Tuple tuple(Object... values) {
return org.assertj.core.groups.Tuple.tuple(values);
}
@@ -75,6 +75,16 @@ class ColoadGroupSqlContractTest {
.doesNotContain("member.active_flag=1", "inbound_role", "split_status", "split_purpose");
}
@Test
void internalOrderAggregationExcludesCancelledGroupsWithoutChangingPlatformReadKey() throws Exception {
Method method = ColoadGroupMapper.class.getDeclaredMethod("linksByOrderIds", java.util.List.class);
String sql = String.join(" ", method.getAnnotation(Select.class).value());
assertThat(sql)
.contains("member.order_id IN")
.contains("group_row.group_status&lt;&gt;'CANCELLED'")
.doesNotContain("inbound_code=#{inboundCode}");
}
private static String tableDefinition(String source, String tableName) {
int start = source.indexOf("CREATE TABLE IF NOT EXISTS " + tableName + " (");
int end = source.indexOf(';', start);