修复商品风险多店铺问题

This commit is contained in:
super
2026-04-30 21:31:11 +08:00
parent b073bbe97d
commit 01bae23df5
17 changed files with 1392 additions and 46 deletions

View File

@@ -170,6 +170,7 @@ const parsing = ref(false)
const pushing = ref(false)
const queuePayloadText = ref('')
const pollingTaskIds = ref<number[]>([])
const pendingFileTaskIds = ref<number[]>([])
const pollTimer = ref<number | null>(null)
const pollingInFlight = ref(false)
let disposed = false
@@ -204,12 +205,14 @@ function pollingKey() {
function savePollingIds() {
if (typeof window === 'undefined') return
if (!pollingTaskIds.value.length) window.localStorage.removeItem(pollingKey())
else window.localStorage.setItem(pollingKey(), JSON.stringify(pollingTaskIds.value))
const ids = Array.from(new Set([...pollingTaskIds.value, ...pendingFileTaskIds.value]))
if (!ids.length) window.localStorage.removeItem(pollingKey())
else window.localStorage.setItem(pollingKey(), JSON.stringify(ids))
}
function clearPollingIds() {
pollingTaskIds.value = []
pendingFileTaskIds.value = []
savePollingIds()
stopPolling()
}
@@ -391,6 +394,18 @@ function removePollingTask(taskId: number) {
savePollingIds()
}
function addPendingFileTask(taskId: number) {
if (!pendingFileTaskIds.value.includes(taskId)) {
pendingFileTaskIds.value = [...pendingFileTaskIds.value, taskId]
savePollingIds()
}
}
function removePendingFileTask(taskId: number) {
pendingFileTaskIds.value = pendingFileTaskIds.value.filter((id) => id !== taskId)
savePollingIds()
}
function ensurePolling() {
if (disposed) return
if (pollTimer.value != null) return
@@ -414,9 +429,9 @@ function scheduleNextPoll(immediate = false) {
const run = async () => {
pollTimer.value = null
if (disposed) return
if (!pollingTaskIds.value.length) return
if (!pollingTaskIds.value.length && !pendingFileTaskIds.value.length) return
await refreshTaskProgress()
if (!disposed && pollingTaskIds.value.length) {
if (!disposed && (pollingTaskIds.value.length || pendingFileTaskIds.value.length)) {
pollTimer.value = timers.setTimeout('task-poll', run, getTaskPollIntervalMs())
}
}
@@ -425,34 +440,68 @@ function scheduleNextPoll(immediate = false) {
}
async function refreshTaskProgress() {
if (pollingInFlight.value || !pollingTaskIds.value.length) {
if (!pollingTaskIds.value.length) stopPolling()
if (pollingInFlight.value || (!pollingTaskIds.value.length && !pendingFileTaskIds.value.length)) {
if (!pollingTaskIds.value.length && !pendingFileTaskIds.value.length) stopPolling()
return
}
pollingInFlight.value = true
try {
const batch = await getAppearancePatentTaskProgressBatch(pollingTaskIds.value)
let hasTerminalTask = false
for (const detail of batch.items || []) {
const task = detail.task
if (!task?.id) continue
if (task.status === 'SUCCESS' || task.status === 'FAILED') {
removePollingTask(task.id)
hasTerminalTask = true
let shouldRefreshHistory = pendingFileTaskIds.value.length > 0
if (pollingTaskIds.value.length) {
const batch = await getAppearancePatentTaskProgressBatch(pollingTaskIds.value)
for (const detail of batch.items || []) {
const task = detail.task
if (!task?.id) continue
if (task.status === 'SUCCESS' || task.status === 'FAILED') {
removePollingTask(task.id)
shouldRefreshHistory = true
if (task.status === 'SUCCESS') addPendingFileTask(task.id)
}
}
if (batch.missingTaskIds?.length) {
batch.missingTaskIds.forEach((taskId) => {
removePollingTask(taskId)
removePendingFileTask(taskId)
})
shouldRefreshHistory = true
}
}
if (batch.missingTaskIds?.length) {
batch.missingTaskIds.forEach((taskId) => removePollingTask(taskId))
}
if (hasTerminalTask) {
if (shouldRefreshHistory) {
await loadDashboard()
await loadHistory()
settlePendingFileTasks()
}
} finally {
pollingInFlight.value = false
}
}
function settlePendingFileTasks() {
if (!pendingFileTaskIds.value.length) return
const remaining: number[] = []
for (const taskId of pendingFileTaskIds.value) {
const item = historyItems.value.find((row) => row.taskId === taskId)
if (!item) continue
const taskStatus = (item.taskStatus || '').toUpperCase()
const fileStatus = (item.fileStatus || '').toUpperCase()
if (taskStatus === 'FAILED' || item.fileReady || fileStatus === 'SUCCESS' || fileStatus === 'FAILED') {
continue
}
remaining.push(taskId)
}
pendingFileTaskIds.value = remaining
savePollingIds()
}
function seedPendingFileTasksFromHistory() {
const ids = historyItems.value
.filter((item) => item.taskId != null && isResultPreparing(item))
.map((item) => item.taskId as number)
pendingFileTaskIds.value = Array.from(new Set(ids))
savePollingIds()
if (pendingFileTaskIds.value.length) ensurePolling()
}
async function loadDashboard() {
dashboard.value = await getAppearancePatentDashboard()
}
@@ -551,6 +600,7 @@ onMounted(async () => {
loadDashboard().catch(() => undefined),
loadHistory().catch(() => undefined),
])
seedPendingFileTasksFromHistory()
})
onUnmounted(() => {

View File

@@ -940,9 +940,6 @@ async function runMatch() {
const batch = res.items || []
matchedItems.value = mergeMatchedItems(matchedItems.value, batch)
saveMatchedItemsToStorage()
if (autoQueueEnabled.value) {
void processMatchedQueue()
}
if (!batch.length) {
ElMessage.warning('未返回匹配结果')
} else {

View File

@@ -521,6 +521,7 @@ export function runDeleteBrand(
...request,
user_id: getCurrentUserId(),
},
{ timeout: 180000 },
),
);
}