IngestBatchStatus.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <script setup lang="ts">
  2. import { shallowRef } from 'vue';
  3. import service from '/@/utils/request';
  4. import { downloadByData } from '/@/utils/download';
  5. import IngestBatchTrace from './IngestBatchTrace.vue';
  6. const props = defineProps<{ datasetId: string; factoryId: string; hasSchema: boolean; canInspect?: boolean }>();
  7. interface BatchStatus {
  8. receiveStatus: string;
  9. batchId: string;
  10. schemaVersion: string;
  11. acceptedRecordCount: number;
  12. workerStatus: string | null;
  13. isolatedRecordCount: number;
  14. receiverAcceptedRecordCount: number | null;
  15. handoffStatus: string;
  16. updatedAt: string;
  17. errorCode: string | null;
  18. }
  19. const batchId = shallowRef('');
  20. const result = shallowRef<BatchStatus>();
  21. const busy = shallowRef(false);
  22. const failed = shallowRef(false);
  23. const downloading = shallowRef(false);
  24. const batchPattern = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i;
  25. const workerLabels: Record<string, string> = {
  26. PENDING: '待处理',
  27. PROCESSING: '处理中',
  28. RETRY_PENDING: '待重试',
  29. HANDOFF_READY: '待交接',
  30. SUCCEEDED: '已完成',
  31. PARTIAL: '部分完成',
  32. QUARANTINED: '已隔离',
  33. FAILED: '处理失败',
  34. };
  35. const receiveLabels: Record<string, string> = {
  36. accepted: '已接收',
  37. captured: '已留存,待解析',
  38. rejected: '校验失败,原文已留存',
  39. empty: '空页,原文已留存',
  40. };
  41. const handoffLabels: Record<string, string> = {
  42. not_started: '未发起',
  43. pending: '待处理',
  44. awaiting_delivery: '待投递',
  45. confirmed: '已确认',
  46. failed: '交接失败',
  47. };
  48. async function downloadContract() {
  49. const path = '/api/DataPlatform/ingest-datasets/' + props.datasetId + '/api-contract';
  50. const { data } = await service.get<{ datasetKey: string; schemaVersion: string }>(path, { params: { factoryId: props.factoryId } });
  51. downloadByData(JSON.stringify(data, null, 2), data.datasetKey + '.' + data.schemaVersion + '.api.json', 'application/json');
  52. }
  53. async function downloadKit() {
  54. if (downloading.value) return;
  55. downloading.value = true;
  56. try {
  57. const path = '/api/DataPlatform/ingest-datasets/' + props.datasetId + '/api-contract';
  58. const { data, headers } = await service.get<Blob>(path, {
  59. params: { factoryId: props.factoryId, kit: true },
  60. responseType: 'blob',
  61. });
  62. const fileName = String(headers['content-disposition'] ?? '').match(/filename="?([a-zA-Z0-9._-]+)"?/i)?.[1];
  63. downloadByData(data, fileName ?? 'api-push-kit.zip', 'application/zip');
  64. } finally {
  65. downloading.value = false;
  66. }
  67. }
  68. function downloadDiagnostics() {
  69. const status = result.value;
  70. if (!status) return;
  71. downloadByData(JSON.stringify(status, null, 2), status.batchId + '.diagnostics.json', 'application/json');
  72. }
  73. async function query() {
  74. const selected = batchId.value.trim();
  75. if (busy.value || !batchPattern.test(selected)) return;
  76. busy.value = true;
  77. failed.value = false;
  78. result.value = undefined;
  79. try {
  80. const path = '/api/DataPlatform/ingest-datasets/' + props.datasetId + '/batches/' + selected;
  81. const { data } = await service.get<BatchStatus>(path, { params: { factoryId: props.factoryId } });
  82. result.value = data;
  83. } catch {
  84. failed.value = true;
  85. } finally {
  86. busy.value = false;
  87. }
  88. }
  89. </script>
  90. <template>
  91. <section>
  92. <h3>API 接收批次</h3>
  93. <el-button v-if="hasSchema" link type="primary" @click="downloadContract">下载 API 推送契约</el-button>
  94. <el-button v-if="hasSchema" link type="primary" :loading="downloading" @click="downloadKit">下载 API 推送接入包</el-button>
  95. <form class="batch-search" @submit.prevent="query">
  96. <el-input v-model="batchId" aria-label="接收批次号" placeholder="输入推送或拉取的 Raw 批次号" :disabled="busy" />
  97. <el-button native-type="submit" :disabled="!batchPattern.test(batchId.trim())" :loading="busy">查询批次</el-button>
  98. </form>
  99. <p v-if="failed" role="alert">查询失败,请核对批次号和当前数据集。</p>
  100. <el-descriptions v-if="result" :column="2" border>
  101. <el-descriptions-item label="Schema 版本">{{ result.schemaVersion }}</el-descriptions-item>
  102. <el-descriptions-item label="接收状态">{{ receiveLabels[result.receiveStatus] ?? result.receiveStatus }}</el-descriptions-item>
  103. <el-descriptions-item label="接收行数">{{ result.acceptedRecordCount }}</el-descriptions-item>
  104. <el-descriptions-item label="处理状态">{{ workerLabels[result.workerStatus ?? ''] ?? '待确认' }}</el-descriptions-item>
  105. <el-descriptions-item label="隔离行数">{{ result.isolatedRecordCount }}</el-descriptions-item>
  106. <el-descriptions-item label="交接状态">{{ handoffLabels[result.handoffStatus] ?? '待确认' }}</el-descriptions-item>
  107. <el-descriptions-item label="接收方确认行数">{{ result.receiverAcceptedRecordCount ?? '待确认' }}</el-descriptions-item>
  108. <el-descriptions-item label="更新时间">{{ new Date(result.updatedAt).toLocaleString() }}</el-descriptions-item>
  109. <el-descriptions-item v-if="result.errorCode" label="诊断码">{{ result.errorCode }}</el-descriptions-item>
  110. </el-descriptions>
  111. <el-button v-if="result" link type="primary" @click="downloadDiagnostics">下载批次排查记录</el-button>
  112. <IngestBatchTrace v-if="result && canInspect" :key="result.batchId" :dataset-id="datasetId"
  113. :factory-id="factoryId" :batch-id="result.batchId"
  114. :can-replay="['SUCCEEDED', 'PARTIAL', 'QUARANTINED'].includes(result.workerStatus ?? '')" />
  115. </section>
  116. </template>
  117. <style scoped>
  118. .batch-search {
  119. display: flex;
  120. gap: 8px;
  121. max-width: 520px;
  122. margin-bottom: 12px;
  123. }
  124. </style>