修复权限管理,角色认证,更新工单认领系统,增加表格导出支持区间选择,增加docker管理(开发中

This commit is contained in:
2026-07-09 10:06:44 +08:00
parent 0c2fe393df
commit 3b84698fd3
25 changed files with 8975 additions and 102 deletions
+39 -10
View File
@@ -25,28 +25,58 @@ function getDbConn() {
// CSV导出接口(支持指定历史日期下载,不输出JSON头)
if ($act === "export_csv") {
date_default_timezone_set('Asia/Shanghai');
$conn = getDbConn();
mysqli_query($conn, "SET time_zone = '+08:00'");
if (!$conn) {
header("Content-Type:text/html;charset=utf-8");
echo "数据库连接失败:" . mysqli_connect_error();
exit;
}
// 接收自定义日期参数,不传则取今日
$targetDate = $_GET['date'] ?? date("Y-m-d");
// 简单日期格式校验 Y-m-d
if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $targetDate)) {
header("Content-Type:application/json;charset=utf-8");
echo json_encode(["code"=>400,"msg"=>"日期格式错误,请使用 Y-m-d,例如 2026-07-01"], JSON_UNESCAPED_UNICODE);
exit;
$singleDate = $_GET['date'] ?? '';
$startDate = $_GET['start'] ?? '';
$endDate = $_GET['end'] ?? '';
$where = "";
$fileName = "";
if (!empty($startDate) && !empty($endDate)) {
if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $startDate) || !preg_match('/^\d{4}-\d{2}-\d{2}$/', $endDate)) {
header("Content-Type:application/json;charset=utf-8");
echo json_encode(["code"=>400,"msg"=>"日期格式错误"], JSON_UNESCAPED_UNICODE);
exit;
}
if ($startDate > $endDate) {
header("Content-Type:application/json;charset=utf-8");
echo json_encode(["code"=>400,"msg"=>"开始日期不能大于结束日期"], JSON_UNESCAPED_UNICODE);
exit;
}
$where = "receive_time >= '$startDate 00:00:00' AND receive_time <= '$endDate 23:59:59'";
$fileName = "告警报表_{$startDate}_至_{$endDate}.csv";
} elseif (!empty($singleDate)) {
if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $singleDate)) {
header("Content-Type:application/json;charset=utf-8");
echo json_encode(["code"=>400,"msg"=>"日期格式错误"], JSON_UNESCAPED_UNICODE);
exit;
}
$where = "DATE(receive_time) = '$singleDate'";
$fileName = "告警报表_{$singleDate}.csv";
} else {
$today = date("Y-m-d");
$where = "DATE(receive_time) = '$today'";
$fileName = "告警报表_今日_{$today}.csv";
}
// 调试:打印where条件,访问接口先看这个
// echo "WHERE条件:".$where;exit;
$sql = "SELECT alert_type,alert_name,instance,severity,starts_at,receive_time
FROM alert_log WHERE DATE(receive_time) = '$targetDate' ORDER BY receive_time DESC";
FROM alert_log WHERE {$where} ORDER BY receive_time DESC";
$res = mysqli_query($conn, $sql);
ob_clean();
header("Content-Type: text/csv; charset=utf-8");
header("Content-Disposition: attachment; filename=告警报表_" . $targetDate . ".csv");
header("Content-Disposition: attachment; filename={$fileName}");
echo "\xEF\xBB\xBF";
$header = ["告警状态", "告警名称", "实例", "级别", "故障开始时间", "接收时间"];
echo implode(",", $header) . "\r\n";
@@ -69,7 +99,6 @@ if ($act === "export_csv") {
mysqli_close($conn);
exit;
}
// 所有JSON接口统一返回头
header("Content-Type:application/json;charset=utf-8");
$conn = getDbConn();