订单数据源增加订单对比功能

This commit is contained in:
wuweihua
2026-10-20 13:55:55 +08:00
parent 8093cb52e7
commit 45969a4d29
20 changed files with 1865 additions and 96 deletions
@@ -0,0 +1,218 @@
<template>
<el-drawer
v-model="visible"
size="720px"
:title="drawerTitle"
append-to-body
destroy-on-close
@closed="onClosed"
>
<div v-loading="starting">
<el-descriptions :column="2" border size="small" class="mb12">
<el-descriptions-item label="任务ID" :span="2">{{ asyncTaskId || '-' }}</el-descriptions-item>
<el-descriptions-item label="客户">{{ filterText.customers }}</el-descriptions-item>
<el-descriptions-item label="提货时间">{{ filterText.time }}</el-descriptions-item>
<el-descriptions-item label="状态">
<el-tag size="small" :type="statusTagType">{{ statusLabel }}</el-tag>
</el-descriptions-item>
<el-descriptions-item label="进度">{{ progress.percent || 0 }}%</el-descriptions-item>
</el-descriptions>
<el-progress
:percentage="Math.min(100, Math.max(0, Number(progress.percent) || 0))"
:status="progressStatus"
:stroke-width="12"
striped
:striped-flow="running"
class="mb12"
/>
<div class="summary-line">
已扫描 {{ progress.scanned || 0 }}
/ 本地已有 {{ progress.matched || 0 }}
/ 本地缺失 {{ progress.missing || 0 }}
</div>
<div v-if="progress.message" class="msg-line">{{ progress.message }}</div>
<div v-if="progress.error" class="err-line">{{ progress.error }}</div>
<el-alert
class="mb12"
type="info"
:closable="false"
show-icon
title="仅比对转单号:上游 TRANSFER_ORDER_ID 有、本地 transfer_no 没有。异步分页扫描,结果已写入操作记录。"
/>
<div class="json-panel__head">
<span>缺失转单号(样本)</span>
<el-button
type="primary"
link
:disabled="!canFillSearch"
@click="fillToSearch"
>回填到单号搜索</el-button>
</div>
<el-table :data="missingRows" border size="small" max-height="360">
<el-table-column type="index" width="55" label="#" />
<el-table-column prop="transferNo" label="转单号" min-width="220" show-overflow-tooltip />
</el-table>
<el-empty v-if="!running && !(progress.missingTransferNos || []).length" description="暂无缺失转单号" />
</div>
</el-drawer>
</template>
<script setup>
import { ElMessage } from 'element-plus'
import { compareOrderSourceByFilter, getOrderSourceCompareProgress } from '@/api/monitor/orderSource'
const emit = defineEmits(['fill-search'])
const visible = ref(false)
const starting = ref(false)
const asyncTaskId = ref('')
const query = ref({})
const progress = ref({})
let timer = null
const filterText = computed(() => {
const q = query.value || {}
const codes = Array.isArray(q.customerCodes) ? q.customerCodes.filter(Boolean) : []
const keywords = Array.isArray(q.customerKeywords) ? q.customerKeywords.filter(Boolean) : []
return {
customers: keywords.join(', ') || codes.join(', ') || '-',
time: (q.beginTime || '-') + ' ~ ' + (q.endTime || '-')
}
})
const running = computed(() => {
const st = (progress.value?.status || '').toUpperCase()
return st === 'PENDING' || st === 'RUNNING' || starting.value
})
const drawerTitle = computed(() => {
if (running.value) return '订单比对任务进行中'
const st = (progress.value?.status || '').toUpperCase()
if (st === 'SUCCESS') return '订单比对完成'
if (st === 'FAIL') return '订单比对失败'
return '订单比对任务'
})
const statusLabel = computed(() => {
const st = (progress.value?.status || '').toUpperCase()
if (st === 'PENDING') return '排队中'
if (st === 'RUNNING') return '扫描中'
if (st === 'SUCCESS') return '完成'
if (st === 'FAIL') return '失败'
return st || '-'
})
const statusTagType = computed(() => {
const st = (progress.value?.status || '').toUpperCase()
if (st === 'SUCCESS') return 'success'
if (st === 'FAIL') return 'danger'
if (st === 'RUNNING' || st === 'PENDING') return 'warning'
return 'info'
})
const progressStatus = computed(() => {
const st = (progress.value?.status || '').toUpperCase()
if (st === 'SUCCESS') return 'success'
if (st === 'FAIL') return 'exception'
return undefined
})
const missingRows = computed(() => {
const list = progress.value?.missingTransferNos || []
return list.map(tn => ({ transferNo: tn }))
})
const canFillSearch = computed(() => {
return !running.value && (progress.value?.missingTransferNos || []).length > 0
})
function fillToSearch() {
const list = (progress.value?.missingTransferNos || [])
.map(s => String(s || '').trim())
.filter(Boolean)
if (!list.length) {
ElMessage.warning('暂无可回填的缺失转单号')
return
}
const truncated = !!(progress.value?.missingTruncated) || (Number(progress.value?.missing || 0) > list.length)
emit('fill-search', { transferNos: list, truncated })
visible.value = false
}
function clearTimer() {
if (timer) {
clearInterval(timer)
timer = null
}
}
function poll() {
if (!asyncTaskId.value) return
getOrderSourceCompareProgress(asyncTaskId.value).then(res => {
progress.value = res.data || {}
const st = (progress.value.status || '').toUpperCase()
if (st === 'SUCCESS' || st === 'FAIL') {
clearTimer()
}
}).catch(() => {})
}
function open(q) {
query.value = q || {}
asyncTaskId.value = ''
progress.value = {}
visible.value = true
starting.value = true
clearTimer()
compareOrderSourceByFilter(query.value).then(res => {
asyncTaskId.value = res.data?.asyncTaskId || ''
if (!asyncTaskId.value) {
ElMessage.error('启动比对任务失败')
return
}
progress.value = { status: 'PENDING', percent: 0, message: 'queued', scanned: 0, matched: 0, missing: 0 }
poll()
timer = setInterval(poll, 1500)
}).catch(() => {
ElMessage.error('启动比对任务失败')
}).finally(() => {
starting.value = false
})
}
function onClosed() {
clearTimer()
}
defineExpose({ open })
</script>
<style scoped>
.mb12 { margin-bottom: 12px; }
.summary-line {
margin-bottom: 6px;
font-weight: 600;
}
.msg-line {
margin-bottom: 8px;
color: var(--el-text-color-secondary);
font-size: 12px;
}
.err-line {
margin-bottom: 8px;
color: #f56c6c;
word-break: break-all;
}
.json-panel__head {
margin: 12px 0 6px;
font-weight: 600;
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
</style>
@@ -109,6 +109,10 @@ function actionLabel(row) {
}
if (action === 'ONE') return '单条同步'
if (action === 'ONE_FAIL') return '同步失败'
if (action === 'COMPARE') return '订单比对'
if (action === 'COMPARE_DONE') {
return row.status === 'FAIL' ? '比对完成(失败)' : '比对完成'
}
return action || '-'
}