-- 请在 CenterDB（后台报表库）执行。
CREATE TABLE IF NOT EXISTS `tk_aiopen_risk_daily` (
    `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
    `report_date` DATE NOT NULL COMMENT '统计日期（Asia/Shanghai）',
    `account_id` INT NOT NULL COMMENT 'tk_pool.id',
    `account_name` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '触发时账号名称',
    `endpoint_id` INT NOT NULL DEFAULT 8 COMMENT 'tk_endpoint_config.ep_id',
    `endpoint_name` VARCHAR(64) NOT NULL DEFAULT 'aiopen' COMMENT '端点名称',
    `reason_code` VARCHAR(64) NOT NULL COMMENT '稳定风控代码',
    `reason` VARCHAR(512) NOT NULL DEFAULT '' COMMENT '上游bizErrorDesc',
    `biz_error_code` INT NOT NULL DEFAULT 0 COMMENT '上游bizErrorCode',
    `result_code` INT NOT NULL DEFAULT 0 COMMENT '上游resultCode',
    `first_trigger_time` DATETIME(3) NOT NULL COMMENT '当日首次触发时间',
    `request_count_at_trigger` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT '包含触发请求的当日端点调用数',
    `success_count_at_trigger` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT '触发时当日成功数',
    `release_time` DATETIME(3) NOT NULL COMMENT '预计自动释放时间',
    `create_time` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT '创建时间',
    PRIMARY KEY (`id`),
    UNIQUE KEY `uk_date_account_reason` (`report_date`, `account_id`, `reason_code`),
    KEY `idx_report_date_trigger_time` (`report_date`, `first_trigger_time`),
    KEY `idx_account_trigger_time` (`account_id`, `first_trigger_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='AI Open账号每日首次风控事件';
