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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user