-- 爬虫错误日志表
CREATE TABLE IF NOT EXISTS `la_crawl_error_log` (
    `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    `task_name` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '任务名称(schedule/standings/match_finish等)',
    `request_url` VARCHAR(1000) NOT NULL DEFAULT '' COMMENT '请求URL',
    `request_method` VARCHAR(10) NOT NULL DEFAULT 'GET' COMMENT '请求方法',
    `request_params` TEXT COMMENT '请求参数(JSON)',
    `http_status` INT NOT NULL DEFAULT 0 COMMENT 'HTTP状态码(0=网络异常)',
    `error_type` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '错误类型(NetworkError/404/timeout等)',
    `error_message` TEXT COMMENT '错误信息',
    `response_body` TEXT COMMENT '响应内容(截断)',
    `channel` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '请求通道(api/tls/playwright/page)',
    `notified` TINYINT NOT NULL DEFAULT 0 COMMENT '是否已发送邮件通知(0=未通知,1=已通知)',
    `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    KEY `idx_notified` (`notified`),
    KEY `idx_task_created` (`task_name`, `created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='爬虫请求错误日志';

-- 定时任务：错误报告邮件(每5分钟)
INSERT INTO `la_dev_crontab` (`name`, `type`, `command`, `params`, `status`, `expression`, `create_time`, `update_time`)
VALUES ('爬虫错误报告邮件', 1, 'crawler', 'error_report', 1, '*/5 * * * *', UNIX_TIMESTAMP(), UNIX_TIMESTAMP());
