From 3c61e79575499a5a7f125cebb2ee5916a1f73ce4 Mon Sep 17 00:00:00 2001 From: Kai Date: Tue, 2 Nov 2021 10:55:16 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E4=BF=AE=E6=94=B9=E9=80=86=E8=AE=8A?= =?UTF-8?q?=E5=99=A8=E5=88=86=E6=9E=90=20=E8=AE=80=E5=8F=96rawdata?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Controllers/AnalysisInverterController.cs | 8 +++++++- SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs | 2 +- .../Repository/Implement/PowerStationRepository.cs | 11 +++++++---- .../Repository/Interface/IPowerStationRepository.cs | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/SolarPower/Controllers/AnalysisInverterController.cs b/SolarPower/Controllers/AnalysisInverterController.cs index 2539ff3..27e603f 100644 --- a/SolarPower/Controllers/AnalysisInverterController.cs +++ b/SolarPower/Controllers/AnalysisInverterController.cs @@ -110,7 +110,13 @@ namespace SolarPower.Controllers StationCodeWithInverterIdsList.Add(stationCodeWithInverterIds); } - inverterHistories = await powerStationRepository.GetInverterHistoryRowData(post.SelectedDate, StationCodeWithInverterIdsList); + var date_start = Convert.ToDateTime(post.SelectedDate.Trim() + " 00:00:00"); + var date_end = Convert.ToDateTime(post.SelectedDate.Trim() + " 23:59:59"); + + var start_timestamp = (long)date_start.Subtract(new DateTime(1970, 1, 1).AddHours(8)).TotalMilliseconds; + var end_timestamp = (long)date_end.Subtract(new DateTime(1970, 1, 1).AddHours(8)).TotalMilliseconds; + + inverterHistories = await powerStationRepository.GetInverterHistoryRowData(start_timestamp, end_timestamp, StationCodeWithInverterIdsList); analysisInverter.XAxis = inverterHistories.Select(x => x.TIMESTAMP).Distinct().ToList(); diff --git a/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs index 06398f5..dca722f 100644 --- a/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs @@ -870,7 +870,7 @@ namespace SolarPower.Quartz.Jobs #endregion #region 寄送日月報 - var users = userRepository.GetAllAsync(); + var users = userRepository.GetAllAsync(); var ttt = new List() { "s506488@gmail.com", "cesarliuc@gmail.com" diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index 1e91b32..be82d22 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -4402,7 +4402,7 @@ namespace SolarPower.Repository.Implement } } - public async Task> GetInverterHistoryRowData(string nowDay, List entities) + public async Task> GetInverterHistoryRowData(long start_timestamp, long end_timestamp, List entities) { List result; using (IDbConnection conn = this._databaseHelper.GetConnection()) @@ -4466,16 +4466,19 @@ namespace SolarPower.Repository.Implement inv.RA4, inv.RA5 FROM {table_name} inv - LEFT JOIN {sensor_table_name} sen ON FROM_UNIXTIME(inv.TIMESTAMP/1000, '%Y-%m-%d %H:%i') = FROM_UNIXTIME(sen.TIMESTAMP/1000, '%Y-%m-%d %H:%i') + LEFT JOIN (select * from {sensor_table_name} where TIMESTAMP between @start_timestamp and @end_timestamp)sen + ON FROM_UNIXTIME(inv.TIMESTAMP/1000, '%Y-%m-%d %H:%i') = FROM_UNIXTIME(sen.TIMESTAMP/1000, '%Y-%m-%d %H:%i') + -- LEFT JOIN {sensor_table_name} sen ON FROM_UNIXTIME(inv.TIMESTAMP/1000, '%Y-%m-%d %H:%i') = FROM_UNIXTIME(sen.TIMESTAMP/1000, '%Y-%m-%d %H:%i') LEFT JOIN {entity.SiteDB}.inverter i ON inv.INVERTERID = i.InverterId - WHERE FROM_UNIXTIME(inv.TIMESTAMP/1000, '%Y-%m-%d') = @NowDay + WHERE inv.`TIMESTAMP` between @start_timestamp and @end_timestamp + -- WHERE FROM_UNIXTIME(inv.TIMESTAMP/1000, '%Y-%m-%d') = @NowDay AND inv.INVERTERID IN ('{inverterIds}')"; sql_perSiteDB.Add(temp_sql); } sql = "SELECT * FROM (" + string.Join(" UNION ", sql_perSiteDB) + ") a ORDER BY a.TIMESTAMP ASC"; - result = (await conn.QueryAsync(sql, new { NowDay = nowDay }, commandTimeout: 300)).ToList(); + result = (await conn.QueryAsync(sql, new { start_timestamp = start_timestamp, end_timestamp = end_timestamp }, commandTimeout: 300)).ToList(); } catch (Exception exception) { diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index 8b585a9..5d02c26 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -574,7 +574,7 @@ namespace SolarPower.Repository.Interface Task> GetPowerStationsByCompanyId(MyUser myUser); Task> GetPowerStationInverter(Dictionary> dic, string filter); Task> GetPowerStationDevice(Dictionary> dic, string filter); - Task> GetInverterHistoryRowData(string nowDay, List entities); + Task> GetInverterHistoryRowData(long start_timestamp, long end_timestamp, List entities); Task> GetInverterHistoryByDate(string startDay, string endDay, List entities); Task> GetInverterHistoryByYear(string year, List entities); Task> GetPowerStationsByCompanyIdWithfilter(MyUser myUser, string filter);