收口(去重库): 五处比对与写入口按 company_id 认公司,不再跨公司去重

读侧(列表/导出)早已按公司收窄,但"去重"这个动作本身一直查全平台:
selectExistingDataValues 是 `WHERE data_value IN (...)`,一个租户条件都没有。
库里唯一键自 V145 起就是 uk_company_data_value(company_id, data_value)——
同值本来就允许归两家,是代码没跟上库的口径。

五处一起收口(第 5 处由编译器抓出,正是 V145 头注释 §1.2 点名的采集侧):
去重执行 ASIN 过滤 / 导入预检"已存在就跳过" / 手工新增与编辑的重名校验
(文案改「本公司已存在该数据」)/ 删除导入(超管不选分组时原先一次删掉全平台
同名行)/ 采集结果过滤(CollectDataBatchQuery 直连 mapper,改为经 dedupe 侧推导)。

超管代导入的归属分裂一并修掉:前端两个导入接口把公司 tab 发下去——原先
group_id 落别家的组、company_id 落超管自己那一家。公司身份一律在请求线程上由
DataReadScope.readCompanyIdOrOwn 解析后传入(导入与去重跑在虚拟线程,那时已无
请求上下文),service 侧 requireScopedCompanyId 只判空不兜底。

删两条零调用者的跨公司通道(selectAllDataValues/listComparableValues 全表读、
deleteFromExcel 两个同步重载)。反转一条反向钉:comparableValueLookupRemainsGlobal
原显式断言"比对不参与公司收窄"(多公司一期的半套遗留),现为 IsScopedToOneCompany。

三把尺子随之改动,均带出处:tsv 基准行搬家(三个标量双双不动)、前端发送口分母
17→18 组/21→22 处、CatchSilenceRatchet 重抛下限 387→386(随死代码离开树那处)。

验证:后端全量 4198 例 0 失败/0 错误/7 跳过;前端 1778 例全绿;变异自证
6/6 全部 KILLED,注入文件按 sha256 还原并复跑绿。
现网只读探针:misfiled=0、同值跨家=0 ⇒ 存量比对结果不变,行为改变只在将来
A 家导入 B 家已有 ASIN 那一刻;两口径差额 1,452 行(0.26%)全属公司 1、
全源于 10-05 账号硬删。
This commit is contained in:
2026-10-09 17:57:37 +08:00
parent 974d0c77d0
commit 5ccf3c896f
22 changed files with 393 additions and 187 deletions
@@ -98,6 +98,8 @@ const SEND_POINTS: ReadonlyArray<SendPoint> = [
{ menuKey: 'admin_dedupe_total_data', file: 'src/pages/asin/dedupe-total-api.ts', fn: 'fetchDedupeTotalList', line: 'if (params.companyId != null) query.company_id = params.companyId', window: 400, title: 'GET /dedupe-total-data 列表' },
{ menuKey: 'admin_dedupe_total_data', file: 'src/pages/asin/dedupe-total-api.ts', fn: 'fetchDedupeTotalGroups', line: 'http.get<unknown>(DEDUPE_GROUPS_ENDPOINT, { params: companyId != null ? { company_id: companyId } : {} })', window: 400, title: 'GET /shop-manages/groups 分组候选(与店铺管理同源,两页口径要对得上)' },
{ menuKey: 'admin_dedupe_total_data', file: 'src/pages/asin/dedupe-total-export.ts', fn: 'buildDedupeExportParams', line: 'if (companyId != null) params.company_id = String(companyId)', window: 800, title: 'GET /dedupe-total-data/export 导出' },
{ menuKey: 'admin_dedupe_total_data', file: 'src/pages/asin/dedupe-import-api.ts', fn: 'startDedupeImport', line: "if (companyId != null) form.append('company_id', String(companyId))", window: 400, title: 'POST /dedupe-total-data/import 新增导入(写侧归属,不发就落进操作者自己那一家)' },
{ menuKey: 'admin_dedupe_total_data', file: 'src/pages/asin/dedupe-import-api.ts', fn: 'startDedupeDeleteImport', line: "if (companyId != null) form.append('company_id', String(companyId))", window: 900, title: 'POST /dedupe-total-data/delete-import 删除导入(不发就会按别家的值删错行)' },
{ menuKey: 'admin_query_asin', file: 'src/pages/asin/query-asin-api.ts', fn: 'fetchQueryAsinList', line: 'if (params.companyId != null) query.company_id = params.companyId', window: 400, title: 'GET /query-asins 列表' },
{ menuKey: 'admin_query_asin', file: 'src/pages/asin/query-asin-export.ts', fn: 'buildQueryAsinExportParams', line: 'if (companyId != null) params.company_id = String(companyId)', window: 700, title: 'GET /query-asins/export 导出' },
{ menuKey: 'admin_skip_price_asin', file: 'src/pages/asin/skip-price-api.ts', fn: 'fetchSkipPriceList', line: 'if (params.companyId != null) query.company_id = params.companyId', window: 400, title: 'GET /skip-price-asins 列表(最低价 ASIN)' },
@@ -237,6 +239,13 @@ const COMPANY_ID_SOURCE_PINS: Readonly<Record<string, readonly CompanyIdPin[]>>
/** 严格判据的分母由本轮实扫得出(修完不许恒绿也不许恒红):求值了几条 shape、其中几条通过。 */
let strictPinsEvaluated = 0
/**
* 「company_id 真被下传」的形状。原先只认 `company_id:` / `company_id =` 两形——那是按
* 「一律走查询参数」写的。去重库的导入与删除导入走 multipart body(form.append),
* 同一件事换了载体就被判成没接线;这里把那一形补进来,取值口仍按登记表的 shape 逐条严判。
*/
const COMPANY_ID_WIRED = /company_id\s*[:=]|form\.append\(\s*['"]company_id['"]/
let strictPinsPassed = 0
test('正向:声明 companyScoped 的页,其 api 文件必须真的带 company_id,页面组件必须 watch activeId', () => {
@@ -254,8 +263,8 @@ test('正向:声明 companyScoped 的页,其 api 文件必须真的带 company
// 旧式 /company_id|companyId/ 接近恒真,Task 8-12 只要写一行 `const companyId = null`
// 或一句「// 由 companyId 决定」就能把这页判成已接线,而实际什么都没下传(约束 6:注释不算)。
// 读之前先 stripComments,与反向那半支同口径——说明注释里的 company_id 不是接线。
if (!/company_id\s*[:=]/.test(stripComments(read(file)))) {
gaps.push(`${file} 没把 company_id 当成查询参数下传`)
if (!COMPANY_ID_WIRED.test(stripComments(read(file)))) {
gaps.push(`${file} 没把 company_id 下传(查询参数或 multipart 字段都算,裸 token 不算)`)
}
}
// 取值口登记(复评 I-2):光"把 company_id 塞进查询对象"不够,右半边必须取自**本函数自己的入参**。
@@ -265,7 +274,7 @@ test('正向:声明 companyScoped 的页,其 api 文件必须真的带 company
continue
}
const src = stripComments(read(pin.file))
const wired = /company_id\s*[:=]/.test(src)
const wired = COMPANY_ID_WIRED.test(src)
if (pin.shape === null) {
// 没登记取值口却已经下传了参数 = 这一页的取值口径没人看守(洞就是这么留下的)。
if (wired) gaps.push(`${pin.file} 已经把 company_id 当下传参数了,登记表里 shape 却还是 null —— 把它换成"company_id 右侧 = 本函数入参"的正则`)
@@ -357,8 +366,8 @@ test('正向:声明 companyScoped 的页,其 api 文件必须真的带 company
if (hit) hit.pinned += 1
else grouped.set(key, { file: p.file, line: p.line, pinned: 1 })
}
assert.equal(grouped.size, 17,
`发送口表按 (文件, 整行) 应聚成 17 组(21 处发送口),现在却有 ${grouped.size} 组 —— 表被改形状了,对平判据失去分母`)
assert.equal(grouped.size, 18,
`发送口表按 (文件, 整行) 应聚成 18 组(22 处发送口),现在却有 ${grouped.size} 组 —— 表被改形状了,对平判据失去分母`)
for (const g of grouped.values()) {
const actual = occurrences(stripComments(read(g.file)), g.line)
assert.equal(g.pinned, actual,