合併總計,除了今天之外抓取 history_day 為主
This commit is contained in:
parent
a31712020b
commit
511dccd742
@ -35,6 +35,7 @@ namespace SolarPower.Repository.Implement
|
|||||||
case 0:
|
case 0:
|
||||||
string timerange = Convert.ToDateTime(post.Timerange).ToString("yyyy-MM-dd");
|
string timerange = Convert.ToDateTime(post.Timerange).ToString("yyyy-MM-dd");
|
||||||
var today = "";
|
var today = "";
|
||||||
|
string today_sumKwh = "";
|
||||||
if(timerange == DateTime.Now.ToString("yyyy-MM-dd"))
|
if(timerange == DateTime.Now.ToString("yyyy-MM-dd"))
|
||||||
{
|
{
|
||||||
today = @$" SELECT
|
today = @$" SELECT
|
||||||
@ -42,6 +43,12 @@ namespace SolarPower.Repository.Implement
|
|||||||
FROM
|
FROM
|
||||||
power_station a
|
power_station a
|
||||||
WHERE a.Id IN @ids ";
|
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
|
else
|
||||||
{
|
{
|
||||||
@ -50,17 +57,18 @@ namespace SolarPower.Repository.Implement
|
|||||||
FROM
|
FROM
|
||||||
sensor_history_day a
|
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
|
sql = $@" SELECT m.*,n.*,o.*,p.* FROM
|
||||||
(
|
(
|
||||||
SELECT
|
{today_sumKwh}
|
||||||
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
|
|
||||||
)
|
)
|
||||||
AS m,
|
AS m,
|
||||||
(
|
(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user