| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <script setup lang="ts">
- import { shallowRef } from 'vue';
- import service from '/@/utils/request';
- import { downloadByData } from '/@/utils/download';
- import IngestBatchTrace from './IngestBatchTrace.vue';
- const props = defineProps<{ datasetId: string; factoryId: string; hasSchema: boolean; canInspect?: boolean }>();
- interface BatchStatus {
- receiveStatus: string;
- batchId: string;
- schemaVersion: string;
- acceptedRecordCount: number;
- workerStatus: string | null;
- isolatedRecordCount: number;
- receiverAcceptedRecordCount: number | null;
- handoffStatus: string;
- updatedAt: string;
- errorCode: string | null;
- }
- const batchId = shallowRef('');
- const result = shallowRef<BatchStatus>();
- const busy = shallowRef(false);
- const failed = shallowRef(false);
- const downloading = shallowRef(false);
- const batchPattern = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i;
- const workerLabels: Record<string, string> = {
- PENDING: '待处理',
- PROCESSING: '处理中',
- RETRY_PENDING: '待重试',
- HANDOFF_READY: '待交接',
- SUCCEEDED: '已完成',
- PARTIAL: '部分完成',
- QUARANTINED: '已隔离',
- FAILED: '处理失败',
- };
- const receiveLabels: Record<string, string> = {
- accepted: '已接收',
- captured: '已留存,待解析',
- rejected: '校验失败,原文已留存',
- empty: '空页,原文已留存',
- };
- const handoffLabels: Record<string, string> = {
- not_started: '未发起',
- pending: '待处理',
- awaiting_delivery: '待投递',
- confirmed: '已确认',
- failed: '交接失败',
- };
- async function downloadContract() {
- const path = '/api/DataPlatform/ingest-datasets/' + props.datasetId + '/api-contract';
- const { data } = await service.get<{ datasetKey: string; schemaVersion: string }>(path, { params: { factoryId: props.factoryId } });
- downloadByData(JSON.stringify(data, null, 2), data.datasetKey + '.' + data.schemaVersion + '.api.json', 'application/json');
- }
- async function downloadKit() {
- if (downloading.value) return;
- downloading.value = true;
- try {
- const path = '/api/DataPlatform/ingest-datasets/' + props.datasetId + '/api-contract';
- const { data, headers } = await service.get<Blob>(path, {
- params: { factoryId: props.factoryId, kit: true },
- responseType: 'blob',
- });
- const fileName = String(headers['content-disposition'] ?? '').match(/filename="?([a-zA-Z0-9._-]+)"?/i)?.[1];
- downloadByData(data, fileName ?? 'api-push-kit.zip', 'application/zip');
- } finally {
- downloading.value = false;
- }
- }
- function downloadDiagnostics() {
- const status = result.value;
- if (!status) return;
- downloadByData(JSON.stringify(status, null, 2), status.batchId + '.diagnostics.json', 'application/json');
- }
- async function query() {
- const selected = batchId.value.trim();
- if (busy.value || !batchPattern.test(selected)) return;
- busy.value = true;
- failed.value = false;
- result.value = undefined;
- try {
- const path = '/api/DataPlatform/ingest-datasets/' + props.datasetId + '/batches/' + selected;
- const { data } = await service.get<BatchStatus>(path, { params: { factoryId: props.factoryId } });
- result.value = data;
- } catch {
- failed.value = true;
- } finally {
- busy.value = false;
- }
- }
- </script>
- <template>
- <section>
- <h3>API 接收批次</h3>
- <el-button v-if="hasSchema" link type="primary" @click="downloadContract">下载 API 推送契约</el-button>
- <el-button v-if="hasSchema" link type="primary" :loading="downloading" @click="downloadKit">下载 API 推送接入包</el-button>
- <form class="batch-search" @submit.prevent="query">
- <el-input v-model="batchId" aria-label="接收批次号" placeholder="输入推送或拉取的 Raw 批次号" :disabled="busy" />
- <el-button native-type="submit" :disabled="!batchPattern.test(batchId.trim())" :loading="busy">查询批次</el-button>
- </form>
- <p v-if="failed" role="alert">查询失败,请核对批次号和当前数据集。</p>
- <el-descriptions v-if="result" :column="2" border>
- <el-descriptions-item label="Schema 版本">{{ result.schemaVersion }}</el-descriptions-item>
- <el-descriptions-item label="接收状态">{{ receiveLabels[result.receiveStatus] ?? result.receiveStatus }}</el-descriptions-item>
- <el-descriptions-item label="接收行数">{{ result.acceptedRecordCount }}</el-descriptions-item>
- <el-descriptions-item label="处理状态">{{ workerLabels[result.workerStatus ?? ''] ?? '待确认' }}</el-descriptions-item>
- <el-descriptions-item label="隔离行数">{{ result.isolatedRecordCount }}</el-descriptions-item>
- <el-descriptions-item label="交接状态">{{ handoffLabels[result.handoffStatus] ?? '待确认' }}</el-descriptions-item>
- <el-descriptions-item label="接收方确认行数">{{ result.receiverAcceptedRecordCount ?? '待确认' }}</el-descriptions-item>
- <el-descriptions-item label="更新时间">{{ new Date(result.updatedAt).toLocaleString() }}</el-descriptions-item>
- <el-descriptions-item v-if="result.errorCode" label="诊断码">{{ result.errorCode }}</el-descriptions-item>
- </el-descriptions>
- <el-button v-if="result" link type="primary" @click="downloadDiagnostics">下载批次排查记录</el-button>
- <IngestBatchTrace v-if="result && canInspect" :key="result.batchId" :dataset-id="datasetId"
- :factory-id="factoryId" :batch-id="result.batchId"
- :can-replay="['SUCCEEDED', 'PARTIAL', 'QUARANTINED'].includes(result.workerStatus ?? '')" />
- </section>
- </template>
- <style scoped>
- .batch-search {
- display: flex;
- gap: 8px;
- max-width: 520px;
- margin-bottom: 12px;
- }
- </style>
|