diff --git a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs index 5223923..2e3364e 100644 --- a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs @@ -131,6 +131,8 @@ namespace SolarPower.Quartz.Jobs #region 發電金額 history.MONEY = history.KWH * powerStation.PowerRate; + history.TODAYMONEY = history.TodayKWh * powerStation.PowerRate; + history.TOTALMONEY = history.TotalKWH * powerStation.PowerRate; //即時發電金額 switch (powerStation.SolarType) @@ -229,6 +231,8 @@ namespace SolarPower.Quartz.Jobs carbonRate = Convert.ToDouble(await powerStationRepository.GetOneVariableByName("CarbonRate")); history.CARBON = history.KWH * carbonRate; + history.TODAYCARBON = history.TodayKWh * carbonRate; + history.TOTALCARBON = history.TotalKWH * carbonRate; //if (lastmoneyhistorybyhour != null) //{ // history.TODAYCARBON = lastmoneyhistorybyhour.TODAYCARBON + history.KWH * carbonRate; diff --git a/SolarPower/Repository/Implement/AnalysisStationCombineRepository.cs b/SolarPower/Repository/Implement/AnalysisStationCombineRepository.cs index c7ebc26..7b40134 100644 --- a/SolarPower/Repository/Implement/AnalysisStationCombineRepository.cs +++ b/SolarPower/Repository/Implement/AnalysisStationCombineRepository.cs @@ -192,57 +192,51 @@ namespace SolarPower.Repository.Implement switch (post.SeacrhType) { case 0: - sql = $@"SELECT DATE_FORMAT(ps.TIMESTAMP,'%h %p') AS `Time`, - SUM(ps.KWH) AS KWH, - SUM(sh.Irradiance) AS Irradiance, - AVG(sh.Temperature) AS Temperature - FROM power_station_history_hour ps - LEFT JOIN sensor_history_hour sh - ON sh.TIMESTAMP = ps.TIMESTAMP AND sh.PowerStationId = ps.PowerStationId - WHERE ps.PowerStationId IN @ids AND DATE_FORMAT(sh.TIMESTAMP,'%Y-%m-%d') = '{post.Timerange}' - GROUP BY ps.TIMESTAMP"; + sql = $@"SELECT DATE_FORMAT(p.TIMESTAMP,'%h %p') AS `Time`, + SUM(p.KWH) AS KWH, + SUM(s.Irradiance) AS Irradiance, + AVG(s.Temperature) AS Temperature + 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"; break; case 1: var time = post.Timerange.Replace(" ","").Split('-'); sql = $@"SELECT - DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d') AS `Time`, - SUM(ps.TODAYKWH) AS KWH, - SUM(sh.Irradiance) AS Irradiance, - AVG(sh.Temperature) AS Temperature - FROM power_station_history_day ps - LEFT JOIN sensor_history_day sh - ON sh.TIMESTAMP = ps.TIMESTAMP - WHERE ps.PowerStationId IN @ids AND DATE_FORMAT(sh.TIMESTAMP,'%Y-%m-%d') BETWEEN '{time[0].Replace('/', '-')}' AND '{time[1].Replace('/', '-')}' - GROUP BY ps.TIMESTAMP"; + DATE_FORMAT(p.TIMESTAMP,'%Y-%m-%d') AS `Time`, + SUM(p.TODAYKWH) AS KWH, + SUM(s.Irradiance) AS Irradiance, + AVG(s.Temperature) AS Temperature + 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"; break; case 2: sql = $@"SELECT - DATE_FORMAT(ps.TIMESTAMP,'%Y-%m-%d') AS `Time`, - SUM(ps.TODAYKWH) AS KWH, - SUM(sh.Irradiance) AS Irradiance, - AVG(sh.Temperature) AS Temperature - FROM power_station_history_day ps - LEFT JOIN sensor_history_day sh - ON sh.TIMESTAMP = ps.TIMESTAMP - WHERE ps.PowerStationId IN @ids AND DATE_FORMAT(sh.TIMESTAMP,'%Y-%m') = '{post.Timerange}' - GROUP BY ps.TIMESTAMP"; + DATE_FORMAT(p.TIMESTAMP,'%Y-%m-%d') AS `Time`, + SUM(p.TODAYKWH) AS KWH, + SUM(s.Irradiance) AS Irradiance, + AVG(s.Temperature) AS Temperature + 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"; break; case 3: sql = $@"SELECT - DATE_FORMAT(ps.TIMESTAMP,'%Y-%m') AS `Time`, - SUM(ps.MONTHKWH) AS KWH, - SUM(sh.Irradiance) AS Irradiance, - AVG(sh.Temperature) AS Temperature - FROM power_station_history_month ps - LEFT JOIN sensor_history_month sh - ON sh.TIMESTAMP = ps.TIMESTAMP - WHERE ps.PowerStationId IN @ids AND DATE_FORMAT(sh.TIMESTAMP,'%Y') = '{post.Timerange}' - GROUP BY ps.TIMESTAMP"; + DATE_FORMAT(p.TIMESTAMP,'%Y-%m') AS `Time`, + SUM(p.MONTHKWH) AS KWH, + SUM(s.Irradiance) AS Irradiance, + AVG(s.Temperature) AS Temperature + 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"; break; } a = (await conn.QueryAsync(sql,new { ids = post.StationIds})).ToList(); - - } catch (Exception exception) { diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index cb93614..32d5cf8 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -4473,7 +4473,7 @@ namespace SolarPower.Repository.Implement sql_perSiteDB.Add(temp_sql); } - sql = string.Join(" UNION ", sql_perSiteDB); + sql = "SELECT * FROM (" + string.Join(" UNION ", sql_perSiteDB) + ") a ORDER BY a.TIMESTAMP ASC"; result = (await conn.QueryAsync(sql, new { NowDay = nowDay })).ToList(); } @@ -4504,7 +4504,7 @@ namespace SolarPower.Repository.Implement var temp_sql = $@"SELECT DATE_FORMAT(inv.TIMESTAMP, '%Y-%m-%d') AS TIMESTAMP, - INVERTERID, + inv.INVERTERID, i.InverterName AS INVERTERName, inv.Irradiance, inv.KWH, @@ -4523,7 +4523,7 @@ namespace SolarPower.Repository.Implement sql_perSiteDB.Add(temp_sql); } - sql = string.Join(" UNION ", sql_perSiteDB); + sql = "SELECT * FROM (" + string.Join(" UNION ", sql_perSiteDB) + ") a ORDER BY a.TIMESTAMP ASC"; result = (await conn.QueryAsync(sql, new { StartDay = startDay, EndDay = endDay })).ToList(); } @@ -4554,7 +4554,7 @@ namespace SolarPower.Repository.Implement var temp_sql = $@"SELECT DATE_FORMAT(inv.TIMESTAMP, '%Y-%m-%d') AS TIMESTAMP, - INVERTERID, + inv.INVERTERID, i.InverterName AS INVERTERName, inv.KWH, inv.TODAYKWH, diff --git a/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml b/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml index 50841ca..237b047 100644 --- a/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml +++ b/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml @@ -22,12 +22,12 @@

- 新竹巨城站 + 電站名稱

-

27°C
降雨幾率: 15%

+

27°C
降雨幾率: 0%