Your Name e4959d584f feat: 完善代理商端业务逻辑与前后端框架
主要更新:
- 更新代理商端文档,明确项目由品牌方分配流程
- 新增Brief配置详情页(已配置)设计稿
- 完善工作台紧急待办中品牌新任务功能
- 整理Pencil设计文件中代理商端页面顺序
- 新增后端FastAPI框架及核心API
- 新增前端Next.js页面和组件库
- 添加.gitignore排除构建和缓存文件

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 19:27:31 +08:00

218 lines
11 KiB
Python

"""初始表结构
Revision ID: 001
Revises:
Create Date: 2024-01-15
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = '001'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# 创建枚举类型
platform_enum = postgresql.ENUM(
'douyin', 'xiaohongshu', 'bilibili', 'kuaishou',
name='platform_enum'
)
platform_enum.create(op.get_bind(), checkfirst=True)
task_status_enum = postgresql.ENUM(
'pending', 'processing', 'completed', 'failed', 'approved', 'rejected',
name='task_status_enum'
)
task_status_enum.create(op.get_bind(), checkfirst=True)
risk_target_type_enum = postgresql.ENUM(
'influencer', 'order', 'content',
name='risk_target_type_enum'
)
risk_target_type_enum.create(op.get_bind(), checkfirst=True)
risk_exception_status_enum = postgresql.ENUM(
'pending', 'approved', 'rejected', 'expired', 'revoked',
name='risk_exception_status_enum'
)
risk_exception_status_enum.create(op.get_bind(), checkfirst=True)
# 租户表
op.create_table(
'tenants',
sa.Column('id', sa.String(64), primary_key=True),
sa.Column('name', sa.String(255), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=False, default=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), nullable=False),
)
# AI 配置表
op.create_table(
'ai_configs',
sa.Column('id', sa.Integer(), primary_key=True, autoincrement=True),
sa.Column('tenant_id', sa.String(64), sa.ForeignKey('tenants.id', ondelete='CASCADE'), unique=True, nullable=False),
sa.Column('provider', sa.String(50), nullable=False),
sa.Column('base_url', sa.String(500), nullable=False),
sa.Column('api_key_encrypted', sa.Text(), nullable=False),
sa.Column('models', postgresql.JSONB(), nullable=False),
sa.Column('temperature', sa.Float(), nullable=False, default=0.7),
sa.Column('max_tokens', sa.Integer(), nullable=False, default=2000),
sa.Column('available_models', postgresql.JSONB(), nullable=True),
sa.Column('last_test_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('last_test_result', postgresql.JSONB(), nullable=True),
sa.Column('is_configured', sa.Boolean(), nullable=False, default=False),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), nullable=False),
)
op.create_index('ix_ai_configs_tenant_id', 'ai_configs', ['tenant_id'])
# 审核任务表
op.create_table(
'review_tasks',
sa.Column('id', sa.String(64), primary_key=True),
sa.Column('tenant_id', sa.String(64), sa.ForeignKey('tenants.id', ondelete='CASCADE'), nullable=False),
sa.Column('video_url', sa.String(2048), nullable=False),
sa.Column('platform', platform_enum, nullable=False),
sa.Column('brand_id', sa.String(64), nullable=False),
sa.Column('creator_id', sa.String(64), nullable=False),
sa.Column('status', task_status_enum, nullable=False, default='pending'),
sa.Column('progress', sa.Integer(), nullable=False, default=0),
sa.Column('current_step', sa.String(100), nullable=False, default='等待处理'),
sa.Column('score', sa.Integer(), nullable=True),
sa.Column('summary', sa.Text(), nullable=True),
sa.Column('violations', postgresql.JSONB(), nullable=True),
sa.Column('soft_warnings', postgresql.JSONB(), nullable=True),
sa.Column('requirements', postgresql.JSONB(), nullable=True),
sa.Column('competitors', postgresql.JSONB(), nullable=True),
sa.Column('error_message', sa.Text(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), nullable=False),
)
op.create_index('ix_review_tasks_tenant_id', 'review_tasks', ['tenant_id'])
op.create_index('ix_review_tasks_brand_id', 'review_tasks', ['brand_id'])
op.create_index('ix_review_tasks_creator_id', 'review_tasks', ['creator_id'])
op.create_index('ix_review_tasks_status', 'review_tasks', ['status'])
# 人工任务表
op.create_table(
'manual_tasks',
sa.Column('id', sa.String(64), primary_key=True),
sa.Column('tenant_id', sa.String(64), sa.ForeignKey('tenants.id', ondelete='CASCADE'), nullable=False),
sa.Column('review_task_id', sa.String(64), sa.ForeignKey('review_tasks.id', ondelete='SET NULL'), nullable=True),
sa.Column('video_url', sa.String(2048), nullable=False),
sa.Column('platform', platform_enum, nullable=False),
sa.Column('creator_id', sa.String(64), nullable=False),
sa.Column('status', task_status_enum, nullable=False, default='pending'),
sa.Column('approve_comment', sa.Text(), nullable=True),
sa.Column('reject_reason', sa.Text(), nullable=True),
sa.Column('reject_violations', postgresql.JSONB(), nullable=True),
sa.Column('reviewer_id', sa.String(64), nullable=True),
sa.Column('reviewed_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), nullable=False),
)
op.create_index('ix_manual_tasks_tenant_id', 'manual_tasks', ['tenant_id'])
op.create_index('ix_manual_tasks_review_task_id', 'manual_tasks', ['review_task_id'])
op.create_index('ix_manual_tasks_creator_id', 'manual_tasks', ['creator_id'])
op.create_index('ix_manual_tasks_status', 'manual_tasks', ['status'])
# 违禁词表
op.create_table(
'forbidden_words',
sa.Column('id', sa.String(64), primary_key=True),
sa.Column('tenant_id', sa.String(64), sa.ForeignKey('tenants.id', ondelete='CASCADE'), nullable=False),
sa.Column('word', sa.String(255), nullable=False),
sa.Column('category', sa.String(100), nullable=False),
sa.Column('severity', sa.String(50), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), nullable=False),
)
op.create_index('ix_forbidden_words_tenant_id', 'forbidden_words', ['tenant_id'])
op.create_index('ix_forbidden_words_word', 'forbidden_words', ['word'])
op.create_index('ix_forbidden_words_category', 'forbidden_words', ['category'])
# 白名单表
op.create_table(
'whitelist_items',
sa.Column('id', sa.String(64), primary_key=True),
sa.Column('tenant_id', sa.String(64), sa.ForeignKey('tenants.id', ondelete='CASCADE'), nullable=False),
sa.Column('brand_id', sa.String(64), nullable=False),
sa.Column('term', sa.String(255), nullable=False),
sa.Column('reason', sa.Text(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), nullable=False),
)
op.create_index('ix_whitelist_items_tenant_id', 'whitelist_items', ['tenant_id'])
op.create_index('ix_whitelist_items_brand_id', 'whitelist_items', ['brand_id'])
op.create_index('ix_whitelist_items_term', 'whitelist_items', ['term'])
# 竞品表
op.create_table(
'competitors',
sa.Column('id', sa.String(64), primary_key=True),
sa.Column('tenant_id', sa.String(64), sa.ForeignKey('tenants.id', ondelete='CASCADE'), nullable=False),
sa.Column('brand_id', sa.String(64), nullable=False),
sa.Column('name', sa.String(255), nullable=False),
sa.Column('logo_url', sa.String(2048), nullable=True),
sa.Column('keywords', postgresql.JSONB(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), nullable=False),
)
op.create_index('ix_competitors_tenant_id', 'competitors', ['tenant_id'])
op.create_index('ix_competitors_brand_id', 'competitors', ['brand_id'])
# 特例审批表
op.create_table(
'risk_exceptions',
sa.Column('id', sa.String(64), primary_key=True),
sa.Column('tenant_id', sa.String(64), sa.ForeignKey('tenants.id', ondelete='CASCADE'), nullable=False),
sa.Column('applicant_id', sa.String(64), nullable=False),
sa.Column('apply_time', sa.DateTime(timezone=True), nullable=False),
sa.Column('target_type', risk_target_type_enum, nullable=False),
sa.Column('target_id', sa.String(64), nullable=False),
sa.Column('risk_rule_id', sa.String(64), nullable=False),
sa.Column('status', risk_exception_status_enum, nullable=False, default='pending'),
sa.Column('valid_start_time', sa.DateTime(timezone=True), nullable=False),
sa.Column('valid_end_time', sa.DateTime(timezone=True), nullable=False),
sa.Column('reason_category', sa.String(100), nullable=False),
sa.Column('justification', sa.Text(), nullable=False),
sa.Column('attachment_url', sa.String(2048), nullable=True),
sa.Column('current_approver_id', sa.String(64), nullable=True),
sa.Column('approval_chain_log', postgresql.JSONB(), nullable=False, server_default='[]'),
sa.Column('auto_rejected', sa.Boolean(), nullable=False, default=False),
sa.Column('rejection_reason', sa.Text(), nullable=True),
sa.Column('last_status_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), nullable=False),
)
op.create_index('ix_risk_exceptions_tenant_id', 'risk_exceptions', ['tenant_id'])
op.create_index('ix_risk_exceptions_applicant_id', 'risk_exceptions', ['applicant_id'])
op.create_index('ix_risk_exceptions_target_id', 'risk_exceptions', ['target_id'])
op.create_index('ix_risk_exceptions_status', 'risk_exceptions', ['status'])
def downgrade() -> None:
# 删除表
op.drop_table('risk_exceptions')
op.drop_table('competitors')
op.drop_table('whitelist_items')
op.drop_table('forbidden_words')
op.drop_table('manual_tasks')
op.drop_table('review_tasks')
op.drop_table('ai_configs')
op.drop_table('tenants')
# 删除枚举类型
op.execute('DROP TYPE IF EXISTS risk_exception_status_enum')
op.execute('DROP TYPE IF EXISTS risk_target_type_enum')
op.execute('DROP TYPE IF EXISTS task_status_enum')
op.execute('DROP TYPE IF EXISTS platform_enum')