合併總計,除了今天之外抓取 history_day 為主

This commit is contained in:
cesar liu 2022-11-29 11:05:51 +08:00
parent a31712020b
commit 511dccd742

View File

@ -35,6 +35,7 @@ namespace SolarPower.Repository.Implement
case 0:
string timerange = Convert.ToDateTime(post.Timerange).ToString("yyyy-MM-dd");
var today = "";
string today_sumKwh = "";
if(timerange == DateTime.Now.ToString("yyyy-MM-dd"))
{
today = @$" SELECT
@ -42,6 +43,12 @@ namespace SolarPower.Repository.Implement
FROM
power_station a
WHERE a.Id IN @ids ";
today_sumKwh = @$"SELECT
SUM(ps.Total_kwh) AS All_kwh,
SUM(ps.total_money) AS All_money,
SUM(ps.total_carbon) AS All_Carbon
FROM power_station ps
WHERE ps.Id IN @ids";
}
else
{
@ -49,18 +56,19 @@ namespace SolarPower.Repository.Implement
AVG(a.irrDayHour) AS Now_irradiance
FROM
sensor_history_day a
WHERE a.PowerStationId IN @ids AND DATE_FORMAT(a.TIMESTAMP,'%Y-%m-%d') = '{timerange}'";
}
WHERE a.PowerStationId IN @ids AND DATE_FORMAT(a.TIMESTAMP,'%Y-%m-%d') = '{timerange}'";
today_sumKwh = @$"SELECT
SUM(ps.Totalkwh) AS All_kwh,
SUM(ps.totalmoney) AS All_money,
SUM(ps.totalCarbon) AS All_Carbon
FROM power_station_history_day ps
WHERE DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = '{timerange}' and PowerStationId IN @ids ";
}
sql = $@" SELECT m.*,n.*,o.*,p.* FROM
(
SELECT
SUM(ps.Total_kwh) AS All_kwh,
SUM(ps.total_money) AS All_money,
SUM(ps.total_carbon) AS All_Carbon
FROM power_station ps
WHERE ps.Id IN @ids
{today_sumKwh}
)
AS m,
(