feat(collect-routing): 前端按服务端开关分流「启动」到本地客户端或后台
- 新增 GET /api/collect-routing 封装与类型,两个工具页进页各读一次 - 外观专利页恢复本地推送链路(取队列载荷 → guard → activate → enqueue_json), 开关关闭时退回「提交后台执行」;按钮与提示文案随开关切换 - 相似ASIN 开关关闭时只建单不推队列,等 Linux 后台认领 - queue-payload / activate 端点与 DTO 从 943cf2d62^ 原样恢复 - catch 棘轮 blocks 301→303:新增两支都有用户可见出口,silent 未变
This commit is contained in:
@@ -22,10 +22,14 @@
|
|||||||
{{ parsing ? '解析中...' : '解析并创建任务' }}
|
{{ parsing ? '解析中...' : '解析并创建任务' }}
|
||||||
</button>
|
</button>
|
||||||
<button type="button" class="btn-run btn-queue" :disabled="pushing || !parseResult?.taskId" @click="pushToPythonQueue">
|
<button type="button" class="btn-run btn-queue" :disabled="pushing || !parseResult?.taskId" @click="pushToPythonQueue">
|
||||||
{{ pushing ? '提交中...' : '提交后台执行' }}
|
{{ pushing ? (localCollectEnabled ? '启动中...' : '提交中...') : (localCollectEnabled ? '启动任务' : '提交后台执行') }}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<p class="loading-msg">提交后系统自动分批检测,进度显示在右侧任务区,完成后可下载结果。</p>
|
<p class="loading-msg">
|
||||||
|
{{ localCollectEnabled
|
||||||
|
? '启动后任务推送到本机客户端采集,进度显示在右侧任务区,完成后可下载结果。'
|
||||||
|
: '提交后系统自动分批检测,进度显示在右侧任务区,完成后可下载结果。' }}
|
||||||
|
</p>
|
||||||
|
|
||||||
<div v-if="visibleTaskSummary" class="parse-card">
|
<div v-if="visibleTaskSummary" class="parse-card">
|
||||||
<div>任务 ID:{{ visibleTaskSummary.taskId }}</div>
|
<div>任务 ID:{{ visibleTaskSummary.taskId }}</div>
|
||||||
@@ -80,17 +84,21 @@ import ModuleTemplateDownload from '@/shared/components/ModuleTemplateDownload.v
|
|||||||
import TaskCenterPanel from '@/shared/components/tasks/TaskCenterPanel.vue'
|
import TaskCenterPanel from '@/shared/components/tasks/TaskCenterPanel.vue'
|
||||||
import type { TaskItemView, TaskStatCard } from '@/shared/components/tasks/types'
|
import type { TaskItemView, TaskStatCard } from '@/shared/components/tasks/types'
|
||||||
import {
|
import {
|
||||||
|
activateAppearancePatentTask,
|
||||||
deleteAppearancePatentHistory,
|
deleteAppearancePatentHistory,
|
||||||
deleteAppearancePatentTask,
|
deleteAppearancePatentTask,
|
||||||
getAppearancePatentDashboard,
|
getAppearancePatentDashboard,
|
||||||
getAppearancePatentHistory,
|
getAppearancePatentHistory,
|
||||||
|
getAppearancePatentQueuePayload,
|
||||||
getAppearancePatentResultDownloadUrl,
|
getAppearancePatentResultDownloadUrl,
|
||||||
getAppearancePatentTaskProgressBatch,
|
getAppearancePatentTaskProgressBatch,
|
||||||
parseAppearancePatent,
|
parseAppearancePatent,
|
||||||
type AppearancePatentHistoryItem,
|
type AppearancePatentHistoryItem,
|
||||||
type AppearancePatentParseVo,
|
type AppearancePatentParseVo,
|
||||||
|
type AppearancePatentParsedPayloadDto,
|
||||||
type UploadedFileRef,
|
type UploadedFileRef,
|
||||||
} from '@/shared/api/java-modules'
|
} from '@/shared/api/java-modules'
|
||||||
|
import { getCollectRouting } from '@/shared/api/types/modules/collect-routing'
|
||||||
import { getPywebviewApi } from '@/shared/bridges/pywebview'
|
import { getPywebviewApi } from '@/shared/bridges/pywebview'
|
||||||
import { useExcelFileUpload } from '@/shared/composables/useExcelFileUpload'
|
import { useExcelFileUpload } from '@/shared/composables/useExcelFileUpload'
|
||||||
import {
|
import {
|
||||||
@@ -101,7 +109,7 @@ import {
|
|||||||
} from '@/shared/composables/useLiveTaskBoard'
|
} from '@/shared/composables/useLiveTaskBoard'
|
||||||
import { getModuleProgressLight } from '@/shared/api/progress-light.ts'
|
import { getModuleProgressLight } from '@/shared/api/progress-light.ts'
|
||||||
import { createRowsVersionTracker } from '@/shared/api/task-progress-polling.ts'
|
import { createRowsVersionTracker } from '@/shared/api/task-progress-polling.ts'
|
||||||
import { checkParseResult } from '@/shared/dispatch-guard'
|
import { checkParseResult, checkQueuePayload } from '@/shared/dispatch-guard'
|
||||||
import { passGuard } from '@/shared/dispatch-guard-ui'
|
import { passGuard } from '@/shared/dispatch-guard-ui'
|
||||||
import { formatDateTime } from '@/shared/utils/datetime'
|
import { formatDateTime } from '@/shared/utils/datetime'
|
||||||
import { resultBuildFailed, taskStatusClass, taskStatusText } from '@/shared/utils/task-status-text'
|
import { resultBuildFailed, taskStatusClass, taskStatusText } from '@/shared/utils/task-status-text'
|
||||||
@@ -135,6 +143,12 @@ const queuedTaskSummary = ref<TaskSummary | null>(null)
|
|||||||
const aiPrompt = ref('')
|
const aiPrompt = ref('')
|
||||||
const parsing = ref(false)
|
const parsing = ref(false)
|
||||||
const pushing = ref(false)
|
const pushing = ref(false)
|
||||||
|
/**
|
||||||
|
* 本地采集开关(服务端 aiimage.collect-routing.local-enabled,默认开)。
|
||||||
|
* 先按「本地」渲染,取不到配置也不改口:真正兜底在服务端——开关关着时 activate 会明确拒绝,
|
||||||
|
* 页面最多多报一次错,不会把任务推给不该跑本地的机器。
|
||||||
|
*/
|
||||||
|
const localCollectEnabled = ref(true)
|
||||||
|
|
||||||
/** 结果行版本跟踪(审查 F5 后续):版本未变的任务跳过行明细拉取 */
|
/** 结果行版本跟踪(审查 F5 后续):版本未变的任务跳过行明细拉取 */
|
||||||
const rowsVersionTracker = createRowsVersionTracker()
|
const rowsVersionTracker = createRowsVersionTracker()
|
||||||
@@ -459,17 +473,97 @@ async function pushToPythonQueue() {
|
|||||||
ElMessage.warning('请先解析文件')
|
ElMessage.warning('请先解析文件')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 2026-09-30 外观专利已迁移 Linux 后台执行(无浏览器抓取):
|
if (!localCollectEnabled.value) {
|
||||||
// 「启动」不再推送客户端队列,任务保持 PENDING,由服务端内部认领
|
// 本地采集关闭:只建单,任务保持 PENDING 由 Linux 后台认领
|
||||||
// (/api/internal/tasks/pull-pending + 主机B maixiang-ap worker)在等待窗口后自动接管。
|
// (/api/internal/tasks/pull-pending + 主机B maixiang-ap worker)在等待窗口后自动接管。
|
||||||
|
pushing.value = true
|
||||||
|
try {
|
||||||
|
queuedTaskSummary.value = toTaskSummary(currentParseResult)
|
||||||
|
board.addPollingTask(taskId)
|
||||||
|
clearParsedTask()
|
||||||
|
await board.loadDashboard()
|
||||||
|
await board.loadHistory({ force: true })
|
||||||
|
ElMessage.success('已提交,后台自动执行中(无需打开浏览器)')
|
||||||
|
} finally {
|
||||||
|
pushing.value = false
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const api = getPywebviewApi()
|
||||||
|
if (!api?.enqueue_json) {
|
||||||
|
ElMessage.error('当前环境未启用 pywebview enqueue_json,请在本地客户端中打开本页后再启动')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!effectiveLlmApiKey()) {
|
||||||
|
// 本地无明文不再阻断:服务端已保存该用户密钥,任务执行时按 uid 兜底读取
|
||||||
|
console.log('[appearance-patent] 本地无密钥明文,启动任务由服务端兜底')
|
||||||
|
}
|
||||||
pushing.value = true
|
pushing.value = true
|
||||||
try {
|
try {
|
||||||
|
const parsedPayload: AppearancePatentParsedPayloadDto = await getAppearancePatentQueuePayload(taskId)
|
||||||
|
const groups = parsedPayload.groups || []
|
||||||
|
const payload = {
|
||||||
|
type: 'appearance-patent-run',
|
||||||
|
ts: Date.now(),
|
||||||
|
data: {
|
||||||
|
taskId,
|
||||||
|
prompt: aiPrompt.value.trim(),
|
||||||
|
api_key: effectiveLlmApiKey(),
|
||||||
|
sourceFileCount: currentParseResult.sourceFileCount || 0,
|
||||||
|
totalRows: currentParseResult.totalRows || 0,
|
||||||
|
acceptedRows: currentParseResult.acceptedRows || 0,
|
||||||
|
groupCount: currentParseResult.groupCount || 0,
|
||||||
|
groups: groups.map((group) => ({
|
||||||
|
sourceFileKey: group.sourceFileKey || '',
|
||||||
|
sourceFilename: group.sourceFilename || '',
|
||||||
|
groupKey: group.groupKey || '',
|
||||||
|
baseId: group.baseId || '',
|
||||||
|
displayId: group.displayId || '',
|
||||||
|
items: (group.items || []).map((row) => ({
|
||||||
|
sourceFileKey: row.sourceFileKey || '',
|
||||||
|
sourceFilename: row.sourceFilename || '',
|
||||||
|
rowToken: row.rowToken || '',
|
||||||
|
groupKey: row.groupKey || '',
|
||||||
|
id: row.displayId,
|
||||||
|
asin: row.asin,
|
||||||
|
country: row.country,
|
||||||
|
sku: row.sku || '',
|
||||||
|
url: row.url || '',
|
||||||
|
title: row.title || '',
|
||||||
|
})),
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
// 后端返回的 groups 为空时推送出去,Python 端没有可执行批次会一直停在执行中
|
||||||
|
const guard = checkQueuePayload(payload, {
|
||||||
|
expectedType: 'appearance-patent-run',
|
||||||
|
// api_key 不列为必填:密钥已服务端化,本地无明文时由服务端按 uid 兜底
|
||||||
|
requiredDataKeys: ['taskId'],
|
||||||
|
nonEmptyArrayKeys: ['groups'],
|
||||||
|
})
|
||||||
|
if (!(await passGuard(guard))) return
|
||||||
|
// 任务可能已被客户端「兜底拉取」/Linux 兜底领走:服务端会拒绝 activate,
|
||||||
|
// 此时必须直接返回,不能再入队,否则同一任务会被执行两次
|
||||||
|
try {
|
||||||
|
await activateAppearancePatentTask(taskId)
|
||||||
|
} catch (activateError) {
|
||||||
|
ElMessage.warning(activateError instanceof Error ? activateError.message : '任务已在执行中,无需重复启动')
|
||||||
|
await Promise.all([board.loadDashboard(), board.loadHistory({ force: true })])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const result = await api.enqueue_json(payload)
|
||||||
|
if (!result?.success) {
|
||||||
|
ElMessage.error(userNotice(result?.error, '启动失败'))
|
||||||
|
return
|
||||||
|
}
|
||||||
queuedTaskSummary.value = toTaskSummary(currentParseResult)
|
queuedTaskSummary.value = toTaskSummary(currentParseResult)
|
||||||
board.addPollingTask(taskId)
|
board.addPollingTask(taskId)
|
||||||
clearParsedTask()
|
clearParsedTask()
|
||||||
await board.loadDashboard()
|
await board.loadDashboard()
|
||||||
await board.loadHistory({ force: true })
|
await board.loadHistory({ force: true })
|
||||||
ElMessage.success('已提交,后台自动执行中(无需打开浏览器)')
|
ElMessage.success('已启动任务')
|
||||||
|
} catch (e) {
|
||||||
|
ElMessage.error(e instanceof Error ? e.message : '启动失败')
|
||||||
} finally {
|
} finally {
|
||||||
pushing.value = false
|
pushing.value = false
|
||||||
}
|
}
|
||||||
@@ -483,6 +577,14 @@ const { batchDeleteHistory, deleteTaskRecord, downloadResult } = board
|
|||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
board.loadPollingIds()
|
board.loadPollingIds()
|
||||||
|
// 本地采集开关:读不到就按「本地」渲染,服务端 activate 会兜底拒绝,不至于误推给后台
|
||||||
|
getCollectRouting()
|
||||||
|
.then((routing) => {
|
||||||
|
localCollectEnabled.value = routing.appearancePatentLocal !== false
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.warn('[appearance-patent] 读取本地采集开关失败,按本地采集处理', error)
|
||||||
|
})
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
board.loadDashboard().catch(() => undefined),
|
board.loadDashboard().catch(() => undefined),
|
||||||
board.loadHistory().catch(() => undefined),
|
board.loadHistory().catch(() => undefined),
|
||||||
|
|||||||
@@ -60,10 +60,14 @@
|
|||||||
</button>
|
</button>
|
||||||
<button type="button" class="btn-run btn-queue" :disabled="pushing || !parseResult?.taskId"
|
<button type="button" class="btn-run btn-queue" :disabled="pushing || !parseResult?.taskId"
|
||||||
@click="pushToPythonQueue">
|
@click="pushToPythonQueue">
|
||||||
{{ pushing ? '启动中...' : '启动任务' }}
|
{{ pushing ? (localCollectEnabled ? '启动中...' : '提交中...') : (localCollectEnabled ? '启动任务' : '提交后台执行') }}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<p class="loading-msg">提交后系统自动分批检测,进度显示在右侧任务区,完成后可下载结果。</p>
|
<p class="loading-msg">
|
||||||
|
{{ localCollectEnabled
|
||||||
|
? '提交后系统自动分批检测,进度显示在右侧任务区,完成后可下载结果。'
|
||||||
|
: '提交后由后台自动分批检测,进度显示在右侧任务区,完成后可下载结果。' }}
|
||||||
|
</p>
|
||||||
|
|
||||||
<div v-if="visibleTaskSummary" class="parse-card">
|
<div v-if="visibleTaskSummary" class="parse-card">
|
||||||
<div>任务 ID:{{ visibleTaskSummary.taskId }}</div>
|
<div>任务 ID:{{ visibleTaskSummary.taskId }}</div>
|
||||||
@@ -146,6 +150,7 @@ import {
|
|||||||
checkQueuePayload,
|
checkQueuePayload,
|
||||||
} from '@/shared/dispatch-guard'
|
} from '@/shared/dispatch-guard'
|
||||||
import { passGuard } from '@/shared/dispatch-guard-ui'
|
import { passGuard } from '@/shared/dispatch-guard-ui'
|
||||||
|
import { getCollectRouting } from '@/shared/api/types/modules/collect-routing'
|
||||||
import { formatDateTime } from '@/shared/utils/datetime'
|
import { formatDateTime } from '@/shared/utils/datetime'
|
||||||
import { isCompletedTask, resultBuildFailed, taskStatusClass, taskStatusText } from '@/shared/utils/task-status-text'
|
import { isCompletedTask, resultBuildFailed, taskStatusClass, taskStatusText } from '@/shared/utils/task-status-text'
|
||||||
import { getStoredApiSecret } from '@/shared/utils/api-secret-store'
|
import { getStoredApiSecret } from '@/shared/utils/api-secret-store'
|
||||||
@@ -182,6 +187,11 @@ type TaskSummary = Pick<SimilarAsinParseVo, 'taskId' | 'totalRows' | 'acceptedRo
|
|||||||
const queuedTaskSummary = ref<TaskSummary | null>(null)
|
const queuedTaskSummary = ref<TaskSummary | null>(null)
|
||||||
const parsing = ref(false)
|
const parsing = ref(false)
|
||||||
const pushing = ref(false)
|
const pushing = ref(false)
|
||||||
|
/**
|
||||||
|
* 本地采集开关(服务端 aiimage.collect-routing.local-enabled,默认开)。
|
||||||
|
* 先按「本地」渲染,取不到配置也不改口:服务端 activate 在开关关着时会明确拒绝。
|
||||||
|
*/
|
||||||
|
const localCollectEnabled = ref(true)
|
||||||
const imgSwitch = ref(false)
|
const imgSwitch = ref(false)
|
||||||
const categorySwitch = ref(false)
|
const categorySwitch = ref(false)
|
||||||
const alipriceUsername = ref('')
|
const alipriceUsername = ref('')
|
||||||
@@ -522,6 +532,21 @@ async function pushToPythonQueue() {
|
|||||||
ElMessage.warning('请先解析文件')
|
ElMessage.warning('请先解析文件')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (!localCollectEnabled.value) {
|
||||||
|
// 本地采集关闭:只建单,任务保持 PENDING 由 Linux 后台认领
|
||||||
|
pushing.value = true
|
||||||
|
try {
|
||||||
|
queuedTaskSummary.value = toTaskSummary(currentParseResult)
|
||||||
|
board.addPollingTask(taskId)
|
||||||
|
clearParsedTask()
|
||||||
|
await board.loadDashboard()
|
||||||
|
await board.loadHistory({ force: true })
|
||||||
|
ElMessage.success('已提交,后台自动执行中')
|
||||||
|
} finally {
|
||||||
|
pushing.value = false
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
if (!api?.enqueue_json) {
|
if (!api?.enqueue_json) {
|
||||||
ElMessage.error('当前环境未启用 pywebview enqueue_json')
|
ElMessage.error('当前环境未启用 pywebview enqueue_json')
|
||||||
return
|
return
|
||||||
@@ -657,6 +682,14 @@ onMounted(async () => {
|
|||||||
}
|
}
|
||||||
window.addEventListener('pywebviewready', pywebviewReadyHandler)
|
window.addEventListener('pywebviewready', pywebviewReadyHandler)
|
||||||
}
|
}
|
||||||
|
// 本地采集开关:读不到就按「本地」渲染,服务端 activate 会兜底拒绝,不至于误推给后台
|
||||||
|
getCollectRouting()
|
||||||
|
.then((routing) => {
|
||||||
|
localCollectEnabled.value = routing.similarAsinLocal !== false
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.warn('[similar-asin] 读取本地采集开关失败,按本地采集处理', error)
|
||||||
|
})
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
board.loadDashboard().catch(() => undefined),
|
board.loadDashboard().catch(() => undefined),
|
||||||
board.loadHistory().catch(() => undefined),
|
board.loadHistory().catch(() => undefined),
|
||||||
|
|||||||
@@ -190,14 +190,20 @@ export const API_ENDPOINTS = {
|
|||||||
},
|
},
|
||||||
appearancePatent: {
|
appearancePatent: {
|
||||||
parse: '/api/appearance-patent/parse',
|
parse: '/api/appearance-patent/parse',
|
||||||
|
queuePayload: '/api/appearance-patent/tasks/{taskId}/queue-payload',
|
||||||
dashboard: '/api/appearance-patent/dashboard',
|
dashboard: '/api/appearance-patent/dashboard',
|
||||||
history: '/api/appearance-patent/history',
|
history: '/api/appearance-patent/history',
|
||||||
historyDelete: '/api/appearance-patent/history/{resultId}',
|
historyDelete: '/api/appearance-patent/history/{resultId}',
|
||||||
progressBatch: '/api/appearance-patent/tasks/progress/batch',
|
progressBatch: '/api/appearance-patent/tasks/progress/batch',
|
||||||
progressLight: '/api/appearance-patent/tasks/progress/light',
|
progressLight: '/api/appearance-patent/tasks/progress/light',
|
||||||
|
taskActivate: '/api/appearance-patent/tasks/{taskId}/activate',
|
||||||
taskDelete: '/api/appearance-patent/tasks/{taskId}',
|
taskDelete: '/api/appearance-patent/tasks/{taskId}',
|
||||||
resultDownload: '/api/appearance-patent/results/{resultId}/download',
|
resultDownload: '/api/appearance-patent/results/{resultId}/download',
|
||||||
},
|
},
|
||||||
|
/** 专利/货源的本地采集开关(服务端唯一真源,前端只读)。 */
|
||||||
|
collectRouting: {
|
||||||
|
get: '/api/collect-routing',
|
||||||
|
},
|
||||||
userSecret: {
|
userSecret: {
|
||||||
bundle: '/api/user-secrets',
|
bundle: '/api/user-secrets',
|
||||||
save: '/api/user-secrets/{moduleKey}',
|
save: '/api/user-secrets/{moduleKey}',
|
||||||
|
|||||||
@@ -33,6 +33,16 @@ export interface AppearancePatentParsedGroup {
|
|||||||
items: AppearancePatentParsedRow[];
|
items: AppearancePatentParsedRow[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface AppearancePatentParsedPayloadDto {
|
||||||
|
aiPrompt?: string;
|
||||||
|
apiKey?: string;
|
||||||
|
sourceFiles?: UploadedFileRef[];
|
||||||
|
headers?: string[];
|
||||||
|
items?: AppearancePatentParsedRow[];
|
||||||
|
groups?: AppearancePatentParsedGroup[];
|
||||||
|
allItems?: AppearancePatentParsedRow[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface AppearancePatentParseVo {
|
export interface AppearancePatentParseVo {
|
||||||
taskId: number;
|
taskId: number;
|
||||||
sourceFilename?: string;
|
sourceFilename?: string;
|
||||||
@@ -180,8 +190,30 @@ export function parseAppearancePatent(files: UploadedFileRef[], aiPrompt: string
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getAppearancePatentDashboard() {
|
/**
|
||||||
|
* 本地采集模式下推本机客户端队列的载荷:只含 Python 当前需要的分组,
|
||||||
|
* 由 /queue-payload 按 taskId 现取,避免前端搬运完整解析大数据。
|
||||||
|
*/
|
||||||
|
export function getAppearancePatentQueuePayload(taskId: number) {
|
||||||
return unwrapJavaResponse(
|
return unwrapJavaResponse(
|
||||||
|
get<JavaApiResponse<AppearancePatentParsedPayloadDto>>(
|
||||||
|
buildJavaUrl(API_ENDPOINTS.appearancePatent.queuePayload.replace('{taskId}', String(taskId))),
|
||||||
|
{ params: { user_id: getCurrentUserId() } },
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 本地采集:推送客户端队列前把任务从 PENDING 翻成 RUNNING(与后台认领互斥)。 */
|
||||||
|
export function activateAppearancePatentTask(taskId: number) {
|
||||||
|
return unwrapJavaResponse(
|
||||||
|
post<JavaApiResponse<null>, undefined>(
|
||||||
|
`${JAVA_API_PREFIX}/appearance-patent/tasks/${taskId}/activate?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||||
|
undefined,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getAppearancePatentDashboard() { return unwrapJavaResponse(
|
||||||
get<JavaApiResponse<AppearancePatentDashboardVo>>(
|
get<JavaApiResponse<AppearancePatentDashboardVo>>(
|
||||||
buildJavaUrl(API_ENDPOINTS.appearancePatent.dashboard),
|
buildJavaUrl(API_ENDPOINTS.appearancePatent.dashboard),
|
||||||
{ params: { user_id: getCurrentUserId() } },
|
{ params: { user_id: getCurrentUserId() } },
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { get, type JavaApiResponse, unwrapJavaResponse } from '../../http.ts'
|
||||||
|
import { buildJavaUrl } from '../../url.ts'
|
||||||
|
import { API_ENDPOINTS } from '../../endpoints.ts'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 专利/货源的本地采集开关(服务端唯一真源,前端只读)。
|
||||||
|
*
|
||||||
|
* 开着=页面把任务推本机客户端队列;关着=只建单、等 Linux 后台认领。
|
||||||
|
* 每次进页面现取,不做模块级缓存:运维改开关后用户刷新页面就该看到新口径,
|
||||||
|
* 一次小 GET 不值得换一个「改了没生效」的排查成本。
|
||||||
|
*/
|
||||||
|
export interface CollectRoutingVo {
|
||||||
|
appearancePatentLocal: boolean;
|
||||||
|
similarAsinLocal: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getCollectRouting() {
|
||||||
|
return unwrapJavaResponse(
|
||||||
|
get<JavaApiResponse<CollectRoutingVo>>(buildJavaUrl(API_ENDPOINTS.collectRouting.get)),
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -36,7 +36,12 @@ const BASELINE = {
|
|||||||
// ——错误既没被吞也没被 console 糊过去(catch 体只做 `lastError = error`,片循环外 throw),
|
// ——错误既没被吞也没被 console 糊过去(catch 体只做 `lastError = error`,片循环外 throw),
|
||||||
// 所以 silent 一格没涨,只进 blocks。断点探测那一步刻意没写 try/catch:问不到已达片号就当场
|
// 所以 silent 一格没涨,只进 blocks。断点探测那一步刻意没写 try/catch:问不到已达片号就当场
|
||||||
// 报错,不闷头把整包从 0 重传。
|
// 报错,不闷头把整包从 0 重传。
|
||||||
blocks: 301,
|
// 303 = 301 + 外观专利页恢复「本地采集」推送链(10-29 采集路由开关)新增的两支 try/catch:
|
||||||
|
// ① 外层包住取队列载荷 + 推送客户端,失败就地 ElMessage.error 报给用户;
|
||||||
|
// ② activate 被服务端拒绝(任务已被兜底拉取/Linux 领走)时 ElMessage.warning 并中止入队,
|
||||||
|
// 防同一任务执行两次。
|
||||||
|
// silent 一格没涨:两支都有用户可见出口,只进 blocks。
|
||||||
|
blocks: 303,
|
||||||
// 298 = 296 + 全局错误出口 app-error.ts 的两支新 try/catch(10-09 装 app.config.errorHandler /
|
// 298 = 296 + 全局错误出口 app-error.ts 的两支新 try/catch(10-09 装 app.config.errorHandler /
|
||||||
// window.onerror / unhandledrejection 时引入),两支都不是"吞":
|
// window.onerror / unhandledrejection 时引入),两支都不是"吞":
|
||||||
// ① String(reason) 对无 toString 的对象/Symbol 会抛,兜法返回一句中文占位文本,
|
// ① String(reason) 对无 toString 的对象/Symbol 会抛,兜法返回一句中文占位文本,
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import { test } from 'node:test'
|
||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import { http } from '../src/shared/api/http.ts'
|
||||||
|
import { getCollectRouting } from '../src/shared/api/types/modules/collect-routing.ts'
|
||||||
|
|
||||||
|
function setupWindow() {
|
||||||
|
;(globalThis as Record<string, unknown>).window = {
|
||||||
|
localStorage: { getItem: () => '42' },
|
||||||
|
location: { origin: 'http://localhost' },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function mockRequest(
|
||||||
|
t: Parameters<typeof test>[1] extends (t: infer T) => unknown ? T : never,
|
||||||
|
impl: (config: { url?: string; method?: string; params?: Record<string, unknown> }) => Promise<unknown>,
|
||||||
|
) {
|
||||||
|
t.mock.method(http, 'request', impl as never)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 采集路由开关读取口:前端两个工具页据这两个布尔决定「启动」走本地客户端还是后台。
|
||||||
|
* 只钉 URL 与返回值原样透传——开关真值来自服务端,前端不自己造默认。
|
||||||
|
*/
|
||||||
|
test('test_collect_routing_url_and_payload', async (t) => {
|
||||||
|
setupWindow()
|
||||||
|
let captured: { url?: string; method?: string } = {}
|
||||||
|
mockRequest(t, (config) => {
|
||||||
|
captured = config
|
||||||
|
return Promise.resolve({
|
||||||
|
data: { success: true, message: 'ok', data: { appearancePatentLocal: true, similarAsinLocal: false } },
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const routing = await getCollectRouting()
|
||||||
|
|
||||||
|
assert.equal(captured.url, '/newApi/api/collect-routing')
|
||||||
|
assert.equal(captured.method, 'GET')
|
||||||
|
assert.equal(routing.appearancePatentLocal, true)
|
||||||
|
assert.equal(routing.similarAsinLocal, false)
|
||||||
|
})
|
||||||
@@ -299,14 +299,19 @@ test('test_endpoints_frozen_snapshot', () => {
|
|||||||
},
|
},
|
||||||
"appearancePatent": {
|
"appearancePatent": {
|
||||||
"parse": "/api/appearance-patent/parse",
|
"parse": "/api/appearance-patent/parse",
|
||||||
|
"queuePayload": "/api/appearance-patent/tasks/{taskId}/queue-payload",
|
||||||
"dashboard": "/api/appearance-patent/dashboard",
|
"dashboard": "/api/appearance-patent/dashboard",
|
||||||
"history": "/api/appearance-patent/history",
|
"history": "/api/appearance-patent/history",
|
||||||
"historyDelete": "/api/appearance-patent/history/{resultId}",
|
"historyDelete": "/api/appearance-patent/history/{resultId}",
|
||||||
"progressBatch": "/api/appearance-patent/tasks/progress/batch",
|
"progressBatch": "/api/appearance-patent/tasks/progress/batch",
|
||||||
"progressLight": "/api/appearance-patent/tasks/progress/light",
|
"progressLight": "/api/appearance-patent/tasks/progress/light",
|
||||||
|
"taskActivate": "/api/appearance-patent/tasks/{taskId}/activate",
|
||||||
"taskDelete": "/api/appearance-patent/tasks/{taskId}",
|
"taskDelete": "/api/appearance-patent/tasks/{taskId}",
|
||||||
"resultDownload": "/api/appearance-patent/results/{resultId}/download"
|
"resultDownload": "/api/appearance-patent/results/{resultId}/download"
|
||||||
},
|
},
|
||||||
|
"collectRouting": {
|
||||||
|
"get": "/api/collect-routing"
|
||||||
|
},
|
||||||
"userSecret": {
|
"userSecret": {
|
||||||
"bundle": "/api/user-secrets",
|
"bundle": "/api/user-secrets",
|
||||||
"save": "/api/user-secrets/{moduleKey}",
|
"save": "/api/user-secrets/{moduleKey}",
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import {
|
|||||||
getAppearancePatentDashboard,
|
getAppearancePatentDashboard,
|
||||||
getAppearancePatentHistory,
|
getAppearancePatentHistory,
|
||||||
getAppearancePatentTaskProgressBatch,
|
getAppearancePatentTaskProgressBatch,
|
||||||
|
getAppearancePatentQueuePayload,
|
||||||
|
activateAppearancePatentTask,
|
||||||
deleteAppearancePatentTask,
|
deleteAppearancePatentTask,
|
||||||
deleteAppearancePatentHistory,
|
deleteAppearancePatentHistory,
|
||||||
getAppearancePatentResultDownloadUrl,
|
getAppearancePatentResultDownloadUrl,
|
||||||
@@ -92,6 +94,31 @@ test('test_appearance_patent_delete_task_history', async (t) => {
|
|||||||
assert.deepEqual(calls[1].params, { user_id: 42 })
|
assert.deepEqual(calls[1].params, { user_id: 42 })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('test_appearance_patent_queue_payload_url', async (t) => {
|
||||||
|
setupWindow()
|
||||||
|
let captured: { url?: string; method?: string; params?: Record<string, unknown> } = {}
|
||||||
|
mockRequest(t, (config) => {
|
||||||
|
captured = config
|
||||||
|
return okResponse({ groups: [] })
|
||||||
|
})
|
||||||
|
await getAppearancePatentQueuePayload(7)
|
||||||
|
assert.equal(captured.url, '/newApi/api/appearance-patent/tasks/7/queue-payload')
|
||||||
|
assert.equal(captured.method, 'GET')
|
||||||
|
assert.deepEqual(captured.params, { user_id: 42 })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('test_appearance_patent_activate', async (t) => {
|
||||||
|
setupWindow()
|
||||||
|
let captured: { url?: string; method?: string } = {}
|
||||||
|
mockRequest(t, (config) => {
|
||||||
|
captured = config
|
||||||
|
return okResponse(null)
|
||||||
|
})
|
||||||
|
await activateAppearancePatentTask(7)
|
||||||
|
assert.equal(captured.url, '/newApi/api/appearance-patent/tasks/7/activate?user_id=42')
|
||||||
|
assert.equal(captured.method, 'POST')
|
||||||
|
})
|
||||||
|
|
||||||
test('test_appearance_patent_download_url', async (t) => {
|
test('test_appearance_patent_download_url', async (t) => {
|
||||||
setupWindow()
|
setupWindow()
|
||||||
const url = getAppearancePatentResultDownloadUrl(7)
|
const url = getAppearancePatentResultDownloadUrl(7)
|
||||||
@@ -105,6 +132,7 @@ test('test_appearance_patent_export_compat', async (t) => {
|
|||||||
const names = [
|
const names = [
|
||||||
'parseAppearancePatent',
|
'parseAppearancePatent',
|
||||||
'getAppearancePatentDashboard', 'getAppearancePatentHistory', 'getAppearancePatentTaskProgressBatch',
|
'getAppearancePatentDashboard', 'getAppearancePatentHistory', 'getAppearancePatentTaskProgressBatch',
|
||||||
|
'getAppearancePatentQueuePayload', 'activateAppearancePatentTask',
|
||||||
'deleteAppearancePatentTask', 'deleteAppearancePatentHistory',
|
'deleteAppearancePatentTask', 'deleteAppearancePatentHistory',
|
||||||
'getAppearancePatentResultDownloadUrl',
|
'getAppearancePatentResultDownloadUrl',
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user