From 511dccd742d2012cbde6869e5e92cc6bbbde9060 Mon Sep 17 00:00:00 2001 From: cesar liu Date: Tue, 29 Nov 2022 11:05:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E4=BD=B5=E7=B8=BD=E8=A8=88=EF=BC=8C?= =?UTF-8?q?=E9=99=A4=E4=BA=86=E4=BB=8A=E5=A4=A9=E4=B9=8B=E5=A4=96=E6=8A=93?= =?UTF-8?q?=E5=8F=96=20history=5Fday=20=E7=82=BA=E4=B8=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AnalysisStationCombineRepository.cs | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) 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, (