| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- <script setup lang="ts">
- import { computed, onMounted, ref } from 'vue';
- import { ElMessage, ElMessageBox } from 'element-plus';
- import ApiPullWorkspace from './ApiPullWorkspace.vue';
- import EdgeDeviceWorkspace from './EdgeDeviceWorkspace.vue';
- import IngestBatchStatus from './IngestBatchStatus.vue';
- import IngestRawRetention from './IngestRawRetention.vue';
- import IngestPushSample from './IngestPushSample.vue';
- import RelationalTrialPanel from './RelationalTrialPanel.vue';
- import { changeLifecycle, releaseAction, saveCandidate, versions, type Candidate, type IngestDataset, type VersionWorkspace } from '../api/ingestDatasets';
- const props = defineProps<{ dataset: IngestDataset; factoryId: string; factoryName: string }>();
- const emit = defineEmits<{ close: []; published: [] }>();
- const model = ref<VersionWorkspace>();
- const busy = ref(false);
- const source = ref(props.dataset.bindings.find((b) => b.sourceEnabled)?.sourceId ?? '');
- const version = ref('');
- const fields = ['PoNo', 'PoLine', 'ItemCode', 'OrderQty', 'SupplierCode', 'OrderDate', 'DueDate', 'Status', 'sourceUpdatedAt'];
- const names = ref<Record<string, string>>(Object.fromEntries(fields.map((f) => [f, f])));
- const selected = ref('');
- const candidate = computed(() => model.value?.history.find((c) => c.id === selected.value));
- const obsolete = computed(() => candidate.value?.baseRevision !== props.dataset.revision);
- const trialSample = ref('');
- const expectedValid = ref(2);
- const expectedIsolated = ref(1);
- const expectedQuantity = ref(15.5);
- const migrationReference = ref('');
- const evidence = computed(() => (candidate.value?.trialJson ? JSON.parse(candidate.value.trialJson) : undefined));
- const labels: Record<string, string> = {
- DRAFT: '草稿',
- PREFLIGHT: '预检通过',
- RECONCILING: '对账中',
- REVIEW: '待审批',
- PUBLISHED: '版本已启用',
- AWAITING_HANDOFF: '等待有效交接回执',
- HANDED_OVER: '已交接',
- PAUSED: '已暂停',
- RETIRED: '已退役',
- Approved: '审批通过',
- Running: '审批中',
- Rejected: '已退回',
- Cancelled: '已撤销',
- Terminated: '已终止',
- };
- const actions: Record<string, string> = { DRAFT: '创建草稿', precheck: '预检通过', trial: '完成沙箱试跑', submit: '提交审批', publish: '启用版本', pause: '暂停', resume: '恢复', retire: '退役', 'schema-migration-ready': '登记迁移完成' };
- const mappingRows = computed(() => {
- if (!candidate.value) return [];
- const live = model.value?.history.find((row) => row.state === 'PUBLISHED' && row.version === props.dataset.activeSchemaVersion);
- const current: Record<string, string> = live ? JSON.parse(live.mappingJson) : {};
- const proposed: Record<string, string> = JSON.parse(candidate.value.mappingJson);
- return fields.map((field) => ({ field, current: current[field] ?? (props.dataset.activeSchemaVersion ? field : '—'), proposed: proposed[field] ?? field }));
- });
- function example(row: Candidate) {
- const map: Record<string, string> = JSON.parse(row.mappingJson);
- const list = [12.5, 3, 2].map((qty, i) => {
- const item: Record<string, string | number> = { PoNo: 'SANDBOX-PO', PoLine: String(i + 1), OrderQty: qty, sourceUpdatedAt: '2026-11-20T09:00:00+08:00' };
- if (i < 2) item.ItemCode = 'ITEM-' + (i + 1);
- return Object.fromEntries(Object.entries(item).map(([k, v]) => [map[k] ?? k, v]));
- });
- trialSample.value = JSON.stringify({ data: { list } }, null, 2);
- }
- async function refresh() {
- model.value = await versions(props.dataset.id, props.factoryId);
- if (!model.value.history.some((c) => c.id === selected.value)) selected.value = model.value.history[0]?.id ?? '';
- }
- onMounted(async () => {
- await refresh();
- const active = model.value?.history.find((c) => c.version === props.dataset.activeSchemaVersion && c.state === 'PUBLISHED');
- if (active) names.value = JSON.parse(active.mappingJson);
- if (candidate.value) example(candidate.value);
- });
- async function run(work: () => Promise<unknown>, published = false) {
- if (busy.value) return;
- busy.value = true;
- try {
- await work();
- if (published) emit('published');
- else {
- await refresh();
- ElMessage.success('操作已保存');
- }
- } finally {
- busy.value = false;
- }
- }
- function draft() {
- return run(async () => {
- const response = await saveCandidate(props.dataset.id, props.factoryId, {
- version: version.value.trim(),
- sourceId: source.value,
- revision: props.dataset.revision,
- mappingJson: JSON.stringify(names.value),
- });
- selected.value = response.data.id;
- await refresh();
- if (candidate.value) example(candidate.value);
- });
- }
- function transition(action: string) {
- if (!candidate.value) return;
- const id = candidate.value.id;
- return run(
- () =>
- releaseAction(
- props.dataset.id,
- props.factoryId,
- id,
- action,
- action === 'trial' ? { sample: trialSample.value, expectedValid: expectedValid.value, expectedIsolated: expectedIsolated.value, expectedQuantity: expectedQuantity.value } : {}
- ),
- action === 'publish'
- );
- }
- function recordMigration() {
- const row = candidate.value;
- if (!row || !migrationReference.value.trim()) return;
- return run(async () => {
- await releaseAction(props.dataset.id, props.factoryId, row.id, 'migration-ready', { evidenceReference: migrationReference.value.trim() });
- migrationReference.value = '';
- });
- }
- async function lifecycle(action: string) {
- const result = await ElMessageBox.prompt('填写原因', '数据集' + (action === 'pause' ? '暂停' : action === 'resume' ? '恢复' : '退役'), { inputPattern: /\S/ });
- await run(() => changeLifecycle(props.dataset, props.factoryId, action, result.value), true);
- }
- </script>
- <template>
- <el-dialog :model-value="true" :title="factoryName + ' · ' + dataset.name" width="min(780px,95vw)" append-to-body @close="emit('close')">
- <p>
- 当前版本 {{ dataset.activeSchemaVersion || '尚未发布' }} · {{ model?.environment }} ·
- {{ model?.lifecycle === 'RETIRED' ? '已退役' : model?.lifecycle === 'PAUSED' ? '已暂停' : dataset.enabled ? '接收中' : '未启用' }}
- </p>
- <el-collapse v-if="model && model.lifecycle !== 'RETIRED'">
- <el-collapse-item title="新建采购接收候选版本" name="draft">
- <el-form label-width="110px">
- <el-form-item label="试跑来源"
- ><el-select v-model="source"><el-option v-for="b in dataset.bindings.filter((x) => x.sourceEnabled)" :key="b.sourceId" :label="b.sourceName" :value="b.sourceId" /></el-select
- ></el-form-item>
- <el-form-item label="版本号"><el-input v-model="version" maxlength="64" placeholder="例如 po-source-v2" /></el-form-item>
- <el-form-item v-for="f in fields" :key="f" :label="f"><el-input v-model="names[f]" placeholder="来源字段名" /></el-form-item>
- <el-button :disabled="!version || !source || busy" @click="draft">保存为候选</el-button>
- </el-form>
- </el-collapse-item>
- </el-collapse>
- <el-table
- :data="model?.history || []"
- highlight-current-row
- @row-click="
- (c: Candidate) => {
- selected = c.id;
- migrationReference = '';
- example(c);
- }
- "
- >
- <el-table-column prop="version" label="版本" /><el-table-column prop="environmentKey" label="环境" />
- <el-table-column label="状态"
- ><template #default="{ row }">{{ labels[row.approval] && row.state === 'REVIEW' ? labels[row.approval] : labels[row.projectState ?? row.state] }}</template></el-table-column
- >
- </el-table>
- <section v-if="candidate">
- <p>{{ candidate.version }} · {{ dataset.bindings.find((b) => b.sourceId === candidate?.sourceId)?.sourceName ?? candidate.sourceId }} · {{ labels[candidate.state] }} <span v-if="obsolete && candidate.state !== 'PUBLISHED'">· 配置已变更,请新建候选</span></p>
- <p v-if="candidate.state === 'PUBLISHED'">项目状态(可见工厂):{{ labels[candidate.projectState] || '尚无可核实回执' }}</p>
- <p v-if="candidate.handoff">
- {{ candidate.handoff.accepted > 0 ? '首个有效交接回执' : '零接收回执' }} · 批次 {{ candidate.handoff.batchId }}
- · 工厂 {{ candidate.handoff.factoryId }} · 接收 {{ candidate.handoff.accepted }} 行 · 隔离 {{ candidate.handoff.isolated }} 行
- · 确认时间 {{ candidate.handoff.acknowledgedAt }}
- </p>
- <el-collapse>
- <el-collapse-item title="查看与当前启用版本的字段差异" name="mapping">
- <el-table :data="mappingRows">
- <el-table-column prop="field" label="采购字段" /><el-table-column prop="current" label="当前来源字段" />
- <el-table-column label="所选版本来源字段"
- ><template #default="{ row }"
- ><strong v-if="row.current !== row.proposed">{{ row.proposed }}</strong
- ><span v-else>{{ row.proposed }}</span></template
- ></el-table-column
- >
- </el-table>
- </el-collapse-item>
- </el-collapse>
- <p v-if="candidate.flowId">审批实例 {{ candidate.flowId }} · {{ labels[candidate.approval || ''] }}</p>
- <template v-if="candidate.schemaMigrationRequired">
- <p v-if="candidate.schemaMigrationReady">调用方迁移已登记</p>
- <p v-else-if="model?.lifecycle !== 'PAUSED'">字段映射有变更。请暂停接收,并按暂停后的修订新建候选。</p>
- <p v-else>字段映射有变更。处理完在途批次后登记调用方迁移记录。</p>
- <template v-if="!candidate.schemaMigrationReady && !obsolete && model?.lifecycle === 'PAUSED' && model.canPublish && candidate.approval === 'Approved'">
- <el-input v-model="migrationReference" maxlength="250" aria-label="迁移完成凭据" placeholder="填写调用方迁移完成的工单或联测记录" />
- <el-button :disabled="busy || !migrationReference.trim()" @click="recordMigration">登记迁移完成</el-button>
- </template>
- </template>
- <el-button v-if="candidate.state === 'DRAFT'" :disabled="busy || obsolete" @click="transition('precheck')">预检</el-button>
- <template v-if="['PREFLIGHT', 'RECONCILING'].includes(candidate.state) && model?.canTrial">
- <el-input v-model="trialSample" type="textarea" :rows="5" aria-label="采购试跑样本" />
- <p>
- 预期有效行 <el-input-number v-model="expectedValid" :min="1" size="small" /> 隔离行 <el-input-number v-model="expectedIsolated" :min="0" size="small" /> 数量合计
- <el-input-number v-model="expectedQuantity" :min="0" size="small" />
- </p>
- <el-button :disabled="busy || obsolete" @click="transition('trial')">沙箱试跑</el-button>
- </template>
- <template v-if="evidence"
- ><p>
- 批次 {{ evidence.batchId }} · 接收 {{ evidence.received }} · 隔离 {{ evidence.isolated }} · 贴源 {{ evidence.staged }} 行 / {{ evidence.stagedQuantity }} · 标准 {{ evidence.standard }} 行 /
- {{ evidence.standardQuantity }} · {{ evidence.matched ? '对账通过' : '存在差额' }}
- </p>
- <p v-if="evidence.expectedValid != null">预期有效 {{ evidence.expectedValid }} 行,隔离 {{ evidence.expectedIsolated }} 行,数量合计 {{ evidence.expectedQuantity }}。</p>
- <p v-for="q in evidence.quarantines" :key="q.rawEventId">{{ q.field }} · {{ q.reason }} · {{ q.rawEventId }}</p>
- </template>
- <el-button v-if="candidate.state === 'RECONCILING' && model?.canTrial" :disabled="busy || obsolete || !evidence?.matched" @click="transition('submit')">提交审批</el-button>
- <el-button v-if="candidate.state === 'REVIEW' && model?.canPublish" :disabled="busy || obsolete || candidate.approval !== 'Approved' || (candidate.schemaMigrationRequired && !candidate.schemaMigrationReady)" type="primary" @click="transition('publish')"
- >启用 {{ candidate.version }}</el-button
- >
- </section>
- <IngestBatchStatus :key="factoryId + '/' + dataset.id" :dataset-id="dataset.id" :factory-id="factoryId" :has-schema="!!dataset.activeSchemaVersion" :can-inspect="model?.canTrial" />
- <IngestRawRetention v-if="model?.canTrial" :key="factoryId + '/retention/' + dataset.id" :dataset-id="dataset.id" :factory-id="factoryId" />
- <IngestPushSample v-if="dataset.activeSchemaVersion" :key="'sample/' + factoryId + '/' + dataset.id" :dataset-id="dataset.id" :factory-id="factoryId" />
- <ApiPullWorkspace v-if="model?.canTrial" :key="factoryId + '/api-pull/' + dataset.id" :dataset="dataset" :factory-id="factoryId" />
- <EdgeDeviceWorkspace v-if="model?.canTrial" :key="factoryId + '/edge/' + dataset.id" :dataset="dataset" :factory-id="factoryId" />
- <RelationalTrialPanel v-if="model?.canTrial" :dataset-id="dataset.id" :factory-id="factoryId" :active="model.lifecycle === 'ACTIVE' && dataset.enabled" />
- <el-collapse v-if="model?.timeline.length">
- <el-collapse-item title="查看操作记录" name="history">
- <p v-for="(event, index) in model.timeline" :key="index">{{ event.createdAt }} · {{ actions[event.action] ?? event.action }} · {{ event.detail }} · 操作人 {{ event.actor }}</p>
- </el-collapse-item>
- </el-collapse>
- <template #footer>
- <el-button :disabled="busy" @click="refresh">刷新审批与交接状态</el-button>
- <el-button v-if="model?.canPublish && dataset.enabled" :disabled="busy" @click="lifecycle('pause')">暂停接收</el-button>
- <el-button v-if="model?.canPublish && model.lifecycle === 'PAUSED'" :disabled="busy" @click="lifecycle('resume')">恢复当前版本</el-button>
- <el-button v-if="model?.canPublish && model.lifecycle === 'PAUSED'" :disabled="busy" @click="lifecycle('retire')">退役</el-button>
- </template>
- </el-dialog>
- </template>
|