fix(看板): 任务状态收成三态,外观专利终态进度带真实状态落库
两次定案方向相反,所以分开钉:主看板只要 执行中/成功/失败 三态(其他状态不再当筛选项); 变体采集那页反过来——撤掉「在跑=0∪1 合并」口径,直接显示 待执行/处理中/成功/失败, 历史终态也要能看到。 - 后端 statusFilter 做同义词展开:成功 = SUCCESS∪COMPLETED,失败 = FAILED∪ERROR∪CANCELLED (取消=没成功也不在跑,并入失败),展开只住这一处,页面模型不再各自 if。前端筛选项随之 收成 全部/执行中/成功/失败 四项(原 待执行/执行中/已排期/已完成/已取消 那一排撤掉)。 - 变体采集:不传 status = 全部状态,后端原样直查麦象(含历史终态),不再有 0∪1 合并哨兵; 前端选项与 label 同步改。上线顺序仍是先 jar 后前端——新前端发 ACTIVE 打旧 jar 会整页空。 - AppearancePatentTaskService.saveFileBuildProgress 的终态必须带任务真实状态落库:save() 只对 终态豁免 500ms 节流,而收尾三连写(组装/上传/完成)都在同一次调用里,若全按 RUNNING 写 就只有第一条落地,满格「结果文件已生成」必被吞——2026-10-04 生产实测的「已完成 0/130、 57/59」就是这么来的。对齐货源查询侧的 isTerminalFileBuildProgress。 - 节流侧补一条用例钉住"终态不受节流",模块侧补一条钉住"终态写的是任务状态而不是 RUNNING"—— 这两条分别在 service 与 mapper 出口,任一处回退都会红。 验证:后端定向 4 类 53/0(外观终态快照 4、进度节流 9、看板查询 34、变体采集 6;与批次①同一轮 mvn 197 例 0 红);admin-frontend-vue 定向 task-center-board 25/0(含三态选项、默认视图、 汇总卡口径)、全量 1726 例中本批 0 红。
This commit is contained in:
@@ -25,6 +25,7 @@ import {
|
||||
VARIANT_STATUS_OPTIONS,
|
||||
buildTaskQuery,
|
||||
buildVariantQuery,
|
||||
countryLabel,
|
||||
createTaskFilter,
|
||||
createVariantFilter,
|
||||
deviceDisplayName,
|
||||
@@ -50,7 +51,7 @@ const activeTab = ref<BoardTab>('tasks')
|
||||
|
||||
const overview = ref<TaskCenterOverview | null>(null)
|
||||
const shopOptions = ref<string[]>([])
|
||||
/** 默认视图 = 只看在跑(合并哨兵,后端展开成三个进行中状态),**不锁创建时间**:
|
||||
/** 默认视图 = 只看执行中(合并哨兵,后端展开成三个进行中状态),**不锁创建时间**:
|
||||
* 卡片「进行中任务」的 SQL 不带时间窗,锁当天必然比卡片少一截(10-04 实测 21 vs 39,
|
||||
* 差的 18 个是跨天仍在上报的长任务)。历史状态与时间窗仍在筛选里,用户自己选。 */
|
||||
function defaultTaskFilter(): TaskCenterTaskFilter {
|
||||
@@ -282,7 +283,7 @@ onUnmounted(() => {
|
||||
客户端任务 <span class="t-count" title="当前在跑任务数,与上方「进行中任务」同源">{{ runningBadge ?? '—' }}</span>
|
||||
</button>
|
||||
<button class="tab" :class="{ active: activeTab === 'variant' }" type="button" @click="switchTab('variant')">
|
||||
变体采集 <span class="t-count" title="麦象在跑批量任务条数(等待执行∪处理中),「—」= 还没查到">{{ variantTotal ?? '—' }}</span>
|
||||
变体采集 <span class="t-count" title="麦象变体采集任务条数(全部状态),「—」= 还没查到">{{ variantTotal ?? '—' }}</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="tc-head-tools">
|
||||
@@ -327,7 +328,7 @@ onUnmounted(() => {
|
||||
<section class="panel-box">
|
||||
<div class="box-head">
|
||||
<h3>任务筛选</h3>
|
||||
<span class="box-note">默认列出全部在跑任务(待执行/执行中/已排期算一个口径),条数与上方「进行中任务」同源;看历史请换状态或选创建时间</span>
|
||||
<span class="box-note">默认列出执行中的任务(待执行/已排期并入执行中口径),条数与上方「进行中任务」同源;看历史请换状态或选创建时间</span>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group" style="min-width: 160px">
|
||||
@@ -401,7 +402,7 @@ onUnmounted(() => {
|
||||
<span class="strong">{{ accountOf(row) }}</span>
|
||||
</td>
|
||||
<td>{{ shopDisplayName(row.shopName, row.shopCount) }}</td>
|
||||
<td class="mono">{{ row.country || '—' }}</td>
|
||||
<td>{{ countryLabel(row.country) }}</td>
|
||||
<td>{{ row.moduleLabel || row.moduleType }}</td>
|
||||
<td>
|
||||
<span class="st-pill" :class="`is-${taskStatusType(row.status)}`">{{ taskStatusLabel(row.status) }}</span>
|
||||
@@ -418,13 +419,19 @@ onUnmounted(() => {
|
||||
</td>
|
||||
<td>{{ row.finishedAt ? formatDateTime(row.finishedAt) : '—' }}</td>
|
||||
<td>
|
||||
<div class="progress-line">
|
||||
<span>{{ progressText(row) }}</span>
|
||||
<template v-if="taskStatusType(row.status) === 'failed'">
|
||||
<span v-if="row.progressFailed > 0" class="badge danger">失败 {{ row.progressFailed }}</span>
|
||||
</div>
|
||||
<div class="p-track" v-if="row.progressTotal > 0">
|
||||
<div class="p-fill" :style="{ width: progressPercent(row) + '%' }"></div>
|
||||
</div>
|
||||
<span v-else>—</span>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="progress-line">
|
||||
<span>{{ progressText(row) }}</span>
|
||||
<span v-if="row.progressFailed > 0" class="badge danger">失败 {{ row.progressFailed }}</span>
|
||||
</div>
|
||||
<div class="p-track" v-if="row.progressTotal > 0">
|
||||
<div class="p-fill" :style="{ width: progressPercent(row) + '%' }"></div>
|
||||
</div>
|
||||
</template>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
@@ -452,7 +459,7 @@ onUnmounted(() => {
|
||||
<section class="panel-box">
|
||||
<div class="box-head">
|
||||
<h3>变体采集(麦象批量任务)</h3>
|
||||
<span class="box-note">数据来自麦象平台,范围限本组账号,只看在跑(历史不展示)</span>
|
||||
<span class="box-note">数据来自麦象平台,范围限本组账号,默认全部状态(待执行/处理中/成功/失败)</span>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group" style="min-width: 150px">
|
||||
@@ -501,7 +508,6 @@ onUnmounted(() => {
|
||||
<td>{{ formatDateTime(row.updateTime) }}</td>
|
||||
<td>
|
||||
<span class="res-mes" :title="row.resMes || ''">{{ row.resMes || '—' }}</span>
|
||||
<span v-if="row.taskData" class="sub mono" :title="row.taskData">{{ row.taskData }}</span>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
@@ -509,7 +515,7 @@ onUnmounted(() => {
|
||||
<td colspan="6" class="empty-tip">加载中...</td>
|
||||
</tr>
|
||||
<tr v-else>
|
||||
<td colspan="6" class="empty-tip">暂无在跑的变体采集任务</td>
|
||||
<td colspan="6" class="empty-tip">暂无变体采集任务</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -543,8 +549,14 @@ onUnmounted(() => {
|
||||
<el-descriptions-item label="最近上报">{{ detail.lastReportAt ? formatDateTime(detail.lastReportAt) : '—' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="结束时间">{{ detail.finishedAt ? formatDateTime(detail.finishedAt) : '—' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="进度">
|
||||
{{ progressText(detail) }}
|
||||
<span v-if="detail.progressFailed > 0" class="badge danger">失败 {{ detail.progressFailed }}</span>
|
||||
<template v-if="taskStatusType(detail.status) === 'failed'">
|
||||
<span v-if="detail.progressFailed > 0" class="badge danger">失败 {{ detail.progressFailed }}</span>
|
||||
<span v-else>—</span>
|
||||
</template>
|
||||
<template v-else>
|
||||
{{ progressText(detail) }}
|
||||
<span v-if="detail.progressFailed > 0" class="badge danger">失败 {{ detail.progressFailed }}</span>
|
||||
</template>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="当前处理">{{ currentScopeOf(detail) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="错误信息" :span="2">{{ detail.errorMessage || detail.message || '—' }}</el-descriptions-item>
|
||||
@@ -871,11 +883,6 @@ td {
|
||||
background: #f8ebeb;
|
||||
border-color: #e4c2c5;
|
||||
}
|
||||
.st-pill.is-cancelled {
|
||||
color: #5b6f83;
|
||||
background: #f1f6fa;
|
||||
border-color: #d6e2ec;
|
||||
}
|
||||
.st-pill.is-pending {
|
||||
color: #8a6d3b;
|
||||
background: #fbf4ea;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/** 客户端任务管理看板纯逻辑:下拉选项、状态/设备/店铺/进度展示映射、查询参数构建。
|
||||
* 无框架依赖,可直接被 node 单测导入(对齐 tasks 域 image-video-model 的拆法)。 */
|
||||
import { asinCountryLabel } from '../asin/asin-country.ts'
|
||||
|
||||
export interface TaskCenterTaskFilter {
|
||||
username: string
|
||||
@@ -12,7 +13,7 @@ export interface TaskCenterTaskFilter {
|
||||
}
|
||||
|
||||
export interface TaskCenterVariantFilter {
|
||||
/** 麦象状态码字符串(''=在跑(0∪1,后端合并)/ 0 等待 / 1 处理中);历史状态不再可选。 */
|
||||
/** 麦象状态码字符串(''=全部状态 / 0 待执行 / 1 处理中 / 2 成功 / 3 失败)。 */
|
||||
status: string
|
||||
}
|
||||
|
||||
@@ -50,63 +51,67 @@ export const MODULE_OPTIONS: Array<{ value: string; label: string }> = [
|
||||
*/
|
||||
export const ACTIVE_TASK_STATUS = 'ACTIVE'
|
||||
|
||||
/**
|
||||
* 状态三态收敛(用户 2026-10-04 定案:任务状态只要 执行中/成功/失败,其他不用):
|
||||
* 「执行中」= ACTIVE 合并哨兵(待执行/已排期并入,与默认视图、汇总卡同口径);
|
||||
* 成功/失败的同义词展开(COMPLETED/ERROR/取消)在后端 TaskCenterQueryService.statusFilter。
|
||||
*/
|
||||
export const TASK_STATUS_OPTIONS: Array<{ value: string; label: string }> = [
|
||||
{ value: '', label: '全部状态' },
|
||||
{ value: ACTIVE_TASK_STATUS, label: '在跑' },
|
||||
{ value: 'PENDING', label: '待执行' },
|
||||
{ value: 'RUNNING', label: '执行中' },
|
||||
{ value: 'SCHEDULED', label: '已排期' },
|
||||
{ value: 'SUCCESS', label: '已完成' },
|
||||
{ value: ACTIVE_TASK_STATUS, label: '执行中' },
|
||||
{ value: 'SUCCESS', label: '成功' },
|
||||
{ value: 'FAILED', label: '失败' },
|
||||
{ value: 'CANCELLED', label: '已取消' },
|
||||
]
|
||||
|
||||
/**
|
||||
* 变体采集只看「在跑」:空值即后端合并口径(0 等待 ∪ 1 处理中),
|
||||
* 已完成 / 处理失败按用户要求彻底不再提供入口(历史不展示)。
|
||||
* 变体采集状态四态(用户 2026-10-05 定案:在跑口径不要,就显示 待执行/处理中/成功/失败):
|
||||
* 空值 = 全部状态(后端原样直查麦象,含历史终态),不再有「在跑」合并口径。
|
||||
*/
|
||||
export const VARIANT_STATUS_OPTIONS: Array<{ value: string; label: string }> = [
|
||||
{ value: '', label: '在跑' },
|
||||
{ value: '0', label: '等待执行' },
|
||||
{ value: '', label: '全部状态' },
|
||||
{ value: '0', label: '待执行' },
|
||||
{ value: '1', label: '处理中' },
|
||||
{ value: '2', label: '成功' },
|
||||
{ value: '3', label: '失败' },
|
||||
]
|
||||
|
||||
/** 三态展示映射(2026-10-04 收敛):进行中各态统一「执行中」,完成态统一「成功」,
|
||||
* 失败/出错/取消统一「失败」(取消 = 没成功也不在跑,并入失败)。 */
|
||||
const TASK_STATUS_LABELS: Record<string, string> = {
|
||||
PENDING: '待执行',
|
||||
PENDING: '执行中',
|
||||
RUNNING: '执行中',
|
||||
SCHEDULED: '已排期',
|
||||
SUCCESS: '已完成',
|
||||
COMPLETED: '已完成',
|
||||
SCHEDULED: '执行中',
|
||||
SUCCESS: '成功',
|
||||
COMPLETED: '成功',
|
||||
FAILED: '失败',
|
||||
ERROR: '失败',
|
||||
CANCELLED: '已取消',
|
||||
CANCELED: '已取消',
|
||||
CANCELLED: '失败',
|
||||
CANCELED: '失败',
|
||||
}
|
||||
|
||||
/** 麦象批量任务状态四态文案(2026-10-05 用户定案):0 待执行 / 1 处理中 / 2 成功 / 3 失败。 */
|
||||
const VARIANT_STATUS_LABELS: Record<number, string> = {
|
||||
0: '等待执行',
|
||||
0: '待执行',
|
||||
1: '处理中',
|
||||
2: '已完成',
|
||||
3: '处理失败',
|
||||
2: '成功',
|
||||
3: '失败',
|
||||
}
|
||||
|
||||
export type TaskStatusType = 'pending' | 'running' | 'success' | 'failed' | 'cancelled'
|
||||
|
||||
export function taskStatusLabel(status: string | null | undefined): string {
|
||||
const key = (status || '').toUpperCase()
|
||||
return TASK_STATUS_LABELS[key] || key || '未知'
|
||||
return TASK_STATUS_LABELS[key] || '执行中'
|
||||
}
|
||||
|
||||
export function taskStatusType(status: string | null | undefined): TaskStatusType {
|
||||
const key = (status || '').toUpperCase()
|
||||
if (key === 'SUCCESS' || key === 'COMPLETED') return 'success'
|
||||
if (key === 'FAILED' || key === 'ERROR') return 'failed'
|
||||
if (key === 'CANCELLED' || key === 'CANCELED') return 'cancelled'
|
||||
if (key === 'PENDING') return 'pending'
|
||||
if (key === 'FAILED' || key === 'ERROR' || key === 'CANCELLED' || key === 'CANCELED') return 'failed'
|
||||
return 'running'
|
||||
}
|
||||
|
||||
/** 麦象批量任务状态:0 等待 / 1 处理中 / 2 已完成 / 3 失败(不冒充成功)。 */
|
||||
/** 麦象批量任务状态:0 待执行 / 1 处理中 / 2 成功 / 3 失败(未识别不冒充成功)。 */
|
||||
export function variantStatusLabel(status: number | string | null | undefined): string {
|
||||
if (status == null || status === '') return '未知'
|
||||
const code = Number(status)
|
||||
@@ -144,6 +149,18 @@ export function shopDisplayName(shopName: string | null | undefined, shopCount:
|
||||
return count > 1 ? `${name} 等${count}个` : name
|
||||
}
|
||||
|
||||
/** 国家列展示:后端已归一成 `UK` / `UK/DE` 形状,逐段走共享国家字典转中文(用户 2026-10-04 要求);
|
||||
* 字典外的国家码原样保留,取不到画「—」。 */
|
||||
export function countryLabel(country: string | null | undefined): string {
|
||||
const value = (country || '').trim()
|
||||
if (!value) return '—'
|
||||
return value
|
||||
.split('/')
|
||||
.map((part) => asinCountryLabel(part.trim()))
|
||||
.filter((label) => label !== '')
|
||||
.join('/')
|
||||
}
|
||||
|
||||
/** 页签徽章用的条数:只有接口真的回了非负数才算一个数,否则回 null 画「—」。
|
||||
* 麦象在结果表未注册时把 total 回成 -1 哨兵,`Number(x || 0)` 会把它读成 0 条。 */
|
||||
export function tabCount(total: unknown): number | null {
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
buildVariantQuery,
|
||||
createTaskFilter,
|
||||
createVariantFilter,
|
||||
countryLabel,
|
||||
deviceDisplayName,
|
||||
progressPercent,
|
||||
progressText,
|
||||
@@ -83,18 +84,25 @@ test('task_center_device_dimension_is_gone', () => {
|
||||
})
|
||||
|
||||
test('task_center_status_labels_cover_backend_states', () => {
|
||||
assert.equal(taskStatusLabel('PENDING'), '待执行')
|
||||
// 三态收敛(2026-10-04 用户定案:只要 执行中/成功/失败):进行中各态并入执行中,
|
||||
// 完成态并入成功,失败/出错/取消并入失败(取消 = 没成功也不在跑)。
|
||||
assert.equal(taskStatusLabel('PENDING'), '执行中')
|
||||
assert.equal(taskStatusLabel('RUNNING'), '执行中')
|
||||
assert.equal(taskStatusLabel('SUCCESS'), '已完成')
|
||||
assert.equal(taskStatusLabel('SCHEDULED'), '执行中')
|
||||
assert.equal(taskStatusLabel('SUCCESS'), '成功')
|
||||
assert.equal(taskStatusLabel('COMPLETED'), '成功', '完成态历史拼写并入成功')
|
||||
assert.equal(taskStatusLabel('FAILED'), '失败')
|
||||
assert.equal(taskStatusLabel('CANCELLED'), '已取消')
|
||||
assert.equal(taskStatusLabel(''), '未知')
|
||||
assert.equal(taskStatusLabel('ERROR'), '失败', '出错并入失败')
|
||||
assert.equal(taskStatusLabel('CANCELLED'), '失败', '取消并入失败')
|
||||
assert.equal(taskStatusLabel('CANCELED'), '失败', '历史脏拼写同样并入失败')
|
||||
assert.equal(taskStatusLabel(''), '执行中', '未知状态不是终态,按执行中读')
|
||||
assert.equal(taskStatusLabel('WEIRD'), '执行中')
|
||||
assert.equal(taskStatusType('SUCCESS'), 'success')
|
||||
assert.equal(taskStatusType('FAILED'), 'failed')
|
||||
assert.equal(taskStatusType('CANCELLED'), 'cancelled')
|
||||
assert.equal(taskStatusType('PENDING'), 'pending')
|
||||
assert.equal(taskStatusType('CANCELLED'), 'failed')
|
||||
assert.equal(taskStatusType('PENDING'), 'running')
|
||||
assert.equal(taskStatusType('RUNNING'), 'running')
|
||||
assert.ok(TASK_STATUS_OPTIONS.length >= 5)
|
||||
assert.ok(TASK_STATUS_OPTIONS.length >= 4)
|
||||
assert.equal(TASK_STATUS_OPTIONS[0].value, '')
|
||||
assert.equal(MODULE_OPTIONS[0].value, '', '首项为「全部业务」')
|
||||
assert.equal(MODULE_OPTIONS.slice(1).every((o) => o.value && o.label), true)
|
||||
@@ -102,34 +110,33 @@ test('task_center_status_labels_cover_backend_states', () => {
|
||||
})
|
||||
|
||||
test('task_center_variant_status_map_follows_maixiang_semantics', () => {
|
||||
assert.equal(variantStatusLabel(0), '等待执行')
|
||||
// 四态文案(2026-10-05 用户定案):待执行/处理中/成功/失败,不再有 等待执行/已完成/处理失败 旧词。
|
||||
assert.equal(variantStatusLabel(0), '待执行')
|
||||
assert.equal(variantStatusLabel(1), '处理中')
|
||||
assert.equal(variantStatusLabel(2), '已完成')
|
||||
assert.equal(variantStatusLabel(3), '处理失败')
|
||||
assert.equal(variantStatusLabel(2), '成功')
|
||||
assert.equal(variantStatusLabel(3), '失败')
|
||||
assert.equal(variantStatusLabel(9), '未知')
|
||||
assert.equal(variantStatusLabel(null), '未知')
|
||||
assert.equal(variantStatusLabel('2'), '已完成', '字符串数字同样识别')
|
||||
assert.equal(variantStatusLabel('2'), '成功', '字符串数字同样识别')
|
||||
})
|
||||
|
||||
/**
|
||||
* 变体采集页签只讲「在跑」(2026-10-04 用户口径:历史彻底不看):
|
||||
* 状态下拉必须收掉 2 已完成 / 3 处理失败 两个入口,空值改成「在跑」而不是「全部状态」——
|
||||
* 文案留着「全部状态」会让用户以为后端还在给他合并历史。
|
||||
* 变体采集状态四态(2026-10-05 用户定案,取代同日早先「只看在跑」的口径):
|
||||
* 空值恢复「全部状态」,2 成功 / 3 失败 回列入口,「在跑」合并口径从下拉与文案里彻底撤掉。
|
||||
*/
|
||||
test('task_center_variant_status_options_drop_history_states', () => {
|
||||
test('task_center_variant_status_options_are_the_four_states', () => {
|
||||
assert.deepEqual(VARIANT_STATUS_OPTIONS, [
|
||||
{ value: '', label: '在跑' },
|
||||
{ value: '0', label: '等待执行' },
|
||||
{ value: '', label: '全部状态' },
|
||||
{ value: '0', label: '待执行' },
|
||||
{ value: '1', label: '处理中' },
|
||||
{ value: '2', label: '成功' },
|
||||
{ value: '3', label: '失败' },
|
||||
])
|
||||
const values = VARIANT_STATUS_OPTIONS.map((o) => o.value)
|
||||
assert.equal(values.includes('2'), false, '已完成不再是可选项')
|
||||
assert.equal(values.includes('3'), false, '处理失败不再是可选项')
|
||||
|
||||
const page = readSource(PAGE)
|
||||
assert.match(page, /只看在跑/, '面板说明写明只看在跑')
|
||||
assert.match(page, /title="麦象在跑批量任务条数/, '徽章 tooltip 是在跑口径不是全部状态')
|
||||
assert.equal(/麦象批量任务条数(全部状态)/.test(page), false)
|
||||
assert.equal(/只看在跑/.test(page), false, '面板说明不再写只看在跑')
|
||||
assert.match(page, /title="麦象变体采集任务条数(全部状态)/, '徽章 tooltip 换成全部状态口径')
|
||||
assert.match(page, /默认全部状态(待执行\/处理中\/成功\/失败)/, '面板说明写明四态')
|
||||
})
|
||||
|
||||
test('task_center_device_display_falls_back_to_truncated_id', () => {
|
||||
@@ -211,6 +218,25 @@ test('task_center_progress_bar_is_dropped_when_there_is_no_progress', () => {
|
||||
assert.match(page, /<div class="p-track" v-if="row\.progressTotal > 0">/, '无进度时不画进度轨')
|
||||
})
|
||||
|
||||
/**
|
||||
* 失败任务的进度列(2026-10-04 用户要求):失败任务的进度快照要么冻在中间阶段、
|
||||
* 要么按构建单位写满格,列表继续画「已完成 N / 总 N」+ 满格条会被读成「跑完了」——
|
||||
* 失败行(含详情抽屉)只给失败徽标,不给进度条也不说「已完成」。
|
||||
*/
|
||||
test('task_center_failed_rows_never_render_a_progress_bar', () => {
|
||||
const page = readSource(PAGE)
|
||||
for (const scope of ['row', 'detail']) {
|
||||
const branch = new RegExp(
|
||||
`<template v-if="taskStatusType\\(${scope}\\.status\\) === 'failed'">[\\s\\S]{0,400}?</template>`,
|
||||
).exec(page)
|
||||
assert.ok(branch, `${scope} 的失败分支存在`)
|
||||
assert.equal(branch[0].includes('p-track'), false, '失败分支不画进度轨')
|
||||
assert.equal(branch[0].includes('progressText'), false, '失败分支不说「已完成 X / 总 Y」')
|
||||
assert.match(branch[0], /badge danger/, '有失败数时给红色失败徽标')
|
||||
assert.match(branch[0], /v-else/, '无失败数时画「—」')
|
||||
}
|
||||
})
|
||||
|
||||
test('task_center_query_builder_omits_blanks_and_normalizes_time', () => {
|
||||
const query = buildTaskQuery(
|
||||
{ username: ' 张三 ', moduleType: 'COLLECT_DATA', status: 'RUNNING', shop: '林芳旗舰店', startTime: '2026-09-28T10:00', endTime: '' },
|
||||
@@ -232,7 +258,7 @@ test('task_center_query_builder_omits_blanks_and_normalizes_time', () => {
|
||||
|
||||
test('task_center_variant_query_builder_keeps_paging', () => {
|
||||
const empty = buildVariantQuery({ status: '' }, 1, 20)
|
||||
assert.equal(empty.status, undefined, '空状态不下传 status ⇒ 后端按在跑(0∪1)合并')
|
||||
assert.equal(empty.status, undefined, '空状态不下传 status ⇒ 后端返回全部状态')
|
||||
assert.equal(empty.page, 1)
|
||||
const filtered = buildVariantQuery({ status: '1' }, 3, 50)
|
||||
assert.equal(filtered.status, 1)
|
||||
@@ -254,7 +280,7 @@ test('task_center_filter_reset_clears_every_field', () => {
|
||||
test('task_center_page_handles_empty_and_error_states', () => {
|
||||
const page = readSource(PAGE)
|
||||
assert.match(page, /暂无符合条件的任务/, '任务空态')
|
||||
assert.match(page, /暂无在跑的变体采集任务/, '变体空态:口径是在跑不是全部')
|
||||
assert.match(page, /暂无变体采集任务/, '变体空态:四态口径下不再限定「在跑」')
|
||||
assert.match(page, /ElMessage\.error/, '接口失败提示')
|
||||
assert.match(page, /resetFilter/, '筛选重置接线')
|
||||
assert.match(page, /@size-change="changeTaskSize"/, '分页每页条数切换')
|
||||
@@ -311,8 +337,8 @@ test('task_center_country_column_is_display_only', () => {
|
||||
const page = readSource(PAGE)
|
||||
|
||||
assert.match(page, /<th style="width: 90px">国家<\/th>/, '国家列在店铺与业务之间')
|
||||
assert.match(page, /<td class="mono">\{\{ row\.country \|\| '—' \}\}<\/td>/,
|
||||
'取不到国家画「—」:七条 JSON 路径只覆盖约七成行,留白会被读成数据缺失')
|
||||
assert.match(page, /<td>\{\{ countryLabel\(row\.country\) \}\}<\/td>/,
|
||||
'国家码转中文展示(UK→英国),空值由 countryLabel 画「—」')
|
||||
assert.equal(readSource(API).includes('country: string | null'), true, '接口类型带 country 且可为 null')
|
||||
|
||||
// 只加列,不做筛选(用户 2026-10-04 定案):不许冒出国家筛选或 country 查询参数
|
||||
@@ -321,25 +347,41 @@ test('task_center_country_column_is_display_only', () => {
|
||||
'查询参数不带 country')
|
||||
})
|
||||
|
||||
/** 国家码 → 中文(用户 2026-10-04 要求):复用 ASIN 五国共享字典,逐段转,未知码原样保留。 */
|
||||
test('task_center_country_labels_are_chinese_with_passthrough_for_unknown', () => {
|
||||
assert.equal(countryLabel('UK'), '英国')
|
||||
assert.equal(countryLabel('DE'), '德国')
|
||||
assert.equal(countryLabel('FR'), '法国')
|
||||
assert.equal(countryLabel('UK/DE'), '英国/德国', '多国家逐段转(后端用 / 连)')
|
||||
assert.equal(countryLabel('UK / DE'), '英国/德国', '带空格的段先归一')
|
||||
assert.equal(countryLabel('US'), 'US', '字典外国家码原样保留,不装死')
|
||||
assert.equal(countryLabel(null), '—', '无国家的模块画「—」')
|
||||
assert.equal(countryLabel(''), '—')
|
||||
assert.equal(countryLabel(' '), '—')
|
||||
})
|
||||
|
||||
/**
|
||||
* 默认「在跑」(用户 2026-10-04 要求:其他状态保留,但默认看执行中的):
|
||||
* 默认「执行中」(2026-10-04 状态三态收敛,取代同日早先「历史状态保留入口」的口径):
|
||||
* ACTIVE 是三个进行中状态的合并哨兵,展开发生在后端,所以这里只钉
|
||||
* ① 选项在位且排在「全部状态」之后,② 页面默认值与重置都走它,③ createTaskFilter 仍是全空
|
||||
* ① 选项四项:全部状态/执行中/成功/失败(待执行/已排期/已取消不再单独出现),
|
||||
* ② 页面默认值与重置都走它,③ createTaskFilter 仍是全空
|
||||
* (全空 = 不裁剪,是「重置到无筛选」语义的底座,页面默认值再覆盖上去)。
|
||||
*/
|
||||
test('task_center_defaults_to_the_merged_active_status', () => {
|
||||
assert.equal(TASK_STATUS_OPTIONS[0].value, '', '首项仍是全部状态')
|
||||
assert.equal(TASK_STATUS_OPTIONS[1].value, ACTIVE_TASK_STATUS, '第二项就是默认的在跑')
|
||||
assert.equal(TASK_STATUS_OPTIONS[1].value, ACTIVE_TASK_STATUS, '第二项就是默认的执行中')
|
||||
assert.deepEqual(TASK_STATUS_OPTIONS.map((o) => o.value),
|
||||
['', 'ACTIVE', 'PENDING', 'RUNNING', 'SCHEDULED', 'SUCCESS', 'FAILED', 'CANCELLED'],
|
||||
'七个状态一个不少(用户要求历史状态保留入口)')
|
||||
['', 'ACTIVE', 'SUCCESS', 'FAILED'],
|
||||
'三态收敛:待执行/已排期/已取消不再单独设选项')
|
||||
assert.deepEqual(TASK_STATUS_OPTIONS.map((o) => o.label),
|
||||
['全部状态', '执行中', '成功', '失败'])
|
||||
assert.equal(buildTaskQuery({ ...createTaskFilter(), status: ACTIVE_TASK_STATUS }, 1, 20).status, 'ACTIVE',
|
||||
'哨兵原样下传,展开在后端做')
|
||||
assert.equal(createTaskFilter().status, '', 'createTaskFilter 保持全空')
|
||||
|
||||
const page = readSource(PAGE)
|
||||
assert.match(page, /status: ACTIVE_TASK_STATUS/, '页面默认筛在跑')
|
||||
assert.match(page, /Object\.assign\(filter, defaultTaskFilter\(\)\)/, '重置回到默认「在跑」而不是全部状态')
|
||||
assert.match(page, /status: ACTIVE_TASK_STATUS/, '页面默认筛执行中')
|
||||
assert.match(page, /Object\.assign\(filter, defaultTaskFilter\(\)\)/, '重置回到默认「执行中」而不是全部状态')
|
||||
})
|
||||
|
||||
// 2026-10-04 生产对不上账:卡片「进行中任务」的 SQL 不带创建时间窗(实测 39 个),
|
||||
@@ -376,6 +418,17 @@ test('task_center_page_wires_tabs_filters_and_polling', () => {
|
||||
assert.equal(/shopName/.test(readSource(PAGE)), true)
|
||||
})
|
||||
|
||||
/**
|
||||
* 变体表「结果信息」列不再附带 taskData 原始 JSON(2026-10-05 用户要求):
|
||||
* 那是任务原始入参(file_url/execute_country/proxy_url/proxy_mode),proxy_url
|
||||
* 内含代理提取 key,写在页面上等于把凭据挂出来。接口层仍透传该字段
|
||||
* (task-center.ts 的类型保持如实),只是页面不渲染。
|
||||
*/
|
||||
test('task_center_variant_result_column_dumps_no_raw_task_data', () => {
|
||||
const page = readSource(PAGE)
|
||||
assert.doesNotMatch(page, /taskData/, '变体表不再渲染 task_data 原始 JSON')
|
||||
})
|
||||
|
||||
/**
|
||||
* 页签徽章的两个口径缺陷:
|
||||
* ① 「客户端任务」曾绑列表 total(默认全部状态、全部时间 = 历史全量,线上 1135 条,
|
||||
|
||||
+9
-1
@@ -2139,10 +2139,18 @@ public class AppearancePatentTaskService {
|
||||
if (previousDisplayPercent > displayPercent && safeCompleted < safeTotal) {
|
||||
displayPercent = previousDisplayPercent;
|
||||
}
|
||||
// 终态必须带任务真实状态落库:save() 只对终态豁免 500ms 节流,收尾三连写(组装/上传/完成)
|
||||
// 都在同一次调用里,若全按 RUNNING 写,只有第一条落地,满格「结果文件已生成」必被吞——
|
||||
// 看板就会永远停在 0/N 或 N-2/N(2026-10-04 生产实测)。对齐货源查询 isTerminalFileBuildProgress。
|
||||
boolean terminalProgress = safeCompleted >= safeTotal
|
||||
&& (STATUS_SUCCESS.equals(task.getStatus()) || STATUS_FAILED.equals(task.getStatus()));
|
||||
if (terminalProgress) {
|
||||
displayPercent = 100;
|
||||
}
|
||||
taskProgressSnapshotService.save(
|
||||
task.getId(),
|
||||
MODULE_TYPE,
|
||||
STATUS_RUNNING,
|
||||
terminalProgress ? task.getStatus() : STATUS_RUNNING,
|
||||
safeTotal,
|
||||
safeCompleted,
|
||||
0,
|
||||
|
||||
+3
-3
@@ -84,10 +84,10 @@ public class AdminTaskCenterController {
|
||||
}
|
||||
|
||||
@GetMapping("/variant-tasks")
|
||||
@Operation(summary = "变体采集列表(只看在跑)",
|
||||
@Operation(summary = "变体采集列表(全部状态)",
|
||||
description = "代理麦象 console 批量任务(默认只看 variant-collection):非超管按可见用户 uid 过滤,"
|
||||
+ "超管看全部;麦象未配置或不可达时返回空页。status 为麦象状态码:0 等待/1 处理中/2 已完成/3 失败;"
|
||||
+ "不传 status = 只看在跑(0∪1 合并,历史不再展示)。")
|
||||
+ "超管看全部;麦象未配置或不可达时返回空页。status 为麦象状态码:0 待执行/1 处理中/2 成功/3 失败;"
|
||||
+ "不传 status = 全部状态(2026-10-05 定案:撤掉在跑合并口径)。")
|
||||
public ApiResponse<TaskCenterVariantPageVo> variantTasks(HttpServletRequest request,
|
||||
@RequestParam(required = false) Integer status,
|
||||
@RequestParam(required = false) String taskType,
|
||||
|
||||
+9
@@ -55,6 +55,15 @@ public interface TaskCenterQueryMapper {
|
||||
/** 状态筛选的合并哨兵值:它不是表里的状态,服务层负责展开成 {@link #ACTIVE_STATUSES_ORDERED}。 */
|
||||
String ACTIVE_STATUS_SENTINEL = "ACTIVE";
|
||||
|
||||
/**
|
||||
* 前端「成功」筛选项的展开口径(2026-10-04 状态三态收敛:只留 执行中/成功/失败):
|
||||
* COMPLETED 是完成态的历史拼写,展示上已并入成功,筛选必须命中同样的行。
|
||||
*/
|
||||
List<String> SUCCESS_STATUSES_ORDERED = List.of("SUCCESS", "COMPLETED");
|
||||
|
||||
/** 前端「失败」筛选项的展开口径:ERROR 与取消/出错都按「没成功」并入失败(SQL 里 CANCELED 已归一为 CANCELLED)。 */
|
||||
List<String> FAILED_STATUSES_ORDERED = List.of("FAILED", "ERROR", "CANCELLED");
|
||||
|
||||
/** biz_file_task 终态(CANCELLED 与历史脏值 CANCELED 并存)。 */
|
||||
Set<String> TERMINAL_STATUS_SET = Set.of("SUCCESS", "FAILED", "CANCELLED", "CANCELED");
|
||||
|
||||
|
||||
+10
-3
@@ -130,9 +130,10 @@ public class TaskCenterQueryService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 状态筛选展开:空白 = 不裁剪;{@code ACTIVE} = 前端默认的「在跑」,等于三个进行中状态的合并
|
||||
* (与判卡住用的 {@link #ACTIVE_STATUSES} 同一组,不另定口径);其余按单值下传。
|
||||
* 品牌表状态本是小写,SQL 里 {@code STATUS_B} 已 UPPER 归一,这里只统一入参大小写。
|
||||
* 状态筛选展开:空白 = 不裁剪;{@code ACTIVE} = 前端默认的「执行中」,等于三个进行中状态的合并
|
||||
* (与判卡住用的 {@link #ACTIVE_STATUSES} 同一组,不另定口径);{@code SUCCESS}/{@code FAILED}
|
||||
* 按三态收敛口径展开同义词(历史拼写 COMPLETED/ERROR 与取消并入,见 mapper 常量);
|
||||
* 其余按单值下传。品牌表状态本是小写,SQL 里 {@code STATUS_B} 已 UPPER 归一,这里只统一入参大小写。
|
||||
*/
|
||||
static List<String> statusFilter(String status) {
|
||||
if (status == null || status.isBlank()) {
|
||||
@@ -142,6 +143,12 @@ public class TaskCenterQueryService {
|
||||
if (TaskCenterQueryMapper.ACTIVE_STATUS_SENTINEL.equals(key)) {
|
||||
return TaskCenterQueryMapper.ACTIVE_STATUSES_ORDERED;
|
||||
}
|
||||
if ("SUCCESS".equals(key)) {
|
||||
return TaskCenterQueryMapper.SUCCESS_STATUSES_ORDERED;
|
||||
}
|
||||
if ("FAILED".equals(key)) {
|
||||
return TaskCenterQueryMapper.FAILED_STATUSES_ORDERED;
|
||||
}
|
||||
return List.of(key);
|
||||
}
|
||||
|
||||
|
||||
+11
-47
@@ -12,7 +12,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
@@ -26,8 +25,8 @@ import java.util.stream.Collectors;
|
||||
* <p>可见范围靠 uid 过滤实现:非超管把可见用户号拼成逗号分隔的 uid 参数(麦象侧拆分后 IN),
|
||||
* 超管不传 uid(看全部)。麦象未配置或不可达时返回空页并记日志,页面不因外部依赖炸掉。</p>
|
||||
*
|
||||
* <p>不传 status 时只看在跑(等待 0 ∪ 处理中 1):麦象一次只能筛一个状态,
|
||||
* 服务层各拉一页合并;历史终态不再作为页签默认口径(徽章说的必须是「在跑几条」)。</p>
|
||||
* <p>不传 status = 全部状态:麦象侧 status 不过滤即返回四态(0 待执行/1 处理中/2 成功/3 失败),
|
||||
* 分页、total 都由麦象完成,服务层原样透传——2026-10-05 用户定案:撤掉「在跑」合并口径。</p>
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
@@ -37,12 +36,6 @@ public class TaskCenterVariantService {
|
||||
/** 页签默认只看变体采集这一类批量任务;传 taskType 可覆盖。 */
|
||||
public static final String VARIANT_TASK_TYPE = "variant-collection";
|
||||
|
||||
/** 麦象状态码:0 等待 / 1 处理中,两者合起来才是「在跑」。 */
|
||||
private static final int STATUS_WAITING = 0;
|
||||
private static final int STATUS_PROCESSING = 1;
|
||||
/** 在跑任务正常在几十量级;触顶时 total 仍按麦象回值,但翻页尾部会缺行(记 warn)。 */
|
||||
private static final int ACTIVE_FETCH_SIZE = 200;
|
||||
|
||||
private static final long DEFAULT_PAGE_SIZE = 20;
|
||||
private static final long MAX_PAGE_SIZE = 100;
|
||||
|
||||
@@ -70,43 +63,14 @@ public class TaskCenterVariantService {
|
||||
|
||||
String uidsCsv = scope.allUsers() ? null
|
||||
: scope.visibleUserIds().stream().sorted().map(String::valueOf).collect(Collectors.joining(","));
|
||||
int size = (int) normalizedSize;
|
||||
if (status != null) {
|
||||
BatchTaskPage maixiang = consoleClient.batchTasksPage(uidsCsv, status, type,
|
||||
(int) normalizedPage, size);
|
||||
vo.setTotal(maixiang.total());
|
||||
vo.setItems(assemble(maixiang.items()));
|
||||
return vo;
|
||||
}
|
||||
|
||||
// 不传状态 = 只看在跑(用户 2026-10-04 定案:历史的不看了)。
|
||||
// 麦象一次只能筛一个状态,等待(0) 与处理中(1) 各拉一页后在内存合并分页。
|
||||
BatchTaskPage waiting = consoleClient.batchTasksPage(uidsCsv, STATUS_WAITING, type, 1, ACTIVE_FETCH_SIZE);
|
||||
BatchTaskPage processing = consoleClient.batchTasksPage(uidsCsv, STATUS_PROCESSING, type, 1, ACTIVE_FETCH_SIZE);
|
||||
List<BatchTaskItem> active = new ArrayList<>(waiting.items());
|
||||
active.addAll(processing.items());
|
||||
active.sort(Comparator.comparing(BatchTaskItem::createTime,
|
||||
Comparator.nullsLast(Comparator.reverseOrder())));
|
||||
// total 用麦象回值(-1 哨兵或缺字段时回落为已拉到的行数),保证徽章说的是「在跑」而不是历史全量。
|
||||
long total = effectiveTotal(waiting) + effectiveTotal(processing);
|
||||
vo.setTotal(total);
|
||||
if (total > active.size()) {
|
||||
log.warn("[task-center] 变体采集在跑数 {} 超过单状态拉取上限 {},翻页尾部会缺行",
|
||||
total, ACTIVE_FETCH_SIZE);
|
||||
}
|
||||
long from = (normalizedPage - 1) * normalizedSize;
|
||||
if (from >= active.size()) {
|
||||
return vo;
|
||||
}
|
||||
long to = Math.min(from + normalizedSize, active.size());
|
||||
vo.setItems(assemble(active.subList((int) from, (int) to)));
|
||||
// status 直传麦象:null = 全部状态(待执行/处理中/成功/失败),分页与 total 都由麦象完成。
|
||||
BatchTaskPage maixiang = consoleClient.batchTasksPage(uidsCsv, status, type,
|
||||
(int) normalizedPage, (int) normalizedSize);
|
||||
vo.setTotal(maixiang.total());
|
||||
vo.setItems(assemble(maixiang.items()));
|
||||
return vo;
|
||||
}
|
||||
|
||||
private static long effectiveTotal(BatchTaskPage page) {
|
||||
return Math.max(page.total(), page.items().size());
|
||||
}
|
||||
|
||||
/** uid → 账号名映射只对数字 uid 生效;麦象任务可能带非数字伪 uid(如 collect-27475)。 */
|
||||
private List<TaskCenterVariantTaskVo> assemble(List<BatchTaskItem> items) {
|
||||
Set<Long> userIds = new LinkedHashSet<>();
|
||||
@@ -162,13 +126,13 @@ public class TaskCenterVariantService {
|
||||
}
|
||||
}
|
||||
|
||||
/** 麦象状态码:0 等待 / 1 处理中 / 2 已完成 / 3 失败;未识别的一律「未知」不冒充成功。 */
|
||||
/** 麦象状态码四态文案(2026-10-05 用户定案):0 待执行 / 1 处理中 / 2 成功 / 3 失败;未识别的一律「未知」不冒充成功。 */
|
||||
private static String statusLabel(int status) {
|
||||
return switch (status) {
|
||||
case 0 -> "等待执行";
|
||||
case 0 -> "待执行";
|
||||
case 1 -> "处理中";
|
||||
case 2 -> "已完成";
|
||||
case 3 -> "处理失败";
|
||||
case 2 -> "成功";
|
||||
case 3 -> "失败";
|
||||
default -> "未知";
|
||||
};
|
||||
}
|
||||
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
package com.nanri.aiimage.modules.appearancepatent.service;
|
||||
|
||||
import com.nanri.aiimage.modules.task.model.entity.FileTaskEntity;
|
||||
import com.nanri.aiimage.modules.task.model.entity.TaskFileJobEntity;
|
||||
import com.nanri.aiimage.modules.task.service.TaskProgressSnapshotService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* 外观专利的进度快照是「文件构建」合成单位(LLM 批次数 + 3 个固定阶段),任务收尾在
|
||||
* completeLlmFileJob 里同一瞬间连发三条进度(组装 N-2 / 上传 N-1 / 完成 N)。快照写入
|
||||
* (TaskProgressSnapshotService.save)只对终态豁免 500ms 节流,所以满格那条必须带任务
|
||||
* 真实状态落库——此前恒按 RUNNING 写,必被节流吞掉,看板永远停在 0/N 或 N-2/N
|
||||
* (2026-10-04 生产实测)。修复:completed 满格且任务已终态时按任务状态写,
|
||||
* 对齐货源查询 isTerminalFileBuildProgress。
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class AppearancePatentSnapshotTerminalWriteTest {
|
||||
|
||||
private static final Long TASK_ID = 31337L;
|
||||
|
||||
@Mock private TaskProgressSnapshotService taskProgressSnapshotService;
|
||||
|
||||
@InjectMocks private AppearancePatentTaskService service;
|
||||
|
||||
@Test
|
||||
void runningTaskKeepsWritingRunningStatus() {
|
||||
save(task("RUNNING"), 3, "正在组装 xlsx");
|
||||
assertSavedStatus("RUNNING");
|
||||
}
|
||||
|
||||
@Test
|
||||
void completedTaskWritesSuccessAsTerminalStatus() {
|
||||
save(task("SUCCESS"), 6, "结果文件已生成");
|
||||
assertSavedStatus("SUCCESS");
|
||||
}
|
||||
|
||||
@Test
|
||||
void failedTaskAtFullProgressWritesFailedAsTerminalStatus() {
|
||||
save(task("FAILED"), 6, "结果文件已生成");
|
||||
assertSavedStatus("FAILED");
|
||||
}
|
||||
|
||||
/** 没跑满格就不算终态进度:失败的中间阶段照旧按 RUNNING 写,节流语义保持不变。 */
|
||||
@Test
|
||||
void failedTaskBelowFullProgressIsNotTerminalYet() {
|
||||
save(task("FAILED"), 3, "正在组装 xlsx");
|
||||
assertSavedStatus("RUNNING");
|
||||
}
|
||||
|
||||
private void save(FileTaskEntity task, int completed, String message) {
|
||||
TaskFileJobEntity job = new TaskFileJobEntity();
|
||||
job.setId(1L);
|
||||
job.setScopeKey("task:31337:owner:instance-a");
|
||||
job.setStatus("RUNNING");
|
||||
|
||||
ReflectionTestUtils.invokeMethod(service, "saveFileBuildProgress",
|
||||
task, job, 6, completed, message);
|
||||
}
|
||||
|
||||
private void assertSavedStatus(String expectedStatus) {
|
||||
ArgumentCaptor<String> status = ArgumentCaptor.forClass(String.class);
|
||||
verify(taskProgressSnapshotService).save(eq(TASK_ID), eq(AppearancePatentTaskService.MODULE_TYPE),
|
||||
status.capture(), anyInt(), anyInt(), anyInt(), anyString(), anyString(), any());
|
||||
assertEquals(expectedStatus, status.getValue());
|
||||
}
|
||||
|
||||
private FileTaskEntity task(String status) {
|
||||
FileTaskEntity task = new FileTaskEntity();
|
||||
task.setId(TASK_ID);
|
||||
task.setModuleType(AppearancePatentTaskService.MODULE_TYPE);
|
||||
task.setStatus(status);
|
||||
return task;
|
||||
}
|
||||
}
|
||||
+15
@@ -145,6 +145,21 @@ class TaskProgressSnapshotServiceThrottleTest {
|
||||
verify(taskProgressSnapshotMapper, times(1)).update(isNull(), any(LambdaUpdateWrapper.class));
|
||||
}
|
||||
|
||||
/** 终态不受节流:外观专利收尾在同一瞬间连发三条进度(组装/上传/完成),只有最后一条带终态——
|
||||
* 若终态也被 500ms 窗口吞掉,快照永远停在中间阶段,看板出现「已完成 0/130、57/59」
|
||||
* (2026-10-04 生产实测,模块侧修复:AppearancePatentTaskService.saveFileBuildProgress 终态带任务状态)。 */
|
||||
@Test
|
||||
void terminalStatusWritesLandEvenInsideTheThrottleWindow() {
|
||||
when(taskProgressSnapshotMapper.selectOne(any(LambdaQueryWrapper.class))).thenReturn(running());
|
||||
rewindLastWrite(20581L, "SIMILAR_ASIN", 100L);
|
||||
|
||||
service.save(20581L, "SIMILAR_ASIN", "RUNNING", 10, 5, 1, "s1", "half", null);
|
||||
verify(taskProgressSnapshotMapper, never()).update(isNull(), any(LambdaUpdateWrapper.class));
|
||||
|
||||
service.save(20581L, "SIMILAR_ASIN", "SUCCESS", 10, 10, 0, "s1", "done", null);
|
||||
verify(taskProgressSnapshotMapper, times(1)).update(isNull(), any(LambdaUpdateWrapper.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_task_063_progress_frontend_boundary_limit_and_overflow() {
|
||||
// 上限/超限:最小更新间隔设为 0(超限值)→ 节流禁用,
|
||||
|
||||
+12
@@ -374,6 +374,18 @@ class TaskCenterQueryServiceTest {
|
||||
assertNull(TaskCenterQueryService.statusFilter(null));
|
||||
}
|
||||
|
||||
/** 三态收敛(2026-10-04 用户定案:状态只留 执行中/成功/失败):成功/失败筛选必须命中
|
||||
* 历史拼写(COMPLETED/ERROR)与取消,否则前端归并后的行在筛选下凭空消失。 */
|
||||
@Test
|
||||
void statusFilterExpandsSuccessAndFailedIntoSynonyms() {
|
||||
assertEquals(TaskCenterQueryMapper.SUCCESS_STATUSES_ORDERED,
|
||||
TaskCenterQueryService.statusFilter("success"));
|
||||
assertEquals(List.of("SUCCESS", "COMPLETED"), TaskCenterQueryService.statusFilter(" SUCCESS "));
|
||||
assertEquals(TaskCenterQueryMapper.FAILED_STATUSES_ORDERED,
|
||||
TaskCenterQueryService.statusFilter("FAILED"));
|
||||
assertEquals(List.of("FAILED", "ERROR", "CANCELLED"), TaskCenterQueryService.statusFilter("failed"));
|
||||
}
|
||||
|
||||
/** 国家列:原文两种形状都要归一,取不到留空(前端画「—」),不许把 null 当国家名。 */
|
||||
@Test
|
||||
void countryColumnIsNormalizedFromBothJsonShapes() {
|
||||
|
||||
+15
-57
@@ -6,7 +6,6 @@ import com.nanri.aiimage.modules.notification.client.MaixiangConsoleClient.Batch
|
||||
import com.nanri.aiimage.modules.taskcenter.mapper.TaskCenterQueryMapper;
|
||||
import com.nanri.aiimage.modules.taskcenter.model.dto.TaskCenterUserRow;
|
||||
import com.nanri.aiimage.modules.taskcenter.model.vo.TaskCenterVariantPageVo;
|
||||
import com.nanri.aiimage.modules.taskcenter.model.vo.TaskCenterVariantTaskVo;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -31,7 +30,7 @@ import static org.mockito.Mockito.when;
|
||||
/**
|
||||
* 变体采集页签的 Java 侧口径:可见用户 → uid 集合(逗号拼接、排序稳定)、
|
||||
* 分页归一化、uid → 账号名映射、麦象不可达/未配置时返回空页;
|
||||
* 不传 status = 只看在跑(等待 0 ∪ 处理中 1 合并,历史终态不进默认口径)。
|
||||
* 不传 status = 全部状态(单次直查麦象,四态与分页都由麦象完成——2026-10-05 定案)。
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class TaskCenterVariantServiceTest {
|
||||
@@ -54,11 +53,6 @@ class TaskCenterVariantServiceTest {
|
||||
resMes, "{\"file_url\": \"https://oss.aishufu.top/a.xlsx\"}");
|
||||
}
|
||||
|
||||
private static BatchTaskItem item(String taskId, String uid, int status, String resMes, LocalDateTime createTime) {
|
||||
return new BatchTaskItem(taskId, "variant-collection", uid, status,
|
||||
createTime, createTime, resMes, "{\"file_url\": \"https://oss.aishufu.top/a.xlsx\"}");
|
||||
}
|
||||
|
||||
private static TaskCenterUserRow userRow(Long id, String username) {
|
||||
TaskCenterUserRow row = new TaskCenterUserRow();
|
||||
row.setUserId(id);
|
||||
@@ -87,7 +81,7 @@ class TaskCenterVariantServiceTest {
|
||||
assertEquals(1, page.getItems().get(0).getStatus());
|
||||
assertEquals("处理中", page.getItems().get(0).getStatusLabel());
|
||||
assertEquals("最新采集到 B0XXXXXXX 数据,已采集 12 条", page.getItems().get(0).getResMes());
|
||||
assertEquals("已完成", page.getItems().get(1).getStatusLabel());
|
||||
assertEquals("成功", page.getItems().get(1).getStatusLabel());
|
||||
assertEquals("bob", page.getItems().get(1).getUsername());
|
||||
}
|
||||
|
||||
@@ -113,58 +107,24 @@ class TaskCenterVariantServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void superAdminWithoutStatusSeesOnlyActiveMergedFromBothStatuses() {
|
||||
void superAdminWithoutStatusFetchesAllStatesInOneCall() {
|
||||
when(consoleClient.configured()).thenReturn(true);
|
||||
when(consoleClient.batchTasksPage(isNull(), eq(0), eq("variant-collection"), eq(1), eq(200)))
|
||||
.thenReturn(new BatchTaskPage(1, List.of(item("t-wait", "5", 0, "已添加至任务队列,等待执行"))));
|
||||
when(consoleClient.batchTasksPage(isNull(), eq(1), eq("variant-collection"), eq(1), eq(200)))
|
||||
.thenReturn(new BatchTaskPage(2, List.of(item("t-run", "5", 1, "已采集 12 条"))));
|
||||
when(consoleClient.batchTasksPage(isNull(), isNull(), eq("variant-collection"), eq(1), eq(20)))
|
||||
.thenReturn(new BatchTaskPage(3, List.of(
|
||||
item("t-wait", "5", 0, "已添加至任务队列,等待执行"),
|
||||
item("t-run", "5", 1, "已采集 12 条"),
|
||||
item("t-done", "5", 2, "已完成,共 30 条"))));
|
||||
when(queryMapper.selectUsernames(List.of(5L))).thenReturn(List.of(userRow(5L, "ali")));
|
||||
|
||||
TaskCenterVariantPageVo page = service.variantTasks(superScope(), null, null, null, null);
|
||||
|
||||
assertEquals(3, page.getTotal(), "不传 status = 在跑(等待+处理中)之和,不再是历史全量 106");
|
||||
assertEquals(2, page.getItems().size());
|
||||
assertEquals(3, page.getTotal(), "不传 status = 全部状态直查麦象,total 原样透传");
|
||||
assertEquals(3, page.getItems().size());
|
||||
assertEquals(1, page.getPage());
|
||||
assertEquals(20, page.getPageSize());
|
||||
assertEquals("等待执行", page.getItems().get(0).getStatusLabel());
|
||||
verify(consoleClient, never()).batchTasksPage(any(), isNull(), any(), anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
void activeMergeSortsByCreateTimeDescAndSlicesPages() {
|
||||
when(consoleClient.configured()).thenReturn(true);
|
||||
when(consoleClient.batchTasksPage(isNull(), eq(0), any(), eq(1), eq(200)))
|
||||
.thenReturn(new BatchTaskPage(2, List.of(
|
||||
item("t-old", "5", 0, "等待", LocalDateTime.of(2026, 10, 4, 1, 0)),
|
||||
item("t-mid", "5", 0, "等待", LocalDateTime.of(2026, 10, 4, 2, 0)))));
|
||||
when(consoleClient.batchTasksPage(isNull(), eq(1), any(), eq(1), eq(200)))
|
||||
.thenReturn(new BatchTaskPage(1, List.of(
|
||||
item("t-new", "5", 1, "处理中", LocalDateTime.of(2026, 10, 4, 3, 0)))));
|
||||
|
||||
TaskCenterVariantPageVo first = service.variantTasks(superScope(), null, null, 1, 2);
|
||||
assertEquals(List.of("t-new", "t-mid"),
|
||||
first.getItems().stream().map(TaskCenterVariantTaskVo::getTaskId).toList(),
|
||||
"两个状态合并后按创建时间倒序,不是先等待后处理中的拼接序");
|
||||
TaskCenterVariantPageVo second = service.variantTasks(superScope(), null, null, 2, 2);
|
||||
assertEquals(List.of("t-old"),
|
||||
second.getItems().stream().map(TaskCenterVariantTaskVo::getTaskId).toList());
|
||||
TaskCenterVariantPageVo beyond = service.variantTasks(superScope(), null, null, 3, 2);
|
||||
assertEquals(0, beyond.getItems().size(), "越界页给空列表");
|
||||
assertEquals(3, beyond.getTotal(), "total 不随空页归零");
|
||||
}
|
||||
|
||||
@Test
|
||||
void activeTotalFallsBackToItemCountWhenMaixiangTotalIsSentinel() {
|
||||
when(consoleClient.configured()).thenReturn(true);
|
||||
when(consoleClient.batchTasksPage(isNull(), eq(0), any(), eq(1), eq(200)))
|
||||
.thenReturn(new BatchTaskPage(-1, List.of(item("t-1", "5", 0, "等待"))));
|
||||
when(consoleClient.batchTasksPage(isNull(), eq(1), any(), eq(1), eq(200)))
|
||||
.thenReturn(new BatchTaskPage(-1, List.of()));
|
||||
|
||||
TaskCenterVariantPageVo page = service.variantTasks(superScope(), null, null, 1, 20);
|
||||
|
||||
assertEquals(1, page.getTotal(), "-1 哨兵不能把在跑数算成负数");
|
||||
assertEquals("待执行", page.getItems().get(0).getStatusLabel());
|
||||
assertEquals("成功", page.getItems().get(2).getStatusLabel());
|
||||
verify(consoleClient).batchTasksPage(isNull(), isNull(), eq("variant-collection"), eq(1), eq(20));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -181,19 +141,17 @@ class TaskCenterVariantServiceTest {
|
||||
@Test
|
||||
void nonNumericUidAndUnknownStatusDegradeGracefully() {
|
||||
when(consoleClient.configured()).thenReturn(true);
|
||||
when(consoleClient.batchTasksPage("5", 0, "variant-collection", 1, 200))
|
||||
when(consoleClient.batchTasksPage("5", null, "variant-collection", 1, 20))
|
||||
.thenReturn(new BatchTaskPage(3, List.of(
|
||||
item("t-1", "collect-27475", 0, "已添加至任务队列,等待执行"),
|
||||
item("t-2", "5", 9, ""))));
|
||||
when(consoleClient.batchTasksPage("5", 1, "variant-collection", 1, 200))
|
||||
.thenReturn(BatchTaskPage.EMPTY);
|
||||
when(queryMapper.selectUsernames(List.of(5L))).thenReturn(List.of(userRow(5L, "ali")));
|
||||
|
||||
TaskCenterVariantPageVo page = service.variantTasks(scoped(5L), null, null, 1, 20);
|
||||
|
||||
assertNull(page.getItems().get(0).getUsername(), "非数字 uid 不参与账号名映射");
|
||||
assertEquals("collect-27475", page.getItems().get(0).getUid());
|
||||
assertEquals("等待执行", page.getItems().get(0).getStatusLabel());
|
||||
assertEquals("待执行", page.getItems().get(0).getStatusLabel());
|
||||
assertEquals("ali", page.getItems().get(1).getUsername());
|
||||
assertEquals("未知", page.getItems().get(1).getStatusLabel(), "未识别的麦象状态码不冒充成功");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user