From 259784f525977329dbe74a45bd1f4c49a209db67 Mon Sep 17 00:00:00 2001 From: mashili Date: Tue, 1 Jul 2025 21:21:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A6=82=E7=8E=87=E7=BB=9F=E8=AE=A1-=E7=94=B5?= =?UTF-8?q?=E9=87=8F=E6=8C=87=E6=A0=87=E9=BB=98=E8=AE=A47=E5=A4=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ems/EmsStatisticalReportController.java | 2 -- .../service/impl/EmsStatsReportServiceImpl.java | 15 +++++++++++++++ .../resources/mapper/ems/EmsPcsDataMapper.xml | 4 +++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/ems-admin/src/main/java/com/xzzn/web/controller/ems/EmsStatisticalReportController.java b/ems-admin/src/main/java/com/xzzn/web/controller/ems/EmsStatisticalReportController.java index 7786264..761484f 100644 --- a/ems-admin/src/main/java/com/xzzn/web/controller/ems/EmsStatisticalReportController.java +++ b/ems-admin/src/main/java/com/xzzn/web/controller/ems/EmsStatisticalReportController.java @@ -10,8 +10,6 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.util.Date; - /** * 单站监控-统计报表 * diff --git a/ems-system/src/main/java/com/xzzn/ems/service/impl/EmsStatsReportServiceImpl.java b/ems-system/src/main/java/com/xzzn/ems/service/impl/EmsStatsReportServiceImpl.java index 631dab7..bd59fc7 100644 --- a/ems-system/src/main/java/com/xzzn/ems/service/impl/EmsStatsReportServiceImpl.java +++ b/ems-system/src/main/java/com/xzzn/ems/service/impl/EmsStatsReportServiceImpl.java @@ -1,16 +1,21 @@ package com.xzzn.ems.service.impl; +import com.xzzn.common.utils.DateUtils; import com.xzzn.ems.domain.vo.DateSearchRequest; import com.xzzn.ems.domain.vo.ElectricDataInfoVo; import com.xzzn.ems.domain.vo.SiteMonitorDataVo; import com.xzzn.ems.mapper.EmsPcsDataMapper; import com.xzzn.ems.service.IEmsStatsReportService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import java.math.BigDecimal; import java.math.RoundingMode; +import java.time.LocalDate; +import java.util.Date; import java.util.List; /** @@ -23,6 +28,8 @@ import java.util.List; public class EmsStatsReportServiceImpl implements IEmsStatsReportService { + private static final Logger log = LoggerFactory.getLogger(EmsStatsReportServiceImpl.class); + @Autowired private EmsPcsDataMapper emsPcsDataMapper; @@ -30,6 +37,14 @@ public class EmsStatsReportServiceImpl implements IEmsStatsReportService public ElectricDataInfoVo getElectricDataResult(DateSearchRequest requestVo) { ElectricDataInfoVo electricDataInfoVo = new ElectricDataInfoVo(); + Date startDate = requestVo.getStartDate(); + Date endDate = requestVo.getEndDate(); + if (startDate == null && endDate == null) { + // 如果没有传时间,默认从今天往前7天 + LocalDate sevenDaysAgo = LocalDate.now().minusDays(6); + startDate = DateUtils.toDate(sevenDaysAgo); + requestVo.setStartDate(startDate); + } // 根据时间获取每天的充放电量 List dataList = emsPcsDataMapper.getPcsDataByDate(requestVo); if (!CollectionUtils.isEmpty(dataList)){ diff --git a/ems-system/src/main/resources/mapper/ems/EmsPcsDataMapper.xml b/ems-system/src/main/resources/mapper/ems/EmsPcsDataMapper.xml index 20dcad0..919d039 100644 --- a/ems-system/src/main/resources/mapper/ems/EmsPcsDataMapper.xml +++ b/ems-system/src/main/resources/mapper/ems/EmsPcsDataMapper.xml @@ -379,8 +379,10 @@ from ( SELECT p.site_id, p.device_id,p.date_month,p.date_day, MAX(p.data_update_time) AS max_update_time FROM ems_pcs_data p where p.site_id = #{siteId} - + and p.data_update_time >= #{startDate} + + and p.data_update_time < DATE_ADD(#{endDate}, INTERVAL 1 DAY) GROUP BY p.site_id,p.device_id,p.date_month,p.date_day