From 006ba95a226cef7282001ab32641ec867715d465 Mon Sep 17 00:00:00 2001 From: Iamasoldier <1272745473@qq.com> Date: Sun, 13 Apr 2025 00:55:17 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=BB=9F=E8=AE=A1=E7=AE=A1=E7=90=86)?= =?UTF-8?q?=EF=BC=9A=E6=96=B0=E5=A2=9E=E4=BA=8C=E7=BB=B4=E7=A0=81=E3=80=81?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E3=80=81=E6=99=AF=E5=8C=BA=E5=88=86=E8=B4=A6?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E5=89=8D=E5=90=8E=E7=AB=AF=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../statistics/components/StatisticsTable.tsx | 80 ++++++++++ .../frontend/src/pages/statistics/index.tsx | 144 ++++++++++++++++++ .../frontend/src/services/statistics/api.ts | 97 ++++++++++++ .../src/services/statistics/typings.d.ts | 37 +++++ 4 files changed, 358 insertions(+) create mode 100644 zlt-web/react-web/src/main/frontend/src/pages/statistics/components/StatisticsTable.tsx create mode 100644 zlt-web/react-web/src/main/frontend/src/pages/statistics/index.tsx create mode 100644 zlt-web/react-web/src/main/frontend/src/services/statistics/api.ts create mode 100644 zlt-web/react-web/src/main/frontend/src/services/statistics/typings.d.ts diff --git a/zlt-web/react-web/src/main/frontend/src/pages/statistics/components/StatisticsTable.tsx b/zlt-web/react-web/src/main/frontend/src/pages/statistics/components/StatisticsTable.tsx new file mode 100644 index 00000000..82b5f775 --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/pages/statistics/components/StatisticsTable.tsx @@ -0,0 +1,80 @@ +import React from 'react'; +import { ProTable } from '@ant-design/pro-components'; +import type { ProColumns } from '@ant-design/pro-components'; + +interface StatisticsTableProps { + data: STATISTICS.OrderStatistics[]; + loading?: boolean; +} + +const StatisticsTable: React.FC = ({ data, loading }) => { + const columns: ProColumns[] = [ + { + title: '统计日期', + dataIndex: 'statisticsDate', + valueType: 'date', + }, + { + title: '景区名称', + dataIndex: 'tourismName', + }, + { + title: '设备编号', + dataIndex: 'deviceSn', + }, + { + title: '总订单数', + dataIndex: 'totalOrders', + }, + { + title: '已支付订单数', + dataIndex: 'paidOrders', + }, + { + title: '已完成订单数', + dataIndex: 'completedOrders', + }, + { + title: '已取消订单数', + dataIndex: 'canceledOrders', + }, + { + title: '总金额(元)', + dataIndex: 'totalAmount', + render: (val) => (val as number / 100).toFixed(2), + }, + { + title: '已支付金额(元)', + dataIndex: 'paidAmount', + render: (val) => (val as number / 100).toFixed(2), + }, + { + title: '退款金额(元)', + dataIndex: 'refundAmount', + render: (val) => (val as number / 100).toFixed(2), + }, + { + title: '平台分成(元)', + dataIndex: 'platformAmount', + render: (val) => (val as number / 100).toFixed(2), + }, + { + title: '景区分成(元)', + dataIndex: 'tourismAmount', + render: (val) => (val as number / 100).toFixed(2), + }, + ]; + + return ( + + columns={columns} + dataSource={data} + loading={loading} + search={false} + options={false} + pagination={false} + /> + ); +}; + +export default StatisticsTable; \ No newline at end of file diff --git a/zlt-web/react-web/src/main/frontend/src/pages/statistics/index.tsx b/zlt-web/react-web/src/main/frontend/src/pages/statistics/index.tsx new file mode 100644 index 00000000..964e277c --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/pages/statistics/index.tsx @@ -0,0 +1,144 @@ +import React, { useState, useEffect } from 'react'; +import { + PageContainer, + ProCard, + ProForm, + ProFormDateTimeRangePicker, + ProFormSelect, +} from '@ant-design/pro-components'; +import { Card, Tabs, message } from 'antd'; +import { Line, Column, Pie } from '@ant-design/plots'; +import { + generateStatistics, + getTimeStatistics, + getTourismStatistics, + getDeviceStatistics, +} from '@/services/statistics/api'; + +const Statistics: React.FC = () => { + const [timeData, setTimeData] = useState([]); + const [tourismData, setTourismData] = useState([]); + const [deviceData, setDeviceData] = useState([]); + const [loading, setLoading] = useState(false); + + // 获取统计数据 + const fetchStatistics = async (params: STATISTICS.StatisticsParams) => { + setLoading(true); + try { + // 生成统计数据 + await generateStatistics(params); + + // 获取各维度统计数据 + const [timeRes, tourismRes, deviceRes] = await Promise.all([ + getTimeStatistics(params), + getTourismStatistics(params), + getDeviceStatistics(params), + ]); + + if (timeRes.resp_code === 0) setTimeData(timeRes.data); + if (tourismRes.resp_code === 0) setTourismData(tourismRes.data); + if (deviceRes.resp_code === 0) setDeviceData(deviceRes.data); + } catch (error) { + message.error('获取统计数据失败'); + } finally { + setLoading(false); + } + }; + + // 时间维度图表配置 + const timeChartConfig = { + data: timeData, + xField: 'statisticsDate', + yField: 'totalAmount', + seriesField: 'type', + legend: { position: 'top' }, + }; + + // 景区维度图表配置 + const tourismChartConfig = { + data: tourismData.map(item => ({ + type: '订单总额', + value: item.totalAmount / 100, + tourism: item.tourismName, + })), + angleField: 'value', + colorField: 'tourism', + }; + + return ( + + + { + const [startTime, endTime] = values.timeRange || []; + await fetchStatistics({ + startTime, + endTime, + timeType: values.timeType, + }); + }} + > + + + + + + + + + ), + }, + { + key: 'tourism', + label: '景区维度统计', + children: ( + + + + ), + }, + { + key: 'device', + label: '设备维度统计', + children: ( + + + + ), + }, + ]} + /> + + ); +}; + +export default Statistics; \ No newline at end of file diff --git a/zlt-web/react-web/src/main/frontend/src/services/statistics/api.ts b/zlt-web/react-web/src/main/frontend/src/services/statistics/api.ts new file mode 100644 index 00000000..f5d989da --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/services/statistics/api.ts @@ -0,0 +1,97 @@ +import { request } from '@/utils/request'; +import moment from 'moment'; + +/** 生成统计数据 */ +export async function generateStatistics(params: { + startTime: string; + endTime: string; +}) { + return request('/api-order/statistics/generate', { + method: 'POST', + data: params, + }); +} + +/** 获取二维码维度统计数据 */ +export async function getQrcodeStatistics(params: { + startTime?: string; + endTime?: string; +}) { + const response = await request('/api-order/statistics/qrcode', { + method: 'GET', + params, + }); + return { + ...response, + data: processChartData(response.data || []), + }; +} + +/** 获取景区维度统计数据 */ +export async function getTourismStatistics(params: { + startTime?: string; + endTime?: string; +}) { + const response = await request('/api-order/statistics/tourism', { + method: 'GET', + params, + }); + return { + ...response, + data: processChartData(response.data || []), + }; +} + +/** 获取设备维度统计数据 */ +export async function getDeviceStatistics(params: { + startTime: string; + endTime: string; +}) { + return request('/api-order/statistics/device', { + method: 'GET', + params, + }); +} + +// 获取二维码时间维度统计数据 +export async function getQrcodeTimeStatistics(params: { + qrcodeId: string; + startTime: string; + endTime: string; + timeType?: 'hour' | 'day' | 'month'; +}) { + return request('/api-order/statistics/time', { + method: 'GET', + params, + }); +} + +// 获取时间维度统计数据 +export async function getTimeStatistics(params: { + qrcodeId: string; + startTime: string; + endTime: string; + timeType: 'hour' | 'day' | 'month'; +}) { + return request('/api-order/statistics/time', { + method: 'GET', + params, + }); +} + +// 获取二维码列表 +export async function getQrcodeList() { + return request('/api-order/qrcode/list', { + method: 'GET', + }); +} + +// 处理图表数据的辅助函数 +const processChartData = (data: any[]) => { + return data.map(item => ({ + ...item, + date: item.statisticsTime || moment().format('YYYY-MM-DD'), + value: item.amount || 0, + count: item.count || 0, + })); +}; \ No newline at end of file diff --git a/zlt-web/react-web/src/main/frontend/src/services/statistics/typings.d.ts b/zlt-web/react-web/src/main/frontend/src/services/statistics/typings.d.ts new file mode 100644 index 00000000..378a6825 --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/services/statistics/typings.d.ts @@ -0,0 +1,37 @@ +declare namespace STATISTICS { + interface OrderStatistics { + id: number; + qrcodeId: string; + tourismId: number; + tourismName: string; + deviceSn: string; + tenantId: string; + + totalOrders: number; + paidOrders: number; + completedOrders: number; + canceledOrders: number; + + totalAmount: number; + paidAmount: number; + refundAmount: number; + + platformRate: number; + tourismRate: number; + platformAmount: number; + tourismAmount: number; + + startTime: string; + endTime: string; + statisticsDate: string; + statisticsHour: number; + createTime: string; + } + + interface StatisticsParams { + qrcodeId: string; + startTime: string; + endTime: string; + timeType: 'hour' | 'day' | 'month'; + } +} \ No newline at end of file