CREATE TABLE IF NOT EXISTS lobster_reply_decision_log (
    id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键',
    trace_id VARCHAR(80) DEFAULT NULL COMMENT '链路追踪ID',
    company_id BIGINT NOT NULL COMMENT '企业ID',
    contact_id BIGINT DEFAULT NULL COMMENT '客户ID',
    channel_type VARCHAR(32) DEFAULT NULL COMMENT '渠道',
    template_id BIGINT DEFAULT NULL COMMENT '模板ID',
    node_code VARCHAR(64) DEFAULT NULL COMMENT '节点编码',
    customer_message TEXT COMMENT '客户消息',
    reply_text TEXT COMMENT 'AI回复',
    strategy_json LONGTEXT COMMENT '策略编排结果JSON',
    context_json LONGTEXT COMMENT '上下文排序结果JSON',
    quality_json LONGTEXT COMMENT '质量评分结果JSON',
    used_knowledge_summary TEXT COMMENT '命中知识库摘要',
    used_sales_corpus_summary TEXT COMMENT '命中销冠语料摘要',
    used_industry_corpus_summary TEXT COMMENT '命中行业语料摘要',
    quality_score INT DEFAULT NULL COMMENT '质量分',
    risk_level VARCHAR(32) DEFAULT NULL COMMENT '风险等级',
    action VARCHAR(64) DEFAULT NULL COMMENT '处理动作',
    send_status VARCHAR(32) DEFAULT 'pending' COMMENT '发送状态',
    response_ms BIGINT DEFAULT NULL COMMENT '响应耗时ms',
    create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    PRIMARY KEY (id),
    KEY idx_company_contact_time (company_id, contact_id, create_time),
    KEY idx_trace_id (trace_id),
    KEY idx_company_time (company_id, create_time)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='数字员工AI回复决策日志';
