diff --git a/SolarPower/Repository/Implement/AnalysisStationCombineRepository.cs b/SolarPower/Repository/Implement/AnalysisStationCombineRepository.cs index a5cd4aa..b1dc7d1 100644 --- a/SolarPower/Repository/Implement/AnalysisStationCombineRepository.cs +++ b/SolarPower/Repository/Implement/AnalysisStationCombineRepository.cs @@ -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, (