feat(phase-1): 京东数据库数据底座——V193~V196 迁移 + jd 模块实体/Mapper + 模块注册与 LOCAL 通道默认 + aiimage.jd 配置

This commit is contained in:
2026-11-14 03:08:32 +08:00
parent 334ed2cadd
commit a429191edd
24 changed files with 683 additions and 39 deletions
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nanri.aiimage.modules.jd.mapper.JdProductImageMapper">
<!-- 京东商品图片登记(V194,v1.4):SQL 全部落 XML(铁律 1)。
登记链唯一写入口:按唯一键 uk_product_image(product_id,image_type,sha256) upsert——
同商品同内容只留一行(AC-5 图片幂等,重复登记刷新排序与属性名),不同内容全保留。 -->
<!-- 多值批量登记(Phase 4 落 JdProductImageIngestService):调用方先按
statObject 对撞「对象存在 + 字节数一致」再落行,对不上进 mismatched 不落本表。
刻意不写 product_id/image_type/sha256 的 UPDATE 段(唯一键三元组自身不随更新漂移);
created_at 列有 DB 默认值且 UPDATE 段不刷——登记时刻取首次登记。 -->
<insert id="upsertBatch">
INSERT INTO biz_jd_product_image
(product_id, company_id, image_type, attr_name, sort_no,
object_key, url, byte_size, sha256, width, height)
VALUES
<foreach collection="rows" item="row" separator=",">
(#{row.productId}, #{row.companyId}, #{row.imageType}, #{row.attrName}, #{row.sortNo},
#{row.objectKey}, #{row.url}, #{row.byteSize}, #{row.sha256}, #{row.width}, #{row.height})
</foreach>
ON DUPLICATE KEY UPDATE
company_id = VALUES(company_id),
attr_name = VALUES(attr_name),
sort_no = VALUES(sort_no),
object_key = VALUES(object_key),
url = VALUES(url),
byte_size = VALUES(byte_size),
width = VALUES(width),
height = VALUES(height)
</insert>
</mapper>
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nanri.aiimage.modules.jd.mapper.JdProductMapper">
<!-- 京东店铺商品(V193,v1.4):SQL 全部落 XML(铁律 1)。
覆盖最新唯一写入口:按唯一键 uk_company_shop_code(company_id,shop_id,product_code)
upsert——同一商品二次采集刷新那条(synced_at 刷新),不同商品全保留,行数不增
(R6/AC-5)。后管只读页的分页/筛选 SQL(Phase 5)落同份 XML。 -->
<!-- 同步链唯一写入口(Phase 2 落 JdResultIngestService):多值批量 upsert,
AppearancePatentCleanItemMapper#upsertBatch 同形。刻意不写 company_id/shop_id/
product_code 的 UPDATE 段(唯一键三元组自身不随更新漂移);
synced_at 在 UPDATE 段显式刷 CURRENT_TIMESTAMP(INSERT 路径走列默认值,
显式传 null 会覆盖掉默认值,故两段口径分开)。
⚠ upsert-only:回传读出 0 行=什么都不写,不得 delete-then-insert 覆盖式重写
(重投递载荷读不准时会抹掉存量,AppearancePatentCleanItemMapper 2026-11-11 实录)。 -->
<insert id="upsertBatch">
INSERT INTO biz_jd_product
(company_id, user_id, task_id, shop_id, shop_name, product_code, sku_id,
title, brand, brand_id, category_path, price_min, price_max, stock_total,
sale_status, list_tab, jd_created_at, jd_updated_at,
main_image_url, detail_url, attr_json, attr_count, image_count, collect_batch_id)
VALUES
<foreach collection="rows" item="row" separator=",">
(#{row.companyId}, #{row.userId}, #{row.taskId}, #{row.shopId}, #{row.shopName},
#{row.productCode}, #{row.skuId}, #{row.title}, #{row.brand}, #{row.brandId},
#{row.categoryPath}, #{row.priceMin}, #{row.priceMax}, #{row.stockTotal},
#{row.saleStatus}, #{row.listTab}, #{row.jdCreatedAt}, #{row.jdUpdatedAt},
#{row.mainImageUrl}, #{row.detailUrl}, #{row.attrJson}, #{row.attrCount},
#{row.imageCount}, #{row.collectBatchId})
</foreach>
ON DUPLICATE KEY UPDATE
user_id = VALUES(user_id),
task_id = VALUES(task_id),
shop_name = VALUES(shop_name),
sku_id = VALUES(sku_id),
title = VALUES(title),
brand = VALUES(brand),
brand_id = VALUES(brand_id),
category_path = VALUES(category_path),
price_min = VALUES(price_min),
price_max = VALUES(price_max),
stock_total = VALUES(stock_total),
sale_status = VALUES(sale_status),
list_tab = VALUES(list_tab),
jd_created_at = VALUES(jd_created_at),
jd_updated_at = VALUES(jd_updated_at),
main_image_url = VALUES(main_image_url),
detail_url = VALUES(detail_url),
attr_json = VALUES(attr_json),
attr_count = VALUES(attr_count),
image_count = VALUES(image_count),
collect_batch_id = VALUES(collect_batch_id),
synced_at = CURRENT_TIMESTAMP
</insert>
</mapper>