From 27d3edaa0f88dbcfd13ffed9a68771e930a14264 Mon Sep 17 00:00:00 2001 From: dev02 Date: Mon, 22 May 2023 18:12:40 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=BE=8C=E7=AB=AF]=20=E6=B0=B4=E9=9B=BB?= =?UTF-8?q?=E5=A0=B1=E8=A1=A8=20=E4=BF=AE=E6=94=B9=E5=B9=B4=E5=BA=A6?= =?UTF-8?q?=E5=A0=B1=E8=A1=A8group=20by=20=E5=95=8F=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FrontendWebApi/ApiControllers/HydroMeterController.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/FrontendWebApi/ApiControllers/HydroMeterController.cs b/FrontendWebApi/ApiControllers/HydroMeterController.cs index 3d9dfcf..ba6a116 100644 --- a/FrontendWebApi/ApiControllers/HydroMeterController.cs +++ b/FrontendWebApi/ApiControllers/HydroMeterController.cs @@ -87,6 +87,8 @@ namespace FrontendWebApi.ApiControllers var table = input.tableType == "year" ? "archive_electric_meter_day" : "archive_electric_meter_" + input.tableType; var dateFormat = input.tableType == "day" || input.tableType == "week" ? "%Y-%m-%d" : input.tableType == "month" ? "%Y-%m" : input.tableType == "year" ? "%Y" : null; + var aemmEndDate = input.tableType == "year" ? $"year(DATE_ADD(fd.date, INTERVAL +1 {input.tableType}))" : $"DATE_ADD(fd.date, INTERVAL +1 {input.tableType})"; + var aemmStaDate = input.tableType == "year" ? "year(fd.date)" : "fd.date"; var sql = $@"set @i = -1; select fd.device_number, aemm.avg_rawdata, DATE_FORMAT(fd.date, @dateFormat) as timestamp from ( @@ -111,7 +113,7 @@ namespace FrontendWebApi.ApiControllers from {table} where start_timestamp >= @startTime and end_timestamp < @endTime and point = 'KWH' and SUBSTRING_INDEX(device_number, '_', 1) = @building_tag {sqlWhere} {sqlGroup} - ) aemm on aemm.start_timestamp >= fd.date and aemm.end_timestamp < DATE_ADD(fd.date, INTERVAL +1 {input.tableType}) and aemm.device_number = fd.device_number + ) aemm on aemm.start_timestamp >= {aemmStaDate} and aemm.end_timestamp < {aemmEndDate} and aemm.device_number = fd.device_number order by fd.device_number, fd.date"; var rawData = await backendRepository.GetAllAsync(sql, new { startTime = startTime, endtime = endTime, building_tag = input.building_tag, floor_tag = input.floor_tag, dateFormat = dateFormat });