99 lines
5.7 KiB
XML
99 lines
5.7 KiB
XML
<?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/
|
||
product_code 的 UPDATE 段(唯一键三元组自身不随更新漂移);
|
||
synced_at 在 UPDATE 段显式刷 CURRENT_TIMESTAMP(INSERT 路径走列默认值,
|
||
显式传 null 会覆盖掉默认值,故两段口径分开)。
|
||
⚠ upsert-only:回传读出 0 行=什么都不写,不得 delete-then-insert 覆盖式重写
|
||
(重投递载荷读不准时会抹掉存量,AppearancePatentCleanItemMapper 2026-11-11 实录)。
|
||
⚠ UPDATE 段不写 image_count / main_image_url(P1-1):buildRow 恒 0/恒 null,
|
||
写进 UPDATE 会把登记链 refreshProductImageCount 刷的真实计数抹回 0
|
||
(后管「图片数」恒 0);image_count 只由登记侧按表实数刷,main_image_url
|
||
是 P2 死列(BACKLOG B98-01)不随更新。 -->
|
||
<insert id="upsertBatch">
|
||
INSERT INTO biz_jd_product
|
||
(company_id, user_id, task_id, shop_id, shop_name, product_code, sku_id, item_num, sku_count,
|
||
health_score, title, brand, brand_id, category_path, price_min, price_max, stock_total,
|
||
sale_status, list_tab, jd_created_at, jd_online_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.itemNum}, #{row.skuCount},
|
||
#{row.healthScore}, #{row.title}, #{row.brand}, #{row.brandId},
|
||
#{row.categoryPath}, #{row.priceMin}, #{row.priceMax}, #{row.stockTotal},
|
||
#{row.saleStatus}, #{row.listTab}, #{row.jdCreatedAt}, #{row.jdOnlineAt}, #{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),
|
||
item_num = VALUES(item_num),
|
||
sku_count = VALUES(sku_count),
|
||
health_score = VALUES(health_score),
|
||
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_online_at = VALUES(jd_online_at),
|
||
jd_updated_at = VALUES(jd_updated_at),
|
||
detail_url = VALUES(detail_url),
|
||
attr_json = VALUES(attr_json),
|
||
attr_count = VALUES(attr_count),
|
||
collect_batch_id = VALUES(collect_batch_id),
|
||
synced_at = CURRENT_TIMESTAMP
|
||
</insert>
|
||
|
||
<!-- 后管只读页(Phase 5,v1.4)过滤面:公司(物化列 eq)、店铺名/商品编码/标题关键词
|
||
(contains LIKE)、商品状态 eq、分组 eq、同步起止(datetime 闭区间)。
|
||
全部走 #{} 占位符;offset/limit 必须是服务侧钳制后的值(铁律 15),mapper 不做第二次换算。 -->
|
||
<sql id="productConds">
|
||
<if test="companyId != null and companyId > 0">AND p.company_id = #{companyId}</if>
|
||
<if test="shopName != null and shopName != ''">AND p.shop_name LIKE CONCAT('%', #{shopName}, '%')</if>
|
||
<if test="productCode != null and productCode != ''">AND p.product_code LIKE CONCAT('%', #{productCode}, '%')</if>
|
||
<if test="titleKeyword != null and titleKeyword != ''">AND p.title LIKE CONCAT('%', #{titleKeyword}, '%')</if>
|
||
<if test="saleStatus != null and saleStatus != ''">AND p.sale_status = #{saleStatus}</if>
|
||
<if test="groupId != null and groupId > 0">AND p.group_id = #{groupId}</if>
|
||
<if test="syncedFrom != null">AND p.synced_at >= #{syncedFrom}</if>
|
||
<if test="syncedTo != null">AND p.synced_at <= #{syncedTo}</if>
|
||
</sql>
|
||
|
||
<!-- 只读页总数(与 selectProductPage 同一过滤面)。 -->
|
||
<select id="countProducts" resultType="long">
|
||
SELECT COUNT(*)
|
||
FROM biz_jd_product p
|
||
WHERE 1=1 <include refid="productConds"/>
|
||
</select>
|
||
|
||
<!-- 只读页分页查询(synced_at 倒序)。
|
||
group_name 不在此联表:读侧按行集 group_id 批量取分组名补齐(一次查询,无逐行查询)。 -->
|
||
<select id="selectProductPage" resultType="com.nanri.aiimage.modules.jd.model.entity.JdProductEntity">
|
||
SELECT p.id, p.company_id, p.user_id, p.task_id, p.shop_id, p.shop_name, p.product_code, p.sku_id,
|
||
p.item_num, p.sku_count, p.health_score,
|
||
p.title, p.brand, p.brand_id, p.category_path, p.price_min, p.price_max, p.stock_total,
|
||
p.sale_status, p.list_tab, p.jd_created_at, p.jd_online_at, p.jd_updated_at,
|
||
p.main_image_url, p.detail_url,
|
||
p.attr_json, p.attr_count, p.image_count, p.group_id, p.collect_batch_id, p.synced_at
|
||
FROM biz_jd_product p
|
||
WHERE 1=1 <include refid="productConds"/>
|
||
ORDER BY p.synced_at DESC, p.id DESC
|
||
LIMIT #{offset}, #{limit}
|
||
</select>
|
||
</mapper>
|