1. 修改合併電站查詢方式
This commit is contained in:
parent
dc9023cf85
commit
ce14c7c84b
@ -192,57 +192,51 @@ namespace SolarPower.Repository.Implement
|
|||||||
switch (post.SeacrhType)
|
switch (post.SeacrhType)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
sql = $@"SELECT DATE_FORMAT(ps.TIMESTAMP,'%h %p') AS `Time`,
|
sql = $@"SELECT DATE_FORMAT(p.TIMESTAMP,'%h %p') AS `Time`,
|
||||||
SUM(ps.KWH) AS KWH,
|
SUM(p.KWH) AS KWH,
|
||||||
SUM(sh.Irradiance) AS Irradiance,
|
SUM(s.Irradiance) AS Irradiance,
|
||||||
AVG(sh.Temperature) AS Temperature
|
AVG(s.Temperature) AS Temperature
|
||||||
FROM power_station_history_hour ps
|
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 sensor_history_hour sh
|
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 sh.TIMESTAMP = ps.TIMESTAMP AND sh.PowerStationId = ps.PowerStationId
|
ON p.TIMESTAMP = s.TIMESTAMP AND p.PowerStationId = s.PowerStationId
|
||||||
WHERE ps.PowerStationId IN @ids AND DATE_FORMAT(sh.TIMESTAMP,'%Y-%m-%d') = '{post.Timerange}'
|
GROUP BY p.TIMESTAMP";
|
||||||
GROUP BY ps.TIMESTAMP";
|
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
var time = post.Timerange.Replace(" ","").Split('-');
|
var time = post.Timerange.Replace(" ","").Split('-');
|
||||||
sql = $@"SELECT
|
sql = $@"SELECT
|
||||||
DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d') AS `Time`,
|
DATE_FORMAT(p.TIMESTAMP,'%Y-%m-%d') AS `Time`,
|
||||||
SUM(ps.TODAYKWH) AS KWH,
|
SUM(p.TODAYKWH) AS KWH,
|
||||||
SUM(sh.Irradiance) AS Irradiance,
|
SUM(s.Irradiance) AS Irradiance,
|
||||||
AVG(sh.Temperature) AS Temperature
|
AVG(s.Temperature) AS Temperature
|
||||||
FROM power_station_history_day ps
|
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 sensor_history_day sh
|
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 sh.TIMESTAMP = ps.TIMESTAMP
|
ON s.TIMESTAMP = p.TIMESTAMP AND p.PowerStationId = s.PowerStationId
|
||||||
WHERE ps.PowerStationId IN @ids AND DATE_FORMAT(sh.TIMESTAMP,'%Y-%m-%d') BETWEEN '{time[0].Replace('/', '-')}' AND '{time[1].Replace('/', '-')}'
|
GROUP BY p.TIMESTAMP";
|
||||||
GROUP BY ps.TIMESTAMP";
|
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
sql = $@"SELECT
|
sql = $@"SELECT
|
||||||
DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d') AS `Time`,
|
DATE_FORMAT(p.TIMESTAMP,'%Y-%m-%d') AS `Time`,
|
||||||
SUM(ps.TODAYKWH) AS KWH,
|
SUM(p.TODAYKWH) AS KWH,
|
||||||
SUM(sh.Irradiance) AS Irradiance,
|
SUM(s.Irradiance) AS Irradiance,
|
||||||
AVG(sh.Temperature) AS Temperature
|
AVG(s.Temperature) AS Temperature
|
||||||
FROM power_station_history_day ps
|
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 sensor_history_day sh
|
LEFT JOIN (SELECT * FROM sensor_history_day sh WHERE sh.PowerStationId IN @ids AND DATE_FORMAT(sh.TIMESTAMP,'%Y-%m') = '{post.Timerange}') s
|
||||||
ON sh.TIMESTAMP = ps.TIMESTAMP
|
ON s.TIMESTAMP = p.TIMESTAMP AND p.PowerStationId = s.PowerStationId
|
||||||
WHERE ps.PowerStationId IN @ids AND DATE_FORMAT(sh.TIMESTAMP,'%Y-%m') = '{post.Timerange}'
|
GROUP BY p.TIMESTAMP";
|
||||||
GROUP BY ps.TIMESTAMP";
|
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
sql = $@"SELECT
|
sql = $@"SELECT
|
||||||
DATE_FORMAT(ps.TIMESTAMP,'%Y-%m') AS `Time`,
|
DATE_FORMAT(p.TIMESTAMP,'%Y-%m') AS `Time`,
|
||||||
SUM(ps.MONTHKWH) AS KWH,
|
SUM(p.MONTHKWH) AS KWH,
|
||||||
SUM(sh.Irradiance) AS Irradiance,
|
SUM(s.Irradiance) AS Irradiance,
|
||||||
AVG(sh.Temperature) AS Temperature
|
AVG(s.Temperature) AS Temperature
|
||||||
FROM power_station_history_month ps
|
FROM (SELECT * FROM power_station_history_month ps WHERE ps.PowerStationId IN @ids AND DATE_FORMAT(ps.TIMESTAMP,'%Y') = '{post.Timerange}') p
|
||||||
LEFT JOIN sensor_history_month sh
|
LEFT JOIN (SELECT * FROM sensor_history_month sh WHERE sh.PowerStationId IN @ids AND DATE_FORMAT(sh.TIMESTAMP,'%Y') = '{post.Timerange}') s
|
||||||
ON sh.TIMESTAMP = ps.TIMESTAMP
|
ON s.TIMESTAMP = p.TIMESTAMP AND p.PowerStationId = s.PowerStationId
|
||||||
WHERE ps.PowerStationId IN @ids AND DATE_FORMAT(sh.TIMESTAMP,'%Y') = '{post.Timerange}'
|
GROUP BY p.TIMESTAMP";
|
||||||
GROUP BY ps.TIMESTAMP";
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
a = (await conn.QueryAsync<Chartoutput>(sql,new { ids = post.StationIds})).ToList();
|
a = (await conn.QueryAsync<Chartoutput>(sql,new { ids = post.StationIds})).ToList();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user