8659a7ed2b
新增「平台店铺表」资产层: 淘宝比价拿到 shopId 后, pricebot server→server 把跨平台 店铺身份(各平台 id/名 + 地理 + 来源)落库, 作为未来"我见过这家店→跳过重搜/匹配"的源头。 与 price_observation(价格事实)平行、独立。 - models/store_mapping.py: store_mapping 表 22 列 —— 跨平台身份(id/name_taobao/meituan/jd) + 地理(city/geohash/lng/lat/taobao_address) + 溯源(source_platform/trace_id/device/user) + 淘宝原料(share_url/resolved_url/deeplink) + attrs(JSONB) + created_at。 - schemas/store_mapping.py + repositories/store_mapping.py: append-only, trace_id 幂等 (pricebot 重试/replay 不重复写; 并发 IntegrityError 兜底返已存在行), 跨方言安全。 - api/internal/store.py: POST /internal/store-mapping(复用 price.py 共享密钥 X-Internal-Secret 校验)。 - 注册 model(__init__) + router(main.py); 迁移 store_mapping_table 接现 head coin_txn_task_ref_uq。 验证: alembic 单 head + 零模型/迁移漂移; TestClient 全链(无密钥401/有密钥inserted=1/幂等inserted=0/错密钥401)。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Reviewed-on: #48
63 lines
1.9 KiB
Python
63 lines
1.9 KiB
Python
"""平台店铺映射内部上报的收发模型。
|
|
|
|
pricebot 在淘宝比价拿到 shopId 后 server→server POST 一行映射。所有字段可空(按比价
|
|
角色稀疏填充),server 端只校验共享密钥 + 幂等(trace_id)落库。
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class StoreMappingIn(BaseModel):
|
|
"""一次比价的跨平台店铺映射上报体(一行)。"""
|
|
|
|
trace_id: str
|
|
business_type: str = "food"
|
|
source_platform: str | None = None
|
|
|
|
# 跨平台身份(按角色稀疏填充)
|
|
id_taobao: str | None = None
|
|
name_taobao: str | None = None
|
|
id_meituan: str | None = None
|
|
name_meituan: str | None = None
|
|
id_jd: str | None = None
|
|
name_jd: str | None = None
|
|
|
|
# 地理
|
|
city: str | None = None
|
|
geohash: str | None = None
|
|
lng: float | None = None
|
|
lat: float | None = None
|
|
taobao_address: str | None = None
|
|
|
|
# 溯源
|
|
source_device_id: str | None = None
|
|
source_user_id: int | None = None
|
|
|
|
# 淘宝原料(可复跳 / 可重解析 / 调试)
|
|
taobao_share_url: str | None = None
|
|
taobao_resolved_url: str | None = None
|
|
taobao_deeplink: str | None = None
|
|
|
|
# 美团原料(poi_id_str 非稳定主键, 单列存; 见 model 注释)
|
|
meituan_poi_id_str: str | None = None
|
|
meituan_share_url: str | None = None
|
|
meituan_resolved_url: str | None = None
|
|
meituan_deeplink: str | None = None
|
|
|
|
# 京东原料(venderId 单列存, storeId 进 id_jd; 见 model 注释)
|
|
jd_vender_id: str | None = None
|
|
jd_share_url: str | None = None
|
|
jd_resolved_url: str | None = None
|
|
jd_deeplink: str | None = None
|
|
|
|
attrs: dict | None = None
|
|
|
|
|
|
class StoreMappingOut(BaseModel):
|
|
"""上报结果。inserted=1 为新建该 trace 行,0 为合并进已存在行(填空,不覆盖);
|
|
row_id 为该 trace 对应行 id。"""
|
|
|
|
inserted: int
|
|
row_id: int | None = None
|