'192.168.2.4', 'db_port' => 3307, 'db_name' => 'task_reporter', 'db_user' => 'task_reporter', 'db_pass' => 'Pass12349ers!', // 报告生成选项 'author' => 'CGNICO Task Reporter', // 报告作者 // 报告配置 'report_days' => 7, // 报告包含的天数(例如:7表示过去一周) 'report_title' => 'CGNICO工具使用报告', // 报告标题 ]; // 根据报告天数设置标题 if (isset($_GET['days'])) { $config['report_days'] = intval($_GET['days']); // 根据天数调整报告标题 if ($config['report_days'] == 7) { $config['report_title'] = 'CGNICO工具使用周报'; } elseif ($config['report_days'] == 30) { $config['report_title'] = 'CGNICO工具使用月报'; } elseif ($config['report_days'] == 90) { $config['report_title'] = 'CGNICO工具使用季报'; } elseif ($config['report_days'] == 365) { $config['report_title'] = 'CGNICO工具使用年报'; } } // 创建数据库连接 try { $pdo = new PDO( "mysql:host={$config['db_host']};port={$config['db_port']};dbname={$config['db_name']}", $config['db_user'], $config['db_pass'] ); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->exec("SET NAMES utf8"); } catch (PDOException $e) { die("数据库连接失败: " . $e->getMessage()); } // 生成报告 function generate_report($pdo, $days) { $report = []; // 获取日期范围 $end_date = date('Y-m-d'); $start_date = date('Y-m-d', strtotime("-{$days} days")); // 1. 总体统计 $stmt = $pdo->prepare(" SELECT COUNT(*) as total_tasks, SUM(time_saved) as total_time_saved, COUNT(DISTINCT username) as total_users, COUNT(DISTINCT tool_name) as total_tools FROM task WHERE timestamp BETWEEN :start_date AND :end_date AND tool_name NOT LIKE '%(Debug)%' "); $stmt->bindParam(':start_date', $start_date); $stmt->bindParam(':end_date', $end_date); $stmt->execute(); $report['summary'] = $stmt->fetch(PDO::FETCH_ASSOC); // 2. 工具使用统计 $stmt = $pdo->prepare(" SELECT tool_name, COUNT(*) as usage_count, SUM(time_saved) as time_saved FROM task WHERE timestamp BETWEEN :start_date AND :end_date AND tool_name NOT LIKE '%(Debug)%' GROUP BY tool_name ORDER BY usage_count DESC LIMIT 10 "); $stmt->bindParam(':start_date', $start_date); $stmt->bindParam(':end_date', $end_date); $stmt->execute(); $report['tools'] = $stmt->fetchAll(PDO::FETCH_ASSOC); // 3. 用户使用统计 $stmt = $pdo->prepare(" SELECT username, COUNT(*) as usage_count, SUM(time_saved) as time_saved FROM task WHERE timestamp BETWEEN :start_date AND :end_date AND tool_name NOT LIKE '%(Debug)%' GROUP BY username ORDER BY usage_count DESC LIMIT 10 "); $stmt->bindParam(':start_date', $start_date); $stmt->bindParam(':end_date', $end_date); $stmt->execute(); $report['users'] = $stmt->fetchAll(PDO::FETCH_ASSOC); // 4. 每日使用趋势 $stmt = $pdo->prepare(" SELECT DATE(timestamp) as date, COUNT(*) as usage_count, SUM(time_saved) as time_saved FROM task WHERE timestamp BETWEEN :start_date AND :end_date AND tool_name NOT LIKE '%(Debug)%' GROUP BY DATE(timestamp) ORDER BY date "); $stmt->bindParam(':start_date', $start_date); $stmt->bindParam(':end_date', $end_date); $stmt->execute(); $report['daily'] = $stmt->fetchAll(PDO::FETCH_ASSOC); return [ 'report' => $report, 'start_date' => $start_date, 'end_date' => $end_date ]; } // 生成HTML报告 function generate_html_report($report_data) { $report = $report_data['report']; $start_date = $report_data['start_date']; $end_date = $report_data['end_date']; $html = ' CGNICO工具使用报告

CGNICO工具使用报告

报告时间范围: ' . $start_date . ' 至 ' . $end_date . '

总体统计

在过去的 ' . round((strtotime($end_date) - strtotime($start_date)) / 86400) . ' 天中:

工具使用排名

'; $rank = 1; foreach ($report['tools'] as $tool) { $html .= ' '; } $html .= '
排名 工具名称 使用次数 节省时间 (小时)
' . $rank++ . ' ' . htmlspecialchars($tool['tool_name']) . ' ' . number_format($tool['usage_count']) . ' ' . number_format($tool['time_saved'], 2) . '

用户使用排名

'; $rank = 1; foreach ($report['users'] as $user) { $html .= ' '; } $html .= '
排名 用户名 使用次数 节省时间 (小时)
' . $rank++ . ' ' . htmlspecialchars($user['username']) . ' ' . number_format($user['usage_count']) . ' ' . number_format($user['time_saved'], 2) . '

每日使用趋势

'; foreach ($report['daily'] as $day) { $html .= ' '; } $html .= '
日期 使用次数 节省时间 (小时)
' . $day['date'] . ' ' . number_format($day['usage_count']) . ' ' . number_format($day['time_saved'], 2) . '

此报告由CGNICO Task Reporter自动生成于 ' . date('Y-m-d H:i:s') . '

'; return $html; } // 记录日志 function log_message($message) { $log_dir = __DIR__ . '/logs'; if (!is_dir($log_dir)) { mkdir($log_dir, 0755, true); } $log_file = $log_dir . '/report_' . date('Y-m-d') . '.log'; $time = date('Y-m-d H:i:s'); file_put_contents($log_file, "[$time] $message\n", FILE_APPEND); } // 主程序 try { // 创建报告目录(如果不存在) $report_dir = __DIR__ . '/reports/'; if (!is_dir($report_dir)) { mkdir($report_dir, 0755, true); } // 检查是否需要生成新报告 $generate_new_report = false; $report_file = $report_dir . 'report_' . date('Y-m-d') . '.html'; if (isset($_GET['generate']) && $_GET['generate'] == '1') { $generate_new_report = true; } elseif (!file_exists($report_file)) { // 如果今天的报告不存在,自动生成 $generate_new_report = true; } if ($generate_new_report) { log_message('===== 开始执行报告生成脚本 ====='); // 生成报告数据 log_message('开始生成报告数据...'); $days = $config['report_days']; $report_data = generate_report($pdo, $days); log_message('报告数据生成完成'); // 生成HTML报告 log_message('生成HTML报告...'); $html_report = generate_html_report($report_data); log_message('HTML报告生成完成'); // 保存报告到文件 file_put_contents($report_file, $html_report); log_message('报告已保存到: ' . $report_file); } // 开始HTML输出 ?> CGNICO工具使用报告生成器

CGNICO工具使用报告生成器

报告已生成成功!

报告时间范围: 过去天 ()

查看最新报告 下载最新报告 返回首页

生成新报告

\n"; echo "

历史报告

\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; rsort($reports); // 按日期降序排序 foreach (array_slice($reports, 0, 10) as $report) { // 只显示最近10个 $filename = basename($report); $date = substr($filename, 7, 10); // 从 report_YYYY-MM-DD.html 提取日期 // 尝试确定报告类型 $report_type = "常规报告"; $file_content = file_get_contents($report); if (strpos($file_content, "工具使用周报") !== false) { $report_type = "周报"; } elseif (strpos($file_content, "工具使用月报") !== false) { $report_type = "月报"; } elseif (strpos($file_content, "工具使用季报") !== false) { $report_type = "季报"; } elseif (strpos($file_content, "工具使用年报") !== false) { $report_type = "年报"; } echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; } echo "
报告日期报告类型操作
{$date}{$report_type}\n"; echo "查看\n"; echo "下载\n"; echo "
\n"; echo "
\n"; } } ?> getMessage()); ?> 错误 - CGNICO工具使用报告生成器

发生错误

错误: getMessage(); ?>

返回首页