feat: scope articles by brand

This commit is contained in:
2026-05-20 15:37:25 +08:00
parent 5fb9d0b0dd
commit dd082e2ed1
72 changed files with 3213 additions and 432 deletions
+7 -6
View File
@@ -236,7 +236,7 @@ func seedBusinessData(ctx context.Context, pool *pgxpool.Pool, membershipCfg con
return nil, err
}
state.ArticleID, err = ensureArticle(ctx, tx, state.TenantID)
state.ArticleID, err = ensureArticle(ctx, tx, state.TenantID, state.BrandID)
if err != nil {
return nil, err
}
@@ -563,17 +563,18 @@ func ensureCompetitor(ctx context.Context, tx pgx.Tx, tenantID, brandID int64) e
return wrapSeedErr("insert competitor", err)
}
func ensureArticle(ctx context.Context, tx pgx.Tx, tenantID int64) (int64, error) {
func ensureArticle(ctx context.Context, tx pgx.Tx, tenantID, brandID int64) (int64, error) {
var articleID int64
err := tx.QueryRow(ctx, `
SELECT a.id
FROM articles a
JOIN article_versions av ON av.id = a.current_version_id
WHERE a.tenant_id = $1
AND a.brand_id = $2
AND av.title = '北京口腔医院全面测评'
AND a.deleted_at IS NULL
LIMIT 1
`, tenantID).Scan(&articleID)
`, tenantID, brandID).Scan(&articleID)
if err == nil {
return articleID, nil
}
@@ -582,10 +583,10 @@ func ensureArticle(ctx context.Context, tx pgx.Tx, tenantID int64) (int64, error
}
err = tx.QueryRow(ctx, `
INSERT INTO articles (tenant_id, source_type, generate_status, publish_status)
VALUES ($1, 'free_create', 'completed', 'published')
INSERT INTO articles (tenant_id, brand_id, source_type, generate_status, publish_status)
VALUES ($1, $2, 'free_create', 'completed', 'published')
RETURNING id
`, tenantID).Scan(&articleID)
`, tenantID, brandID).Scan(&articleID)
if err != nil {
return 0, wrapSeedErr("insert article", err)
}