feat(phase-5): B60 console 分页与矩阵预聚合+P1-B5/6/7/8 性能热点收口
接管另一路会话的 Phase 5 在飞件收口(5A/5C 主体由那一路落码,本笔补齐 P1-B7 与两处台账并整量验证)。 - 5A/B60:撞款 console 的行窗口在服务端真分页(响应 dup 行数 ≤ pageSize,total_dup 仍是未分页 总数)、dupGroup 判据收归服务端单一出处(前端 dupWithinGroup 删掉,两套同名规则不再分叉)、 排序先于切窗;后管矩阵改预聚合+列窗 40。读数(200 列 × 50 行):每行 3 店 8.4 → 5.3 → 0.7ms (12.4×),每行 40 店 83.7 → 18.4 → 1.8ms(45.3×)。服务端不设列窗是判断不是漏做:shops 每行 只有 5 个标量,而矩阵的列来自已分页的行——给 shops 再加分页会把"全局指标读全集"和"列窗读本页" 两套语义搅在一起。浏览器首屏/交互耗时本机拿不到,登记为 Phase 6 现网复量。 - P1-B6:claim 循环的父任务终态判定折成一次批量 IN(TaskFileJobBatchQueries+Mapper XML, 铁律 1 收口在 Mapper),逐行 CAS 认领一字不动。 - P1-B5:V187 只建 idx_biz_file_task_resume_of;审计给的候选集索引**有意不建**(V184 前缀已覆盖, OR/IS-NULL 与 COALESCE 不可索引),判据把这条负判定钉住。真库 EXPLAIN 本机无 MySQL,顺延现网。 - P1-B8:结果载荷的对象存储删除移到 afterCommit,事务里不再做 120s 超时的网络调用。 - P1-B7:结果集读取按窗提交+收割(窗口=线程池队列容量的一半)。审计把它记成"无 limit",但截断 是正确性错误不是性能取舍,真能收的是"整份结果集被读两遍"——一次性提交时每支 Future 把解好的 载荷扣在自己身上直到全部收割完,峰值=结果集+另一份整副本;分窗后副本只驻留一窗。流式组装 契约要改 4 个模块的调用方,本 Phase 未做,别读成 P1-B7 已闭环。 - SourceScanTest 台账随之登记:裸名 25 → 26、调用方 18 → 19(P1-B7 的窗口判据只能打在源码上—— 线程池只有 8 个线程,"同时开始读几行"改前改后读数相同,差异只体现在堆上,mock 数不出来)。
This commit is contained in:
@@ -9,7 +9,16 @@ import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
import { useCompanyTabStore } from '@/stores/company-tab'
|
||||
import type { DuplicateItem, DuplicateOccurrence, DuplicateMetrics, DuplicateShop } from './duplicate-model.ts'
|
||||
import { fetchDuplicateConsole, fetchDuplicateLedger, requestDuplicateExportBlob, type LedgerSortKey } from './duplicate-console-api.ts'
|
||||
import { aggregateDrawerRows, drawerSummaryOf, dupWithinGroup, indexShopGroups, type DrawerAggRow, type DrawerSummary, type ShopGroups } from './duplicate-console-logic.ts'
|
||||
import {
|
||||
aggregateDrawerRows,
|
||||
drawerSummaryOf,
|
||||
indexShopGroups,
|
||||
itemBrandOf,
|
||||
type DrawerAggRow,
|
||||
type DrawerSummary,
|
||||
type ShopGroups,
|
||||
} from './duplicate-console-logic.ts'
|
||||
import { useDuplicateMatrix } from './duplicate-matrix-window.ts'
|
||||
import type { DuplicateConsole, LedgerRow } from './duplicate-console-model.ts'
|
||||
import { ASIN_COUNTRY_CODES, asinCountryLabel } from '../asin/asin-country.ts'
|
||||
import { orderedPair } from '@/utils/datetime'
|
||||
@@ -73,7 +82,8 @@ function toast(msg: string) {
|
||||
const overview = computed(() => consoleData.value?.overview ?? null)
|
||||
const summary = computed<DuplicateMetrics | null>(() => overview.value?.summary ?? null)
|
||||
const shops = computed(() => overview.value?.shops ?? [])
|
||||
const dupItems = computed(() => consoleData.value?.dup ?? [])
|
||||
/** 当前撞款行窗口:服务端按 page/page_size(+dup_group) 切好的一窗(B60),页面不再自切全集。 */
|
||||
const dupItems = computed<DuplicateItem[]>(() => consoleData.value?.dup ?? [])
|
||||
const groupStats = computed(() => consoleData.value?.groups ?? [])
|
||||
|
||||
const countryOptions = computed<string[]>(() => {
|
||||
@@ -118,26 +128,32 @@ function selectedGroupMembers(): string[] {
|
||||
|
||||
const groupChips = computed(() => groupStats.value.filter((group) => group.shopCount >= 2))
|
||||
|
||||
/** 当前撞款行集:全局=撞款全集;分组=组内成员撞款子集;均按 ASIN 升序(reference 台账顺序)。 */
|
||||
const dupRows = computed<DuplicateItem[]>(() => {
|
||||
const rows = scope.value === 'global' ? dupItems.value : dupWithinGroup(dupItems.value, selectedGroupMembers())
|
||||
return [...rows].sort((a, b) => a.asin.localeCompare(b.asin))
|
||||
})
|
||||
|
||||
/** 矩阵列:分组范围=该组成员店;全店=全部可见店铺(按上架量降序)。 */
|
||||
const matrixShops = computed<string[]>(() => {
|
||||
if (scope.value === 'group') return selectedGroupMembers()
|
||||
return orderedShops.value.map((shop) => shop.shopName)
|
||||
})
|
||||
|
||||
const activeGroupStat = computed(() => groupStats.value.find((group) => group.name === selectedGroup.value) || null)
|
||||
/** 撞款 Tab 计数:全店范围取后端权威 total_dup(防后端截断计数偏小);分组范围取组内子集长度。 */
|
||||
const totalDupCount = computed(() => (scope.value === 'global' ? (consoleData.value?.totalDup ?? dupRows.value.length) : dupRows.value.length))
|
||||
/** 撞款行总数:服务端在本页 + 本范围(全局或所选分组)内未分页的计数,翻页控件与 KPI 共用。 */
|
||||
const totalDupCount = computed(() => consoleData.value?.totalDup ?? 0)
|
||||
|
||||
function itemBrand(item: DuplicateItem): string {
|
||||
for (const occ of item.occurrences || []) if (occ.brand) return occ.brand
|
||||
return ''
|
||||
}
|
||||
/** 撞款矩阵的行窗 + 列窗 + 格子视图(B60):状态与算法在 `duplicate-matrix-window.ts`,翻页动作交回这里。 */
|
||||
const {
|
||||
matrixPage,
|
||||
matrixPageSize,
|
||||
columnPage,
|
||||
columnWindowTotal,
|
||||
matrixAllColumns,
|
||||
matrixShops,
|
||||
matrixView,
|
||||
matrixHint,
|
||||
goMatrixPage,
|
||||
changeMatrixSize,
|
||||
goColumnPage,
|
||||
resetMatrixWindows,
|
||||
} = useDuplicateMatrix({
|
||||
rows: dupItems,
|
||||
groupMembers: computed(() => selectedGroupMembers()),
|
||||
groupScoped: computed(() => scope.value === 'group'),
|
||||
selectedGroup,
|
||||
reload: () => void loadConsole(),
|
||||
dataVersion: consoleData,
|
||||
})
|
||||
|
||||
|
||||
// ---- 撞款视图分页(分布/矩阵/撞款详情/抽屉明细;10/20/50/100 可选) ----
|
||||
@@ -147,16 +163,7 @@ const distPageSize = ref(10)
|
||||
const pagedDistBars = computed(() =>
|
||||
storeDistribution.value.list.slice((distPage.value - 1) * distPageSize.value, distPage.value * distPageSize.value),
|
||||
)
|
||||
const matrixPage = ref(1)
|
||||
const matrixPageSize = ref(10)
|
||||
const matrixRows = computed(() =>
|
||||
dupRows.value.slice((matrixPage.value - 1) * matrixPageSize.value, matrixPage.value * matrixPageSize.value),
|
||||
)
|
||||
const dupCardPage = ref(1)
|
||||
const dupCardPageSize = ref(10)
|
||||
const dupCardRows = computed(() =>
|
||||
dupRows.value.slice((dupCardPage.value - 1) * dupCardPageSize.value, dupCardPage.value * dupCardPageSize.value),
|
||||
)
|
||||
|
||||
const drawerPage = ref(1)
|
||||
const drawerPageSize = ref(10)
|
||||
const drawerRows = computed(() =>
|
||||
@@ -168,46 +175,15 @@ const groupStatsPageSize = ref(10)
|
||||
const pagedGroupStats = computed(() =>
|
||||
groupStats.value.slice((groupStatsPage.value - 1) * groupStatsPageSize.value, groupStatsPage.value * groupStatsPageSize.value),
|
||||
)
|
||||
watch([dupRows, drawerOccurrences, groupStats], () => {
|
||||
matrixPage.value = Math.min(matrixPage.value, Math.max(1, Math.ceil(dupRows.value.length / matrixPageSize.value)))
|
||||
dupCardPage.value = Math.min(dupCardPage.value, Math.max(1, Math.ceil(dupRows.value.length / dupCardPageSize.value)))
|
||||
watch([drawerOccurrences, groupStats], () => {
|
||||
drawerPage.value = 1
|
||||
groupStatsPage.value = Math.min(groupStatsPage.value, Math.max(1, Math.ceil(groupStats.value.length / groupStatsPageSize.value)))
|
||||
})
|
||||
|
||||
const matrixHint = computed(() =>
|
||||
scope.value === 'global'
|
||||
? '行 = 全店撞款ASIN,列 = 全部店铺;有数字表示该店在售此 ASIN,点击行可看上架时间明细'
|
||||
: selectedGroup.value
|
||||
? `行 = 分组「${selectedGroup.value}」内的撞款ASIN,列 = 该分组店铺;有数字表示组内该店在售此 ASIN`
|
||||
: '行 = 分组内撞款ASIN,列 = 该分组店铺;有数字表示组内该店在售此 ASIN',
|
||||
)
|
||||
|
||||
/* ----- 矩阵单元格辅助 ----- */
|
||||
function shopKey(name: string): string {
|
||||
return (name || '').trim().toLowerCase()
|
||||
}
|
||||
function cellOccurrences(item: DuplicateItem, shop: string): DuplicateOccurrence[] {
|
||||
const key = shopKey(shop)
|
||||
return (item.occurrences || []).filter((occ) => shopKey(occ.shopName) === key)
|
||||
}
|
||||
function cellCount(item: DuplicateItem, shop: string): number {
|
||||
return cellOccurrences(item, shop).length
|
||||
}
|
||||
function cellCountryDots(item: DuplicateItem, shop: string): string[] {
|
||||
const codes = new Set<string>()
|
||||
for (const occ of cellOccurrences(item, shop)) if (occ.country) codes.add(occ.country.toUpperCase())
|
||||
return [...codes]
|
||||
}
|
||||
function cellCountryCount(item: DuplicateItem, shop: string, code: string): number {
|
||||
return cellOccurrences(item, shop).filter((occ) => (occ.country || '').toUpperCase() === code).length
|
||||
}
|
||||
function cellTitle(item: DuplicateItem, shop: string): string {
|
||||
const count = cellCount(item, shop)
|
||||
if (!count) return `${shop} 无此 ASIN`
|
||||
const sites = cellCountryDots(item, shop).map((code) => `${asinCountryLabel(code)} ${cellCountryCount(item, shop, code)}条`).join('、')
|
||||
return `${shop} 在售 ${count} 条 · ${sites}`
|
||||
}
|
||||
|
||||
function activeFilterParams() {
|
||||
return { asin: filter.asin.trim(), shopName: filter.shop.trim(), group: filter.group.trim(), country: filter.country, site: '', dateFrom: filter.dateFrom, dateTo: filter.dateTo }
|
||||
@@ -217,7 +193,13 @@ async function loadConsole() {
|
||||
loading.value = true
|
||||
loadError.value = ''
|
||||
try {
|
||||
consoleData.value = await fetchDuplicateConsole({ view: '', ...activeFilterParams() }, companyTab.requestCompanyId)
|
||||
consoleData.value = await fetchDuplicateConsole(
|
||||
{ view: '', ...activeFilterParams() },
|
||||
companyTab.requestCompanyId,
|
||||
matrixPage.value,
|
||||
matrixPageSize.value,
|
||||
scope.value === 'group' ? selectedGroup.value : '',
|
||||
)
|
||||
shopGroups.value = indexShopGroups(orderedShops.value)
|
||||
if (groupStats.value.length && !groupStats.value.some((group) => group.name === selectedGroup.value)) {
|
||||
selectedGroup.value = groupChips.value[0] ? groupChips.value[0].name : ''
|
||||
@@ -270,6 +252,7 @@ function resetQuery() {
|
||||
scope.value = 'global'
|
||||
selectedGroup.value = ''
|
||||
activeTab.value = 'dup'
|
||||
resetMatrixWindows()
|
||||
applyQuery()
|
||||
toast('筛选已重置')
|
||||
}
|
||||
@@ -280,8 +263,21 @@ function switchTab(tab: Tab) {
|
||||
}
|
||||
|
||||
function switchScope(next: Scope) {
|
||||
if (scope.value === next) return
|
||||
scope.value = next
|
||||
if (next === 'group' && !selectedGroup.value && groupChips.value.length) selectedGroup.value = groupChips.value[0].name
|
||||
// 行范围换了(全局 ↔ 组内),服务端裁出来的那一窗也就换了 ⇒ 重新请一窗。
|
||||
resetMatrixWindows()
|
||||
void loadConsole()
|
||||
}
|
||||
|
||||
/** 分组 chip:选中即换行范围,与 switchScope 同一条出口(不再在客户端重裁一遍全集)。 */
|
||||
function selectGroup(name: string) {
|
||||
if (selectedGroup.value === name && scope.value === 'group') return
|
||||
scope.value = 'group'
|
||||
selectedGroup.value = name
|
||||
resetMatrixWindows()
|
||||
void loadConsole()
|
||||
}
|
||||
|
||||
async function reAnalyze() {
|
||||
@@ -338,7 +334,7 @@ function openDrawer(asin: string, brand: string, dupFlag: boolean, occurrences:
|
||||
}
|
||||
|
||||
function openDupDrawer(item: DuplicateItem) {
|
||||
openDrawer(item.asin, itemBrand(item), item.shopCount >= 2, item.occurrences)
|
||||
openDrawer(item.asin, itemBrandOf(item), item.shopCount >= 2, item.occurrences)
|
||||
}
|
||||
|
||||
function openLedgerDrawer(row: LedgerRow) {
|
||||
@@ -553,7 +549,7 @@ onMounted(() => {
|
||||
</div>
|
||||
<div v-if="scope === 'group'" class="group-chips">
|
||||
<template v-if="groupChips.length">
|
||||
<button v-for="group in groupChips" :key="group.name" type="button" class="g-chip" :class="{ active: selectedGroup === group.name, dup: group.dupCount > 0 }" @click="selectedGroup = group.name">
|
||||
<button v-for="group in groupChips" :key="group.name" type="button" class="g-chip" :class="{ active: selectedGroup === group.name, dup: group.dupCount > 0 }" @click="selectGroup(group.name)">
|
||||
{{ group.name }} <span class="g-count">{{ group.shopCount }}店 · {{ group.dupCount }}撞款</span>
|
||||
</button>
|
||||
</template>
|
||||
@@ -568,9 +564,16 @@ onMounted(() => {
|
||||
<div class="gs-item" :class="{ warn: activeGroupStat.dupCount > 0 }"><div class="gs-v">{{ activeGroupStat.dupCount }}</div><div class="gs-l">组内撞款ASIN</div></div>
|
||||
</div>
|
||||
|
||||
<div class="section-title">撞款覆盖矩阵 <span class="hint">{{ matrixHint }}</span></div>
|
||||
<div class="section-title">
|
||||
撞款覆盖矩阵 <span class="hint">{{ matrixHint }}</span>
|
||||
<span v-if="columnWindowTotal > 1" class="col-window">
|
||||
<button type="button" class="link-btn" :disabled="columnPage <= 1" @click="goColumnPage(-1)">‹ 上一窗列</button>
|
||||
列 {{ columnPage }}/{{ columnWindowTotal }}(共 {{ matrixAllColumns.length }} 列)
|
||||
<button type="button" class="link-btn" :disabled="columnPage >= columnWindowTotal" @click="goColumnPage(1)">下一窗列 ›</button>
|
||||
</span>
|
||||
</div>
|
||||
<div class="matrix-wrap">
|
||||
<table v-if="dupRows.length" class="matrix">
|
||||
<table v-if="dupItems.length" class="matrix">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ASIN</th>
|
||||
@@ -579,13 +582,13 @@ onMounted(() => {
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="item in matrixRows" :key="item.asin" @click="openDupDrawer(item)">
|
||||
<td><span class="asin-code">{{ item.asin }}</span></td>
|
||||
<td><span class="m-brand">{{ itemBrand(item) || '—' }}</span></td>
|
||||
<td v-for="shop in matrixShops" :key="shop" style="text-align:center">
|
||||
<div class="m-cell" :class="{ empty: cellCount(item, shop) === 0 }" :title="cellTitle(item, shop)">
|
||||
{{ cellCount(item, shop) || '' }}
|
||||
<span class="dots"><span v-for="code in cellCountryDots(item, shop)" :key="code" class="m-dot" :style="{ background: siteColor(code) }"></span></span>
|
||||
<tr v-for="row in matrixView" :key="row.asin" @click="openDupDrawer(row.item)">
|
||||
<td><span class="asin-code">{{ row.asin }}</span></td>
|
||||
<td><span class="m-brand">{{ row.brand }}</span></td>
|
||||
<td v-for="(cell, index) in row.cells" :key="matrixShops[index]" style="text-align:center">
|
||||
<div class="m-cell" :class="{ empty: cell.count === 0 }" :title="cell.title">
|
||||
{{ cell.count || '' }}
|
||||
<span class="dots"><span v-for="code in cell.dots" :key="code" class="m-dot" :style="{ background: siteColor(code) }"></span></span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -596,15 +599,15 @@ onMounted(() => {
|
||||
调整筛选条件或切换到其他分组查看
|
||||
</div>
|
||||
</div>
|
||||
<OldPagination :total="dupRows.length" :page="matrixPage" :page-size="matrixPageSize" @change="matrixPage = $event" @size-change="(s: number) => { matrixPageSize = s; matrixPage = 1 }" />
|
||||
<OldPagination :total="totalDupCount" :page="matrixPage" :page-size="matrixPageSize" @change="goMatrixPage" @size-change="changeMatrixSize" />
|
||||
|
||||
<div class="section-title" style="margin-top:24px">撞款详情 <span class="hint">同一 ASIN 在多家店铺的上架时间明细</span></div>
|
||||
<div v-if="dupRows.length" class="dup-grid">
|
||||
<div v-for="item in dupCardRows" :key="item.asin" class="dup-card">
|
||||
<div v-if="dupItems.length" class="dup-grid">
|
||||
<div v-for="item in dupItems" :key="item.asin" class="dup-card">
|
||||
<div class="dup-head">
|
||||
<span class="asin-code">{{ item.asin }}</span>
|
||||
<span class="badge dup">{{ item.shopCount }}店在售</span>
|
||||
<span class="d-brand">{{ itemBrand(item) || '未知品牌' }}</span>
|
||||
<span class="d-brand">{{ itemBrandOf(item) || '未知品牌' }}</span>
|
||||
<button class="link-btn" type="button" @click="openDupDrawer(item)">查看明细</button>
|
||||
</div>
|
||||
<div class="dup-body">
|
||||
@@ -620,8 +623,8 @@ onMounted(() => {
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="dup-empty">当前范围下没有撞款ASIN</div>
|
||||
<OldPagination :total="dupRows.length" :page="dupCardPage" :page-size="dupCardPageSize" @change="dupCardPage = $event" @size-change="(s: number) => { dupCardPageSize = s; dupCardPage = 1 }" />
|
||||
<div class="dup-total">共 <b>{{ dupRows.length }}</b> 条{{ scope === 'group' && selectedGroup ? `分组「${selectedGroup}」组内撞款ASIN` : '全店撞款ASIN' }}</div>
|
||||
<OldPagination :total="totalDupCount" :page="matrixPage" :page-size="matrixPageSize" @change="goMatrixPage" @size-change="changeMatrixSize" />
|
||||
<div class="dup-total">共 <b>{{ dupItems.length }}</b> 条{{ scope === 'group' && selectedGroup ? `分组「${selectedGroup}」组内撞款ASIN` : '全店撞款ASIN' }}</div>
|
||||
</template>
|
||||
|
||||
<!-- ============ 全部ASIN台账 ============ -->
|
||||
@@ -885,6 +888,9 @@ onMounted(() => {
|
||||
.dup-ref .section-title { font-size: 14px; font-weight: 700; display: flex; align-items: baseline; gap: 8px; margin-bottom: 12px; }
|
||||
.dup-ref .section-title .hint { font-size: 11px; font-weight: 400; color: var(--text3); }
|
||||
.dup-ref .matrix-wrap { overflow-x: auto; overflow-y: auto; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); max-height: 480px; }
|
||||
/* 列窗口控件:与 section-title 同行,只在看得到第二窗列时出现。 */
|
||||
.dup-ref .col-window { margin-left: 12px; display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text2); }
|
||||
.dup-ref .col-window .link-btn:disabled { color: var(--text3); cursor: not-allowed; }
|
||||
.dup-ref table.matrix { border-collapse: separate; border-spacing: 0; width: 100%; background: var(--surface); }
|
||||
.dup-ref table.matrix th {
|
||||
background: #F7F9FC; color: var(--text2); font-size: 12px; font-weight: 600; padding: 10px 12px;
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
|
||||
export const DUPLICATE_CHECK_ENDPOINT = '/api/admin/shop-data-crawl'
|
||||
|
||||
/** console 端点吃 asin/shop_name/group/country/site/date_from/date_to;多余分页参数后端忽略。 */
|
||||
/** console 端点吃 asin/shop_name/group/country/site/date_from/date_to(行窗口的 page/page_size/dup_group 由调用方另传)。 */
|
||||
function toConsoleQuery(filter: DuplicateFilter): Record<string, string> {
|
||||
const query: Record<string, string> = {}
|
||||
const asin = (filter.asin || '').trim()
|
||||
@@ -32,14 +32,25 @@ function toConsoleQuery(filter: DuplicateFilter): Record<string, string> {
|
||||
|
||||
export type LedgerSortKey = 'asin' | 'brand' | 'store_count' | 'record_count' | 'earliest' | 'latest'
|
||||
|
||||
/** 加载撞款控制台快照:GET /duplicate-check-console。 */
|
||||
/**
|
||||
* 加载撞款控制台快照:GET /duplicate-check-console。
|
||||
*
|
||||
* 行窗口(B60):`page`/`pageSize` 决定返回的 `dup` 是这一窗,`dupGroup` 非空时行集先按
|
||||
* 该分组成员裁剪(组内 ≥2 店才算撞款)。三者都是**服务端**口径——矩阵与详情卡片共用同一窗口,
|
||||
* 页面不再自己从全集里切片(那需要后端把整份撞款数组发回来,正是 B60 要收掉的那件事)。
|
||||
*/
|
||||
export async function fetchDuplicateConsole(
|
||||
filter: DuplicateFilter,
|
||||
companyId?: number | null,
|
||||
page = 1,
|
||||
pageSize = 100,
|
||||
dupGroup = '',
|
||||
): Promise<DuplicateConsole> {
|
||||
// toConsoleQuery 是白名单构造(只点名 asin/shop_name/group/country/site/date_*),
|
||||
// 公司值只许落在本函数自己的 companyId 形参上。
|
||||
const query: Record<string, string | number> = toConsoleQuery(filter)
|
||||
const query: Record<string, string | number> = { ...toConsoleQuery(filter), page, page_size: pageSize }
|
||||
const group = (dupGroup || '').trim()
|
||||
if (group) query.dup_group = group
|
||||
if (companyId != null) query.company_id = companyId
|
||||
const { data } = await http.get<unknown>(`${DUPLICATE_CHECK_ENDPOINT}/duplicate-check-console`, { params: query })
|
||||
return parseDuplicateConsole(data)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/** 撞款控制台视图派生(分组索引 / 组内撞款子集 / 店铺列并集):纯逻辑。 */
|
||||
/** 撞款控制台视图派生(分组索引 / 店铺列并集 / 矩阵格子预聚合):纯逻辑。 */
|
||||
import type { DuplicateItem, DuplicateOccurrence, DuplicateShop } from './duplicate-model.ts'
|
||||
|
||||
export interface ShopGroups {
|
||||
@@ -41,27 +41,6 @@ export function indexShopGroups(shops: DuplicateShop[]): ShopGroups {
|
||||
return { members, shopGroupNames }
|
||||
}
|
||||
|
||||
/** 仅在指定成员店铺(展示名)内保留 occurrences;重算 shop_count,返回 ≥2 店的撞款子集。 */
|
||||
export function dupWithinGroup(items: DuplicateItem[], memberShops: string[]): DuplicateItem[] {
|
||||
const memberKeys = new Set<string>()
|
||||
for (const shop of memberShops || []) memberKeys.add(shopKey(shop))
|
||||
const result: DuplicateItem[] = []
|
||||
for (const item of items || []) {
|
||||
const kept: DuplicateOccurrence[] = []
|
||||
const shops = new Set<string>()
|
||||
for (const occ of item.occurrences || []) {
|
||||
if (memberKeys.has(shopKey(occ.shopName))) {
|
||||
kept.push(occ)
|
||||
shops.add(occ.shopName || '')
|
||||
}
|
||||
}
|
||||
if (kept.length > 0 && shops.size >= 2) {
|
||||
result.push({ asin: item.asin, shopCount: shops.size, recordCount: kept.length, occurrences: kept })
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/** 撞款行涉及店铺的并集列(出现顺序去重);memberShops 非空时仅取交集成员的子集顺序。 */
|
||||
export function storeColumnsOf(items: DuplicateItem[], memberShops: string[] = []): string[] {
|
||||
const restricted = new Set(memberShops.map((shop) => shopKey(shop)))
|
||||
@@ -90,6 +69,74 @@ export function storeColumnsOf(items: DuplicateItem[], memberShops: string[] = [
|
||||
return order
|
||||
}
|
||||
|
||||
/** 矩阵一格:该店在售此 ASIN 的条数 + 站点(国家)分布。 */
|
||||
export interface MatrixCell {
|
||||
count: number
|
||||
sites: { code: string; count: number }[]
|
||||
}
|
||||
|
||||
/** 空格的单份实例:模板每格都要拿一个,不能每格 new 一个对象。 */
|
||||
export const EMPTY_MATRIX_CELL: MatrixCell = { count: 0, sites: [] }
|
||||
|
||||
function cellKey(asin: string, shop: string): string {
|
||||
// 用 \u0000 拼键:ASIN 与店铺名都可打印,任何可见分隔符都可能出现在店铺名里(那样就会串格)。
|
||||
return `${(asin || '').trim()}\u0000${shopKey(shop)}`
|
||||
}
|
||||
|
||||
/**
|
||||
* 撞款矩阵的格子集合:把 rows×columns 一次算完(B60 的「预聚合」)。
|
||||
*
|
||||
* <p>原形状是每格现算:`cellCount`/`cellCountryDots`/`cellTitle` 各自把该行 occurrences 全 filter
|
||||
* 一遍,一格 4~6 次、50 行 × 200 列就是每帧上万次整行扫描,勾选/翻页都要重付。这里每行只按
|
||||
* 店铺分桶一次(O(occurrences)),之后一格一次 Map 取值。
|
||||
*
|
||||
* 只给 `columns` 里点名的列建格:不在列集内的 occurrence 直接不装桶,列窗口收窄时开销跟着降。
|
||||
*/
|
||||
export function buildMatrixCells(items: DuplicateItem[], columns: string[]): Map<string, MatrixCell> {
|
||||
const cells = new Map<string, MatrixCell>()
|
||||
const wanted = new Set<string>()
|
||||
for (const column of columns || []) wanted.add(shopKey(column))
|
||||
if (!wanted.size) return cells
|
||||
for (const item of items || []) {
|
||||
const buckets = new Map<string, DuplicateOccurrence[]>()
|
||||
const siteCounts = new Map<string, Map<string, number>>()
|
||||
for (const occ of item.occurrences || []) {
|
||||
const key = shopKey(occ.shopName)
|
||||
if (!wanted.has(key)) continue
|
||||
const bucket = buckets.get(key)
|
||||
if (bucket) bucket.push(occ)
|
||||
else buckets.set(key, [occ])
|
||||
const code = (occ.country || '').trim().toUpperCase()
|
||||
if (!code) continue
|
||||
let counts = siteCounts.get(key)
|
||||
if (!counts) {
|
||||
counts = new Map<string, number>()
|
||||
siteCounts.set(key, counts)
|
||||
}
|
||||
counts.set(code, (counts.get(code) || 0) + 1)
|
||||
}
|
||||
for (const [key, occurrences] of buckets) {
|
||||
const codes = siteCounts.get(key)
|
||||
cells.set(cellKey(item.asin, key), {
|
||||
count: occurrences.length,
|
||||
sites: codes ? [...codes].map(([code, count]) => ({ code, count })) : [],
|
||||
})
|
||||
}
|
||||
}
|
||||
return cells
|
||||
}
|
||||
|
||||
/** 取一格;没有格子时返回同一份空对象(模板里 `cellOf(...).count` 要能直接读)。 */
|
||||
export function matrixCellOf(cells: Map<string, MatrixCell>, asin: string, shop: string): MatrixCell {
|
||||
return cells.get(cellKey(asin, shop)) || EMPTY_MATRIX_CELL
|
||||
}
|
||||
|
||||
/** 一个撞款 ASIN 的品牌:取第一条带品牌的上架记录,全空就是"未知品牌"(页面自己决定怎么显示)。 */
|
||||
export function itemBrandOf(item: DuplicateItem): string {
|
||||
for (const occ of item.occurrences || []) if (occ.brand) return occ.brand
|
||||
return ''
|
||||
}
|
||||
|
||||
/** 明细抽屉聚合行:店铺×站点聚合(对齐 reference 抽屉的 店铺/分组/站点/上架时间(升序堆叠)/次数)。 */
|
||||
export interface DrawerAggRow {
|
||||
shopName: string
|
||||
|
||||
@@ -18,12 +18,19 @@ export interface ConsoleGroupStat {
|
||||
dupCount: number
|
||||
}
|
||||
|
||||
/** 撞款控制台单次快照:总览(指标/店铺分布) + 撞款全集 + 分组统计。 */
|
||||
/**
|
||||
* 撞款控制台单次快照:总览(指标/店铺分布) + 撞款**行窗口** + 分组统计。
|
||||
*
|
||||
* `dup` 是服务端按 page/pageSize 切出来的一窗(B60),`totalDup` 是该范围内未分页的总数;
|
||||
* 两者不是同一个口径,页面分页器读 totalDup、列表读 dup。
|
||||
*/
|
||||
export interface DuplicateConsole {
|
||||
overview: DuplicateOverview
|
||||
dup: DuplicateItem[]
|
||||
groups: ConsoleGroupStat[]
|
||||
totalDup: number
|
||||
page: number
|
||||
pageSize: number
|
||||
}
|
||||
|
||||
/** 台账单行(含 occurrences,供明细抽屉还原每店上架时间线)。 */
|
||||
@@ -87,7 +94,14 @@ export function parseDuplicateConsole(payload: unknown): DuplicateConsole {
|
||||
const groups = Array.isArray(record.groups)
|
||||
? record.groups.map((raw) => parseConsoleGroup(raw)).filter((group): group is ConsoleGroupStat => group !== null)
|
||||
: []
|
||||
return { overview, dup, groups, totalDup: count(record.total_dup ?? record.totalDup) }
|
||||
return {
|
||||
overview,
|
||||
dup,
|
||||
groups,
|
||||
totalDup: count(record.total_dup ?? record.totalDup),
|
||||
page: count(record.page) || 1,
|
||||
pageSize: count(record.page_size ?? record.pageSize),
|
||||
}
|
||||
}
|
||||
|
||||
/** 解析单条台账行。 */
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
/**
|
||||
* 撞款覆盖矩阵的「行窗 + 列窗」组合式(B60 从 DuplicateCheckPage.vue 拆出)。
|
||||
*
|
||||
* 为什么单独立一支:那一屏矩阵原本是每格现算——`cellCount / cellCountryDots / cellTitle`
|
||||
* 各自把该行 occurrences 全 filter 一遍(一格 4~6 次),而且整份撞款全集一次性铺成
|
||||
* 「全部行 × 全部列」的 DOM。收口后行由服务端切窗、列在本模块切窗,格子的文案与
|
||||
* 国家点一次算完、空格按列共享同一份视图。这些状态(列游标、行游标、三份 computed)
|
||||
* 是一件事,留在页面里会把本页推到可读性基线之外,也更难单测。
|
||||
*
|
||||
* 纯逻辑部分(分桶、取列)在 `duplicate-console-logic.ts`,本文件只做"窗口"这一层,
|
||||
* 数据从页面注入,不认识 store。
|
||||
*/
|
||||
import { computed, ref, watch, type ComputedRef, type Ref } from 'vue'
|
||||
import { buildMatrixCells, itemBrandOf, matrixCellOf, storeColumnsOf } from './duplicate-console-logic.ts'
|
||||
import { asinCountryLabel } from '../asin/asin-country.ts'
|
||||
import type { DuplicateItem } from './duplicate-model.ts'
|
||||
|
||||
/**
|
||||
* 列窗口上限(B60「限制列数」)。一窗 40 列 × 最多 100 行=单帧最多 4,000 格;
|
||||
* 不封顶时 200 列 × 100 行=2 万格 DOM,任何一次勾选/翻页都要重排。
|
||||
* 列没被裁掉,只是切成窗口(`goColumnPage`),所以信息一条不丢。
|
||||
*/
|
||||
export const MATRIX_COLUMN_WINDOW = 40
|
||||
|
||||
/** 模板只读这一份:数字、国家点、悬浮说明都在这里算完。 */
|
||||
export interface MatrixCellView {
|
||||
count: number
|
||||
dots: string[]
|
||||
title: string
|
||||
}
|
||||
|
||||
/** 一行矩阵视图:行对象本身(点开抽屉要用)+ 品牌 + 本窗每一格。 */
|
||||
export interface MatrixRowView {
|
||||
item: DuplicateItem
|
||||
asin: string
|
||||
brand: string
|
||||
cells: MatrixCellView[]
|
||||
}
|
||||
|
||||
export interface MatrixWindowSource {
|
||||
/** 当前行窗(服务端切好的那一窗)。 */
|
||||
rows: ComputedRef<DuplicateItem[]>
|
||||
/** 列范围的第二正本=分组页签选中的组员(非分组范围给空数组)。 */
|
||||
groupMembers: ComputedRef<string[]>
|
||||
/** 分组范围与否:决定列要不要与组员取交集。 */
|
||||
groupScoped: Ref<boolean> | ComputedRef<boolean>
|
||||
/** 选中的分组名(只用于矩阵那行说明文案,让"看到的是什么范围"写在屏上)。 */
|
||||
selectedGroup: Ref<string> | ComputedRef<string>
|
||||
/** 行窗换页/换档都要重新请一窗(服务端切,页面不再从全集里自切)。 */
|
||||
reload: () => void
|
||||
/** 数据到达的版本号(一般是 consoleData 本身):新数据 ⇒ 旧游标已指向不存在的位置。 */
|
||||
dataVersion: Ref<unknown>
|
||||
}
|
||||
|
||||
/** 空格共用同一份 dots(模板只读不写,共享数组不会被改)。 */
|
||||
const NO_DOTS: string[] = []
|
||||
|
||||
export function useDuplicateMatrix(source: MatrixWindowSource) {
|
||||
const matrixPage = ref(1)
|
||||
const matrixPageSize = ref(10)
|
||||
const columnPage = ref(1)
|
||||
|
||||
/** 本页行里真出现过的店铺=矩阵该配的列(分组范围再与组员取交集)。 */
|
||||
const matrixAllColumns = computed<string[]>(() =>
|
||||
storeColumnsOf(source.rows.value, source.groupScoped.value ? source.groupMembers.value : []),
|
||||
)
|
||||
|
||||
const columnWindowTotal = computed(() =>
|
||||
Math.max(1, Math.ceil(matrixAllColumns.value.length / MATRIX_COLUMN_WINDOW)),
|
||||
)
|
||||
|
||||
/** 矩阵列:按窗口切(超出部分用列窗口控件翻)。 */
|
||||
const matrixShops = computed<string[]>(() => {
|
||||
const start = Math.max(0, (columnPage.value - 1) * MATRIX_COLUMN_WINDOW)
|
||||
return matrixAllColumns.value.slice(start, start + MATRIX_COLUMN_WINDOW)
|
||||
})
|
||||
|
||||
/** 一次把「本窗行 × 本窗列」全部算完,模板只读不算。 */
|
||||
const matrixCells = computed(() => buildMatrixCells(source.rows.value, matrixShops.value))
|
||||
|
||||
function cellView(shop: string, cell: ReturnType<typeof matrixCellOf>): MatrixCellView {
|
||||
const sites = cell.sites.map((site) => `${asinCountryLabel(site.code)} ${site.count}条`).join('、')
|
||||
return {
|
||||
count: cell.count,
|
||||
dots: cell.sites.map((site) => site.code),
|
||||
title: sites ? `${shop} 在售 ${cell.count} 条 · ${sites}` : `${shop} 在售 ${cell.count} 条`,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 每列一份「本格为空」的视图,整列复用同一对象。
|
||||
*
|
||||
* <p>矩阵里绝大多数格是空的(一个 ASIN 只在几家店在售,列却是几十上百家店)。原先一格
|
||||
* 一条 `无此 ASIN` 文案,50 行 × 200 列=1 万条字符串;按列准备一次之后行数再多也不
|
||||
* 乘上去——这条才是"每格现算"剩下的那半开销。
|
||||
*/
|
||||
const emptyColumnViews = computed<MatrixCellView[]>(() =>
|
||||
matrixShops.value.map((shop) => ({ count: 0, dots: NO_DOTS, title: `${shop} 无此 ASIN` })),
|
||||
)
|
||||
|
||||
const matrixView = computed<MatrixRowView[]>(() => {
|
||||
const cells = matrixCells.value
|
||||
const blanks = emptyColumnViews.value
|
||||
return source.rows.value.map((item) => ({
|
||||
item,
|
||||
asin: item.asin,
|
||||
brand: itemBrandOf(item) || '—',
|
||||
cells: matrixShops.value.map((shop, index) => {
|
||||
const cell = matrixCellOf(cells, item.asin, shop)
|
||||
return cell.count ? cellView(shop, cell) : blanks[index]
|
||||
}),
|
||||
}))
|
||||
})
|
||||
|
||||
/** 屏上那行说明:把"行/列各是什么范围"写清楚,尤其分组范围是服务端裁过行的那一窗。 */
|
||||
const matrixHint = computed(() =>
|
||||
source.groupScoped.value
|
||||
? source.selectedGroup.value
|
||||
? `行 = 分组「${source.selectedGroup.value}」内的撞款ASIN(服务端裁行+分页),列 = 组内在售店铺;有数字表示组内该店在售此 ASIN`
|
||||
: '行 = 分组内撞款ASIN,列 = 该分组店铺;有数字表示组内该店在售此 ASIN'
|
||||
: '行 = 本页撞款ASIN(服务端分页),列 = 本页撞款涉及店铺;有数字表示该店在售此 ASIN,点击行可看上架时间明细',
|
||||
)
|
||||
|
||||
/** 行窗口翻页:同一页重复点不重新请(翻页控件的当前页也会触发 change)。 */
|
||||
function goMatrixPage(page: number): void {
|
||||
if (page === matrixPage.value) return
|
||||
matrixPage.value = page
|
||||
source.reload()
|
||||
}
|
||||
|
||||
function changeMatrixSize(size: number): void {
|
||||
matrixPageSize.value = size
|
||||
matrixPage.value = 1
|
||||
source.reload()
|
||||
}
|
||||
|
||||
/** 列窗口翻页:行不动,只把看得见的店铺换一窗。 */
|
||||
function goColumnPage(step: number): void {
|
||||
const next = columnPage.value + step
|
||||
if (next < 1 || next > columnWindowTotal.value) return
|
||||
columnPage.value = next
|
||||
}
|
||||
|
||||
/** 换了行范围(全局 ↔ 组内、换分组、重置筛选):两个游标都回到第一窗。 */
|
||||
function resetMatrixWindows(): void {
|
||||
matrixPage.value = 1
|
||||
columnPage.value = 1
|
||||
}
|
||||
|
||||
watch(source.dataVersion, () => {
|
||||
columnPage.value = Math.min(columnPage.value, columnWindowTotal.value)
|
||||
})
|
||||
|
||||
return {
|
||||
MATRIX_COLUMN_WINDOW,
|
||||
matrixPage,
|
||||
matrixPageSize,
|
||||
columnPage,
|
||||
columnWindowTotal,
|
||||
matrixAllColumns,
|
||||
matrixShops,
|
||||
matrixView,
|
||||
matrixHint,
|
||||
goMatrixPage,
|
||||
changeMatrixSize,
|
||||
goColumnPage,
|
||||
resetMatrixWindows,
|
||||
}
|
||||
}
|
||||
@@ -52,15 +52,46 @@ test('align_dup_console_pagination_all_lists', () => {
|
||||
// 且分布/矩阵/详情常显(不足一页也显示分页器,反馈:数据少时看不到分页)。
|
||||
const page = readSource('src/pages/tasks/DuplicateCheckPage.vue')
|
||||
assert.match(page, /:total="distCount"/, '店铺上架分布有分页器(常显)')
|
||||
assert.match(page, /:total="dupRows\.length"/, '撞款覆盖矩阵有分页器(常显)')
|
||||
assert.match(page, /v-for="item in dupCardRows"/, '撞款详情卡片绑定分页切片')
|
||||
assert.match(page, /:total="dupRows\.length"[\s\S]*dupCardPageSize/, '撞款详情卡片有分页器(常显)')
|
||||
// B60:撞款行改由服务端切窗口,矩阵与详情卡片读同一窗 ⇒ 两个分页器必须共用同一个游标
|
||||
// (各自独立翻页在"一窗"的形状下已经不可表示,留着就是界面说一套、请求发另一套)。
|
||||
assert.match(page, /:total="totalDupCount"[\s\S]*:page="matrixPage"/, '撞款覆盖矩阵分页器绑服务端总数与行窗口游标')
|
||||
assert.match(page, /v-for="item in dupItems"/, '撞款详情卡片绑这一窗行集')
|
||||
assert.match(page, /:total="totalDupCount"[\s\S]*:page-size="matrixPageSize"/, '撞款详情卡片分页器与矩阵同游标')
|
||||
assert.doesNotMatch(page, /dupCardPage/, '卡片不再自持一个分页游标(同窗就是同游标)')
|
||||
assert.doesNotMatch(page, /matrixRows/, '矩阵不再客户端切片(行窗口是服务端切的)')
|
||||
assert.match(page, /<OldPagination[^>]*:total="distCount"/, '分布分页器无 v-if 条件')
|
||||
assert.match(page, /<OldPagination[^>]*:total="dupRows\.length"/, '矩阵/详情分页器无 v-if 条件')
|
||||
assert.match(page, /<OldPagination[^>]*:total="totalDupCount"/, '矩阵/详情分页器无 v-if 条件')
|
||||
assert.match(page, /v-for="group in pagedGroupStats"/, '分组说明抽屉表绑定分页切片')
|
||||
assert.match(page, /:total="groupStats\.length"/, '分组说明抽屉表有分页器')
|
||||
})
|
||||
|
||||
/**
|
||||
* B60 的前后两处出口:行窗口三键要真发出去,矩阵格子要一次算完。
|
||||
* 反向自证:把 api 改回不带 page/page_size、或把模板改回逐格 filter,即红。
|
||||
*/
|
||||
test('align_dup_console_b60_row_window_and_precomputed_cells', () => {
|
||||
const api = readSource('src/pages/tasks/duplicate-console-api.ts')
|
||||
assert.match(api, /page, page_size: pageSize/, 'console 请求带行窗口参数')
|
||||
assert.match(api, /query\.dup_group = group/, 'console 请求带分组裁行参数')
|
||||
assert.doesNotMatch(api, /多余分页参数后端忽略/, '旧注释说分页参数被后端忽略,现在后端认了')
|
||||
|
||||
const page = readSource('src/pages/tasks/DuplicateCheckPage.vue')
|
||||
// 矩阵窗口那一层已从页面拆进 `duplicate-matrix-window.ts`(B60 之后本页顶在可读性基线的
|
||||
// 超长文件名单上,只许减)。绊线跟着搬,判据一字不松:改回逐格 filter 照样红。
|
||||
const matrix = readSource('src/pages/tasks/duplicate-matrix-window.ts')
|
||||
assert.match(page, /useDuplicateMatrix\(/, '页面接的是矩阵窗口组合式')
|
||||
assert.match(matrix, /buildMatrixCells\(/, '矩阵格子一次预聚合')
|
||||
assert.match(matrix, /MATRIX_COLUMN_WINDOW = 40/, '列数有窗口上限(按列切窗)')
|
||||
assert.match(page, /v-for="\(cell, index\) in row\.cells"/, '模板只读预聚合好的格子')
|
||||
assert.doesNotMatch(page, /function cellCount\(/, '逐格 filter 那套函数已收掉')
|
||||
assert.doesNotMatch(matrix, /function cellCount\(/, '窗口组合式里也不许再长出逐格 filter')
|
||||
|
||||
const service = readSource('../backend-java/src/main/java/com/nanri/aiimage/modules/shopduplicatecheck/service/ShopDataDuplicateCheckQueryService.java')
|
||||
assert.match(service, /consoleData\(DuplicateScanView view, Set<String> visibleKeys, Filters filters,\s*\n?\s*int page, int pageSize, String dupGroup\)/,
|
||||
'服务端 console 收行窗口与分组参数')
|
||||
assert.match(service, /"total_dup", total,/, 'total_dup 是未分页总数,不是本页行数')
|
||||
})
|
||||
|
||||
test('align_dup_console_ledger_total_preload', () => {
|
||||
const page = readSource('src/pages/tasks/DuplicateCheckPage.vue')
|
||||
assert.match(page, /onMounted\(\(\) => \{\s*loadConsole\(\).*loadLedger\(1\)/s, '挂载即预取台账计数')
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"note": "readSource 钉子逐文件基线。两把尺子:pins=落在用例体内的读盘,reads=全文读点总数(含模块级夹具与 helper)。都只许减;pins 下降而 reads 没同步下降=把读盘挪出体内,不算改进。由 tests/source-pin-ratchet.test.ts 生成。",
|
||||
"totals": {
|
||||
"files": 253,
|
||||
"cases": 1772,
|
||||
"pins": 457,
|
||||
"reads": 652
|
||||
"files": 254,
|
||||
"cases": 1778,
|
||||
"pins": 458,
|
||||
"reads": 656
|
||||
},
|
||||
"files": {
|
||||
"admin-scaffold.test.ts": {
|
||||
@@ -48,9 +48,9 @@
|
||||
"reads": 3
|
||||
},
|
||||
"align-dup-console.test.ts": {
|
||||
"cases": 10,
|
||||
"pins": 9,
|
||||
"reads": 12
|
||||
"cases": 11,
|
||||
"pins": 10,
|
||||
"reads": 16
|
||||
},
|
||||
"align-edit-user-auth-guard.test.ts": {
|
||||
"cases": 1,
|
||||
@@ -272,8 +272,13 @@
|
||||
"pins": 5,
|
||||
"reads": 6
|
||||
},
|
||||
"dup-matrix-window.test.ts": {
|
||||
"cases": 4,
|
||||
"pins": 0,
|
||||
"reads": 0
|
||||
},
|
||||
"duplicate-console.test.ts": {
|
||||
"cases": 5,
|
||||
"cases": 6,
|
||||
"pins": 0,
|
||||
"reads": 0
|
||||
},
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { buildMatrixCells, matrixCellOf, storeColumnsOf } from '../src/pages/tasks/duplicate-console-logic.ts'
|
||||
import type { DuplicateItem, DuplicateOccurrence } from '../src/pages/tasks/duplicate-model.ts'
|
||||
|
||||
/**
|
||||
* B60 撞款矩阵:预聚合的等价性与前后读数。
|
||||
*
|
||||
* 审计指的那件事是「每格多次全量 filter」——模板一格要付 cellCount ×2 + cellTitle(内部再
|
||||
* cellCount + cellCountryDots + 每站点一次 cellCountryCount),每次都是把该行 occurrences 整份
|
||||
* filter 一遍,而且**每格都新建一条文案字符串**。下面 `legacyCell` 就是页面原来那几行函数的
|
||||
* 原样搬运,当"前";与新一次算完的 `buildMatrixCells`(空格按列共用一份视图)对撞:
|
||||
* 先证明结果逐字相同(预聚合不是靠少算蒙过去的),再同尺量时间。
|
||||
*/
|
||||
function occ(asin: string, shopName: string, country: string): DuplicateOccurrence {
|
||||
return {
|
||||
asin,
|
||||
date: '2026-09-01',
|
||||
price: '',
|
||||
brand: 'B',
|
||||
shopName,
|
||||
groupName: '',
|
||||
countryCodes: [country],
|
||||
country,
|
||||
}
|
||||
}
|
||||
|
||||
const shopKey = (name: string): string => (name || '').trim().toLowerCase()
|
||||
|
||||
interface CellView {
|
||||
count: number
|
||||
dots: string[]
|
||||
title: string
|
||||
}
|
||||
|
||||
/** 原页面的逐格算法(一格扫整行 occurrences 若干次,并且每格造一条文案)。 */
|
||||
function legacyCellOccurrences(item: DuplicateItem, shop: string): DuplicateOccurrence[] {
|
||||
const key = shopKey(shop)
|
||||
return (item.occurrences || []).filter((entry) => shopKey(entry.shopName) === key)
|
||||
}
|
||||
|
||||
function legacyCell(item: DuplicateItem, shop: string): CellView {
|
||||
const count = legacyCellOccurrences(item, shop).length
|
||||
const codes = new Set<string>()
|
||||
for (const entry of legacyCellOccurrences(item, shop)) if (entry.country) codes.add(entry.country.toUpperCase())
|
||||
const dots = [...codes]
|
||||
const sites = dots.map((code) => `${code} ${legacyCellOccurrences(item, shop).filter((entry) => (entry.country || '').toUpperCase() === code).length}条`)
|
||||
return {
|
||||
count,
|
||||
dots,
|
||||
title: count ? `${shop} 在售 ${count} 条 · ${sites.join('、')}` : `${shop} 无此 ASIN`,
|
||||
}
|
||||
}
|
||||
|
||||
/** 页面现在的读法:一次取值;空格取该列那一份共用视图(不再造文案)。 */
|
||||
function fastCell(cells: ReturnType<typeof buildMatrixCells>, item: DuplicateItem, shop: string, blank: CellView): CellView {
|
||||
const cell = matrixCellOf(cells, item.asin, shop)
|
||||
if (!cell.count) return blank
|
||||
const sites = cell.sites.map((site) => `${site.code} ${site.count}条`)
|
||||
return {
|
||||
count: cell.count,
|
||||
dots: cell.sites.map((site) => site.code),
|
||||
title: sites.length ? `${shop} 在售 ${cell.count} 条 · ${sites.join('、')}` : `${shop} 在售 ${cell.count} 条`,
|
||||
}
|
||||
}
|
||||
|
||||
function fixtureItem(asin: string, shops: [string, string][]): DuplicateItem {
|
||||
const occurrences = shops.map(([shop, country]) => occ(asin, shop, country))
|
||||
return {
|
||||
asin,
|
||||
shopCount: new Set(occurrences.map((entry) => shopKey(entry.shopName))).size,
|
||||
recordCount: occurrences.length,
|
||||
occurrences,
|
||||
}
|
||||
}
|
||||
|
||||
function blankViews(columns: string[]): CellView[] {
|
||||
return columns.map((shop) => ({ count: 0, dots: [] as string[], title: `${shop} 无此 ASIN` }))
|
||||
}
|
||||
|
||||
/**
|
||||
* 200 列 × 50 行的矩阵夹具。`shopsPerRow` 决定密度:现实中一个撞款 ASIN 落在几家到几十家店,
|
||||
* 而逐格 filter 的代价正是按「行内 occurrences × 列数」乘出来的——密度越高旧算法越吃亏,
|
||||
* 所以两种密度都取读数,不挑对自己有利的那一档。
|
||||
*/
|
||||
function matrixFixture(columns: string[], shopsPerRow: number): DuplicateItem[] {
|
||||
return Array.from({ length: 50 }, (_, index) => {
|
||||
const pairs: [string, string][] = []
|
||||
for (let offset = 0; offset < shopsPerRow; offset++) {
|
||||
const shop = columns[(index * 7 + offset * 61) % columns.length]
|
||||
pairs.push([shop, 'UK'], [shop, 'DE'])
|
||||
}
|
||||
return fixtureItem(`B${String(index).padStart(4, '0')}`, pairs)
|
||||
})
|
||||
}
|
||||
|
||||
test('矩阵预聚合与逐格 filter 结果逐字相同', () => {
|
||||
const rows = [
|
||||
fixtureItem('A1', [['Shop a', 'UK'], ['Shop a', 'uk'], ['ShopB', ''], ['ShopB', 'DE']]),
|
||||
fixtureItem('A2', [['ShopC', 'FR']]),
|
||||
]
|
||||
const columns = storeColumnsOf(rows)
|
||||
const cells = buildMatrixCells(rows, columns)
|
||||
const blanks = blankViews(columns)
|
||||
columns.forEach((column, index) => {
|
||||
for (const item of rows) {
|
||||
assert.deepEqual(fastCell(cells, item, column, blanks[index]), legacyCell(item, column), `${item.asin}/${column}`)
|
||||
}
|
||||
})
|
||||
// 每行只给「本行真涉及」的列建格:A1 涉及 2 店(大小写/空格归一后同店)+ A2 涉及 1 店。
|
||||
assert.equal(cells.size, 3)
|
||||
})
|
||||
|
||||
test('列集或行集为空时不建任何格', () => {
|
||||
const rows = [fixtureItem('A1', [['ShopA', 'UK']])]
|
||||
assert.equal(buildMatrixCells(rows, []).size, 0)
|
||||
assert.equal(buildMatrixCells([], ['ShopA']).size, 0)
|
||||
})
|
||||
|
||||
/** 列窗口:只给本窗点名的列建格(120 列的夹具切 40 列窗口,格子数就按 40 乘)。 */
|
||||
test('列窗口切窗后每行最多铺满窗口宽度的格', () => {
|
||||
const window = 40
|
||||
const rows = Array.from({ length: 50 }, (_, index) =>
|
||||
fixtureItem(`A${index}`, Array.from({ length: window * 3 }, (_, shop) => [`Shop${shop}`, 'UK'])))
|
||||
const all = storeColumnsOf(rows)
|
||||
assert.equal(all.length, window * 3, '夹具本身就有 120 列(不设上限时的形状)')
|
||||
|
||||
const columns = all.slice(0, window)
|
||||
const cells = buildMatrixCells(rows, columns)
|
||||
assert.equal(columns.length, window, '本窗只铺 40 列')
|
||||
assert.equal(cells.size, rows.length * window, '窗口外的 80 列一格都不建')
|
||||
})
|
||||
|
||||
/**
|
||||
* B60 判据的读数:200 列 × 50 行,同一把尺前后各跑一遍(5 轮取最好一次——本机同时有别的路在跑,
|
||||
* 单次读数能被调度噪声放大好几倍)。
|
||||
*
|
||||
* 度量对象是「矩阵格集合的 JS 计算」,审计点名的就是这条。**浏览器首屏/交互耗时本机拿不到**
|
||||
* (没有真实店铺数据、也没有浏览器现场),按准出括注登记为现网复量项,不许拿这条当"首屏已实测"读。
|
||||
*/
|
||||
test('200列×50行:预聚合与按列切窗都必须快过逐格 filter', () => {
|
||||
const columns = Array.from({ length: 200 }, (_, index) => `Shop${index}`)
|
||||
const blanks = blankViews(columns)
|
||||
const windowColumns = columns.slice(0, 40)
|
||||
const windowBlanks = blanks.slice(0, 40)
|
||||
const best = (run: () => unknown): number => {
|
||||
let ms = Number.POSITIVE_INFINITY
|
||||
for (let attempt = 0; attempt < 5; attempt++) {
|
||||
const start = performance.now()
|
||||
run()
|
||||
ms = Math.min(ms, performance.now() - start)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
|
||||
const readings: string[] = []
|
||||
for (const shopsPerRow of [3, 40]) {
|
||||
const rows = matrixFixture(columns, shopsPerRow)
|
||||
const legacySweep = () => {
|
||||
const out: CellView[] = []
|
||||
for (const item of rows) for (const column of columns) out.push(legacyCell(item, column))
|
||||
return out
|
||||
}
|
||||
const precomputedSweep = (cols: string[], cellBlanks: CellView[]) => {
|
||||
const cells = buildMatrixCells(rows, cols)
|
||||
const out: CellView[] = []
|
||||
for (const item of rows) {
|
||||
cols.forEach((column, index) => out.push(fastCell(cells, item, column, cellBlanks[index])))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
assert.deepEqual(precomputedSweep(columns, blanks), legacySweep(), '前后必须同一份格子(快不是靠少算)')
|
||||
|
||||
const beforeMs = best(legacySweep)
|
||||
const precomputeMs = best(() => precomputedSweep(columns, blanks))
|
||||
const shippedMs = best(() => precomputedSweep(windowColumns, windowBlanks))
|
||||
readings.push(`每行${shopsPerRow}店:逐格filter=${beforeMs.toFixed(1)}ms → 预聚合=${precomputeMs.toFixed(1)}ms(${(beforeMs / precomputeMs).toFixed(1)}×) → 预聚合+切窗40列=${shippedMs.toFixed(1)}ms(${(beforeMs / shippedMs).toFixed(1)}×)`)
|
||||
assert.ok(precomputeMs < beforeMs, `预聚合没省下来(每行${shopsPerRow}店):${beforeMs.toFixed(1)}ms → ${precomputeMs.toFixed(1)}ms`)
|
||||
assert.ok(shippedMs * 2 < beforeMs, `切窗后仍不够快(每行${shopsPerRow}店):${beforeMs.toFixed(1)}ms → ${shippedMs.toFixed(1)}ms`)
|
||||
}
|
||||
console.log(`[B60 读数] 200列×50行 ${readings.join(' | ')}`)
|
||||
})
|
||||
@@ -2,8 +2,9 @@ import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { parseDuplicateConsole, parseLedgerPage, parseConsoleGroup, parseLedgerRow } from '../src/pages/tasks/duplicate-console-model.ts'
|
||||
import {
|
||||
buildMatrixCells,
|
||||
indexShopGroups,
|
||||
dupWithinGroup,
|
||||
matrixCellOf,
|
||||
storeColumnsOf,
|
||||
} from '../src/pages/tasks/duplicate-console-logic.ts'
|
||||
|
||||
@@ -49,6 +50,21 @@ test('test_dup_console_model_parses_overview_dup_and_groups', () => {
|
||||
assert.deepEqual(group, { name: 'GroupA', shopCount: 2, asinUnique: 4, recordCount: 6, dupCount: 2 })
|
||||
})
|
||||
|
||||
/** B60:console 多了行窗口三键;缺字段要退得回安全默认(page 至少 1,pageSize 缺省 0=调用方自持)。 */
|
||||
test('test_dup_console_model_parses_row_window', () => {
|
||||
const windowed = parseDuplicateConsole({
|
||||
success: true,
|
||||
data: { pending: false, dup: [], groups: [], total_dup: 2650, page: 3, page_size: 50 },
|
||||
})
|
||||
assert.equal(windowed.totalDup, 2650, 'total_dup 是该范围未分页总数,不是本页行数')
|
||||
assert.equal(windowed.page, 3)
|
||||
assert.equal(windowed.pageSize, 50)
|
||||
|
||||
const legacy = parseDuplicateConsole({ success: true, data: { pending: false, dup: [], groups: [] } })
|
||||
assert.equal(legacy.page, 1, '没有 page 字段时读成第一页,别让分页控件显示第 0 页')
|
||||
assert.equal(legacy.pageSize, 0)
|
||||
})
|
||||
|
||||
test('test_dup_console_parse_group_ignores_missing_name', () => {
|
||||
assert.equal(parseConsoleGroup({ shop_count: 1 }), null)
|
||||
assert.ok(parseConsoleGroup({ name: 'G', shop_count: 2 }))
|
||||
@@ -71,15 +87,9 @@ test('test_dup_console_group_derivation_restricts_to_members', () => {
|
||||
])
|
||||
assert.deepEqual(groups.members.GroupA, ['ShopA', 'ShopB'])
|
||||
assert.deepEqual(groups.shopGroupNames.ShopC, ['GroupC'])
|
||||
|
||||
const inGroupA = dupWithinGroup([dupA, dupE], groups.members.GroupA)
|
||||
assert.equal(inGroupA.length, 2)
|
||||
// E 组内只剩 ShopA/ShopB 两条记录。
|
||||
const e = inGroupA.find((item) => item.asin === 'E')
|
||||
assert.equal(e?.shopCount, 2)
|
||||
assert.equal(e?.recordCount, 2)
|
||||
// 单店成员组内不会命中(ShopD 不在数据里)。
|
||||
assert.deepEqual(dupWithinGroup([dupA, dupE], ['ShopD']), [])
|
||||
assert.deepEqual(storeColumnsOf([dupA, dupE], groups.members.GroupA), ['ShopA', 'ShopB'])
|
||||
// 「组内 ≥2 店才算撞款」的裁行只剩服务端一处正本(console 的 dup_group)——
|
||||
// 页面原先在客户端用 dupWithinGroup 再裁一遍,那是同一规则的第二个正本,B60 收掉它。
|
||||
})
|
||||
|
||||
test('test_dup_console_store_columns_order_and_restriction', () => {
|
||||
|
||||
Reference in New Issue
Block a user