feat(appearance-patent): 外观专利数据库改为按主管划分的一主管一卡(2026-11-11 客户「应该是只显示一个卡片的才对」「获取店铺那边是按店铺做成卡片 我们这边就是按主管划分」)——后端新增 GET /supervisors 主管聚合(组键=与「所属主管」列同源的归属表达式:主管本人取自己、普通账户取创建人、读不到归同一 NULL 组;返回条数/任务数/最近任务号/最近同步/国家集,total 是主管数),卡片[下载]走 /export 新增 supervisor_user_id 按同一表达式收窄(不近似成 user_id OR created_by_id);共享 cleanItemConds 前移到 i. 前缀并复用(铁律 20 SQL 下推);后管页面由「每明细一卡」改为「一主管一卡」(卡头主管名/条数/任务/国家/最新 + 下载,对齐店铺数据记录一店一卡),明细分页卡片下架(3488 条铺成几千张卡是客户不要的形态),明细仍走 /export 表格看;护栏台账同轮更新(XML_SELECT_TOTAL 105→109、XML_STATEMENT_TOTAL 151→155、PageDefaults 56→58、SourceScan 52→55/vo 11→14、wiring 新增 /supervisors 发送口);后端 test-compile rc=0、controller 22 例绿+6 支护栏绿,前端 vue-tsc rc=0、mount 13/13、三支 node --test 21/21
This commit is contained in:
@@ -1,31 +1,24 @@
|
||||
<script setup lang="ts">
|
||||
import { formatDateTime, orderedPair } from '@/utils/datetime'
|
||||
/** 外观专利无侵权数据 · 只读分页列表(v1.3)。展示形式 2026-11-11 客户改版:参照「店铺数据记录」页
|
||||
* (ShopDataTasksPage)——form-box 筛选条件 + panel-box 工具条[导出] + 卡片宫格(4/3/2/1 响应式)
|
||||
* + OldPagination 服务端分页,推翻 2026-11-10「参照去重库页自绘 table」的旧拍板。
|
||||
* 筛选面同日二次精简(客户「筛选条件只要…和获取店铺一样」「按账号对应的主管吧 不需要店铺」):
|
||||
* 只留 分组(下拉,主管=组长,选中按「组长本人+名下子账户」整集 SQL 下推过滤)/国家/同步起止
|
||||
* 时间,字段顺序对齐获取店铺页(分组→国家→时间);任务号/ASIN 输入框下架——后端 §3.2 参数契约
|
||||
* (task_id/asin)与前端过滤模块逐字对撞护栏原样保留,只是 UI 不再暴露。数据由出表成功点
|
||||
* 自动同步(后端 SyncService),本页零写操作:无编辑/导入;单条明细没有可下载文件,下载/导出
|
||||
* 统一走既有 /export 全量出 xlsx(带当前过滤面 + 公司 tab,含所属主管列)。分组下拉选项与去重页
|
||||
* 共用 GET /shop-manages/groups,选中后以 group_id 走同一过滤面(列表与导出同源)。
|
||||
* 同日三改(客户「要按主管分组显示」「价格 asin 无侵权 这些都不需要展示的」「到时候能下载
|
||||
* 表格看就行」):卡片按所属主管连续分组——组头=主管名+本页条数(grid 全宽一行),组内行序
|
||||
* 保持服务端 synced_at DESC 原样,不跨页聚合、不按名重排(跨主管交错时按行序出多个同名组头,
|
||||
* 忠实反映同步顺序;要只看一个主管用分组下拉过滤)。卡片字段同批精简:只留 标题(卡头,替下
|
||||
* 原 ASIN 卡头)/任务/国家/品牌/SKU/同步;价格、ASIN、结论徽章(无侵权)、所属主管行不再
|
||||
* 上卡——全量明细(含价格/ASIN/结论/主管列)仍走 /export xlsx。同日四改(客户反馈「选了
|
||||
* 主管应该只显示这一个主管的才对」):分组(主管)下拉选中即查——选完立刻按该主管过滤刷新
|
||||
* (回第一页),不必再点查询;国家/时间仍走查询按钮。 */
|
||||
/** 外观专利数据库 · 按主管划分的卡片列表(v1.3 后续,2026-11-11 客户三连拍板:
|
||||
* 「要按主管分组显示」→「应该是只显示一个卡片的才对」→「获取店铺那边是按店铺做成卡片
|
||||
* 我们这边就是按主管划分」)。
|
||||
*
|
||||
* 形态:一主管一卡(对齐「店铺数据记录」页的一店一卡),卡内是该主管名下的汇总——
|
||||
* 条数 / 任务(几个任务、最近任务号)/ 国家 / 最新同步时间 + [下载](导出该主管名下全量 xlsx)。
|
||||
* 明细分页卡片(每明细一卡)已下架:3488 条明细会铺成几千张卡,客户明确不要。
|
||||
* 数据来自 GET /supervisors(后端按「主管本人取自己、普通账户取创建人」的归属表达式聚合,
|
||||
* total 是主管数),与明细导出走同一过滤面(分组/国家/同步起止 + 公司 tab)。
|
||||
* 页签零写操作:明细本身仍走 /export xlsx 看(客户「到时候能下载表格看就行」)。
|
||||
* 分组(主管)下拉选中即查(同日四改):客户选了主管就该只看到这一位/这一组的主管卡片。 */
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import {
|
||||
exportAppearancePatentCleanList,
|
||||
fetchAppearancePatentCleanList,
|
||||
fetchAppearancePatentCleanSupervisors,
|
||||
fetchDedupeTotalGroups,
|
||||
type DedupeGroupOption,
|
||||
} from './appearance-patent-clean-api.ts'
|
||||
import type { AppearancePatentCleanItem } from './appearance-patent-clean-model.ts'
|
||||
import type { AppearancePatentSupervisorCard } from './appearance-patent-clean-model.ts'
|
||||
import { createAppearancePatentCleanFilterState } from './appearance-patent-clean-filter.ts'
|
||||
import { ASIN_COUNTRY_CODES, asinCountryLabel } from '../asin/asin-country.ts'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
@@ -38,12 +31,15 @@ const companyTab = useCompanyTabStore()
|
||||
|
||||
const loading = ref(false)
|
||||
const loadFailure = ref('')
|
||||
const rows = ref<AppearancePatentCleanItem[]>([])
|
||||
const cards = ref<AppearancePatentSupervisorCard[]>([])
|
||||
/** 主管数(不是明细条数)。 */
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
const pageSize = ref(10)
|
||||
/** 导出在途锁:避免连点导出把同一份过滤面重复请求两遍。 */
|
||||
const exporting = ref(false)
|
||||
/** 单卡下载在途标记(存 supervisorId,避免连点同一张卡)。 */
|
||||
const downloadingId = ref<number | null>(null)
|
||||
/** 同步台账是累计数据,日期初值故意留空(默认当天会让首屏只剩今天同步的行);见 date-filter-default-today 护栏的 EXEMPT。 */
|
||||
const filter = reactive(createAppearancePatentCleanFilterState())
|
||||
/** 分组(主管)下拉选项:公司 tab 切换时重取;选项失败不拦列表,只回空下拉(可见「全部分组」)。 */
|
||||
@@ -57,22 +53,8 @@ function clampDatePair(): void {
|
||||
|
||||
const totalPages = computed(() => Math.max(1, Math.ceil(total.value / pageSize.value)))
|
||||
|
||||
/** 主管分组视图(2026-11-11 三改「要按主管分组显示」):按服务端下发顺序(synced_at DESC)把
|
||||
* 连续同主管的行切段,组头带本页条数;只在当前页窗口内分组——不跨页聚合、不按名重排,
|
||||
* 同名主管被别的主管隔开时按行序出多个同名组头。读不到主管名不猜,展示 -。 */
|
||||
const groupedRows = computed<{ name: string; items: AppearancePatentCleanItem[] }[]>(() => {
|
||||
const groups: { name: string; items: AppearancePatentCleanItem[] }[] = []
|
||||
for (const row of rows.value) {
|
||||
const name = row.supervisorName || '-'
|
||||
const last = groups[groups.length - 1]
|
||||
if (last && last.name === name) last.items.push(row)
|
||||
else groups.push({ name, items: [row] })
|
||||
}
|
||||
return groups
|
||||
})
|
||||
|
||||
/** 分组选项与去重页/店铺管理同源(GET /shop-manages/groups);失败静默回空——分组只是筛选项,
|
||||
* 不该让它把首屏行集一起拖死(列表失败有自己的 LoadFailureBar)。 */
|
||||
* 不该让它把首屏卡片一起拖死(列表失败有自己的 LoadFailureBar)。 */
|
||||
async function loadGroupOptions(): Promise<void> {
|
||||
try {
|
||||
groupOptions.value = await fetchDedupeTotalGroups(companyTab.requestCompanyId)
|
||||
@@ -85,18 +67,16 @@ async function load(): Promise<void> {
|
||||
loading.value = true
|
||||
loadFailure.value = ''
|
||||
try {
|
||||
const result = await fetchAppearancePatentCleanList({
|
||||
const result = await fetchAppearancePatentCleanSupervisors({
|
||||
page: page.value,
|
||||
pageSize: pageSize.value,
|
||||
taskId: filter.taskId,
|
||||
asin: filter.asin,
|
||||
country: filter.country,
|
||||
groupId: filter.groupId,
|
||||
startDate: filter.startDate,
|
||||
endDate: filter.endDate,
|
||||
companyId: companyTab.requestCompanyId,
|
||||
})
|
||||
rows.value = result.items
|
||||
cards.value = result.items
|
||||
total.value = result.total
|
||||
if (result.page >= 1) page.value = result.page
|
||||
} catch (error) {
|
||||
@@ -107,7 +87,7 @@ async function load(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
/** 导出与页签同一过滤面(含公司 tab 与分组),服务端全量出 xlsx;成功后浏览器落盘,失败弹可读文案。 */
|
||||
/** 顶部导出:当前过滤面(含公司 tab 与分组)全量出 xlsx。 */
|
||||
async function exportAll(): Promise<void> {
|
||||
if (exporting.value) return
|
||||
exporting.value = true
|
||||
@@ -121,14 +101,7 @@ async function exportAll(): Promise<void> {
|
||||
endDate: filter.endDate,
|
||||
companyId: companyTab.requestCompanyId,
|
||||
})
|
||||
const url = URL.createObjectURL(result.blob)
|
||||
const anchor = document.createElement('a')
|
||||
anchor.href = url
|
||||
anchor.download = result.filename
|
||||
document.body.appendChild(anchor)
|
||||
anchor.click()
|
||||
anchor.remove()
|
||||
URL.revokeObjectURL(url)
|
||||
saveBlob(result.blob, result.filename)
|
||||
showAdminFeedback(`已导出 ${result.filename}`, 'success')
|
||||
} catch (error) {
|
||||
const message = error instanceof Error && error.message ? error.message : '导出失败,请稍后重试'
|
||||
@@ -138,6 +111,43 @@ async function exportAll(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
/** 单卡下载:只导出该主管名下明细(与卡片同一归属口径,supervisor_user_id 收窄)。
|
||||
* 读不到主管的那组没有 id,不给按钮(不猜是哪位主管)。 */
|
||||
async function downloadSupervisor(card: AppearancePatentSupervisorCard): Promise<void> {
|
||||
if (card.supervisorId == null || downloadingId.value !== null) return
|
||||
downloadingId.value = card.supervisorId
|
||||
try {
|
||||
const result = await exportAppearancePatentCleanList({
|
||||
taskId: '',
|
||||
asin: '',
|
||||
country: filter.country,
|
||||
groupId: filter.groupId,
|
||||
startDate: filter.startDate,
|
||||
endDate: filter.endDate,
|
||||
companyId: companyTab.requestCompanyId,
|
||||
supervisorUserId: card.supervisorId,
|
||||
})
|
||||
saveBlob(result.blob, result.filename)
|
||||
showAdminFeedback(`已导出 ${card.supervisorName || '该主管'} 的数据`, 'success')
|
||||
} catch (error) {
|
||||
const message = error instanceof Error && error.message ? error.message : '下载失败,请稍后重试'
|
||||
showAdminFeedback(message, 'error')
|
||||
} finally {
|
||||
downloadingId.value = null
|
||||
}
|
||||
}
|
||||
|
||||
function saveBlob(blob: Blob, filename: string): void {
|
||||
const url = URL.createObjectURL(blob)
|
||||
const anchor = document.createElement('a')
|
||||
anchor.href = url
|
||||
anchor.download = filename
|
||||
document.body.appendChild(anchor)
|
||||
anchor.click()
|
||||
anchor.remove()
|
||||
URL.revokeObjectURL(url)
|
||||
}
|
||||
|
||||
function apply(): void {
|
||||
page.value = 1
|
||||
void load()
|
||||
@@ -216,45 +226,49 @@ onMounted(() => {
|
||||
</button>
|
||||
</div>
|
||||
<div class="clean-toolbar-side">
|
||||
<span class="clean-summary">共 {{ total }} 条记录 · 本页 {{ rows.length }} 条</span>
|
||||
<span class="clean-summary">共 {{ total }} 位主管 · 本页 {{ cards.length }} 位</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="clean-card-grid">
|
||||
<template v-if="groupedRows.length">
|
||||
<template v-for="(group, groupIndex) in groupedRows" :key="groupIndex">
|
||||
<div class="clean-group-head">
|
||||
<span class="clean-group-name" :title="group.name">{{ group.name }}</span>
|
||||
<span class="clean-group-count">本页 {{ group.items.length }} 条</span>
|
||||
<template v-if="cards.length">
|
||||
<article v-for="card in cards" :key="card.supervisorId ?? `unknown-${card.lastSyncedAt || ''}`" class="clean-card">
|
||||
<header class="clean-card-head">
|
||||
<span class="clean-card-supervisor" :title="card.supervisorName || '-'">{{ card.supervisorName || '-' }}</span>
|
||||
</header>
|
||||
<div class="clean-card-row">
|
||||
<span class="clean-card-label">条数</span>
|
||||
<span class="clean-card-value">{{ card.itemCount }} 条无侵权数据</span>
|
||||
</div>
|
||||
<article v-for="row in group.items" :key="row.id" class="clean-card">
|
||||
<header class="clean-card-head">
|
||||
<span class="clean-card-title" :title="row.title">{{ row.title || '-' }}</span>
|
||||
</header>
|
||||
<div class="clean-card-row">
|
||||
<span class="clean-card-label">任务</span>
|
||||
<span class="clean-card-value">{{ row.taskId ?? '-' }}</span>
|
||||
</div>
|
||||
<div class="clean-card-row">
|
||||
<span class="clean-card-label">国家</span>
|
||||
<span class="clean-card-value">
|
||||
<span class="country-chip">{{ asinCountryLabel(row.country || '') }}</span>
|
||||
</span>
|
||||
</div>
|
||||
<div class="clean-card-row">
|
||||
<span class="clean-card-label">品牌</span>
|
||||
<span class="clean-card-value">{{ row.brand || '-' }}</span>
|
||||
</div>
|
||||
<div class="clean-card-row">
|
||||
<span class="clean-card-label">SKU</span>
|
||||
<span class="clean-card-value mono">{{ row.sku || '-' }}</span>
|
||||
</div>
|
||||
<div class="clean-card-row">
|
||||
<span class="clean-card-label">同步</span>
|
||||
<span class="clean-card-value">{{ formatDateTime(row.syncedAt || '') || '-' }}</span>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
<div class="clean-card-row">
|
||||
<span class="clean-card-label">任务</span>
|
||||
<span class="clean-card-value">
|
||||
{{ card.taskCount }} 个任务<span v-if="card.lastTaskId != null"> · 最近 {{ card.lastTaskId }}</span>
|
||||
</span>
|
||||
</div>
|
||||
<div class="clean-card-row">
|
||||
<span class="clean-card-label">国家</span>
|
||||
<span class="clean-card-value">
|
||||
<span v-for="code in card.countryCodes" :key="code" class="country-chip">{{ asinCountryLabel(code) }}</span>
|
||||
<span v-if="!card.countryCodes.length">-</span>
|
||||
</span>
|
||||
</div>
|
||||
<div class="clean-card-row">
|
||||
<span class="clean-card-label">最新</span>
|
||||
<span class="clean-card-value">{{ formatDateTime(card.lastSyncedAt || '') || '-' }}</span>
|
||||
</div>
|
||||
<div class="clean-card-actions">
|
||||
<button
|
||||
class="btn btn-sm"
|
||||
type="button"
|
||||
:disabled="card.supervisorId == null || downloadingId !== null"
|
||||
:title="card.supervisorId == null ? '读不到主管账号,无法按主管导出(可用顶部导出)' : undefined"
|
||||
@click="downloadSupervisor(card)"
|
||||
>
|
||||
{{ downloadingId === card.supervisorId && card.supervisorId != null ? '下载中...' : '下载' }}
|
||||
</button>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
<div v-else-if="loading" class="empty-tip">加载中...</div>
|
||||
<div v-else class="empty-tip">暂无无侵权数据</div>
|
||||
@@ -266,10 +280,9 @@ onMounted(() => {
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* 像素复刻参照「店铺数据记录」页(ShopDataTasksPage):form-box 筛选 + panel-box 工具条 +
|
||||
卡片宫格 + 旧式分页,蓝白末层;只读卡片无勾选/无单卡操作(本页零写操作)。
|
||||
2026-11-11 三改:卡片宫格按所属主管分段(.clean-group-head 全宽组头),卡头=标题;
|
||||
ASIN/结论徽章(st-pill)/价格/主管行的样式随下卡一并退役。 */
|
||||
/* 形态参照「店铺数据记录」页(ShopDataTasksPage):form-box 筛选 + panel-box 工具条 +
|
||||
卡片宫格 + 旧式分页,蓝白末层。2026-11-11 客户三连拍板后本页是<b>一主管一卡</b>:
|
||||
卡头=主管名,卡内条数/任务/国家/最新 + [下载];明细不再铺卡(几千条明细=几千张卡)。 */
|
||||
.clean-items-view {
|
||||
font-family: inherit;
|
||||
color: #24384d;
|
||||
@@ -380,6 +393,10 @@ h3 {
|
||||
border-color: #95b1cb;
|
||||
background: #edf5fb;
|
||||
}
|
||||
.btn-sm {
|
||||
min-height: 36px;
|
||||
padding: 7px 14px;
|
||||
}
|
||||
.clean-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -425,10 +442,10 @@ h3 {
|
||||
padding: 12px 16px;
|
||||
border-bottom: 1px solid #e6edf4;
|
||||
}
|
||||
.clean-card-title {
|
||||
.clean-card-supervisor {
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
color: #24384d;
|
||||
font-size: 13px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
@@ -442,7 +459,7 @@ h3 {
|
||||
}
|
||||
.clean-card-label {
|
||||
flex: none;
|
||||
width: 60px;
|
||||
width: 46px;
|
||||
color: #8293a5;
|
||||
}
|
||||
.clean-card-value {
|
||||
@@ -452,33 +469,11 @@ h3 {
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.mono {
|
||||
font-family: "Cascadia Mono", "SF Mono", Consolas, "Courier New", monospace;
|
||||
font-size: 12.5px;
|
||||
}
|
||||
.clean-group-head {
|
||||
grid-column: 1 / -1;
|
||||
.clean-card-actions {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 10px;
|
||||
padding: 9px 14px;
|
||||
border: 1px solid #d8e3ee;
|
||||
border-radius: 10px;
|
||||
background: #f2f7fc;
|
||||
}
|
||||
.clean-group-name {
|
||||
font-weight: 650;
|
||||
font-size: 13.5px;
|
||||
color: #24384d;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.clean-group-count {
|
||||
flex: none;
|
||||
color: #5b6f83;
|
||||
font-size: 12px;
|
||||
white-space: nowrap;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
padding: 8px 16px 14px;
|
||||
}
|
||||
.country-chip {
|
||||
padding: 1px 8px;
|
||||
|
||||
@@ -12,10 +12,14 @@ import {
|
||||
} from './appearance-patent-clean-filter.ts'
|
||||
import {
|
||||
parseAppearancePatentCleanPage,
|
||||
parseAppearancePatentSupervisorPage,
|
||||
type AppearancePatentCleanPageResult,
|
||||
type AppearancePatentSupervisorPageResult,
|
||||
} from './appearance-patent-clean-model.ts'
|
||||
|
||||
export const APPEARANCE_PATENT_CLEAN_ENDPOINT = '/api/admin/appearance-patent-clean-items'
|
||||
/** 主管聚合卡片端点(2026-11-11 客户「获取店铺那边是按店铺做成卡片 我们这边就是按主管划分」)。 */
|
||||
export const APPEARANCE_PATENT_SUPERVISOR_ENDPOINT = `${APPEARANCE_PATENT_CLEAN_ENDPOINT}/supervisors`
|
||||
|
||||
export async function fetchAppearancePatentCleanList(
|
||||
params: AppearancePatentCleanListParams,
|
||||
@@ -37,6 +41,37 @@ export async function fetchAppearancePatentCleanList(
|
||||
return parseAppearancePatentCleanPage(data)
|
||||
}
|
||||
|
||||
export interface AppearancePatentSupervisorListParams {
|
||||
page: number
|
||||
pageSize: number
|
||||
country?: string
|
||||
groupId?: string
|
||||
startDate?: string
|
||||
endDate?: string
|
||||
companyId?: number | null
|
||||
}
|
||||
|
||||
/** 主管聚合卡片列表(一主管一卡):与明细列表同一过滤面 + 公司 tab,total 是主管数。 */
|
||||
export async function fetchAppearancePatentCleanSupervisors(
|
||||
params: AppearancePatentSupervisorListParams,
|
||||
): Promise<AppearancePatentSupervisorPageResult> {
|
||||
const query = toAppearancePatentCleanListParams(
|
||||
{
|
||||
taskId: '',
|
||||
asin: '',
|
||||
country: params.country ?? '',
|
||||
groupId: params.groupId ?? '',
|
||||
startDate: params.startDate ?? '',
|
||||
endDate: params.endDate ?? '',
|
||||
},
|
||||
params.page,
|
||||
params.pageSize,
|
||||
)
|
||||
if (params.companyId != null) query.company_id = params.companyId
|
||||
const { data } = await http.get<unknown>(APPEARANCE_PATENT_SUPERVISOR_ENDPOINT, { params: query })
|
||||
return parseAppearancePatentSupervisorPage(data)
|
||||
}
|
||||
|
||||
export interface AppearancePatentCleanExportResult {
|
||||
blob: Blob
|
||||
filename: string
|
||||
@@ -57,19 +92,22 @@ function exportFilenameOf(disposition: unknown): string {
|
||||
return plain?.[1] || '外观专利数据库.xlsx'
|
||||
}
|
||||
|
||||
/** 导出当前过滤面全量明细:与列表共用同一过滤面取值口(含公司 tab),blob 下载交给页面触发保存。 */
|
||||
/** 导出当前过滤面全量明细:与列表共用同一过滤面取值口(含公司 tab),blob 下载交给页面触发保存。
|
||||
* {@code supervisorUserId} 传入=只导出该主管名下明细(卡片上的「下载」,2026-11-11 一主管一卡)。 */
|
||||
export async function exportAppearancePatentCleanList(
|
||||
params: AppearancePatentCleanExportParams,
|
||||
params: AppearancePatentCleanExportParams & { supervisorUserId?: number | null },
|
||||
): Promise<AppearancePatentCleanExportResult> {
|
||||
const query: AppearancePatentCleanExportQuery = toAppearancePatentCleanExportParams({
|
||||
taskId: params.taskId ?? '',
|
||||
asin: params.asin ?? '',
|
||||
country: params.country ?? '',
|
||||
groupId: params.groupId ?? '',
|
||||
startDate: params.startDate ?? '',
|
||||
endDate: params.endDate ?? '',
|
||||
})
|
||||
const query: AppearancePatentCleanExportQuery & { supervisor_user_id?: number } =
|
||||
toAppearancePatentCleanExportParams({
|
||||
taskId: params.taskId ?? '',
|
||||
asin: params.asin ?? '',
|
||||
country: params.country ?? '',
|
||||
groupId: params.groupId ?? '',
|
||||
startDate: params.startDate ?? '',
|
||||
endDate: params.endDate ?? '',
|
||||
})
|
||||
if (params.companyId != null) query.company_id = params.companyId
|
||||
if (params.supervisorUserId != null) query.supervisor_user_id = params.supervisorUserId
|
||||
const response = await http.get<Blob>(`${APPEARANCE_PATENT_CLEAN_ENDPOINT}/export`, {
|
||||
params: query,
|
||||
responseType: 'blob',
|
||||
|
||||
@@ -37,10 +37,82 @@ export interface AppearancePatentCleanPageResult {
|
||||
/** 前端首屏默认容量:与后端 PageDefaults.CLEAN_ITEMS_PAGE_SIZE(蓝图 §3.2 默认 10)同值。 */
|
||||
export const APPEARANCE_PATENT_CLEAN_DEFAULT_SIZE = 10
|
||||
|
||||
/** 主管卡片(2026-11-11 客户「获取店铺那边是按店铺做成卡片 我们这边就是按主管划分」):
|
||||
* 一主管一卡,卡内是该主管名下的汇总——不再按明细铺卡(几千条明细=几千张卡,客户明确不要)。 */
|
||||
export interface AppearancePatentSupervisorCard {
|
||||
/** 主管用户 id;null=读不到主管的那一组(该卡不提供按主管下载)。 */
|
||||
supervisorId: number | null
|
||||
/** 主管名(读不到为空,界面展示 -)。 */
|
||||
supervisorName: string
|
||||
/** 无侵权明细条数。 */
|
||||
itemCount: number
|
||||
/** 涉及任务数。 */
|
||||
taskCount: number
|
||||
/** 最近涉及的任务号。 */
|
||||
lastTaskId: number | null
|
||||
/** 最近同步时间。 */
|
||||
lastSyncedAt?: string
|
||||
/** 涉及国家码集(前端用自己的国家字典翻中文)。 */
|
||||
countryCodes: string[]
|
||||
}
|
||||
|
||||
export interface AppearancePatentSupervisorPageResult {
|
||||
items: AppearancePatentSupervisorCard[]
|
||||
/** 主管数(不是明细条数)。 */
|
||||
total: number
|
||||
page: number
|
||||
pageSize: number
|
||||
}
|
||||
|
||||
export function emptyAppearancePatentCleanPage(): AppearancePatentCleanPageResult {
|
||||
return { items: [], total: 0, page: 1, pageSize: APPEARANCE_PATENT_CLEAN_DEFAULT_SIZE }
|
||||
}
|
||||
|
||||
/** 解析主管卡片;缺 supervisorId 的(未知主管组)依然保留(那一卡展示 -),不算无效行。 */
|
||||
export function toAppearancePatentSupervisorCard(raw: unknown): AppearancePatentSupervisorCard | null {
|
||||
if (!raw || typeof raw !== 'object') return null
|
||||
const record = raw as Record<string, unknown>
|
||||
const itemCount = numberOrNull(record.itemCount ?? record.item_count)
|
||||
if (itemCount === null) return null
|
||||
const rawCodes = record.countryCodes ?? record.country_codes
|
||||
const countryCodes = Array.isArray(rawCodes)
|
||||
? rawCodes.map((code) => text(code)).filter((code) => code.length > 0)
|
||||
: []
|
||||
return {
|
||||
supervisorId: numberOrNull(record.supervisorId ?? record.supervisor_id),
|
||||
supervisorName: text(record.supervisorName ?? record.supervisor_name),
|
||||
itemCount,
|
||||
taskCount: numberOrNull(record.taskCount ?? record.task_count) ?? 0,
|
||||
lastTaskId: numberOrNull(record.lastTaskId ?? record.last_task_id),
|
||||
lastSyncedAt: text(record.lastSyncedAt ?? record.last_synced_at) || undefined,
|
||||
countryCodes,
|
||||
}
|
||||
}
|
||||
|
||||
/** 解析主管卡片分页信封({items,total,page,pageSize});total 是主管数。 */
|
||||
export function parseAppearancePatentSupervisorPage(payload: unknown): AppearancePatentSupervisorPageResult {
|
||||
const out: AppearancePatentSupervisorPageResult = {
|
||||
items: [],
|
||||
total: 0,
|
||||
page: 1,
|
||||
pageSize: APPEARANCE_PATENT_CLEAN_DEFAULT_SIZE,
|
||||
}
|
||||
const core = unwrap<unknown>(payload)
|
||||
if (!core || typeof core !== 'object') return out
|
||||
const record = core as Record<string, unknown>
|
||||
if (Array.isArray(record.items)) {
|
||||
out.items = record.items
|
||||
.map((raw) => toAppearancePatentSupervisorCard(raw))
|
||||
.filter((item): item is AppearancePatentSupervisorCard => item !== null)
|
||||
}
|
||||
if (typeof record.total === 'number') out.total = Math.floor(record.total)
|
||||
if (typeof record.page === 'number' && record.page >= 1) out.page = Math.floor(record.page)
|
||||
const rawSize = record.pageSize ?? record.page_size
|
||||
if (typeof rawSize === 'number' && rawSize >= 1) out.pageSize = Math.floor(rawSize)
|
||||
return out
|
||||
}
|
||||
|
||||
|
||||
function text(value: unknown): string {
|
||||
return typeof value === 'string' ? value.trim() : ''
|
||||
}
|
||||
|
||||
@@ -130,6 +130,8 @@ const SEND_POINTS: ReadonlyArray<SendPoint> = [
|
||||
// 500 够得着自己、够不到隔壁(对平用例逐处从真文件重算,注释过期即红)。
|
||||
{ menuKey: 'admin_appearance_patent_clean_items', file: 'src/pages/patent/appearance-patent-clean-api.ts', fn: 'fetchAppearancePatentCleanList', line: 'if (params.companyId != null) query.company_id = params.companyId', window: 500, title: 'GET /appearance-patent-clean-items 无侵权只读列表' },
|
||||
{ menuKey: 'admin_appearance_patent_clean_items', file: 'src/pages/patent/appearance-patent-clean-api.ts', fn: 'exportAppearancePatentCleanList', line: 'if (params.companyId != null) query.company_id = params.companyId', window: 500, title: 'GET /appearance-patent-clean-items/export 导出(2026-11-11 客户需求「数据得导出来」,与列表共用同一过滤面)' },
|
||||
// 2026-11-11 二次改版(一主管一卡):/supervisors 主管聚合卡片的取数口,与列表/导出同一过滤面与正门。
|
||||
{ menuKey: 'admin_appearance_patent_clean_items', file: 'src/pages/patent/appearance-patent-clean-api.ts', fn: 'fetchAppearancePatentCleanSupervisors', line: 'if (params.companyId != null) query.company_id = params.companyId', window: 500, title: 'GET /appearance-patent-clean-items/supervisors 主管聚合卡片(客户「我们这边就是按主管划分」)' },
|
||||
]
|
||||
|
||||
/** 任务看板那 5 处(1b ④ 那条用例按文件筛它们,沿用旧名字不漂;表只有一份,不会漂出两个口径)。 */
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
/**
|
||||
* 外观专利无侵权数据页(v1.3 AC-5)的挂载契约 —— Phase 3 激活。
|
||||
* 外观专利无侵权数据页(v1.3 AC-5)的挂载契约。
|
||||
*
|
||||
* 展示形式(2026-11-11 客户改版,推翻 2026-11-10「参照去重库页自绘 table、不做卡片宫格」的
|
||||
* 旧拍板):参照「店铺数据记录」页(ShopDataTasksPage)——form-box 筛选条件 + panel-box
|
||||
* 工具条[导出] + 卡片宫格 + `OldPagination.vue` 服务端分页。同日三改(客户「要按主管分组
|
||||
* 显示」「价格 asin 无侵权 这些都不需要展示的」「到时候能下载表格看就行」):卡片按所属主管
|
||||
* 连续分组(组头=主管名+本页条数,保持行序、不跨页聚合、不按名重排),每卡一条明细:标题
|
||||
* (卡头)/任务号/国家/品牌/SKU/同步时间;价格、ASIN、结论徽章(无侵权)、所属主管行不再
|
||||
* 上卡——全量明细(含价格/ASIN/结论/主管列)仍走 /export xlsx。筛选面同日二次精简(客户「按账号对应的
|
||||
* 主管吧 不需要店铺」):分组(=主管)/国家/起止时间三样,任务号/ASIN 输入框下架(后端
|
||||
* §3.2 参数契约与过滤模块逐字对撞护栏保留,UI 不再暴露)。取数/导出/公司 tab 契约不变:
|
||||
* `companyScoped: true` 公司 Tab;`page`/`page_size` snake 参数,响应
|
||||
* `{items, total, page, pageSize}`。默认仅 super_admin 可见(菜单不预授权,
|
||||
* 判据在后端 AdminAppearancePatentCleanItemsControllerTest 的菜单迁移支,这里只管前端接线)。
|
||||
* 形态(2026-11-11 客户三连拍板:「要按主管分组显示」→「应该是只显示一个卡片的才对」→
|
||||
* 「获取店铺那边是按店铺做成卡片 我们这边就是按主管划分」):<b>一主管一卡</b>,对齐
|
||||
* 「店铺数据记录」页的一店一卡——卡头=主管名,卡内 条数 / 任务(几个任务·最近任务号)/
|
||||
* 国家 / 最新同步时间 + [下载](导出该主管名下 xlsx)。明细分页卡片(每明细一卡)已下架:
|
||||
* 3488 条明细铺成几千张卡是客户明确不要的形态;明细仍走 /export 表格看。
|
||||
* 数据来自 GET /supervisors(后端按归属表达式聚合,total 是主管数)。筛选面不变
|
||||
* (分组=主管/国家/同步起止,分组选中即查),取数/导出/公司 tab 契约照旧。
|
||||
*
|
||||
* 跑法:`npx vitest run tests/mount/appearance-patent-clean-page.test.ts`
|
||||
*/
|
||||
@@ -32,36 +27,22 @@ const PAGE_PATH = 'src/pages/patent/AppearancePatentCleanItemsPage.vue'
|
||||
const MENU_KEY = 'admin_appearance_patent_clean_items'
|
||||
|
||||
const cleanApi = vi.hoisted(() => ({
|
||||
fetchAppearancePatentCleanList: vi.fn(),
|
||||
fetchAppearancePatentCleanSupervisors: vi.fn(),
|
||||
exportAppearancePatentCleanList: vi.fn(),
|
||||
fetchDedupeTotalGroups: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/pages/patent/appearance-patent-clean-api.ts', () => cleanApi)
|
||||
|
||||
function row(id: number, over: Record<string, unknown> = {}) {
|
||||
function card(supervisorId: number | null, over: Record<string, unknown> = {}) {
|
||||
return {
|
||||
id,
|
||||
resultId: 900 + id,
|
||||
taskId: 33179,
|
||||
userId: 7,
|
||||
supervisorName: `主管${id}`,
|
||||
companyId: 1,
|
||||
rowNo: id,
|
||||
asin: `B0AB8CDEF${id}`,
|
||||
country: 'DE',
|
||||
sku: `SKU-${id}`,
|
||||
brand: 'Anker',
|
||||
price: '29.99',
|
||||
title: `无侵权商品 ${id}`,
|
||||
imageUrl: '',
|
||||
itemUrl: '',
|
||||
conclusion: '无侵权',
|
||||
titleReason: '',
|
||||
appearanceReason: '',
|
||||
patentReason: '',
|
||||
sourceFilename: 'list.xlsx',
|
||||
syncedAt: '2026-11-10T10:30:00',
|
||||
supervisorId,
|
||||
supervisorName: supervisorId == null ? '' : `主管${supervisorId}`,
|
||||
itemCount: 120,
|
||||
taskCount: 3,
|
||||
lastTaskId: 33874,
|
||||
lastSyncedAt: '2026-11-11T11:34:29',
|
||||
countryCodes: ['DE', 'UK'],
|
||||
...over,
|
||||
}
|
||||
}
|
||||
@@ -74,28 +55,26 @@ beforeEach(() => {
|
||||
setActivePinia(pinia)
|
||||
useAdminSessionStore().user = { id: 1, username: 'root', role: 'super_admin' }
|
||||
useCompanyTabStore().setActiveId(1)
|
||||
// 分组(主管)选项默认空集:分组用例各自覆写
|
||||
cleanApi.fetchDedupeTotalGroups.mockResolvedValue([])
|
||||
})
|
||||
|
||||
async function mountWith(payload: unknown): Promise<VueWrapper<Element>> {
|
||||
cleanApi.fetchAppearancePatentCleanList.mockImplementation(() => Promise.resolve(payload))
|
||||
cleanApi.fetchAppearancePatentCleanSupervisors.mockImplementation(() => Promise.resolve(payload))
|
||||
const wrapper = mount(AppearancePatentCleanItemsPage, { global: { plugins: [pinia] } })
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
return wrapper
|
||||
}
|
||||
|
||||
describe('AC-5 外观专利无侵权数据页(卡片宫格,2026-11-11 改版参照店铺数据记录页)', () => {
|
||||
it('页面组件落位且是店铺数据记录式卡片宫格 + OldPagination 的分页列表', () => {
|
||||
// vitest 的 cwd = admin-frontend-vue 根(Phase 0 预置用 new URL 模板串,被 vite 静态分析成
|
||||
// undefined——skip 期间从未执行所以没暴露,激活时改走 cwd 解析)。
|
||||
describe('外观专利数据库页(一主管一卡,2026-11-11 客户「我们这边就是按主管划分」)', () => {
|
||||
it('页面组件落位:卡片宫格 + 主管聚合端点,不再按明细铺卡', () => {
|
||||
const src = readFileSync(resolve(process.cwd(), PAGE_PATH), 'utf-8')
|
||||
expect(src).toContain('OldPagination')
|
||||
expect(src).toContain('clean-card-grid', '卡片宫格容器必须就位(2026-11-11 客户改版)')
|
||||
expect(src).toContain('clean-card-grid', '卡片宫格容器必须就位')
|
||||
expect(src).toContain('clean-card-head', '卡片本体结构必须就位')
|
||||
expect(src).toContain('clean-group-head', '主管分组头必须就位(2026-11-11 三改「按主管分组显示」)')
|
||||
expect(src).not.toContain('<table', '改版后不再有自绘行列表(推翻 2026-11-10 旧拍板)')
|
||||
expect(src).toContain('fetchAppearancePatentCleanSupervisors', '必须走主管聚合端点(一主管一卡)')
|
||||
expect(src).toContain('supervisorUserId', '单卡下载按主管收窄导出')
|
||||
expect(src).not.toContain('<table', '本页不是自绘行列表')
|
||||
expect(src).not.toContain('el-card')
|
||||
})
|
||||
|
||||
@@ -110,65 +89,81 @@ describe('AC-5 外观专利无侵权数据页(卡片宫格,2026-11-11 改版
|
||||
expect(scoped?.pageFiles).toContain(PAGE_PATH)
|
||||
})
|
||||
|
||||
it('挂载后按首屏 snake 分页参数取数并解包 {items,total,page,pageSize}', async () => {
|
||||
const wrapper = await mountWith({ items: [row(1), row(2)], total: 42, page: 1, pageSize: 10 })
|
||||
it('挂载后按首屏分页参数取主管聚合,卡片数=主管数而不是明细条数', async () => {
|
||||
const wrapper = await mountWith({
|
||||
items: [card(9), card(44), card(null, { supervisorName: '' })],
|
||||
total: 3,
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
})
|
||||
|
||||
expect(cleanApi.fetchAppearancePatentCleanList).toHaveBeenCalledTimes(1)
|
||||
const firstCall = cleanApi.fetchAppearancePatentCleanList.mock.calls[0][0]
|
||||
expect(cleanApi.fetchAppearancePatentCleanSupervisors).toHaveBeenCalledTimes(1)
|
||||
const firstCall = cleanApi.fetchAppearancePatentCleanSupervisors.mock.calls[0][0]
|
||||
expect(firstCall.page).toBe(1)
|
||||
expect(firstCall.pageSize).toBe(10)
|
||||
expect(firstCall.companyId).toBe(1)
|
||||
expect(wrapper.findAll('.clean-card')).toHaveLength(2, '一卡一条明细')
|
||||
expect(wrapper.text()).toContain('共 42 条')
|
||||
// 2026-11-11 三改:ASIN/价格/结论徽章不再上卡(全量明细走导出),卡头换成标题
|
||||
expect(wrapper.text()).not.toContain('B0AB8CDEF1')
|
||||
expect(wrapper.text()).not.toContain('29.99')
|
||||
expect(wrapper.find('.st-pill').exists()).toBe(false, '无侵权结论徽章不再上卡')
|
||||
const heads = wrapper.findAll('.clean-card-head')
|
||||
expect(heads).toHaveLength(2)
|
||||
expect(heads[0].text()).toContain('无侵权商品 1', '卡头=标题(替下原 ASIN 卡头)')
|
||||
expect(wrapper.findAll('.clean-card')).toHaveLength(3, '一主管一卡')
|
||||
expect(wrapper.text()).toContain('共 3 位主管', '汇总按主管计数(不是明细条数)')
|
||||
})
|
||||
|
||||
it('按所属主管分组显示(2026-11-11 三改):组头=主管名+本页条数,卡片不再重复主管行', async () => {
|
||||
const wrapper = await mountWith({
|
||||
items: [row(1, { supervisorName: '主管甲' }), row(2, { supervisorName: '主管甲' }), row(3, { supervisorName: '主管乙' })],
|
||||
total: 3,
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
})
|
||||
const heads = wrapper.findAll('.clean-group-head')
|
||||
expect(heads).toHaveLength(2, '连续同主管的行切段成组')
|
||||
expect(heads[0].text()).toContain('主管甲')
|
||||
expect(heads[0].text()).toContain('本页 2 条')
|
||||
expect(heads[1].text()).toContain('主管乙')
|
||||
expect(heads[1].text()).toContain('本页 1 条')
|
||||
expect(wrapper.findAll('.clean-card')).toHaveLength(3, '组头不占卡片位,三张明细卡都在')
|
||||
// 主管行已由组头表达,卡片不再重复;价格行同批下卡
|
||||
expect(wrapper.text()).not.toContain('所属主管')
|
||||
expect(wrapper.text()).not.toContain('价格')
|
||||
it('卡片内容=主管名/条数/任务/国家/最新(对齐店铺数据记录的一卡一主体信息面)', async () => {
|
||||
const wrapper = await mountWith({ items: [card(9)], total: 1, page: 1, pageSize: 10 })
|
||||
const one = wrapper.find('.clean-card')
|
||||
expect(one.find('.clean-card-supervisor').text()).toBe('主管9', '卡头=主管名')
|
||||
const rowValue = (label: string): string => {
|
||||
const row = one.findAll('.clean-card-row').find((r) => r.find('.clean-card-label').text() === label)
|
||||
expect(row, `卡片必须有「${label}」行`).toBeTruthy()
|
||||
return row!.find('.clean-card-value').text()
|
||||
}
|
||||
expect(rowValue('条数')).toContain('120 条', '明细条数是汇总不是列表')
|
||||
expect(rowValue('任务')).toContain('3 个任务')
|
||||
expect(rowValue('任务')).toContain('33874', '带最近任务号')
|
||||
expect(rowValue('国家')).toContain('德国')
|
||||
expect(rowValue('国家')).toContain('英国')
|
||||
expect(rowValue('最新')).not.toBe('')
|
||||
})
|
||||
|
||||
it('分组只在当前页窗口内连续切段:保持服务端行序、不跨页聚合、不按名重排', async () => {
|
||||
const wrapper = await mountWith({
|
||||
items: [row(1, { supervisorName: '主管甲' }), row(2, { supervisorName: '主管乙' }), row(3, { supervisorName: '主管甲' })],
|
||||
total: 3,
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
})
|
||||
const names = wrapper.findAll('.clean-group-name').map((n) => n.text())
|
||||
expect(names).toEqual(['主管甲', '主管乙', '主管甲'], '同名主管被隔开时按行序出多个同名组头,忠实反映同步顺序')
|
||||
expect(wrapper.findAll('.clean-card')).toHaveLength(3)
|
||||
it('读不到主管的那一卡展示 -,且不给下载按钮(不猜是哪位主管)', async () => {
|
||||
const wrapper = await mountWith({ items: [card(null)], total: 1, page: 1, pageSize: 10 })
|
||||
const one = wrapper.find('.clean-card')
|
||||
expect(one.find('.clean-card-supervisor').text()).toBe('-', '读不到主管不猜名字')
|
||||
const downloadBtn = one.findAll('button').find((b) => b.text() === '下载')
|
||||
expect(downloadBtn).toBeTruthy()
|
||||
expect((downloadBtn!.element as HTMLButtonElement).disabled).toBe(true, '无主管 id 不可按主管导出')
|
||||
})
|
||||
|
||||
it('读不到主管名的行不猜:组头展示 -(与旧卡片行同口径)', async () => {
|
||||
const wrapper = await mountWith({ items: [row(9, { supervisorName: '' })], total: 1, page: 1, pageSize: 10 })
|
||||
const heads = wrapper.findAll('.clean-group-head')
|
||||
expect(heads).toHaveLength(1)
|
||||
expect(heads[0].text()).toContain('-', '读不到主管展示 -')
|
||||
expect(heads[0].text()).toContain('本页 1 条')
|
||||
it('单卡下载=按该主管导出(带 supervisorUserId 与当前过滤面)', async () => {
|
||||
const createObjectURL = vi.fn(() => 'blob:mock-url')
|
||||
const revokeObjectURL = vi.fn()
|
||||
const urlRecord = URL as unknown as Record<string, unknown>
|
||||
Object.defineProperty(URL, 'createObjectURL', { value: createObjectURL, configurable: true, writable: true })
|
||||
Object.defineProperty(URL, 'revokeObjectURL', { value: revokeObjectURL, configurable: true, writable: true })
|
||||
const clickSpy = vi.spyOn(HTMLAnchorElement.prototype, 'click').mockImplementation(() => {})
|
||||
cleanApi.exportAppearancePatentCleanList.mockImplementation(() =>
|
||||
Promise.resolve({ blob: new Blob(['xlsx']), filename: '外观专利数据库-20261111120000.xlsx' }),
|
||||
)
|
||||
|
||||
try {
|
||||
const wrapper = await mountWith({ items: [card(9)], total: 1, page: 1, pageSize: 10 })
|
||||
const btn = wrapper.find('.clean-card').findAll('button').find((b) => b.text() === '下载')
|
||||
await btn!.trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
|
||||
expect(cleanApi.exportAppearancePatentCleanList).toHaveBeenCalledTimes(1)
|
||||
const call = cleanApi.exportAppearancePatentCleanList.mock.calls[0][0]
|
||||
expect(call).toMatchObject({ supervisorUserId: 9, companyId: 1, country: '', groupId: '' })
|
||||
expect(createObjectURL).toHaveBeenCalledTimes(1)
|
||||
expect(clickSpy).toHaveBeenCalled()
|
||||
expect(document.body.textContent).toContain('已导出', '成功反馈点名落盘文件')
|
||||
} finally {
|
||||
Object.defineProperty(URL, 'createObjectURL', { value: undefined, configurable: true, writable: true })
|
||||
Object.defineProperty(URL, 'revokeObjectURL', { value: undefined, configurable: true, writable: true })
|
||||
clickSpy.mockRestore()
|
||||
}
|
||||
})
|
||||
|
||||
it('导出按钮带当前过滤面与公司 tab 调导出接口,成功触发 blob 落盘', async () => {
|
||||
it('顶部导出带当前过滤面与公司 tab,不带 supervisorUserId(全量)', async () => {
|
||||
const createObjectURL = vi.fn(() => 'blob:mock-url')
|
||||
const revokeObjectURL = vi.fn()
|
||||
const urlRecord = URL as unknown as Record<string, unknown>
|
||||
@@ -178,18 +173,15 @@ describe('AC-5 外观专利无侵权数据页(卡片宫格,2026-11-11 改版
|
||||
Object.defineProperty(URL, 'revokeObjectURL', { value: revokeObjectURL, configurable: true, writable: true })
|
||||
const clickSpy = vi.spyOn(HTMLAnchorElement.prototype, 'click').mockImplementation(() => {})
|
||||
cleanApi.exportAppearancePatentCleanList.mockImplementation(() =>
|
||||
Promise.resolve({ blob: new Blob(['xlsx'], { type: 'application/vnd.ms-excel' }), filename: '外观专利数据库-20261111103000.xlsx' }),
|
||||
Promise.resolve({ blob: new Blob(['xlsx']), filename: '外观专利数据库-20261111120000.xlsx' }),
|
||||
)
|
||||
|
||||
try {
|
||||
const wrapper = await mountWith({ items: [row(1)], total: 1, page: 1, pageSize: 10 })
|
||||
const exportBtn = wrapper.findAll('button').find((b) => b.text() === '导出')
|
||||
expect(exportBtn).toBeTruthy()
|
||||
await exportBtn!.trigger('click')
|
||||
const wrapper = await mountWith({ items: [card(9)], total: 1, page: 1, pageSize: 10 })
|
||||
await wrapper.findAll('button').find((b) => b.text() === '导出')!.trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
|
||||
expect(cleanApi.exportAppearancePatentCleanList).toHaveBeenCalledTimes(1)
|
||||
const call = cleanApi.exportAppearancePatentCleanList.mock.calls[0][0]
|
||||
expect(call).toMatchObject({
|
||||
taskId: '',
|
||||
@@ -200,10 +192,9 @@ describe('AC-5 外观专利无侵权数据页(卡片宫格,2026-11-11 改版
|
||||
endDate: '',
|
||||
companyId: 1,
|
||||
})
|
||||
expect(call.supervisorUserId).toBeUndefined()
|
||||
expect(createObjectURL).toHaveBeenCalledTimes(1)
|
||||
expect(revokeObjectURL).toHaveBeenCalledWith('blob:mock-url')
|
||||
expect(clickSpy).toHaveBeenCalled()
|
||||
expect(document.body.textContent).toContain('已导出', '成功反馈点名落盘文件')
|
||||
} finally {
|
||||
Object.defineProperty(URL, 'createObjectURL', { value: origCreate, configurable: true })
|
||||
Object.defineProperty(URL, 'revokeObjectURL', { value: origRevoke, configurable: true })
|
||||
@@ -213,42 +204,40 @@ describe('AC-5 外观专利无侵权数据页(卡片宫格,2026-11-11 改版
|
||||
|
||||
it('导出失败把服务端业务文案弹出来,不许静默', async () => {
|
||||
cleanApi.exportAppearancePatentCleanList.mockImplementation(() =>
|
||||
Promise.reject(new Error('无侵权数据共 90001 行,超过导出上限 50000 行,请缩小筛选范围后重试')))
|
||||
Promise.reject(new Error('该主管的无侵权数据共 90001 行,超过导出上限 50000 行,请缩小筛选范围后重试')))
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 10 })
|
||||
await wrapper.findAll('button').find((b) => b.text() === '导出')!.trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
expect(document.body.textContent).toContain('超过导出上限', '失败反馈必须是服务端那句可读文案')
|
||||
// 失败后导出锁复位,按钮可再次点击
|
||||
expect(document.body.textContent).toContain('超过导出上限')
|
||||
expect(wrapper.findAll('button').find((b) => b.text() === '导出')!.text()).toBe('导出')
|
||||
})
|
||||
|
||||
it('翻页与改每页条数都重发请求,改条数回第一页', async () => {
|
||||
const wrapper = await mountWith({ items: [row(11)], total: 42, page: 2, pageSize: 10 })
|
||||
const wrapper = await mountWith({ items: [card(9)], total: 42, page: 2, pageSize: 10 })
|
||||
|
||||
await wrapper.findAll('button').find((b) => b.text() === '下一页')!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(cleanApi.fetchAppearancePatentCleanList).toHaveBeenCalledTimes(2)
|
||||
expect(cleanApi.fetchAppearancePatentCleanList.mock.calls[1][0].page).toBe(3)
|
||||
expect(cleanApi.fetchAppearancePatentCleanSupervisors).toHaveBeenCalledTimes(2)
|
||||
expect(cleanApi.fetchAppearancePatentCleanSupervisors.mock.calls[1][0].page).toBe(3)
|
||||
|
||||
const sizeSelect = wrapper.find('.page-size-select')
|
||||
await sizeSelect.setValue('50')
|
||||
await flushPromises()
|
||||
const last = cleanApi.fetchAppearancePatentCleanList.mock.calls.at(-1)![0]
|
||||
const last = cleanApi.fetchAppearancePatentCleanSupervisors.mock.calls.at(-1)![0]
|
||||
expect(last.pageSize).toBe(50)
|
||||
expect(last.page).toBe(1, '改每页条数后回第一页')
|
||||
})
|
||||
|
||||
it('分组/国家/起止时间筛选生效(任务号/ASIN 输入框已下架,2026-11-11 客户拍板)', async () => {
|
||||
it('分组/国家/起止时间筛选生效(任务号/ASIN 输入框已下架)', async () => {
|
||||
cleanApi.fetchDedupeTotalGroups.mockResolvedValue([{ id: 7, name: '甲组', leaderUserId: 9 }])
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 10 })
|
||||
|
||||
// 筛选面只剩分组/国家/时间,页面上不再有任务号/ASIN 文本框(OldPagination 跳页框除外)
|
||||
const filterTextInputs = wrapper.findAll('.form-row input[type="text"]')
|
||||
expect(filterTextInputs).toHaveLength(0)
|
||||
|
||||
const selects = wrapper.findAll('select')
|
||||
await selects[0].setValue('7') // 分组(主管=组长)排在国家前,对齐获取店铺页字段顺序
|
||||
await selects[0].setValue('7') // 分组(主管=组长)排在国家前
|
||||
await selects[1].setValue('DE')
|
||||
const dateInputs = wrapper.findAll('input[type="date"]')
|
||||
await dateInputs[0].setValue('2026-11-01')
|
||||
@@ -256,10 +245,8 @@ describe('AC-5 外观专利无侵权数据页(卡片宫格,2026-11-11 改版
|
||||
await wrapper.findAll('button').find((b) => b.text() === '查询')!.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
const last = cleanApi.fetchAppearancePatentCleanList.mock.calls.at(-1)![0]
|
||||
const last = cleanApi.fetchAppearancePatentCleanSupervisors.mock.calls.at(-1)![0]
|
||||
expect(last).toMatchObject({
|
||||
taskId: '',
|
||||
asin: '',
|
||||
country: 'DE',
|
||||
groupId: '7',
|
||||
startDate: '2026-11-01',
|
||||
@@ -268,37 +255,28 @@ describe('AC-5 外观专利无侵权数据页(卡片宫格,2026-11-11 改版
|
||||
})
|
||||
})
|
||||
|
||||
it('分组下拉(主管=组长):选项与去重页同源,选中即查(不必点查询)', async () => {
|
||||
it('分组下拉(主管=组长)选中即查', async () => {
|
||||
cleanApi.fetchDedupeTotalGroups.mockResolvedValue([
|
||||
{ id: 7, name: '甲组', leaderUserId: 9 },
|
||||
{ id: 8, name: '乙组', leaderUserId: 10 },
|
||||
])
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 10 })
|
||||
|
||||
// 选项取数走的是公司隔离的同一分组集(GET /shop-manages/groups 的适配层)
|
||||
expect(cleanApi.fetchDedupeTotalGroups).toHaveBeenCalledWith(1)
|
||||
|
||||
const groupSelect = wrapper.findAll('select')[0]
|
||||
const optionTexts = groupSelect.findAll('option').map((o) => o.text())
|
||||
expect(optionTexts).toContain('全部分组')
|
||||
expect(optionTexts).toContain('甲组')
|
||||
expect(optionTexts).toContain('乙组')
|
||||
|
||||
// 2026-11-11 四改「选中即查」:选完主管立刻重发请求(回第一页),不等查询按钮
|
||||
const callsBeforeSelect = cleanApi.fetchAppearancePatentCleanList.mock.calls.length
|
||||
const callsBeforeSelect = cleanApi.fetchAppearancePatentCleanSupervisors.mock.calls.length
|
||||
await groupSelect.setValue('7')
|
||||
await flushPromises()
|
||||
expect(cleanApi.fetchAppearancePatentCleanList.mock.calls.length).toBe(callsBeforeSelect + 1, '选中分组必须立刻重查')
|
||||
expect(cleanApi.fetchAppearancePatentCleanList.mock.calls.at(-1)![0]).toMatchObject({
|
||||
expect(cleanApi.fetchAppearancePatentCleanSupervisors.mock.calls.length).toBe(callsBeforeSelect + 1,
|
||||
'选中分组必须立刻重查')
|
||||
expect(cleanApi.fetchAppearancePatentCleanSupervisors.mock.calls.at(-1)![0]).toMatchObject({
|
||||
groupId: '7',
|
||||
page: 1,
|
||||
}, '选中的分组 id 以 groupId 进列表过滤面(服务端解析组长+名下整集),且回第一页')
|
||||
|
||||
// 显式点查询仍然生效(同一过滤面再发一次)
|
||||
await wrapper.findAll('button').find((b) => b.text() === '查询')!.trigger('click')
|
||||
await flushPromises()
|
||||
const last = cleanApi.fetchAppearancePatentCleanList.mock.calls.at(-1)![0]
|
||||
expect(last.groupId).toBe('7', '查询按钮走同一过滤面(分组选中即查不改变查询按钮语义)')
|
||||
})
|
||||
})
|
||||
|
||||
it('空态与加载失败条(失败给重试,不把整页打死)', async () => {
|
||||
@@ -308,7 +286,7 @@ describe('AC-5 外观专利无侵权数据页(卡片宫格,2026-11-11 改版
|
||||
expect(tip.text()).toContain('暂无无侵权数据')
|
||||
empty.unmount()
|
||||
|
||||
cleanApi.fetchAppearancePatentCleanList.mockRejectedValue(new Error('上游 502'))
|
||||
cleanApi.fetchAppearancePatentCleanSupervisors.mockRejectedValue(new Error('上游 502'))
|
||||
const failed = mount(AppearancePatentCleanItemsPage, { global: { plugins: [pinia] } })
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
@@ -318,23 +296,20 @@ describe('AC-5 外观专利无侵权数据页(卡片宫格,2026-11-11 改版
|
||||
|
||||
it('切公司 Tab 重取并清掉上一家的筛选(company-tab-wiring 同口径)', async () => {
|
||||
cleanApi.fetchDedupeTotalGroups.mockResolvedValue([{ id: 7, name: '甲组', leaderUserId: 9 }])
|
||||
const wrapper = await mountWith({ items: [row(1)], total: 1, page: 1, pageSize: 10 })
|
||||
// 选上上一家公司的分组:切走后必须连同 groupId 一起清(分组的成员集是公司隔离的)
|
||||
const wrapper = await mountWith({ items: [card(9)], total: 1, page: 1, pageSize: 10 })
|
||||
const groupSelect = wrapper.findAll('select')[0]
|
||||
await groupSelect.setValue('7')
|
||||
const callsAfterMount = cleanApi.fetchAppearancePatentCleanList.mock.calls.length
|
||||
const callsBefore = cleanApi.fetchAppearancePatentCleanSupervisors.mock.calls.length
|
||||
|
||||
useCompanyTabStore().setActiveId(2)
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
|
||||
expect(cleanApi.fetchAppearancePatentCleanList.mock.calls.length).toBeGreaterThan(callsAfterMount)
|
||||
const last = cleanApi.fetchAppearancePatentCleanList.mock.calls.at(-1)![0]
|
||||
expect(cleanApi.fetchAppearancePatentCleanSupervisors.mock.calls.length).toBeGreaterThan(callsBefore)
|
||||
const last = cleanApi.fetchAppearancePatentCleanSupervisors.mock.calls.at(-1)![0]
|
||||
expect(last.companyId).toBe(2)
|
||||
expect(last.groupId).toBe('', '切公司必须清掉上一家选的分组')
|
||||
expect(last.taskId).toBe('', 'watch token 仍整把清栏(taskId/asin 字段留在契约里,UI 不再暴露)')
|
||||
expect(last.page).toBe(1)
|
||||
// 分组选项按新公司重取(选项集公司隔离)
|
||||
expect(cleanApi.fetchDedupeTotalGroups).toHaveBeenLastCalledWith(2)
|
||||
})
|
||||
})
|
||||
|
||||
+34
-2
@@ -9,6 +9,7 @@ import com.nanri.aiimage.common.security.DeviceSessionPolicy;
|
||||
import com.nanri.aiimage.common.service.DataReadScope;
|
||||
import com.nanri.aiimage.common.support.DownloadHeaderUtil;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentCleanItemPageVo;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentSupervisorPageVo;
|
||||
import com.nanri.aiimage.modules.appearancepatent.service.AppearancePatentCleanItemQueryService;
|
||||
import com.nanri.aiimage.modules.permission.service.PermissionMenuService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@@ -93,6 +94,31 @@ public class AdminAppearancePatentCleanItemsController {
|
||||
startDate, endDate, groupId, scopedCompanyId));
|
||||
}
|
||||
|
||||
@GetMapping("/supervisors")
|
||||
@Operation(summary = "按主管聚合查询(一主管一卡)", description = "后管「外观专利数据库」页的卡片面"
|
||||
+ "(2026-11-11 客户口径「获取店铺那边是按店铺做成卡片 我们这边就是按主管划分」):按主管"
|
||||
+ "归组返回条数/任务数/最近同步时间/国家集,total 是主管数;过滤面与明细分页同一段 SQL 谓词"
|
||||
+ "(公司/国家/同步起止/分组用户集),公司隔离走同一 readCompanyIdOrOwn 正门。")
|
||||
public ApiResponse<AppearancePatentSupervisorPageVo> supervisors(
|
||||
@Parameter(description = "页码") @RequestParam(name = "page", defaultValue = PageDefaults.FIRST_PAGE) Long page,
|
||||
@Parameter(description = "每页数量(主管卡片数)")
|
||||
@RequestParam(name = "page_size", defaultValue = PageDefaults.CLEAN_ITEMS_PAGE_SIZE) Long pageSize,
|
||||
@Parameter(description = "国家代码(如 DE、UK)") @RequestParam(name = "country", required = false) String country,
|
||||
@Parameter(description = "同步开始日期(包含)")
|
||||
@RequestParam(name = "start_date", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
|
||||
@Parameter(description = "同步结束日期(包含)")
|
||||
@RequestParam(name = "end_date", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate,
|
||||
@Parameter(description = "分组 id:按该分组「组长本人+名下子账户」的用户集过滤(主管=组长)")
|
||||
@RequestParam(name = "group_id", required = false) Long groupId,
|
||||
@Parameter(description = "公司 ID") @RequestParam(name = "company_id", required = false) Long companyId,
|
||||
HttpServletRequest request) {
|
||||
RequestOperator operator = requireCleanItemsAccess(request);
|
||||
AdminUserEntity user = operator.user();
|
||||
Long scopedCompanyId = dataReadScope.readCompanyIdOrOwn(user, companyId);
|
||||
return ApiResponse.success(cleanItemQueryService.supervisorPage(page, pageSize, country,
|
||||
startDate, endDate, groupId, scopedCompanyId));
|
||||
}
|
||||
|
||||
@GetMapping("/export")
|
||||
@Operation(summary = "导出外观专利数据库 Excel", description = "与分页查询同一过滤面(任务号/ASIN/国家/同步起止日期/分组),"
|
||||
+ "公司隔离走同一正门:company_id 只对站点超管生效(显式传才收窄,不传全量),非超管强制本公司。"
|
||||
@@ -108,6 +134,9 @@ public class AdminAppearancePatentCleanItemsController {
|
||||
@RequestParam(name = "end_date", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate,
|
||||
@Parameter(description = "分组 id:按该分组「组长本人+名下子账户」的用户集过滤(主管=组长)")
|
||||
@RequestParam(name = "group_id", required = false) Long groupId,
|
||||
@Parameter(description = "主管用户 id:只导出该主管名下明细(卡片上的「下载」,"
|
||||
+ "归属口径与主管聚合卡片同一表达式)")
|
||||
@RequestParam(name = "supervisor_user_id", required = false) Long supervisorUserId,
|
||||
@Parameter(description = "公司 ID") @RequestParam(name = "company_id", required = false) Long companyId,
|
||||
HttpServletRequest request) {
|
||||
RequestOperator operator = requireCleanItemsAccess(request);
|
||||
@@ -115,8 +144,11 @@ public class AdminAppearancePatentCleanItemsController {
|
||||
// 导出与分页共用 readCompanyIdOrOwn 正门(同 page 的口径注释):超管显式传才收窄、
|
||||
// 不传全量;非超管强制本公司(忽略请求传参),绝不让导出绕过页签的公司隔离。
|
||||
Long scopedCompanyId = dataReadScope.readCompanyIdOrOwn(user, companyId);
|
||||
byte[] bytes = cleanItemQueryService.export(taskId, asin, country, startDate, endDate, groupId,
|
||||
scopedCompanyId);
|
||||
byte[] bytes = supervisorUserId != null
|
||||
? cleanItemQueryService.exportBySupervisor(supervisorUserId, country, startDate, endDate, groupId,
|
||||
scopedCompanyId)
|
||||
: cleanItemQueryService.export(taskId, asin, country, startDate, endDate, groupId,
|
||||
scopedCompanyId);
|
||||
String filename = "外观专利数据库-" + LocalDateTime.now().format(EXPORT_FILENAME_FORMATTER) + ".xlsx";
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, DownloadHeaderUtil.contentDisposition(filename))
|
||||
|
||||
+52
@@ -2,6 +2,7 @@ package com.nanri.aiimage.modules.appearancepatent.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.entity.CleanItemEntity;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentSupervisorSummaryVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@@ -59,4 +60,55 @@ public interface AppearancePatentCleanItemMapper extends BaseMapper<CleanItemEnt
|
||||
@Param("userIds") List<Long> userIds,
|
||||
@Param("offset") long offset,
|
||||
@Param("limit") int limit);
|
||||
|
||||
/**
|
||||
* 主管聚合分组数(2026-11-11「按主管划分」):组键由 XML 的 {@code supervisorIdExpr} 现算,
|
||||
* 与读侧 {@code fillSupervisorNames} 同口径(主管本人取自己、普通账户取创建人、读不到归 NULL 组)。
|
||||
* 过滤面与 {@link #selectSupervisorSummaries} 完全同一段 {@code cleanItemConds}。
|
||||
*/
|
||||
long countSupervisors(@Param("companyId") Long companyId,
|
||||
@Param("taskId") Long taskId,
|
||||
@Param("asin") String asin,
|
||||
@Param("country") String country,
|
||||
@Param("startDate") LocalDate startDate,
|
||||
@Param("endDate") LocalDate endDate,
|
||||
@Param("userIds") List<Long> userIds);
|
||||
|
||||
/**
|
||||
* 主管聚合分页(一主管一行:条数/任务数/最近任务号/最近同步时间/国家集)。
|
||||
*
|
||||
* <p>{@code offset}/{@code limit} 同样只收服务侧钳制后的值(铁律 15)。国家列是
|
||||
* GROUP_CONCAT 出来的 csv,服务侧拆列表(读侧不加工明细值,只在这个聚合面上做一次收集)。</p>
|
||||
*/
|
||||
List<AppearancePatentSupervisorSummaryVo> selectSupervisorSummaries(@Param("companyId") Long companyId,
|
||||
@Param("taskId") Long taskId,
|
||||
@Param("asin") String asin,
|
||||
@Param("country") String country,
|
||||
@Param("startDate") LocalDate startDate,
|
||||
@Param("endDate") LocalDate endDate,
|
||||
@Param("userIds") List<Long> userIds,
|
||||
@Param("offset") long offset,
|
||||
@Param("limit") int limit);
|
||||
|
||||
/** 单个主管名下的明细行数(卡片「下载」的导出口,先卡上限再取数)。 */
|
||||
long countSupervisorItems(@Param("companyId") Long companyId,
|
||||
@Param("taskId") Long taskId,
|
||||
@Param("asin") String asin,
|
||||
@Param("country") String country,
|
||||
@Param("startDate") LocalDate startDate,
|
||||
@Param("endDate") LocalDate endDate,
|
||||
@Param("userIds") List<Long> userIds,
|
||||
@Param("supervisorUserId") Long supervisorUserId);
|
||||
|
||||
/** 单个主管名下的明细页(导出全量用 offset=0、limit=上限;与明细分页同一过滤面)。 */
|
||||
List<CleanItemEntity> selectSupervisorItems(@Param("companyId") Long companyId,
|
||||
@Param("taskId") Long taskId,
|
||||
@Param("asin") String asin,
|
||||
@Param("country") String country,
|
||||
@Param("startDate") LocalDate startDate,
|
||||
@Param("endDate") LocalDate endDate,
|
||||
@Param("userIds") List<Long> userIds,
|
||||
@Param("supervisorUserId") Long supervisorUserId,
|
||||
@Param("offset") long offset,
|
||||
@Param("limit") int limit);
|
||||
}
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.nanri.aiimage.modules.appearancepatent.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 主管卡片分页信封(2026-11-11「按主管划分」):形状与明细页一致(items/total/page/pageSize),
|
||||
* total 是<b>主管数</b>而不是明细条数——前端分页条按主管翻页。
|
||||
*/
|
||||
@Data
|
||||
public class AppearancePatentSupervisorPageVo {
|
||||
|
||||
private List<AppearancePatentSupervisorVo> items;
|
||||
|
||||
private Long total;
|
||||
|
||||
private Long page;
|
||||
|
||||
private Long pageSize;
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.nanri.aiimage.modules.appearancepatent.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 主管聚合的 mapper 行(2026-11-11「按主管划分」):SQL 侧 {@code GROUP BY supervisorIdExpr}
|
||||
* 的原始读数,只负责搬运,不在这一层加工国家 csv(拆列表在服务层,避免 mapper 里做字符串处理)。
|
||||
*/
|
||||
@Data
|
||||
public class AppearancePatentSupervisorSummaryVo {
|
||||
|
||||
/** 主管用户 id(读不到主管的行=null,聚合时归入同一个「未知主管」组)。 */
|
||||
private Long supervisorId;
|
||||
|
||||
/** 该主管名下「无侵权」明细条数。 */
|
||||
private Long itemCount;
|
||||
|
||||
/** 该主管名下涉及的任务数(COUNT(DISTINCT task_id))。 */
|
||||
private Long taskCount;
|
||||
|
||||
/** 该主管名下最近一次涉及的任务号(MAX(task_id),卡片的「任务」行用它)。 */
|
||||
private Long lastTaskId;
|
||||
|
||||
/** 该主管名下最近一次同步时间(MAX(synced_at),卡片的「最新」列与默认排序键)。 */
|
||||
private LocalDateTime lastSyncedAt;
|
||||
|
||||
/** 国家集 csv(GROUP_CONCAT,服务层拆成列表;原样搬运不做翻译)。 */
|
||||
private String countryCsv;
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.nanri.aiimage.modules.appearancepatent.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 后管「外观专利数据库」页的一个主管卡片(2026-11-11 客户口径「获取店铺那边是按店铺做成卡片,
|
||||
* 我们这边就是按主管划分」):一主管一卡,卡内是该主管名下的汇总,不再铺明细。
|
||||
*
|
||||
* <p>{@code supervisorName} 是唯一的读侧加工列(同明细分页的「所属主管」口径:主管本人取自己、
|
||||
* 普通账户取创建人),读不到时为空、前端展示 -(铁律 30 不猜名)。</p>
|
||||
*/
|
||||
@Data
|
||||
public class AppearancePatentSupervisorVo {
|
||||
|
||||
/** 主管用户 id;null=读不到主管的那一组(该卡不提供按主管下载)。 */
|
||||
private Long supervisorId;
|
||||
|
||||
/** 主管名(读不到为空)。 */
|
||||
private String supervisorName;
|
||||
|
||||
/** 无侵权明细条数。 */
|
||||
private Long itemCount;
|
||||
|
||||
/** 涉及任务数。 */
|
||||
private Long taskCount;
|
||||
|
||||
/** 最近涉及的任务号。 */
|
||||
private Long lastTaskId;
|
||||
|
||||
/** 最近同步时间。 */
|
||||
private LocalDateTime lastSyncedAt;
|
||||
|
||||
/** 涉及国家码集(原样搬运,前端用自己的国家字典翻中文)。 */
|
||||
private List<String> countryCodes;
|
||||
}
|
||||
+130
@@ -10,6 +10,9 @@ import com.nanri.aiimage.modules.appearancepatent.mapper.AppearancePatentCleanIt
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.entity.CleanItemEntity;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentCleanItemPageVo;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentCleanItemVo;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentSupervisorPageVo;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentSupervisorSummaryVo;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentSupervisorVo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
@@ -20,6 +23,7 @@ import org.springframework.stereotype.Service;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
@@ -136,6 +140,101 @@ public class AppearancePatentCleanItemQueryService {
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 主管聚合分页(2026-11-11 客户「要按主管分组显示」「应该是只显示一个卡片的才对」「获取店铺
|
||||
* 那边是按店铺做成卡片 我们这边就是按主管划分」):一主管一卡,total 是<b>主管数</b>,
|
||||
* 不再按明细铺页(3488 条明细铺成卡片等于整页上千张卡)。
|
||||
*
|
||||
* <p>组键与「所属主管」列同源(XML {@code supervisorIdExpr} ↔ {@link #fillSupervisorNames}):
|
||||
* 主管本人跑的单归自己、普通账户归创建人、读不到归同一个 NULL 组(该组 supervisorId 为 null,
|
||||
* 前端展示 - 且不提供按主管下载)。过滤面复用共享 {@code cleanItemConds}(公司/国家/同步起止/
|
||||
* 分组用户集),SQL 侧下推,铁律 20。</p>
|
||||
*/
|
||||
public AppearancePatentSupervisorPageVo supervisorPage(Long page, Long pageSize, String country,
|
||||
LocalDate startDate, LocalDate endDate, Long groupId, Long scopedCompanyId) {
|
||||
if (startDate != null && endDate != null && startDate.isAfter(endDate)) {
|
||||
throw new BusinessException("开始日期不能晚于结束日期");
|
||||
}
|
||||
long safePage = page == null || page < 1 ? 1 : Math.min(page, MAX_PAGE);
|
||||
long safeSize = pageSize == null ? PageDefaults.CLEAN_ITEMS_PAGE_SIZE_INT
|
||||
: Math.min(Math.max(pageSize, 1), MAX_PAGE_SIZE);
|
||||
Long companyId = scopedCompanyId != null && scopedCompanyId > 0 ? scopedCompanyId : null;
|
||||
String safeCountry = trimToNull(country);
|
||||
List<Long> groupUserIds = groupUserIds(groupId);
|
||||
AppearancePatentSupervisorPageVo vo = new AppearancePatentSupervisorPageVo();
|
||||
vo.setPage(safePage);
|
||||
vo.setPageSize(safeSize);
|
||||
if (groupUserIds != null && groupUserIds.isEmpty()) {
|
||||
vo.setItems(List.of());
|
||||
vo.setTotal(0L);
|
||||
return vo;
|
||||
}
|
||||
long total = cleanItemMapper.countSupervisors(companyId, null, null, safeCountry, startDate, endDate,
|
||||
groupUserIds);
|
||||
if (total <= 0) {
|
||||
vo.setItems(List.of());
|
||||
vo.setTotal(0L);
|
||||
return vo;
|
||||
}
|
||||
List<AppearancePatentSupervisorSummaryVo> summaries = cleanItemMapper.selectSupervisorSummaries(
|
||||
companyId, null, null, safeCountry, startDate, endDate, groupUserIds,
|
||||
(safePage - 1) * safeSize, (int) safeSize);
|
||||
vo.setItems(toSupervisorVos(summaries));
|
||||
vo.setTotal(total);
|
||||
return vo;
|
||||
}
|
||||
|
||||
/** 聚合行 → 卡片:主管名批量富化(与明细同一 {@code fillSupervisorNames} 口径的两步批量查询),
|
||||
* 国家 csv 拆列表(空值不下发)。 */
|
||||
private List<AppearancePatentSupervisorVo> toSupervisorVos(List<AppearancePatentSupervisorSummaryVo> summaries) {
|
||||
List<AppearancePatentSupervisorVo> items = new ArrayList<>(summaries.size());
|
||||
for (AppearancePatentSupervisorSummaryVo summary : summaries) {
|
||||
AppearancePatentSupervisorVo vo = new AppearancePatentSupervisorVo();
|
||||
vo.setSupervisorId(summary.getSupervisorId());
|
||||
vo.setItemCount(summary.getItemCount());
|
||||
vo.setTaskCount(summary.getTaskCount());
|
||||
vo.setLastTaskId(summary.getLastTaskId());
|
||||
vo.setLastSyncedAt(summary.getLastSyncedAt());
|
||||
vo.setCountryCodes(splitCountryCsv(summary.getCountryCsv()));
|
||||
items.add(vo);
|
||||
}
|
||||
List<Long> supervisorIds = items.stream()
|
||||
.map(AppearancePatentSupervisorVo::getSupervisorId)
|
||||
.filter(id -> id != null)
|
||||
.distinct()
|
||||
.toList();
|
||||
if (supervisorIds.isEmpty()) {
|
||||
return items;
|
||||
}
|
||||
Map<Long, String> namesById = new LinkedHashMap<>();
|
||||
for (AdminUserEntity user : adminUserMapper.selectBatchIds(supervisorIds)) {
|
||||
String username = trimmed(user.getUsername());
|
||||
if (user.getId() != null && !username.isEmpty()) {
|
||||
namesById.put(user.getId(), username);
|
||||
}
|
||||
}
|
||||
for (AppearancePatentSupervisorVo vo : items) {
|
||||
if (vo.getSupervisorId() != null) {
|
||||
vo.setSupervisorName(namesById.get(vo.getSupervisorId()));
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
private static List<String> splitCountryCsv(String csv) {
|
||||
if (csv == null || csv.isBlank()) {
|
||||
return List.of();
|
||||
}
|
||||
List<String> codes = new ArrayList<>();
|
||||
for (String part : csv.split(",")) {
|
||||
String code = part.trim();
|
||||
if (!code.isEmpty()) {
|
||||
codes.add(code);
|
||||
}
|
||||
}
|
||||
return codes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出当前过滤面全量明细为 xlsx 字节(控制器直接回 {@code ResponseEntity<byte[]>},
|
||||
* 口径同 {@code QueryAsinService.export})。
|
||||
@@ -171,6 +270,37 @@ public class AppearancePatentCleanItemQueryService {
|
||||
return writeExportWorkbook(items);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出<b>单个主管</b>名下明细为 xlsx 字节(2026-11-11 卡片上的「下载」):过滤面=当前页签
|
||||
* (公司/国家/同步起止/分组)+主管归属条件(与卡片分组同一表达式,不是 user_id OR created_by_id
|
||||
* 的近似写法)。上限与全量导出同一条 {@link #EXPORT_MAX_ROWS}。{@code supervisorUserId} 为空
|
||||
* 按「不按主管收窄」处理(控制器不会走到这里,纯防呆)。
|
||||
*/
|
||||
public byte[] exportBySupervisor(Long supervisorUserId, String country, LocalDate startDate,
|
||||
LocalDate endDate, Long groupId, Long scopedCompanyId) {
|
||||
if (startDate != null && endDate != null && startDate.isAfter(endDate)) {
|
||||
throw new BusinessException("开始日期不能晚于结束日期");
|
||||
}
|
||||
Long companyId = scopedCompanyId != null && scopedCompanyId > 0 ? scopedCompanyId : null;
|
||||
String safeCountry = trimToNull(country);
|
||||
List<Long> groupUserIds = groupUserIds(groupId);
|
||||
if (groupUserIds != null && groupUserIds.isEmpty()) {
|
||||
return writeExportWorkbook(List.of());
|
||||
}
|
||||
long total = cleanItemMapper.countSupervisorItems(companyId, null, null, safeCountry, startDate, endDate,
|
||||
groupUserIds, supervisorUserId);
|
||||
if (total > EXPORT_MAX_ROWS) {
|
||||
throw new BusinessException("该主管的无侵权数据共 " + total + " 行,超过导出上限 " + EXPORT_MAX_ROWS
|
||||
+ " 行,请缩小筛选范围后重试");
|
||||
}
|
||||
List<CleanItemEntity> rows = total <= 0 ? List.of()
|
||||
: cleanItemMapper.selectSupervisorItems(companyId, null, null, safeCountry, startDate, endDate,
|
||||
groupUserIds, supervisorUserId, 0L, (int) EXPORT_MAX_ROWS);
|
||||
List<AppearancePatentCleanItemVo> items = rows.stream().map(AppearancePatentCleanItemQueryService::toVo).toList();
|
||||
fillSupervisorNames(items);
|
||||
return writeExportWorkbook(items);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分组筛选 → 该分组「组长本人+名下子账户」的用户 id 集({@code null} = 没选分组、不过滤);
|
||||
* id 非法(≤0)按没选处理,不把它当全量之外的第三档。解析交给
|
||||
|
||||
+88
-13
@@ -9,18 +9,41 @@
|
||||
全部走 #{} 占位符。offset/limit 必须是服务侧钳制后的值(铁律 15)。 -->
|
||||
|
||||
<sql id="cleanItemConds">
|
||||
<if test="companyId != null">AND company_id = #{companyId}</if>
|
||||
<if test="taskId != null">AND task_id = #{taskId}</if>
|
||||
<if test="asin != null and asin != ''">AND asin LIKE CONCAT(#{asin}, '%')</if>
|
||||
<if test="country != null and country != ''">AND country = #{country}</if>
|
||||
<if test="startDate != null">AND synced_at >= #{startDate}</if>
|
||||
<if test="endDate != null">AND synced_at < DATE_ADD(#{endDate}, INTERVAL 1 DAY)</if>
|
||||
<if test="companyId != null">AND i.company_id = #{companyId}</if>
|
||||
<if test="taskId != null">AND i.task_id = #{taskId}</if>
|
||||
<if test="asin != null and asin != ''">AND i.asin LIKE CONCAT(#{asin}, '%')</if>
|
||||
<if test="country != null and country != ''">AND i.country = #{country}</if>
|
||||
<if test="startDate != null">AND i.synced_at >= #{startDate}</if>
|
||||
<if test="endDate != null">AND i.synced_at < DATE_ADD(#{endDate}, INTERVAL 1 DAY)</if>
|
||||
<if test="userIds != null and userIds.size() > 0">
|
||||
AND user_id IN
|
||||
AND i.user_id IN
|
||||
<foreach collection="userIds" item="uid" open="(" separator="," close=")">#{uid}</foreach>
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<!-- 主管归属表达式(2026-11-11「按主管划分」):与读侧 fillSupervisorNames 同口径
|
||||
(DeviceSessionPolicy#resolveRole)——owner 是 super_admin/company_super_admin/admin
|
||||
或 (role 空 且 is_admin=1)=主管本人(取自己);普通账户=创建人 created_by_id;
|
||||
读不到创建人=NULL(聚合时归入同一个「未知主管」组,界面展示 -,铁律 30 不猜名)。
|
||||
只允许带 users 联表的语句引用(u = users 别名,i = 明细表别名)。 -->
|
||||
<sql id="supervisorIdExpr">
|
||||
CASE
|
||||
WHEN u.role IS NOT NULL AND LOWER(TRIM(u.role)) IN ('super_admin', 'company_super_admin', 'admin') THEN i.user_id
|
||||
WHEN (u.role IS NULL OR TRIM(u.role) = '') AND u.is_admin = 1 THEN i.user_id
|
||||
WHEN u.created_by_id IS NOT NULL AND u.created_by_id > 0 THEN u.created_by_id
|
||||
ELSE NULL
|
||||
END
|
||||
</sql>
|
||||
|
||||
<!-- 按主管过滤(卡片上的「下载」=导出该主管数据):判据就是上面那个表达式等于入参,
|
||||
不许改写成 user_id = S OR created_by_id = S——那会把「主管本人跑的单」误并进谁的子账户集。 -->
|
||||
<sql id="supervisorScopeConds">
|
||||
<if test="supervisorUserId != null">
|
||||
AND (<include refid="supervisorIdExpr"/>) = #{supervisorUserId}
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
|
||||
<delete id="deleteByResultId">
|
||||
DELETE FROM biz_appearance_patent_clean_item
|
||||
WHERE result_id = #{resultId}
|
||||
@@ -43,17 +66,69 @@
|
||||
|
||||
<select id="countCleanItems" resultType="long">
|
||||
SELECT COUNT(*)
|
||||
FROM biz_appearance_patent_clean_item
|
||||
FROM biz_appearance_patent_clean_item i
|
||||
WHERE 1=1 <include refid="cleanItemConds"/>
|
||||
</select>
|
||||
|
||||
<select id="selectCleanItemPage" resultType="com.nanri.aiimage.modules.appearancepatent.model.entity.CleanItemEntity">
|
||||
SELECT id, result_id, task_id, user_id, company_id, row_no,
|
||||
asin, country, sku, brand, price, title, image_url, item_url, conclusion,
|
||||
title_reason, appearance_reason, patent_reason, source_filename, synced_at
|
||||
FROM biz_appearance_patent_clean_item
|
||||
SELECT i.id, i.result_id, i.task_id, i.user_id, i.company_id, i.row_no,
|
||||
i.asin, i.country, i.sku, i.brand, i.price, i.title, i.image_url, i.item_url, i.conclusion,
|
||||
i.title_reason, i.appearance_reason, i.patent_reason, i.source_filename, i.synced_at
|
||||
FROM biz_appearance_patent_clean_item i
|
||||
WHERE 1=1 <include refid="cleanItemConds"/>
|
||||
ORDER BY synced_at DESC, id DESC
|
||||
ORDER BY i.synced_at DESC, i.id DESC
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
|
||||
<!-- 主管聚合(2026-11-11 客户「要按主管分组显示」「应该是只显示一个卡片的才对」「获取店铺那边
|
||||
是按店铺做成卡片 我们这边就是按主管划分」):一主管一卡,不按明细分页。
|
||||
组键=supervisorIdExpr(与读侧 fillSupervisorNames 同口径);读不到主管的行归入同一个
|
||||
NULL 组(那一卡展示 -,铁律 30)。国家用 GROUP_CONCAT 收成 csv,服务侧拆成列表;
|
||||
排序按最近同步倒序(卡片的「最新」列),同刻按条数、主管 id 兜稳定序。
|
||||
company_id 等条件全部走共享 cleanItemConds(与明细分页/导出同一过滤面,铁律 20 下推)。 -->
|
||||
<select id="countSupervisors" resultType="long">
|
||||
SELECT COUNT(*) FROM (
|
||||
SELECT 1
|
||||
FROM biz_appearance_patent_clean_item i
|
||||
LEFT JOIN users u ON u.id = i.user_id
|
||||
WHERE 1=1 <include refid="cleanItemConds"/>
|
||||
GROUP BY (<include refid="supervisorIdExpr"/>)
|
||||
) supervisor_groups
|
||||
</select>
|
||||
|
||||
<select id="selectSupervisorSummaries"
|
||||
resultType="com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentSupervisorSummaryVo">
|
||||
SELECT (<include refid="supervisorIdExpr"/>) AS supervisor_id,
|
||||
COUNT(*) AS item_count,
|
||||
COUNT(DISTINCT i.task_id) AS task_count,
|
||||
MAX(i.task_id) AS last_task_id,
|
||||
MAX(i.synced_at) AS last_synced_at,
|
||||
GROUP_CONCAT(DISTINCT i.country ORDER BY i.country SEPARATOR ',') AS country_csv
|
||||
FROM biz_appearance_patent_clean_item i
|
||||
LEFT JOIN users u ON u.id = i.user_id
|
||||
WHERE 1=1 <include refid="cleanItemConds"/>
|
||||
GROUP BY supervisor_id
|
||||
ORDER BY last_synced_at DESC, item_count DESC, supervisor_id DESC
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
|
||||
<!-- 卡片「下载」=导出该主管名下全量明细(分页/导出同一过滤面 + 主管归属条件)。 -->
|
||||
<select id="countSupervisorItems" resultType="long">
|
||||
SELECT COUNT(*)
|
||||
FROM biz_appearance_patent_clean_item i
|
||||
LEFT JOIN users u ON u.id = i.user_id
|
||||
WHERE 1=1 <include refid="cleanItemConds"/> <include refid="supervisorScopeConds"/>
|
||||
</select>
|
||||
|
||||
<select id="selectSupervisorItems"
|
||||
resultType="com.nanri.aiimage.modules.appearancepatent.model.entity.CleanItemEntity">
|
||||
SELECT i.id, i.result_id, i.task_id, i.user_id, i.company_id, i.row_no,
|
||||
i.asin, i.country, i.sku, i.brand, i.price, i.title, i.image_url, i.item_url, i.conclusion,
|
||||
i.title_reason, i.appearance_reason, i.patent_reason, i.source_filename, i.synced_at
|
||||
FROM biz_appearance_patent_clean_item i
|
||||
LEFT JOIN users u ON u.id = i.user_id
|
||||
WHERE 1=1 <include refid="cleanItemConds"/> <include refid="supervisorScopeConds"/>
|
||||
ORDER BY i.synced_at DESC, i.id DESC
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -82,7 +82,10 @@ class MigratedSqlEquivalenceTest {
|
||||
// 103 → 105:v1.3(外观专利无侵权数据同步后管)appearancepatent 模块首份 mapper 新写
|
||||
// 2 条只读 select(count/page),逐条点名进 NOT_MIGRATED
|
||||
// (SqlLayeringConventionTest.XML_STATEMENT_TOTAL 同轮 147 → 151)。
|
||||
private static final int XML_SELECT_TOTAL = 105;
|
||||
// 105 → 109:2026-11-11「按主管划分」同一 mapper 再落 4 条 select(主管聚合 count/page
|
||||
// +按主管导出 count/page),同样从来没有注解原文可对撞,逐条点名
|
||||
//(SqlLayeringConventionTest.XML_STATEMENT_TOTAL 同轮 151 → 155)。
|
||||
private static final int XML_SELECT_TOTAL = 109;
|
||||
|
||||
/**
|
||||
* 不是「从注解搬过来」的语句:注解时代没有原文可对撞,等价性这支只能跳过它们。
|
||||
@@ -164,7 +167,14 @@ class MigratedSqlEquivalenceTest {
|
||||
"AppearancePatentCleanItemMapper#deleteByResultId",
|
||||
"AppearancePatentCleanItemMapper#insertBatch",
|
||||
"AppearancePatentCleanItemMapper#countCleanItems",
|
||||
"AppearancePatentCleanItemMapper#selectCleanItemPage");
|
||||
"AppearancePatentCleanItemMapper#selectCleanItemPage",
|
||||
// 2026-11-11「按主管划分」(一主管一卡):4 条新写的 select——主管聚合
|
||||
// count/page 与按主管导出的 count/page(带 users 联表按归属表达式收窄),
|
||||
// 注解时代没有原文可对撞,逐条点名留痕(XML_SELECT_TOTAL 105 → 109)。
|
||||
"AppearancePatentCleanItemMapper#countSupervisors",
|
||||
"AppearancePatentCleanItemMapper#selectSupervisorSummaries",
|
||||
"AppearancePatentCleanItemMapper#countSupervisorItems",
|
||||
"AppearancePatentCleanItemMapper#selectSupervisorItems");
|
||||
|
||||
/** 账本 5 列:接口 / 方法 / @Select 种类 / 是否含常量插值 / 注解原文(Java 反转义后那条串)。 */
|
||||
private static final int LEDGER_COLUMNS = 5;
|
||||
|
||||
@@ -101,7 +101,10 @@ class SqlLayeringConventionTest {
|
||||
// 147 → 151:v1.3(外观专利无侵权数据同步后管)appearancepatent 模块首份 XML 4 条语句——
|
||||
// 覆盖式重写 delete/insert + 只读页 count/page select(V189 建表同窗),全部新写,
|
||||
// 同轮登记进 MigratedSqlEquivalenceTest.NOT_MIGRATED(该文件 XML_SELECT_TOTAL 同轮 103 → 105)。
|
||||
private static final int XML_STATEMENT_TOTAL = 151;
|
||||
// 151 → 155:2026-11-11「按主管划分」同一 mapper 再落 4 条 select——主管聚合 count/page
|
||||
// +按主管导出 count/page(users 联表按归属表达式收窄),同轮登记进 NOT_MIGRATED
|
||||
//(该文件 XML_SELECT_TOTAL 105 → 109)。
|
||||
private static final int XML_STATEMENT_TOTAL = 155;
|
||||
|
||||
/**
|
||||
* wrapper 里夹带函数级 SQL 的现状("这不是简单单表"的证据),文件名 → 条数:
|
||||
|
||||
+10
-5
@@ -61,6 +61,10 @@ class PageDefaultsLedgerTest {
|
||||
"AdminNotificationController.java#pageSize=ADMIN_LIST_PAGE_SIZE",
|
||||
"AdminAppearancePatentCleanItemsController.java#page=FIRST_PAGE",
|
||||
"AdminAppearancePatentCleanItemsController.java#page_size=CLEAN_ITEMS_PAGE_SIZE",
|
||||
// 2026-11-11「按主管划分」:同一控制器上的 /supervisors 主管聚合卡片页也分页(total 是主管数),
|
||||
// 与明细列表端点同参数名同默认值(按出站点计数、不去重)
|
||||
"AdminAppearancePatentCleanItemsController.java#page=FIRST_PAGE",
|
||||
"AdminAppearancePatentCleanItemsController.java#page_size=CLEAN_ITEMS_PAGE_SIZE",
|
||||
"AppearancePatentController.java#limit=DEFAULT_RESULT_LIMIT",
|
||||
"CollectDataController.java#page=FIRST_PAGE",
|
||||
"CollectDataController.java#page_size=TASK_LIST_PAGE_SIZE",
|
||||
@@ -111,10 +115,11 @@ class PageDefaultsLedgerTest {
|
||||
List<String> constants = actual.stream().filter(s -> !s.contains("LITERAL")).sorted().toList();
|
||||
|
||||
assertThat(constants)
|
||||
.as("56 处分页/条数出站点的具名默认值必须与台账一一对应")
|
||||
.as("58 处分页/条数出站点的具名默认值必须与台账一一对应"
|
||||
+ "(56→58:2026-11-11 /supervisors 主管聚合卡片页的 page/page_size 两处出站点)")
|
||||
.isEqualTo(LEDGER.stream().sorted().toList());
|
||||
// 同口径非零对照:台账不是空的,扫描器也确实数得出 56 处
|
||||
assertThat(constants).hasSize(56);
|
||||
// 同口径非零对照:台账不是空的,扫描器也确实数得出 58 处
|
||||
assertThat(constants).hasSize(58);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,8 +134,8 @@ class PageDefaultsLedgerTest {
|
||||
void oneSemanticCannotGrowASecondDefault() {
|
||||
List<String> actual = sites();
|
||||
assertThat(kindsUsing(actual, "page", "FIRST_PAGE"))
|
||||
.as("页码口径只有一套:全部从 1 起")
|
||||
.isEqualTo(25);
|
||||
.as("页码口径只有一套:全部从 1 起(25→26:2026-11-11 /supervisors 主管聚合卡片页也是分页出站点)")
|
||||
.isEqualTo(26);
|
||||
assertThat(distinctConstants(actual, "page_size"))
|
||||
.as("page_size 的默认容量集合:10/15/20/50/1000 五种各自登记,新来第六种要红"
|
||||
+ "(10 是 v1.3 无侵权只读页,蓝图 §3.2 拍板、与前端 OldPagination 首屏同值)")
|
||||
|
||||
+131
-7
@@ -12,6 +12,9 @@ import com.nanri.aiimage.modules.appearancepatent.mapper.AppearancePatentCleanIt
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.entity.CleanItemEntity;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentCleanItemPageVo;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentCleanItemVo;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentSupervisorPageVo;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentSupervisorSummaryVo;
|
||||
import com.nanri.aiimage.modules.appearancepatent.model.vo.AppearancePatentSupervisorVo;
|
||||
import com.nanri.aiimage.modules.appearancepatent.service.AppearancePatentCleanItemQueryService;
|
||||
import com.nanri.aiimage.modules.permission.service.PermissionMenuService;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
@@ -378,15 +381,21 @@ class AdminAppearancePatentCleanItemsControllerTest {
|
||||
long scopeCalls = source.split("readCompanyIdOrOwn\\(", -1).length - 1;
|
||||
assertTrue(scopeCalls >= 2, "分页与导出两支 handler 都必须走 readCompanyIdOrOwn 公司隔离,实得 " + scopeCalls);
|
||||
// 导出是全量导出(服务侧另有 EXPORT_MAX_ROWS 上限),不收 page/page_size:
|
||||
// 全文件 page_size 只允许出现一次(分页 handler 的参数声明)。
|
||||
// 带分页参数的两个 handler 各声明一次 page_size(明细分页 + 2026-11-11 主管聚合卡片页,
|
||||
// total 是主管数);导出两支(全量/按主管)都不收分页参数,所以分母恒为 2。
|
||||
long pageSizeParams = source.split("page_size", -1).length - 1;
|
||||
assertEquals(1, pageSizeParams, "导出不收分页参数,page_size 只许出现在分页 handler 的参数声明里");
|
||||
assertEquals(2, pageSizeParams, "page_size 只许出现在两个分页 handler 的参数声明里(明细分页+主管卡片),"
|
||||
+ "导出不许收分页参数");
|
||||
// 分组(主管=组长)筛选:group_id 在分页与导出两支都要收;选项不下新端点(复用
|
||||
// 既有 GET /shop-manages/groups,与去重页/店铺管理同源)。
|
||||
long groupParams = source.split("group_id", -1).length - 1;
|
||||
assertTrue(groupParams >= 2, "分页与导出都必须收 group_id(主管=组长,就是分组,2026-11-11 客户口径)");
|
||||
assertFalse(source.contains("\"/supervisors\""),
|
||||
"选项复用既有分组端点,本控制器不得再挂 /supervisors 第二份选项源");
|
||||
// 2026-11-11 二次改版:/supervisors 是<b>主管聚合卡片</b>(一主管一卡),不是分组选项源;
|
||||
// 「选项不得另开端点」的判据改成看 /groups——本控制器不许自带一份分组选项。
|
||||
assertTrue(source.contains("\"/supervisors\""),
|
||||
"主管聚合卡片端点必须是 GET /supervisors(客户「获取店铺那边是按店铺做成卡片 我们这边就是按主管划分」)");
|
||||
assertFalse(source.contains("\"/groups\""),
|
||||
"分组选项复用既有 GET /shop-manages/groups,本控制器不得再挂分组选项端点");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -408,7 +417,7 @@ class AdminAppearancePatentCleanItemsControllerTest {
|
||||
byte[] payload = "xlsx-bytes".getBytes(StandardCharsets.UTF_8);
|
||||
when(queryService.export(null, null, null, null, null, null, 5L)).thenReturn(payload);
|
||||
|
||||
ResponseEntity<byte[]> response = controller.export(null, null, null, null, null, null, 5L, request);
|
||||
ResponseEntity<byte[]> response = controller.export(null, null, null, null, null, null, null, 5L, request);
|
||||
|
||||
verify(dataReadScope).readCompanyIdOrOwn(operator, 5L);
|
||||
verify(queryService).export(null, null, null, null, null, null, 5L);
|
||||
@@ -538,9 +547,124 @@ class AdminAppearancePatentCleanItemsControllerTest {
|
||||
}
|
||||
}
|
||||
|
||||
// ===================== 2026-11-11 二次改版:按主管聚合(一主管一卡) =====================
|
||||
|
||||
@Test
|
||||
void 主管聚合一主管一卡_条数任务国家最新与主管名齐备() {
|
||||
AppearancePatentCleanItemMapper mapper = mock(AppearancePatentCleanItemMapper.class);
|
||||
AdminUserMapper adminUserMapper = mock(AdminUserMapper.class);
|
||||
AppearancePatentCleanItemQueryService service = new AppearancePatentCleanItemQueryService(
|
||||
mapper, adminUserMapper, mock(ShopManageGroupMapper.class));
|
||||
|
||||
when(mapper.countSupervisors(any(), any(), any(), any(), any(), any(), any())).thenReturn(2L);
|
||||
AppearancePatentSupervisorSummaryVo leaderCard = new AppearancePatentSupervisorSummaryVo();
|
||||
leaderCard.setSupervisorId(9L);
|
||||
leaderCard.setItemCount(120L);
|
||||
leaderCard.setTaskCount(3L);
|
||||
leaderCard.setLastTaskId(33874L);
|
||||
leaderCard.setLastSyncedAt(LocalDateTime.of(2026, 11, 11, 11, 34));
|
||||
leaderCard.setCountryCsv("DE,UK");
|
||||
AppearancePatentSupervisorSummaryVo unknownCard = new AppearancePatentSupervisorSummaryVo();
|
||||
unknownCard.setSupervisorId(null);
|
||||
unknownCard.setItemCount(5L);
|
||||
unknownCard.setTaskCount(1L);
|
||||
when(mapper.selectSupervisorSummaries(any(), any(), any(), any(), any(), any(), any(), eq(0L), anyInt()))
|
||||
.thenReturn(List.of(leaderCard, unknownCard));
|
||||
AdminUserEntity leader = new AdminUserEntity();
|
||||
leader.setId(9L);
|
||||
leader.setUsername(" 主管甲 ");
|
||||
when(adminUserMapper.selectBatchIds(anyCollection())).thenAnswer(invocation -> {
|
||||
Collection<?> ids = invocation.getArgument(0);
|
||||
List<AdminUserEntity> out = new ArrayList<>();
|
||||
if (ids.contains(9L)) out.add(leader);
|
||||
return out;
|
||||
});
|
||||
|
||||
AppearancePatentSupervisorPageVo vo = service.supervisorPage(1L, 10L, null, null, null, null, 5L);
|
||||
|
||||
assertEquals(2L, vo.getTotal(), "total 是主管数(不是明细条数——铺明细分页会把几千条画成几千张卡)");
|
||||
assertEquals(2, vo.getItems().size(), "一主管一卡");
|
||||
AppearancePatentSupervisorVo first = vo.getItems().get(0);
|
||||
assertEquals("主管甲", first.getSupervisorName(), "主管名批量富化,两侧空白剥掉");
|
||||
assertEquals(120L, first.getItemCount());
|
||||
assertEquals(3L, first.getTaskCount(), "任务数是 COUNT(DISTINCT task_id)");
|
||||
assertEquals(33874L, first.getLastTaskId(), "卡片「任务」行显示最近任务号");
|
||||
assertEquals(LocalDateTime.of(2026, 11, 11, 11, 34), first.getLastSyncedAt());
|
||||
assertEquals(List.of("DE", "UK"), first.getCountryCodes(), "国家 csv 拆成码集(前端用自己的字典翻中文)");
|
||||
AppearancePatentSupervisorVo second = vo.getItems().get(1);
|
||||
assertNull(second.getSupervisorName(), "读不到主管=不猜名字(铁律 30),前端展示 -");
|
||||
assertNull(second.getSupervisorId(), "未知主管组的 supervisorId 为 null(该卡不提供按主管下载)");
|
||||
assertEquals(List.of(), second.getCountryCodes(), "空国家 csv 拆成空列表,不下发 null");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 主管聚合_分组读不出用户时短路不碰mapper() {
|
||||
AppearancePatentCleanItemMapper mapper = mock(AppearancePatentCleanItemMapper.class);
|
||||
ShopManageGroupMapper groupMapper = mock(ShopManageGroupMapper.class);
|
||||
AppearancePatentCleanItemQueryService service = new AppearancePatentCleanItemQueryService(
|
||||
mapper, mock(AdminUserMapper.class), groupMapper);
|
||||
|
||||
when(groupMapper.selectUserIdsByGroupId(9L)).thenReturn(List.of());
|
||||
|
||||
AppearancePatentSupervisorPageVo vo = service.supervisorPage(1L, 10L, null, null, null, 9L, 5L);
|
||||
|
||||
assertEquals(0L, vo.getTotal());
|
||||
assertTrue(vo.getItems().isEmpty());
|
||||
verify(mapper, never()).countSupervisors(any(), any(), any(), any(), any(), any(), any());
|
||||
verify(mapper, never()).selectSupervisorSummaries(any(), any(), any(), any(), any(), any(), any(),
|
||||
anyLong(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
void 按主管导出走主管专口并保留xlsx主管列() throws Exception {
|
||||
AppearancePatentCleanItemMapper mapper = mock(AppearancePatentCleanItemMapper.class);
|
||||
AdminUserMapper adminUserMapper = mock(AdminUserMapper.class);
|
||||
AppearancePatentCleanItemQueryService service = new AppearancePatentCleanItemQueryService(
|
||||
mapper, adminUserMapper, mock(ShopManageGroupMapper.class));
|
||||
|
||||
when(mapper.countSupervisorItems(any(), any(), any(), any(), any(), any(), any(), eq(9L))).thenReturn(1L);
|
||||
when(mapper.selectSupervisorItems(any(), any(), any(), any(), any(), any(), any(), eq(9L), eq(0L), anyInt()))
|
||||
.thenReturn(List.of(rowEntity(1L, 33L)));
|
||||
AdminUserEntity plainOwner = new AdminUserEntity();
|
||||
plainOwner.setId(33L);
|
||||
plainOwner.setUsername("sub-user-1");
|
||||
plainOwner.setCreatedById(9L);
|
||||
AdminUserEntity creator = new AdminUserEntity();
|
||||
creator.setId(9L);
|
||||
creator.setUsername("主管甲");
|
||||
when(adminUserMapper.selectBatchIds(anyCollection())).thenAnswer(invocation -> {
|
||||
Collection<?> ids = invocation.getArgument(0);
|
||||
List<AdminUserEntity> out = new ArrayList<>();
|
||||
if (ids.contains(33L)) out.add(plainOwner);
|
||||
if (ids.contains(9L)) out.add(creator);
|
||||
return out;
|
||||
});
|
||||
|
||||
byte[] bytes = service.exportBySupervisor(9L, null, null, null, null, 5L);
|
||||
|
||||
// 走的是主管专口:不能落到不按主管收窄的 countCleanItems/selectCleanItemPage 上
|
||||
verify(mapper, never()).countCleanItems(any(), any(), any(), any(), any(), any(), any());
|
||||
verify(mapper, never()).selectCleanItemPage(any(), any(), any(), any(), any(), any(), any(),
|
||||
anyLong(), anyInt());
|
||||
try (XSSFWorkbook workbook = new XSSFWorkbook(new ByteArrayInputStream(bytes))) {
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
assertEquals(1, sheet.getLastRowNum(), "表头 + 1 行明细");
|
||||
assertEquals("主管甲", sheet.getRow(1).getCell(8).getStringCellValue(),
|
||||
"按主管导出同样带所属主管列(与全量导出同一表头)");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void 主管聚合端点与按主管导出参数就位() throws IOException {
|
||||
String source = stripComments(Files.readString(CONTROLLER));
|
||||
assertTrue(source.contains("supervisorPage("), "主管聚合必须落到服务的 supervisorPage");
|
||||
assertTrue(source.contains("supervisor_user_id"), "按主管导出参数名 supervisor_user_id(卡片「下载」)");
|
||||
assertTrue(source.contains("exportBySupervisor("), "按主管导出必须走主管专口(按归属表达式收窄,不近似成 user_id OR created_by_id)");
|
||||
assertTrue(source.contains("AppearancePatentSupervisorPageVo"), "主管卡片页信封类型必须点名");
|
||||
}
|
||||
|
||||
/** 导出/分页用例共用的明细行夹具:task 归 owner,值非空便于按列对撞。 */
|
||||
private static CleanItemEntity rowEntity(long id, long userId) {
|
||||
CleanItemEntity entity = new CleanItemEntity();
|
||||
private static CleanItemEntity rowEntity(long id, long userId) { CleanItemEntity entity = new CleanItemEntity();
|
||||
entity.setId(id);
|
||||
entity.setResultId(900 + id);
|
||||
entity.setTaskId(33179L);
|
||||
|
||||
@@ -318,17 +318,19 @@ class SourceScanTest {
|
||||
List<Path> files = SourceScan.moduleSources("modules/appearancepatent");
|
||||
|
||||
assertThat(files)
|
||||
.as("真实集成:对真仓目录求值。52 支=2 controller+1 client+8 service 根件"
|
||||
.as("真实集成:对真仓目录求值。55 支=2 controller+1 client+8 service 根件"
|
||||
+ "(主件/只读查询/同步/出表作业/缓存/心跳与拉取与重试 SPI)"
|
||||
+ "+21 service/support+19 model(dto7/entity1/vo11)+1 mapper,"
|
||||
+ "+21 service/support+22 model(dto7/entity1/vo14)+1 mapper,"
|
||||
+ "与 find 实测同号"
|
||||
+ "(3A 拆薄第十三笔再落 5 支;失败任务重试再落 1 支 RetrySpi;"
|
||||
+ "v1.3 Phase 1 无侵权同步底座再落 2 支:model/entity/CleanItemEntity+"
|
||||
+ "mapper/AppearancePatentCleanItemMapper;Phase 2 同步服务再落 1 支"
|
||||
+ " AppearancePatentCleanSyncService;Phase 3 只读页再落 4 支:"
|
||||
+ "controller/AdminAppearancePatentCleanItemsController+"
|
||||
+ "service/AppearancePatentCleanItemQueryService+model/vo 两件)")
|
||||
.hasSize(52);
|
||||
+ "service/AppearancePatentCleanItemQueryService+model/vo 两件;"
|
||||
+ "2026-11-11「按主管划分」再落 3 支 model/vo:"
|
||||
+ "SupervisorPageVo/SummaryVo/SupervisorVo)")
|
||||
.hasSize(55);
|
||||
assertThat(files.stream().map(p -> p.toString().replace('\\', '/')).toList())
|
||||
.as("support 目录里的既有件必须在面里——聚合入口存在的理由就是拆分后的新文件要自动被看到")
|
||||
.anyMatch(rel -> rel.endsWith("service/support/AppearancePatentRowNormalizer.java"));
|
||||
@@ -463,8 +465,8 @@ class SourceScanTest {
|
||||
.as("model/dto 一层嵌套")
|
||||
.isEqualTo(7);
|
||||
assertThat(rel.stream().filter(p -> p.contains("/model/vo/")).count())
|
||||
.as("model/vo 一层嵌套")
|
||||
.isEqualTo(11);
|
||||
.as("model/vo 一层嵌套(11→14:2026-11-11「按主管划分」三支 Supervisor 聚合 VO)")
|
||||
.isEqualTo(14);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user