feat: 支持蝦皮批量创建 PDD 采集任务 (#185)
This commit is contained in:
@@ -301,6 +301,37 @@ func GetShopeeProductByGoodsID(q Execer, goodsID string) (*model.ShopeeProduct,
|
||||
return &p, nil
|
||||
}
|
||||
|
||||
// ListShopeePddLinksByGoodsIDs 批量读取蝦皮商品当前关联的 PDD 商品 ID。
|
||||
// 返回结果只包含仍存在的蝦皮商品;值为空表示商品存在但尚未关联 PDD。
|
||||
func ListShopeePddLinksByGoodsIDs(q Execer, goodsIDs []string) (map[string]string, error) {
|
||||
links := make(map[string]string, len(goodsIDs))
|
||||
if len(goodsIDs) == 0 {
|
||||
return links, nil
|
||||
}
|
||||
placeholders := strings.TrimSuffix(strings.Repeat("?,", len(goodsIDs)), ",")
|
||||
args := make([]any, len(goodsIDs))
|
||||
for i, goodsID := range goodsIDs {
|
||||
args[i] = goodsID
|
||||
}
|
||||
rows, err := q.Query(`SELECT goods_id, COALESCE(pdd_goods_id, '')
|
||||
FROM shopee_products WHERE goods_id IN (`+placeholders+`)`, args...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("批量查询蝦皮商品 PDD 关联失败: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var shopeeGoodsID, pddGoodsID string
|
||||
if err := rows.Scan(&shopeeGoodsID, &pddGoodsID); err != nil {
|
||||
return nil, fmt.Errorf("读取蝦皮商品 PDD 关联失败: %w", err)
|
||||
}
|
||||
links[shopeeGoodsID] = pddGoodsID
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, fmt.Errorf("遍历蝦皮商品 PDD 关联失败: %w", err)
|
||||
}
|
||||
return links, nil
|
||||
}
|
||||
|
||||
// UpdateShopeePddLink 更新蝦皮商品当前关联的 PDD 商品。
|
||||
// 调用方必须先在同一事务里保证 PDD 商品存在,避免留下悬空关联。
|
||||
func UpdateShopeePddLink(q Execer, shopeeGoodsID, pddGoodsID, pddURL string) error {
|
||||
|
||||
Reference in New Issue
Block a user