修复订单列表排序与活动时间刷新

This commit is contained in:
andy
2026-07-13 13:48:52 +08:00
parent 4cb0119e32
commit 3e94a146b9
7 changed files with 79 additions and 7 deletions

View File

@@ -248,6 +248,44 @@ class ReservationFrontendQueryControllerTest {
.andExpect(jsonPath("$.page.total").value(2));
}
@Test
void shouldKeepOrderLatestActivityAtRequiredForIndexedSorting() {
String isNullable = jdbcTemplate.queryForObject("""
SELECT IS_NULLABLE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'WORKFLOW_RESERVATION_ORDER'
AND COLUMN_NAME = 'LATEST_ACTIVITY_AT'
""", String.class);
assertThat(isNullable).isEqualTo("NO");
}
@Test
void shouldOnlyReturnVisibleOrdersInFrontendOrderList() throws Exception {
SourceMessageCaptureResult visibleSource = captureSourceMessage(
"mail-frontend-order-visible-filter-001",
"Frontend Query Visible Filter");
SourceMessageCaptureResult archivedSource = captureSourceMessage(
"mail-frontend-order-visible-filter-archived-001",
"Frontend Query Visible Filter Archived");
Long visibleOrderId = 930000000000002201L;
Long archivedOrderId = 930000000000002202L;
insertGroupOrder(visibleOrderId, visibleSource.inboxId(),
"GRP-FRONTEND-VISIBLE-FILTER-001", "ACTIVE");
insertGroupOrder(archivedOrderId, archivedSource.inboxId(),
"GRP-FRONTEND-VISIBLE-FILTER-ARCHIVED", "ACTIVE");
updateOrderVisibility(archivedOrderId, "ARCHIVED_SYSTEM");
mockMvc.perform(get("/api/reservation/orders")
.param("hotel_id", HOTEL_ID)
.param("keyword", "GRP-FRONTEND-VISIBLE-FILTER-")
.param("page_num", "1")
.param("page_size", "20"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.items[0].order_id").value(visibleOrderId.toString()))
.andExpect(jsonPath("$.page.total").value(1));
}
@Test
void shouldTouchOrderLatestActivityWhenRepositoryInsertsTask() {
SourceMessageCaptureResult source = captureSourceMessage(
@@ -457,6 +495,14 @@ class ReservationFrontendQueryControllerTest {
""", Timestamp.from(latestActivityAt), orderId);
}
private void updateOrderVisibility(Long orderId, String orderVisibility) {
jdbcTemplate.update("""
UPDATE workflow_reservation_order
SET order_visibility = ?
WHERE id = ?
""", orderVisibility, orderId);
}
private void insertActiveGroupOrder(Long orderId, Long sourceMessageId, String groupCode) {
insertGroupOrder(orderId, sourceMessageId, groupCode, "ACTIVE");
}

View File

@@ -19,6 +19,7 @@ import cn.nianxx.thhotel.platform.message.common.result.SourceMessageCaptureResu
import cn.nianxx.thhotel.platform.message.service.SourceMessageCaptureService;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.sql.Timestamp;
import java.time.Instant;
import java.util.HexFormat;
import java.util.List;
@@ -1968,6 +1969,18 @@ class SuperAgentTaskResultControllerTest {
"CNF-CP5-OPERA-RETRY-001");
String taskId = taskAndOperationIds[0];
String firstOperationId = taskAndOperationIds[1];
Long orderId = jdbcTemplate.queryForObject("""
SELECT order_id
FROM workflow_reservation_task
WHERE id = ?
""", Long.class, Long.valueOf(taskId));
Timestamp staleLatestActivityAt = Timestamp.from(Instant.parse("2026-07-01T00:00:00Z"));
jdbcTemplate.update("""
UPDATE workflow_reservation_order
SET latest_activity_at = ?,
updated_at = ?
WHERE id = ?
""", staleLatestActivityAt, staleLatestActivityAt, orderId);
mockMvc.perform(post(
"/api/reservation/tasks/{taskId}/opera-operations/{operationId}/execute",
@@ -1984,6 +1997,12 @@ class SuperAgentTaskResultControllerTest {
.andExpect(jsonPath("$.operation_status").value("FAILED"))
.andExpect(jsonPath("$.attempt_count").value(1))
.andExpect(jsonPath("$.attempts[0].attempt_status").value("FAILED"));
Timestamp failedAttemptLatestActivityAt = jdbcTemplate.queryForObject("""
SELECT latest_activity_at
FROM workflow_reservation_order
WHERE id = ?
""", Timestamp.class, orderId);
assertThat(failedAttemptLatestActivityAt.toInstant()).isAfter(staleLatestActivityAt.toInstant());
mockMvc.perform(post(
"/api/reservation/tasks/{taskId}/opera-operations/{operationId}/retry",