debug : 合併電站 - 累計日照欄位

This commit is contained in:
cesar liu 2022-09-15 11:37:10 +08:00
parent 518ec7ec81
commit 437e3e3150

View File

@ -46,7 +46,7 @@ namespace SolarPower.Repository.Implement
else
{
today = $@" SELECT
AVG(a.Irradiance) AS Now_irradiance
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}'";
@ -101,13 +101,13 @@ namespace SolarPower.Repository.Implement
FROM
(SELECT AVG(a.today_irradiance) AS Now_irradiance FROM power_station a WHERE a.Id IN (1)
UNION
SELECT AVG(b.Irradiance) AS Now_irradiance FROM sensor_history_day b
SELECT AVG(b.irrDay) AS Now_irradiance FROM sensor_history_day b
WHERE b.PowerStationId IN (1) AND DATE_FORMAT(b.TIMESTAMP, '%Y/%m/%d') BETWEEN '{time[0].Replace(" ", "")}' AND '{Convert.ToDateTime(time[1].Replace(" ", "")).AddDays(-1).ToString("yyyy/MM/dd")}') c";
}
else
{
ttot = @$" SELECT
AVG(a.Irradiance) AS Now_irradiance
AVG(a.irrDay) AS Now_irradiance
FROM
sensor_history_day a
WHERE a.PowerStationId IN @ids AND DATE_FORMAT(a.TIMESTAMP, '%Y/%m/%d') BETWEEN '{time[0].Replace(" ", "")}' AND '{time[1].Replace(" ", "")}'";
@ -181,7 +181,7 @@ namespace SolarPower.Repository.Implement
AS o,
(
SELECT
AVG(a.Irradiance) AS Now_irradiance
AVG(a.IrrDay) AS Now_irradiance
from sensor_history_month a
WHERE PowerStationId IN @ids AND DATE_FORMAT(TIMESTAMP, '%Y-%m') = '{post.Timerange}'
) AS p";
@ -220,7 +220,7 @@ namespace SolarPower.Repository.Implement
AS o,
(
SELECT
AVG(a.Irradiance) AS Now_irradiance
AVG(a.IrrDay) AS Now_irradiance
from sensor_history_month a
WHERE PowerStationId IN @ids AND DATE_FORMAT(TIMESTAMP, '%Y') = '{post.Timerange}'
) AS p";
@ -263,7 +263,7 @@ namespace SolarPower.Repository.Implement
FROM (SELECT * FROM power_station_history_hour ps WHERE ps.PowerStationId IN @ids AND DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d') = '{post.Timerange}') p
LEFT JOIN (SELECT * FROM sensor_history_hour sh WHERE sh.PowerStationId IN @ids AND DATE_FORMAT(sh.TIMESTAMP,'%Y-%m-%d') = '{post.Timerange}') s
ON p.TIMESTAMP = s.TIMESTAMP AND p.PowerStationId = s.PowerStationId
GROUP BY p.TIMESTAMP";
GROUP BY p.TIMESTAMP order by p.TIMESTAMP";
break;
case 1:
var time = post.Timerange.Replace(" ","").Split('-');
@ -275,7 +275,7 @@ namespace SolarPower.Repository.Implement
FROM (SELECT * FROM power_station_history_day ps WHERE ps.PowerStationId IN @ids AND DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d') BETWEEN '{time[0].Replace('/', '-')}' AND '{time[1].Replace('/', '-')}') p
LEFT JOIN (SELECT * FROM sensor_history_day sh WHERE sh.PowerStationId IN @ids AND DATE_FORMAT(sh.TIMESTAMP,'%Y-%m-%d') BETWEEN '{time[0].Replace('/', '-')}' AND '{time[1].Replace('/', '-')}') s
ON s.TIMESTAMP = p.TIMESTAMP AND p.PowerStationId = s.PowerStationId
GROUP BY p.TIMESTAMP";
GROUP BY DATE_FORMAT(p.TIMESTAMP,'%Y-%m-%d') order by p.TIMESTAMP ";
break;
case 2:
sql = $@"SELECT
@ -286,7 +286,7 @@ namespace SolarPower.Repository.Implement
FROM (SELECT * FROM power_station_history_day ps WHERE ps.PowerStationId IN @ids AND DATE_FORMAT(ps.TIMESTAMP,'%Y-%m') = '{post.Timerange}') p
LEFT JOIN (SELECT * FROM sensor_history_day sh WHERE sh.PowerStationId IN @ids AND DATE_FORMAT(sh.TIMESTAMP,'%Y-%m') = '{post.Timerange}') s
ON s.TIMESTAMP = p.TIMESTAMP AND p.PowerStationId = s.PowerStationId
GROUP BY p.TIMESTAMP";
GROUP BY p.TIMESTAMP order by p.TIMESTAMP";
break;
case 3:
sql = $@"SELECT
@ -297,7 +297,7 @@ namespace SolarPower.Repository.Implement
FROM (SELECT * FROM power_station_history_month ps WHERE ps.PowerStationId IN @ids AND DATE_FORMAT(ps.TIMESTAMP,'%Y') = '{post.Timerange}') p
LEFT JOIN (SELECT * FROM sensor_history_month sh WHERE sh.PowerStationId IN @ids AND DATE_FORMAT(sh.TIMESTAMP,'%Y') = '{post.Timerange}') s
ON s.TIMESTAMP = p.TIMESTAMP AND p.PowerStationId = s.PowerStationId
GROUP BY p.TIMESTAMP";
GROUP BY p.TIMESTAMP order by p.TIMESTAMP";
break;
}
a = (await conn.QueryAsync<Chartoutput>(sql,new { ids = post.StationIds})).ToList();