[後端] 水電報表 修改年度報表group by 問題
This commit is contained in:
parent
86548b7fb6
commit
27d3edaa0f
@ -87,6 +87,8 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
|
|
||||||
var table = input.tableType == "year" ? "archive_electric_meter_day" : "archive_electric_meter_" + input.tableType;
|
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 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;
|
var sql = $@"set @i = -1;
|
||||||
select fd.device_number, aemm.avg_rawdata, DATE_FORMAT(fd.date, @dateFormat) as timestamp
|
select fd.device_number, aemm.avg_rawdata, DATE_FORMAT(fd.date, @dateFormat) as timestamp
|
||||||
from (
|
from (
|
||||||
@ -111,7 +113,7 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
from {table}
|
from {table}
|
||||||
where start_timestamp >= @startTime and end_timestamp < @endTime and point = 'KWH' and SUBSTRING_INDEX(device_number, '_', 1) = @building_tag
|
where start_timestamp >= @startTime and end_timestamp < @endTime and point = 'KWH' and SUBSTRING_INDEX(device_number, '_', 1) = @building_tag
|
||||||
{sqlWhere} {sqlGroup}
|
{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";
|
order by fd.device_number, fd.date";
|
||||||
var rawData = await backendRepository.GetAllAsync<HydroMeterRawDataOutput>(sql,
|
var rawData = await backendRepository.GetAllAsync<HydroMeterRawDataOutput>(sql,
|
||||||
new { startTime = startTime, endtime = endTime, building_tag = input.building_tag, floor_tag = input.floor_tag, dateFormat = dateFormat });
|
new { startTime = startTime, endtime = endTime, building_tag = input.building_tag, floor_tag = input.floor_tag, dateFormat = dateFormat });
|
||||||
|
Loading…
Reference in New Issue
Block a user