This is an automated email from the ASF dual-hosted git repository.

lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 28ca3a596 fix(dlq): report the rows the Excel export actually wrote, 
not the requested selection (#5936)
28ca3a596 is described below

commit 28ca3a5969ed78a3ebfa988c232fd4cdac21a00f
Author: 烤化の初雪 <[email protected]>
AuthorDate: Fri Nov 27 12:18:12 2026 +0800

    fix(dlq): report the rows the Excel export actually wrote, not the 
requested selection (#5936)
---
 .../studio/common/util/DlqExportHeaders.java       |  5 +-
 .../studio/instance/dlq/DLQController.java         |  4 ++
 .../instance/dlq/DLQExcelExportResultVO.java       |  4 ++
 .../provider/apache/RocketMQDLQProvider.java       |  5 ++
 .../provider/apache/RocketMQDLQProviderTest.java   | 34 +++++++++++++
 web/src/api/message.ts                             |  8 ++++
 web/src/pages/instance/__tests__/DLQPage.test.tsx  | 56 ++++++++++++++++++++++
 web/src/pages/instance/dlq.tsx                     | 13 ++++-
 8 files changed, 127 insertions(+), 2 deletions(-)

diff --git 
a/server/src/main/java/org/apache/rocketmq/studio/common/util/DlqExportHeaders.java
 
b/server/src/main/java/org/apache/rocketmq/studio/common/util/DlqExportHeaders.java
index 539a48697..811779e73 100644
--- 
a/server/src/main/java/org/apache/rocketmq/studio/common/util/DlqExportHeaders.java
+++ 
b/server/src/main/java/org/apache/rocketmq/studio/common/util/DlqExportHeaders.java
@@ -31,8 +31,11 @@ public final class DlqExportHeaders {
     public static final String TRUNCATED = "X-DLQ-Export-Truncated";
     public static final String FAILED_QUEUES = "X-DLQ-Export-FailedQueues";
     public static final String LIMIT = "X-DLQ-Export-Limit";
+    /** Rows written to the sheet, and how many msgIds the caller had 
selected. */
+    public static final String EXPORTED_ROWS = "X-DLQ-Export-Rows";
+    public static final String SELECTED_ROWS = "X-DLQ-Export-SelectedRows";
 
-    public static final List<String> ALL = List.of(TRUNCATED, FAILED_QUEUES, 
LIMIT);
+    public static final List<String> ALL = List.of(TRUNCATED, FAILED_QUEUES, 
LIMIT, EXPORTED_ROWS, SELECTED_ROWS);
 
     private DlqExportHeaders() {
     }
diff --git 
a/server/src/main/java/org/apache/rocketmq/studio/instance/dlq/DLQController.java
 
b/server/src/main/java/org/apache/rocketmq/studio/instance/dlq/DLQController.java
index ec64d68f8..2ea761b16 100644
--- 
a/server/src/main/java/org/apache/rocketmq/studio/instance/dlq/DLQController.java
+++ 
b/server/src/main/java/org/apache/rocketmq/studio/instance/dlq/DLQController.java
@@ -53,6 +53,8 @@ public class DLQController {
     private static final String HEADER_EXPORT_TRUNCATED = 
DlqExportHeaders.TRUNCATED;
     private static final String HEADER_EXPORT_FAILED_QUEUES = 
DlqExportHeaders.FAILED_QUEUES;
     private static final String HEADER_EXPORT_LIMIT = DlqExportHeaders.LIMIT;
+    private static final String HEADER_EXPORT_ROWS = 
DlqExportHeaders.EXPORTED_ROWS;
+    private static final String HEADER_EXPORT_SELECTED_ROWS = 
DlqExportHeaders.SELECTED_ROWS;
     private static final String EXCEL_MEDIA_TYPE =
             
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
     private static final int MAX_SELECTED_MESSAGES = 100;
@@ -119,6 +121,8 @@ public class DLQController {
                 .header(HEADER_EXPORT_TRUNCATED, 
String.valueOf(result.isTruncated()))
                 .header(HEADER_EXPORT_FAILED_QUEUES, 
String.valueOf(result.getFailedQueueCount()))
                 .header(HEADER_EXPORT_LIMIT, String.valueOf(result.getLimit()))
+                .header(HEADER_EXPORT_ROWS, 
String.valueOf(result.getExportedRows()))
+                .header(HEADER_EXPORT_SELECTED_ROWS, 
String.valueOf(result.getSelectedRows()))
                 .contentType(MediaType.parseMediaType(EXCEL_MEDIA_TYPE))
                 .body(result.getData());
     }
diff --git 
a/server/src/main/java/org/apache/rocketmq/studio/instance/dlq/DLQExcelExportResultVO.java
 
b/server/src/main/java/org/apache/rocketmq/studio/instance/dlq/DLQExcelExportResultVO.java
index 48f4132de..471bd38d0 100644
--- 
a/server/src/main/java/org/apache/rocketmq/studio/instance/dlq/DLQExcelExportResultVO.java
+++ 
b/server/src/main/java/org/apache/rocketmq/studio/instance/dlq/DLQExcelExportResultVO.java
@@ -36,4 +36,8 @@ public class DLQExcelExportResultVO {
     private boolean truncated;
     private int failedQueueCount;
     private int limit;
+    /** Rows actually written to the sheet. */
+    private int exportedRows;
+    /** msgIds the caller selected ({@code 0} when the whole window was 
requested). */
+    private int selectedRows;
 }
diff --git 
a/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQDLQProvider.java
 
b/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQDLQProvider.java
index c7cdc8444..baef31b8b 100644
--- 
a/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQDLQProvider.java
+++ 
b/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQDLQProvider.java
@@ -383,6 +383,11 @@ public class RocketMQDLQProvider implements DLQProvider {
                 .truncated(scanResult.truncated())
                 .failedQueueCount(scanResult.failedQueueCount())
                 .limit(RESEND_HARD_CAP)
+                // The selection is applied as a filter over the scanned 
window, so the sheet can be
+                // shorter than the selection (a message outside the window, 
or already resent by
+                // someone else); report both counts instead of letting the 
caller assume.
+                .exportedRows(messages.size())
+                .selectedRows(selected.size())
                 .build();
     }
 
diff --git 
a/server/src/test/java/org/apache/rocketmq/studio/provider/apache/RocketMQDLQProviderTest.java
 
b/server/src/test/java/org/apache/rocketmq/studio/provider/apache/RocketMQDLQProviderTest.java
index ebc65cb2c..3b1592ee9 100644
--- 
a/server/src/test/java/org/apache/rocketmq/studio/provider/apache/RocketMQDLQProviderTest.java
+++ 
b/server/src/test/java/org/apache/rocketmq/studio/provider/apache/RocketMQDLQProviderTest.java
@@ -1663,6 +1663,40 @@ class RocketMQDLQProviderTest {
         verify(pullConsumer, never()).searchOffset(queue, Long.MIN_VALUE);
     }
 
+    @Test
+    void exportExcelReportsTheRowsItWroteForASelectionTest() throws Exception {
+        String dlqTopic = MixAll.DLQ_GROUP_TOPIC_PREFIX + "group-a";
+        MessageQueue queue = new MessageQueue(dlqTopic, "broker-a", 0);
+        MessageExt present = new MessageExt();
+        present.setMsgId("msg-selected");
+        present.setTopic(dlqTopic);
+        present.setQueueId(0);
+        present.setQueueOffset(5L);
+        present.setStoreTimestamp(150L);
+        present.setKeys("key-selected");
+        present.setBody("hello dlq".getBytes(StandardCharsets.UTF_8));
+        MessageExt other = new MessageExt();
+        other.setMsgId("msg-other");
+        other.setTopic(dlqTopic);
+        other.setQueueId(0);
+        other.setQueueOffset(6L);
+        other.setStoreTimestamp(160L);
+        other.setKeys("key-other");
+        other.setBody("hello other".getBytes(StandardCharsets.UTF_8));
+        
when(pullConsumer.fetchSubscribeMessageQueues(dlqTopic)).thenReturn(Set.of(queue));
+        when(pullConsumer.searchOffset(queue, 100L)).thenReturn(0L);
+        when(pullConsumer.maxOffset(queue)).thenReturn(2L);
+        when(pullConsumer.pull(queue, "*", 0L, 32))
+                .thenReturn(new PullResult(PullStatus.FOUND, 2L, 0L, 2L, 
List.of(present, other)));
+
+        // One of the two selected messages is not in the scanned window any 
more.
+        DLQExcelExportResultVO result = provider.exportExcel("instance-a", 
"group-a", 100L,
+                Long.MAX_VALUE, List.of("msg-selected", "msg-vanished"));
+
+        assertThat(result.getExportedRows()).isEqualTo(1);
+        assertThat(result.getSelectedRows()).isEqualTo(2);
+    }
+
     @Test
     void 
exportExcelTruncatesOversizedBodiesInsteadOfFailingTheWholeExportTest() throws 
Exception {
         String dlqTopic = MixAll.DLQ_GROUP_TOPIC_PREFIX + "group-a";
diff --git a/web/src/api/message.ts b/web/src/api/message.ts
index 66e7f9cb8..370b16042 100644
--- a/web/src/api/message.ts
+++ b/web/src/api/message.ts
@@ -269,6 +269,12 @@ export interface DLQExportMeta {
   truncated: boolean;
   failedQueueCount: number;
   limit: number;
+  /**
+   * Rows the server wrote to the sheet, and how many msgIds were selected (0 
= whole window).
+   * Only the Excel endpoint reports them.
+   */
+  exportedRows?: number;
+  selectedRows?: number;
 }
 
 export async function exportDLQMessages(params: {
@@ -363,6 +369,8 @@ export async function exportDLQExcel(params: {
       truncated: header('x-dlq-export-truncated') === 'true',
       failedQueueCount: Number.parseInt(header('x-dlq-export-failedqueues'), 
10) || 0,
       limit: Number.parseInt(header('x-dlq-export-limit'), 10) || 0,
+      exportedRows: Number.parseInt(header('x-dlq-export-rows'), 10) || 0,
+      selectedRows: Number.parseInt(header('x-dlq-export-selectedrows'), 10) 
|| 0,
     },
   };
 }
diff --git a/web/src/pages/instance/__tests__/DLQPage.test.tsx 
b/web/src/pages/instance/__tests__/DLQPage.test.tsx
index dc371ed4d..33fd3910a 100644
--- a/web/src/pages/instance/__tests__/DLQPage.test.tsx
+++ b/web/src/pages/instance/__tests__/DLQPage.test.tsx
@@ -716,6 +716,62 @@ describe('DLQ page', () => {
     expect(revokeObjectURL).toHaveBeenCalledWith('blob:dlq');
   });
 
+  it('reports how many selected messages the export actually contained', async 
() => {
+    const message = (msgId: string, offset: number) => ({
+      msgId,
+      topic: 'orders',
+      queueId: 0,
+      offset,
+      storeTime: 1_700_000_000_000,
+      keys: `key-${msgId}`,
+      body: 'payload',
+      bodyBase64: null,
+      properties: {},
+      propertiesTruncated: false,
+    });
+    vi.mocked(messageService.listDLQMessages).mockResolvedValue({
+      items: [message('dlq-1', 7), message('dlq-2', 8)],
+      total: 2,
+      page: 1,
+      size: 20,
+    } satisfies DLQMessagePage);
+    vi.mocked(messageService.exportDLQExcel).mockResolvedValue({
+      blob: new Blob([''], {
+        type: 
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
+      }),
+      // Two ids were selected, but only one of them was in the scanned window.
+      meta: {
+        truncated: false,
+        failedQueueCount: 0,
+        limit: 5000,
+        exportedRows: 1,
+        selectedRows: 2,
+      },
+    });
+    const user = userEvent.setup({ pointerEventsCheck: 0 });
+    renderWithProviders(<DLQPage />);
+
+    await screen.findByText('cg-order');
+    const groupRow = (await screen.findByText('cg-order')).closest('tr');
+    if (!groupRow) throw new Error('DLQ group row not found');
+    await user.click(within(groupRow).getByRole('button', { name: /消息明细/ }));
+    const dialog = await screen.findByRole('dialog', { name: /cg-order/ });
+    for (const msgId of ['dlq-1', 'dlq-2']) {
+      const messageRow = (await 
within(dialog).findByText(msgId)).closest('tr');
+      if (!messageRow) throw new Error(`DLQ message row not found: ${msgId}`);
+      await user.click(within(messageRow).getByRole('checkbox'));
+    }
+    await user.click(within(dialog).getByRole('button', { name: /导出选中 \(2\)/ 
}));
+
+    // The page now reports what the server wrote instead of what was 
requested: two ids were
+    // selected and only one of them was still in the scanned window.
+    await waitFor(() =>
+      expect(
+        screen.getByText('选中的 2 条死信消息中有 1 条不在导出窗口内,未写入文件'),
+      ).toBeInTheDocument(),
+    );
+  });
+
   it('warns when the export scan is incomplete', async () => {
     vi.mocked(messageService.exportDLQExcel).mockResolvedValue({
       blob: new Blob([''], {
diff --git a/web/src/pages/instance/dlq.tsx b/web/src/pages/instance/dlq.tsx
index d89c199ff..ee1075f73 100644
--- a/web/src/pages/instance/dlq.tsx
+++ b/web/src/pages/instance/dlq.tsx
@@ -517,13 +517,24 @@ const DLQPage = () => {
         msgIds: detailSelectedMsgIds.length > 0 ? detailSelectedMsgIds : 
undefined,
       });
       downloadBlob(blob, `${detailGroup.groupName}-dlq-messages.xlsx`);
+      // The selection is a filter over the scanned window, so the sheet can 
hold fewer rows than
+      // were ticked (a message outside the window, or already resent by 
someone else). The server
+      // reports what it wrote; go by that instead of the request.
+      const selectedCount = meta.selectedRows ?? detailSelectedMsgIds.length;
+      const exportedRows = meta.exportedRows;
+      const missingSelectedRows =
+        exportedRows === undefined ? 0 : Math.max(0, selectedCount - 
exportedRows);
       if (meta.truncated || meta.failedQueueCount > 0) {
         message.warning(
           `导出可能不完整:${meta.failedQueueCount} 个队列无法扫描,导出上限 ${meta.limit} 条`,
         );
+      } else if (missingSelectedRows > 0) {
+        message.warning(
+          `选中的 ${selectedCount} 条死信消息中有 ${missingSelectedRows} 条不在导出窗口内,未写入文件`,
+        );
       } else {
         message.success(
-          `已导出 ${detailSelectedMsgIds.length > 0 ? `选中的 
${detailSelectedMsgIds.length} 条` : '全部'}死信消息(${blob.size} 字节)`,
+          `已导出 ${selectedCount > 0 ? `选中的 ${exportedRows ?? selectedCount} 条` 
: '全部'}死信消息(${blob.size} 字节)`,
         );
       }
     } catch (error) {

Reply via email to