feat(jd): 京东数据库货号系统生成——行号即货号(2026-11-15 用户口径「系统自行生成货号,不用之前的货号;从 1 开始递增或随机数(唯一)」):新落库行 item_num 在回传落库后由 reassignItemNums 刷成行号(CONVERT(id, CHAR)——全局唯一、从 1 递增、行不变货号就不变,零并发竞争);upsertBatch 的 UPDATE 段摘掉 item_num 覆盖(重爬命中已有行不得把系统货号刷回京东原值,绊线钉住);锁定行(manual_locked=1)不刷——人工编辑过的货号优先;京东原货号仍在 attr_json 属性区留档溯源。存量行随下一次同店铺重爬刷成行号(item_num != id 命中);如需立即生效可对存量跑一次同款 UPDATE(发版窗口决定)。判据:SyncServiceTest +3(落库后刷写被调/整批被保护不刷/UPDATE 段不覆盖+刷写排除锁定行的 XML 绊线);SqlLayeringConventionTest 账本 162→163 逐笔记名。同笔修存量红:CompanyIdParamGoesThroughReadScopeTest 的 ProductCategory 子串锚剥除 JdProductCategoryVo 字样(京东商品库自己的类目下拉 VO 与全平台共享表无关,子串撞车把整个 AdminJdProductController 误拖进消费者清单;剥字样非整行排除——同行真引用 ProductCategoryEntity 照样命中,护栏意图不削弱)。后端整量 5,610 例 0 失败全绿;编辑抽屉货号 label 注明「系统生成=行号,可改」
This commit is contained in:
@@ -120,7 +120,11 @@ class SqlLayeringConventionTest {
|
||||
// 与 V198 迁移同窗、商品行 upsert 之后登记),全部新写,非迁移语句。
|
||||
// 160 → 161:2026-11-15 类目筛选下拉在 JdProductMapper 落 1 条只读 select
|
||||
//(selectProductCategories,DISTINCT category_path +行数),全部新写,非迁移语句。
|
||||
private static final int XML_STATEMENT_TOTAL = 162;
|
||||
// 162 → 163:2026-11-15 货号系统生成在 JdProductMapper 落 1 条写侧 update
|
||||
//(reassignItemNums,行号即货号 item_num = CONVERT(id, CHAR),按本任务刷、锁定行排除、
|
||||
// 幂等——已等于行号的行不重复写),全部新写,非迁移语句;同笔 upsertBatch 的 UPDATE 段
|
||||
// 摘掉 item_num 覆盖(语句数不变)。
|
||||
private static final int XML_STATEMENT_TOTAL = 163;
|
||||
|
||||
/**
|
||||
* wrapper 里夹带函数级 SQL 的现状("这不是简单单表"的证据),文件名 → 条数:
|
||||
|
||||
+14
-2
@@ -1181,8 +1181,7 @@ class CompanyIdParamGoesThroughReadScopeTest {
|
||||
for (Path file : files) {
|
||||
String rel = relativeKey(file);
|
||||
if (SHARED_TABLES_MUST_STAY_UNSCOPED.stream().anyMatch(rel::startsWith)) continue;
|
||||
if (executableLines(read(file)).stream()
|
||||
.anyMatch(line -> SHARED_TABLE_TYPE_ANCHORS.stream().anyMatch(line::contains))) {
|
||||
if (executableLines(read(file)).stream().anyMatch(CompanyIdParamGoesThroughReadScopeTest::hitsSharedTableAnchor)) {
|
||||
consumers.add(rel);
|
||||
}
|
||||
}
|
||||
@@ -1190,6 +1189,19 @@ class CompanyIdParamGoesThroughReadScopeTest {
|
||||
return consumers;
|
||||
}
|
||||
|
||||
/**
|
||||
* 锚命中判定:先剥掉 {@code JdProductCategoryVo} 字样再比子串。锚 {@code ProductCategory}
|
||||
* 是子串匹配,而京东商品库自己的类目下拉 VO(biz_jd_product.category_path 聚合统计,
|
||||
* 与全平台共享的商品类目表毫无关系)名字里含这个子串——2026-11-15 实录:它把整个
|
||||
* {@code AdminJdProductController} 误拖进「共享表消费者」清单,controller 里正常按公司
|
||||
* 隔离取数的 company_id 行全被判违规。剥字样而非整行排除:同一行真引用
|
||||
* {@code ProductCategoryEntity} 时照样命中,护栏意图不削弱。
|
||||
*/
|
||||
private static boolean hitsSharedTableAnchor(String line) {
|
||||
String stripped = line.replace("JdProductCategoryVo", "");
|
||||
return SHARED_TABLE_TYPE_ANCHORS.stream().anyMatch(stripped::contains);
|
||||
}
|
||||
|
||||
/**
|
||||
* 断言 C 的探针驱动器:先确认这段样本真被切成"1 支收公司 id 参数、体内写了 readScope(" 的 handler,
|
||||
* 再跑 {@link Block#scopeCatchFailure()}。切不出 handler / 不认公司参数 / 没有 readScope( 这三种
|
||||
|
||||
+47
-1
@@ -216,7 +216,7 @@ class JdProductSyncServiceTest {
|
||||
assertThat(first.getJdOnlineAt()).as("上架时间与创建时间不是同一个值(京麦后台两列)")
|
||||
.isEqualTo(LocalDateTime.of(2026, 11, 12, 15, 3, 37));
|
||||
assertThat(first.getJdUpdatedAt()).isEqualTo(LocalDateTime.of(2026, 11, 13, 14, 6, 7));
|
||||
assertThat(first.getItemNum()).as("货号(京麦列表列,≠ skuId)").isEqualTo("956597306407");
|
||||
assertThat(first.getItemNum()).as("货号:回传面暂存京麦原值,落库后由 reassignItemNums 刷成行号(系统生成)").isEqualTo("956597306407");
|
||||
assertThat(first.getSkuCount()).isEqualTo(12);
|
||||
assertThat(first.getHealthScore()).isEqualTo(81);
|
||||
assertThat(first.getAttrCount()).as("detail 键数进 attr_count").isEqualTo(2);
|
||||
@@ -225,6 +225,52 @@ class JdProductSyncServiceTest {
|
||||
assertThat(first.getImageCount()).isZero().as("Phase 2 图片只记 tempKey 待位");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 落库后货号刷写为系统生成的行号() {
|
||||
// 2026-11-15 用户口径「系统自行生成货号,不用之前的货号;从 1 开始递增(唯一)」:
|
||||
// 行号即货号——落库后按本任务刷一次(幂等,锁定行不动)。
|
||||
stubHappyPath();
|
||||
|
||||
service.submitChunk(TASK_ID, chunk(item("10036442942137", "艺考形体服女")), true);
|
||||
|
||||
verify(jdProductMapper).reassignItemNums(COMPANY_ID, TASK_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
void 整批被保护不落库时不刷货号() {
|
||||
stubHappyPath();
|
||||
// 保护集:唯一一行命中锁定(后管编辑过)⇒ 本批零落库 ⇒ 货号刷写也不该发生。
|
||||
JdProductEntity locked = new JdProductEntity();
|
||||
locked.setShopId("shop-001");
|
||||
locked.setProductCode("10036442942137");
|
||||
when(jdProductMapper.selectList(any())).thenReturn(List.of(locked));
|
||||
when(jdProductIgnoreMapper.selectList(any())).thenReturn(List.of());
|
||||
|
||||
JdIngestChunkVo vo = service.submitChunk(TASK_ID,
|
||||
chunk(item("10036442942137", "艺考形体服女")), true);
|
||||
|
||||
assertThat(vo.getUpserted()).isZero();
|
||||
verify(jdProductMapper, never()).upsertBatch(anyList());
|
||||
verify(jdProductMapper, never()).reassignItemNums(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void 货号不随重爬覆盖_系统生成为行号_绊线() throws Exception {
|
||||
// 货号=行号(reassignItemNums 落库后刷写)的三个 SQL 侧前提,改回即红:
|
||||
// ① upsertBatch 的 UPDATE 段不得覆盖 item_num(否则重爬把系统货号刷回京东原值);
|
||||
// ② 刷写语句必须按行号 SET 且排除锁定行;③ 刷写必须限定本任务(不碰历史行)。
|
||||
String xml = Files.readString(Path.of("src/main/resources/mapper/jd/JdProductMapper.xml"));
|
||||
String upsert = xml.substring(xml.indexOf("upsertBatch"), xml.indexOf("reassignItemNums"));
|
||||
assertThat(upsert)
|
||||
.as("货号不进 upsertBatch 的 UPDATE 段(2026-11-15 用户口径:系统生成货号,重爬不得刷回京东原值)")
|
||||
.doesNotContain("item_num = VALUES(item_num)");
|
||||
String reassign = xml.substring(xml.indexOf("reassignItemNums"));
|
||||
assertThat(reassign)
|
||||
.contains("item_num = CONVERT(id, CHAR)")
|
||||
.contains("manual_locked = 0")
|
||||
.contains("task_id = #{taskId}");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 同一批两次提交行数不增且无delete() {
|
||||
stubHappyPath();
|
||||
|
||||
Reference in New Issue
Block a user