Files
web-Iot/src/pages/ReportCenter.tsx

582 lines
19 KiB
TypeScript
Raw Normal View History

import React, { useState } from 'react';
import {
Card, Row, Col, Tabs, Button, Space, Select, Table, Statistic,
DatePicker, message, Tag, Empty,
Typography
} from 'antd';
import {
CloudOutlined, BarChartOutlined, BellOutlined,
CalendarOutlined, LinkOutlined, FileTextOutlined,
DownloadOutlined
} from '@ant-design/icons';
import { Line, Pie } from '@ant-design/charts';
import dayjs from 'dayjs';
const { TabPane } = Tabs;
const { RangePicker } = DatePicker;
const { Option } = Select;
// 模拟数据
const overviewData = {
powerToday: 69302.3,
currentPower: 89343.1,
currentAlarm: 5,
processingOrder: 2,
deviceOnlineRate: 92.3,
generatedReport: 4
};
// 发电报表模拟数据
const powerTrendData = [
{ date: '2026-04-28', avgPower: 40.33, dailyPower: 4580.6 }
];
const powerDetailData = [
{ date: '2026-04-28', avgPower: 40.33, dailyPower: 4580.6, totalPower: 182345.7 }
];
// 告警报表模拟数据
const alarmLevelData = [
{ type: 'MAJOR', value: 2 },
{ type: 'INFO', value: 2 },
{ type: 'MINOR', value: 1 }
];
const alarmStatusData = [
{ type: 'PENDING', value: 3 },
{ type: 'PROCESSING', value: 2 }
];
const alarmTrendData = [
{ date: '2026-04-28', count: 5 }
];
const deviceAlarmRankData = [
{ device: 'INV-A02', count: 2 },
{ device: 'CAM-02', count: 2 },
{ device: 'CMB-A01', count: 1 }
];
// 工单报表模拟数据
const orderStatusData = [
{ type: 'DISPATCHED', value: 1 },
{ type: 'PENDING', value: 1 },
{ type: 'PROCESSING', value: 1 }
];
const orderPriorityData = [
{ type: 'LOW', value: 1 },
{ type: 'MEDIUM', value: 1 },
{ type: 'HIGH', value: 1 }
];
const orderSourceData = [
{ type: 'ALARM', value: 2 },
{ type: 'MANUAL', value: 1 }
];
const orderTrendData = [
{ date: '2026-04-28', newOrder: 3, completed: 0 }
];
const orderEfficiencyData = {
avgProcessHour: 0.00,
completionRate: '0.0%',
newOrderToday: 0
};
// 设备健康模拟数据
const deviceHealthList = [
{ deviceCode: 'CAM-02', deviceName: '摄像头 CAM-02', type: 'CAMERA', online: 'OFFLINE', run: 'FAULT', temp: 0, power: 0, healthScore: 40, healthStatus: 'OFFLINE' },
{ deviceCode: 'INV-A02', deviceName: '逆变器 INV-A02', type: 'INVERTER', online: 'ONLINE', run: 'WARNING', temp: 82.5, power: 54.2, healthScore: 70, healthStatus: 'WARNING' },
{ deviceCode: 'CMB-A01', deviceName: '汇流箱 CMB-A01', type: 'COMBINER_BOX', online: 'ONLINE', run: 'WARNING', temp: 46.3, power: 0, healthScore: 70, healthStatus: 'WARNING' },
{ deviceCode: 'INV-A01', deviceName: '逆变器 INV-A01', type: 'INVERTER', online: 'ONLINE', run: 'NORMAL', temp: 46, power: 66.8, healthScore: 92, healthStatus: 'HEALTHY' },
{ deviceCode: 'INV-B01', deviceName: '逆变器 INV-B01', type: 'INVERTER', online: 'ONLINE', run: 'NORMAL', temp: 43.8, power: 22410.8, healthScore: 92, healthStatus: 'HEALTHY' },
{ deviceCode: 'CMB-A02', deviceName: '汇流箱 CMB-A02', type: 'COMBINER_BOX', online: 'ONLINE', run: 'NORMAL', temp: 41.1, power: 0, healthScore: 92, healthStatus: 'HEALTHY' },
{ deviceCode: 'MET-01', deviceName: '气象站 MET-01', type: 'WEATHER_STATION', online: 'ONLINE', run: 'NORMAL', temp: 28.4, power: 0, healthScore: 92, healthStatus: 'HEALTHY' },
{ deviceCode: 'METER-01', deviceName: '电表 METER-01', type: 'METER', online: 'ONLINE', run: 'NORMAL', temp: 39.2, power: 66811.3, healthScore: 92, healthStatus: 'HEALTHY' },
{ deviceCode: 'CAM-01', deviceName: '摄像头 CAM-01', type: 'CAMERA', online: 'ONLINE', run: 'NORMAL', temp: 35.2, power: 0, healthScore: 92, healthStatus: 'HEALTHY' },
{ deviceCode: 'CAM-03', deviceName: '摄像头 CAM-03', type: 'CAMERA', online: 'ONLINE', run: 'NORMAL', temp: 33.9, power: 0, healthScore: 92, healthStatus: 'HEALTHY' }
];
// 报表文件模拟数据
const reportFileList = [
{ id: 'RPT-ALARM_STAT-20260429092501', name: '告警统计报表', type: 'ALARM_STAT', format: 'EXCEL', status: 'SUCCESS', time: '2026-04-29T09:25:03+08:00' },
{ id: 'RPT-DEMO-WORKORDER-001', name: '西北荒漠一号光伏电站工单效率统计', type: 'WORK_ORDER_STAT', format: 'EXCEL', status: 'SUCCESS', time: '2026-04-29T09:12:42+08:00' },
{ id: 'RPT-DEMO-ALARM-001', name: '西北荒漠一号光伏电站告警统计', type: 'ALARM_STAT', format: 'EXCEL', status: 'SUCCESS', time: '2026-04-29T09:12:42+08:00' },
{ id: 'RPT-DEMO-POWER-001', name: '西北荒漠一号光伏电站发电日报', type: 'POWER_DAILY', format: 'EXCEL', status: 'SUCCESS', time: '2026-04-29T09:12:42+08:00' }
];
export default function ReportCenterPage() {
const [activeTab, setActiveTab] = useState('power');
const [timeType, setTimeType] = useState('day');
const [dateRange, setDateRange] = useState([dayjs().subtract(7, 'day'), dayjs()]);
// 顶部概览卡片
const OverviewCards = () => (
< div
style={{
display: 'flex',
flexWrap: 'wrap', // 自动换行
gap: '16px', // 卡片间距
marginBottom: '20px'
}
}
>
{/* 今日发电量 */}
< div
style={{
flex: '1 1 210px', // 基础宽度 210px,允许扩展
height: '140px', // 固定高度
flexShrink: 0 // 不压缩
}}
>
<Card bordered={false} style={{ borderRadius: 8, height: '100%' }}>
<Statistic
title="今日发电量"
value={overviewData.powerToday}
precision={1}
suffix="kWh"
2026-05-08 15:53:27 +08:00
valueStyle={{ color: '#52c41a', fontSize: 24, fontWeight: 700 }}
prefix={<CloudOutlined style={{ fontSize: 32, color: '#52c41a' }} />}
/>
2026-05-08 15:53:27 +08:00
<div style={{ fontSize: 12, color: '#666', marginTop: 4 }}>遥测与 latest 聚合</div>
</Card>
</div >
{/* 当前功率 */}
< div
style={{
flex: '1 1 210px', // 基础宽度 210px,允许扩展
height: '140px',
flexShrink: 0
}}
>
<Card bordered={false} style={{ borderRadius: 8, height: '100%' }}>
<Statistic
title="当前功率"
value={overviewData.currentPower}
precision={1}
suffix="kW"
2026-05-08 15:53:27 +08:00
valueStyle={{ color: '#1890ff', fontSize: 24, fontWeight: 700 }}
prefix={<BarChartOutlined style={{ fontSize: 32, color: '#1890ff' }} />}
/>
2026-05-08 15:53:27 +08:00
<div style={{ fontSize: 12, color: '#666', marginTop: 4 }}>实时功率汇总</div>
</Card>
</div >
{/* 当前告警 */}
< div
style={{
flex: '1 1 210px', // 基础宽度 210px,允许扩展
height: '140px',
flexShrink: 0
}}
>
<Card bordered={false} style={{ borderRadius: 8, height: '100%' }}>
<Statistic
title="当前告警"
value={overviewData.currentAlarm}
suffix="条"
2026-05-08 15:53:27 +08:00
valueStyle={{ color: '#ff4d4f', fontSize: 24, fontWeight: 700 }}
prefix={<BellOutlined style={{ fontSize: 32, color: '#ff4d4f' }} />}
/>
2026-05-08 15:53:27 +08:00
<div style={{ fontSize: 12, color: '#666', marginTop: 4 }}>累计 5 条</div>
</Card>
</div >
{/* 处理中工单 */}
< div
style={{
flex: '1 1 210px', // 基础宽度 210px,允许扩展
height: '140px',
flexShrink: 0
}}
>
<Card bordered={false} style={{ borderRadius: 8, height: '100%' }}>
<Statistic
title="处理中工单"
value={overviewData.processingOrder}
suffix="单"
2026-05-08 15:53:27 +08:00
valueStyle={{ color: '#faad14', fontSize: 24, fontWeight: 700 }}
prefix={<CalendarOutlined style={{ fontSize: 32, color: '#faad14' }} />}
/>
2026-05-08 15:53:27 +08:00
<div style={{ fontSize: 12, color: '#666', marginTop: 4 }}>全部 3 单</div>
</Card>
</div >
{/* 设备在线率 */}
< div
style={{
flex: '1 1 210px', // 基础宽度 210px,允许扩展
height: '140px',
flexShrink: 0
}}
>
<Card bordered={false} style={{ borderRadius: 8, height: '100%' }}>
<Statistic
title="设备在线率"
value={overviewData.deviceOnlineRate}
precision={1}
suffix="%"
2026-05-08 15:53:27 +08:00
valueStyle={{ color: '#52c41a', fontSize: 24, fontWeight: 700 }}
prefix={<LinkOutlined style={{ fontSize: 32, color: '#52c41a' }} />}
/>
2026-05-08 15:53:27 +08:00
<div style={{ fontSize: 12, color: '#666', marginTop: 4 }}>来自设备主数据</div>
</Card>
</div >
{/* 已生成报表 */}
< div
style={{
flex: '1 1 210px', // 基础宽度 210px,允许扩展
height: '140px',
flexShrink: 0
}}
>
<Card bordered={false} style={{ borderRadius: 8, height: '100%' }}>
<Statistic
title="已生成报表"
value={overviewData.generatedReport}
suffix="份"
2026-05-08 15:53:27 +08:00
valueStyle={{ color: '#722ed1', fontSize: 24, fontWeight: 700 }}
prefix={<FileTextOutlined style={{ fontSize: 32, color: '#722ed1' }} />}
/>
2026-05-08 15:53:27 +08:00
<div style={{ fontSize: 12, color: '#666', marginTop: 4 }}>SUCCESS 文件记录</div>
</Card>
</div >
</div >
);
// 发电报表
const PowerReportTab = () => (
<div>
<div style={{ display: 'flex', alignItems: 'center', marginBottom: 16, gap: 16 }}>
<RangePicker
value={dateRange}
onChange={setDateRange}
style={{ flex: 1 }}
/>
<Space>
<Button size="small" onClick={() => setTimeType('hour')}>小时</Button>
<Button size="small" type={timeType === 'day' ? 'primary' : 'default'} onClick={() => setTimeType('day')}>日</Button>
<Button size="small" onClick={() => setTimeType('month')}>月</Button>
</Space>
<Button type="primary">查询</Button>
</div>
<Card bordered={false} style={{ borderRadius: 8, marginBottom: 16 }} title="发电趋势">
<Line
data={powerTrendData}
xField="date"
yField={['avgPower', 'dailyPower']}
seriesField="type"
color={['#1890ff', '#52c41a']}
point={{ size: 5 }}
legend={{ position: 'top-right' }}
yAxis={{
label: { formatter: (v) => `${v}` },
}}
/>
</Card>
<Card bordered={false} style={{ borderRadius: 8 }} title="发电趋势明细">
<Table
rowKey="date"
columns={[
{ title: '时间', dataIndex: 'date' },
{ title: '平均功率(kW)', dataIndex: 'avgPower' },
{ title: '日发电量(kWh)', dataIndex: 'dailyPower' },
{ title: '累计发电量(kWh)', dataIndex: 'totalPower' }
]}
dataSource={powerDetailData}
pagination={false}
/>
</Card>
</div>
);
// 告警报表
const AlarmReportTab = () => (
<div>
<Row gutter={16} style={{ marginBottom: 16 }}>
<Col span={8}>
<Card bordered={false} style={{ borderRadius: 8 }} title="告警等级分布">
<Pie
data={alarmLevelData}
angleField="value"
colorField="type"
color={['#1890ff', '#52c41a', '#faad14']}
radius={0.8}
innerRadius={0.5}
legend={{ position: 'right' }}
/>
</Card>
</Col>
<Col span={8}>
<Card bordered={false} style={{ borderRadius: 8 }} title="告警状态分布">
<Pie
data={alarmStatusData}
angleField="value"
colorField="type"
color={['#1890ff', '#52c41a']}
radius={0.8}
innerRadius={0.5}
legend={{ position: 'right' }}
/>
</Card>
</Col>
<Col span={8}>
<Card bordered={false} style={{ borderRadius: 8 }} title="告警日趋势">
<Line
data={alarmTrendData}
xField="date"
yField="count"
color="#1890ff"
point={{ size: 5 }}
legend={{ position: 'top-right' }}
/>
</Card>
</Col>
</Row>
<Card bordered={false} style={{ borderRadius: 8 }} title="设备告警排行">
<Table
rowKey="device"
columns={[
{ title: '设备编码', dataIndex: 'device' },
{ title: '告警数', dataIndex: 'count' }
]}
dataSource={deviceAlarmRankData}
pagination={false}
/>
</Card>
</div>
);
// 工单报表
const WorkOrderReportTab = () => (
<div>
<Row gutter={16} style={{ marginBottom: 16 }}>
<Col span={8}>
<Card bordered={false} style={{ borderRadius: 8 }} title="工单状态分布">
<Pie
data={orderStatusData}
angleField="value"
colorField="type"
color={['#1890ff', '#52c41a', '#faad14']}
radius={0.8}
innerRadius={0.5}
legend={{ position: 'right' }}
/>
</Card>
</Col>
<Col span={8}>
<Card bordered={false} style={{ borderRadius: 8 }} title="优先级分布">
<Pie
data={orderPriorityData}
angleField="value"
colorField="type"
color={['#1890ff', '#52c41a', '#faad14']}
radius={0.8}
innerRadius={0.5}
legend={{ position: 'right' }}
/>
</Card>
</Col>
<Col span={8}>
<Card bordered={false} style={{ borderRadius: 8 }} title="来源分布">
<Pie
data={orderSourceData}
angleField="value"
colorField="type"
color={['#1890ff', '#52c41a']}
radius={0.8}
innerRadius={0.5}
legend={{ position: 'right' }}
/>
</Card>
</Col>
</Row>
<Row gutter={16}>
<Col span={6}>
<Card bordered={false} style={{ borderRadius: 8 }} title="处理效率">
<div style={{ display: 'flex', gap: 16 }}>
<div>
<Statistic
value={orderEfficiencyData.avgProcessHour}
precision={2}
valueStyle={{ color: '#1890ff', fontSize: 24 }}
/>
<div style={{ fontSize: 12, color: '#666' }}>平均处理小时</div>
</div>
<div>
<Statistic
value={0}
suffix="%"
valueStyle={{ color: '#1890ff', fontSize: 24 }}
formatter={() => orderEfficiencyData.completionRate}
/>
<div style={{ fontSize: 12, color: '#666' }}>完成率</div>
</div>
<div>
<Statistic
value={orderEfficiencyData.newOrderToday}
valueStyle={{ color: '#1890ff', fontSize: 24 }}
/>
<div style={{ fontSize: 12, color: '#666' }}>今日新增</div>
</div>
</div>
</Card>
</Col>
<Col span={18}>
<Card bordered={false} style={{ borderRadius: 8 }} title="工单日趋势">
<Table
rowKey="date"
columns={[
{ title: '日期', dataIndex: 'date' },
{ title: '新增', dataIndex: 'newOrder' },
{ title: '完成', dataIndex: 'completed' }
]}
dataSource={orderTrendData}
pagination={false}
/>
</Card>
</Col>
</Row>
</div>
);
// 设备健康报表
const DeviceHealthTab = () => (
<div>
<Row gutter={16} style={{ marginBottom: 16 }}>
<Col span={6}>
<Card bordered={false} style={{ borderRadius: 8 }}>
<Statistic
title="设备在线率"
value={92.3}
precision={1}
suffix="%"
valueStyle={{ color: '#52c41a', fontSize: 24, fontWeight: 700 }}
prefix={<LinkOutlined style={{ fontSize: 28, color: '#52c41a' }} />}
/>
<div style={{ fontSize: 12, color: '#666' }}>来自 pv_device</div>
</Card>
</Col>
<Col span={6}>
<Card bordered={false} style={{ borderRadius: 8 }}>
<Statistic
title="离线设备"
value={1}
suffix="台"
valueStyle={{ color: '#faad14', fontSize: 24, fontWeight: 700 }}
prefix={<BellOutlined style={{ fontSize: 28, color: '#faad14' }} />}
/>
<div style={{ fontSize: 12, color: '#666' }}>在线状态统计</div>
</Card>
</Col>
<Col span={6}>
<Card bordered={false} style={{ borderRadius: 8 }}>
<Statistic
title="异常设备"
value={3}
suffix="台"
valueStyle={{ color: '#ff4d4f', fontSize: 24, fontWeight: 700 }}
prefix={<BellOutlined style={{ fontSize: 28, color: '#ff4d4f' }} />}
/>
<div style={{ fontSize: 12, color: '#666' }}>运行状态统计</div>
</Card>
</Col>
<Col span={6}>
<Card bordered={false} style={{ borderRadius: 8 }}>
<Statistic
title="平均温度"
value={38.4}
precision={1}
suffix="℃"
valueStyle={{ color: '#1890ff', fontSize: 24, fontWeight: 700 }}
prefix={<BarChartOutlined style={{ fontSize: 28, color: '#1890ff' }} />}
/>
<div style={{ fontSize: 12, color: '#666' }}>来自 device_latest</div>
</Card>
</Col>
</Row>
<Card bordered={false} style={{ borderRadius: 8 }} title="设备健康列表">
<Table
rowKey="deviceCode"
columns={[
{ title: '设备编码', dataIndex: 'deviceCode' },
{ title: '设备名称', dataIndex: 'deviceName' },
{ title: '类型', dataIndex: 'type' },
{ title: '在线', dataIndex: 'online', render: (v) => <Tag color={v === 'ONLINE' ? 'green' : 'red'}>{v}</Tag> },
{ title: '运行', dataIndex: 'run', render: (v) => <Tag color={v === 'NORMAL' ? 'green' : v === 'WARNING' ? 'orange' : 'red'}>{v}</Tag> },
{ title: '温度', dataIndex: 'temp' },
{ title: '功率', dataIndex: 'power' },
{ title: '健康分', dataIndex: 'healthScore' },
{ title: '健康状态', dataIndex: 'healthStatus', render: (v) => <Tag color={v === 'HEALTHY' ? 'green' : v === 'WARNING' ? 'orange' : 'red'}>{v}</Tag> }
]}
dataSource={deviceHealthList}
pagination={false}
scroll={{ x: 'max-content' }}
/>
</Card>
</div>
);
// 报表文件
const ReportFileTab = () => (
<div>
<div style={{ display: 'flex', alignItems: 'center', marginBottom: 16, gap: 16 }}>
<Select placeholder="报表类型" style={{ width: 150 }} allowClear>
<Option value="POWER_DAILY">发电日报</Option>
<Option value="ALARM_STAT">告警统计</Option>
<Option value="WORK_ORDER_STAT">工单统计</Option>
</Select>
<Select placeholder="生成状态" style={{ width: 150 }} allowClear>
<Option value="SUCCESS">成功</Option>
<Option value="FAILED">失败</Option>
</Select>
<Button type="primary">查询</Button>
<Button type="primary" onClick={() => message.success('报表生成任务已提交')}>生成报表</Button>
</div>
<Card bordered={false} style={{ borderRadius: 8 }}>
<Table
rowKey="id"
columns={[
{ title: '报表编码', dataIndex: 'id' },
{ title: '报表名称', dataIndex: 'name' },
{ title: '类型', dataIndex: 'type' },
{ title: '格式', dataIndex: 'format' },
{ title: '状态', dataIndex: 'status', render: (v) => <Tag color={v === 'SUCCESS' ? 'green' : 'red'}>{v}</Tag> },
{ title: '生成时间', dataIndex: 'time' },
{ title: '操作', render: () => <Button type="link" icon={<DownloadOutlined />}>下载</Button> }
]}
dataSource={reportFileList}
pagination={{ total: 4, pageSize: 10, showSizeChanger: true, showTotal: (total) => `共 ${total} 条` }}
/>
</Card>
</div>
);
return (
<div style={{ padding: 20, background: '#f5f7fa', minHeight: '100vh' }}>
{/* 页面头部 */}
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 20 }}>
<div>
<Typography.Title level={4} style={{ margin: 0 }}>报表中心</Typography.Title>
<p style={{ color: '#666', margin: '4px 0 0' }}>发电、告警、工单效率、设备健康与报表文件统一分析</p>
</div>
<Button type="primary" size="large">生成报表</Button>
</div>
{/* 顶部概览卡片 */}
<OverviewCards />
{/* 标签页 */}
<Tabs activeKey={activeTab} onChange={setActiveTab}>
<TabPane tab="发电报表" key="power">{PowerReportTab()}</TabPane>
<TabPane tab="告警报表" key="alarm">{AlarmReportTab()}</TabPane>
<TabPane tab="工单报表" key="order">{WorkOrderReportTab()}</TabPane>
<TabPane tab="设备健康" key="device">{DeviceHealthTab()}</TabPane>
<TabPane tab="报表文件" key="file">{ReportFileTab()}</TabPane>
</Tabs>
</div>
);
}