From 3472af5b4341d655e862a757adb32c2e4898e370 Mon Sep 17 00:00:00 2001 From: Kai Date: Wed, 7 Jul 2021 17:17:30 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E8=83=8C=E6=99=AF=E5=9F=B7=E8=A1=8C=20?= =?UTF-8?q?=E6=97=A5=E7=85=A7=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Models/PowerStation.cs | 23 +- .../Quartz/Jobs/CalcAvgPowerStationJob.cs | 103 ++++-- SolarPower/Quartz/Jobs/CalcPowerStationJob.cs | 67 ++-- .../Implement/PowerStationRepository.cs | 307 +++++++++++++++++- .../Interface/IPowerStationRepository.cs | 22 +- 5 files changed, 464 insertions(+), 58 deletions(-) diff --git a/SolarPower/Models/PowerStation.cs b/SolarPower/Models/PowerStation.cs index c243ffd..b65e300 100644 --- a/SolarPower/Models/PowerStation.cs +++ b/SolarPower/Models/PowerStation.cs @@ -123,6 +123,8 @@ namespace SolarPower.Models.PowerStation public double Avg_PR { get; set; } public double Today_Carbon { get; set; } //今日減碳量 public double Total_Carbon { get; set; } //總減碳量 + public double Today_irradiance { get; set; } //即時平均日照度 + public double Avg_irradiance { get; set; } //平均日照度(30天) public double SolarHour { get; set; } //總運轉小時 public string SiteDB { get; set; } //電站 DB name: solar_com public string TodayWeather { get; set; } //今日天氣 @@ -569,7 +571,7 @@ namespace SolarPower.Models.PowerStation public class PowerStationHistory { public int PowerStationId { get; set; } - public Int64 Timestamp { get; set; } + public string Timestamp { get; set; } public string SITEID { get; set; } public string SiteType { get; set; } public double KWH { get; set; } @@ -586,7 +588,6 @@ namespace SolarPower.Models.PowerStation public int PowerStationId { get; set; } public double AvgKWHKWP { get; set; } public double AvgPR { get; set; } - } public class PowerStationHistoryDay @@ -617,6 +618,24 @@ namespace SolarPower.Models.PowerStation public double SolarHour { get; set; } } + public class PyrheliometerHistory + { + public int PowerStationId { get; set; } + public string Timestamp { get; set; } + public double Irradiance { get; set; } + } + public class AvgPyrheliometerHistory + { + public int PowerStationId { get; set; } + public double AvgIrradiance { get; set; } + } + + public class PyrheliometerHistoryDay + { + public int PowerStationId { get; set; } + public string Timestamp { get; set; } + public double Irradiance { get; set; } + } } diff --git a/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs index 02e38cd..8114a38 100644 --- a/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs @@ -29,31 +29,33 @@ namespace SolarPower.Quartz.Jobs var powerStations = await powerStationRepository.GetAllAsync(); #endregion - List powerStationHistoryDays = new List(); List calcAvgPowerStations = new List(); - + List powerStationHistoryDays = new List(); List insertPowerStationHistoryMonths = new List(); List updatePowerStationHistoryMonths = new List(); + List pyrheliometerHistoryDays = new List(); + List insertPyrheliometerHistoryMonths = new List(); + List updatePyrheliometerHistoryMonths = new List(); + var DateTimeNow = DateTime.Now; #region step2. 從電站的DB及電站編號找出該電站的控制器 foreach (var powerStation in powerStations) { - #region step2-1. 取得該電站的30天平均資料 - var table_name = String.Format("`{0}`.`{1}01_ficstationhistory`", powerStation.SiteDB, powerStation.Code); + var calcPowerStation = new PowerStation(); + calcPowerStation.Id = powerStation.Id; var dateNowDay = DateTimeNow.AddDays(-1).ToString("yyyy-MM-dd"); - dateNowDay = "2021-06-24"; - var history = await powerStationRepository.GetAvgPowerStationHistory30day(dateNowDay, table_name); + #region step2-1. 計算該電站的30天平均資料 + var table_name = String.Format("`{0}`.`{1}01_station`", powerStation.SiteDB, powerStation.Code); + var history = await powerStationRepository.CalcAvgPowerStationHistory30day(dateNowDay, table_name); if (history != null) { history.PowerStationId = powerStation.Id; #region 計算電站30天的 kWh/kWp 與 PR 值 - var calcPowerStation = new PowerStation(); - calcPowerStation.Id = powerStation.Id; #region 平均kWh/kWp //直接填寫 @@ -65,33 +67,47 @@ namespace SolarPower.Quartz.Jobs calcPowerStation.Avg_PR = history.AvgPR; #endregion - #endregion - calcAvgPowerStations.Add(calcPowerStation); } #endregion - #region step2-2. 計算昨天的所有值總和 + #region step2-2 計算電站30天的日照計平均值 + var avgPyrheliometerHistory = await powerStationRepository.CalcAvgPyrheliometerHistory30day(dateNowDay, powerStation.Id); + if (avgPyrheliometerHistory != null) + { + calcPowerStation.Avg_irradiance = avgPyrheliometerHistory.AvgIrradiance; + } + + calcAvgPowerStations.Add(calcPowerStation); + #endregion + + #region step2-3. 計算昨天的所有值總和 var historyDay = await powerStationRepository.GetLastOnePowerStationHistoryByDay(dateNowDay, table_name); - if(historyDay != null) + if (historyDay != null) { historyDay.PowerStationId = powerStation.Id; powerStationHistoryDays.Add(historyDay); } + + var pyrheliometerHistorDay = await powerStationRepository.CalcPyrheliometerHistoryDayDataByPowerStationId(dateNowDay, powerStation.Id); + if (pyrheliometerHistorDay != null) + { + pyrheliometerHistoryDays.Add(pyrheliometerHistorDay); + } #endregion - #region step2-3. 計算這個月的所有值總和 + #region step2-4. 計算這個月的所有值總和 //判斷這個月是否已存在 var dateNowMonth = DateTimeNow.ToString("yyyy-MM"); dateNowMonth = "2021-06"; - var exist = await powerStationRepository.GetOnePowerStationHistoryByPowerStationIdAndMonth(powerStation.Id, dateNowMonth); - - if (exist == null) + //電站該月份的歷史資料 + var exist_history = await powerStationRepository.GetOnePowerStationHistoryByPowerStationIdAndMonth(powerStation.Id, dateNowMonth); + if (exist_history == null) { //新增 - var historyMonth = await powerStationRepository.GetPowerStationHistoryMonthDataByPowerStationId(powerStation.Id, dateNowMonth); - if(historyMonth != null) + var historyMonth = await powerStationRepository.ClacPowerStationHistoryMonthDataByPowerStationId(powerStation.Id, dateNowMonth); + if (historyMonth != null) { historyMonth.Timestamp = Convert.ToDateTime(historyMonth.Timestamp).ToString("yyyy-MM-dd"); @@ -100,29 +116,49 @@ namespace SolarPower.Quartz.Jobs } else { //修改 - var historyMonth = await powerStationRepository.GetPowerStationHistoryMonthDataByPowerStationId(powerStation.Id, dateNowMonth); + var historyMonth = await powerStationRepository.ClacPowerStationHistoryMonthDataByPowerStationId(powerStation.Id, dateNowMonth); if (historyMonth != null) { updatePowerStationHistoryMonths.Add(historyMonth); } } + + //電站該月份的的日照度歷史資料 + var exist_pyrheliometer_history = await powerStationRepository.GetOnePyrheliometerHistoryByMonth(dateNowMonth, powerStation.Id); + if (exist_pyrheliometer_history == null) + { //新增 + var pyrheliometerHistoryMonth = await powerStationRepository.CalcPyrheliometerHistoryMonthDataByPowerStationId(dateNowMonth, powerStation.Id); + if (pyrheliometerHistoryMonth != null) + { + pyrheliometerHistoryMonth.Timestamp = Convert.ToDateTime(pyrheliometerHistoryMonth.Timestamp).ToString("yyyy-MM-dd"); + insertPyrheliometerHistoryMonths.Add(pyrheliometerHistoryMonth); + } + } + else + { //修改 + var pyrheliometerHistoryMonth = await powerStationRepository.CalcPyrheliometerHistoryMonthDataByPowerStationId(dateNowMonth, powerStation.Id); + if (pyrheliometerHistoryMonth != null) + { + updatePyrheliometerHistoryMonths.Add(pyrheliometerHistoryMonth); + } + } #endregion } #endregion - //TODO 日照 #region step3. calcPowerStations UPDATE 到 power_station 資料表 List power_station_properties = new List() { "Id", "avg_kwhkwp", "avg_PR", + "avg_irradiance" }; await powerStationRepository.UpdateList(calcAvgPowerStations, power_station_properties); #endregion - #region step4. 將各電站的每日及月的資料insert or update 個資料表 + #region step4. 將各電站的每日及月的資料insert or update 各資料表 //每日 List history_properties_day = new List() { @@ -140,6 +176,7 @@ namespace SolarPower.Quartz.Jobs await powerStationRepository.AddPowerStationHistoryDayList(powerStationHistoryDays, history_properties_day); + //每月 List history_properties_month = new List() { "PowerStationId", @@ -154,7 +191,29 @@ namespace SolarPower.Quartz.Jobs "SolarHour" }; - if(insertPowerStationHistoryMonths.Count > 0) + if (insertPowerStationHistoryMonths.Count > 0) + { + await powerStationRepository.AddPowerStationHistoryMonthList(insertPowerStationHistoryMonths, history_properties_month); + } + + if (updatePowerStationHistoryMonths.Count > 0) + { + await powerStationRepository.UpdatePowerStationHistoryMonthList(updatePowerStationHistoryMonths); + } + #endregion + + #region step5. 將各電站的每日及月的日照度資料insert or update 各資料表 + List pyrheliometer_history_properties = new List() + { + "PowerStationId", + "Timestamp", + "Irradiance" + }; + //每日 + await powerStationRepository.AddPyrheliometerHistoryDayList(pyrheliometerHistoryDays, pyrheliometer_history_properties); + + //每月 + if (insertPowerStationHistoryMonths.Count > 0) { await powerStationRepository.AddPowerStationHistoryMonthList(insertPowerStationHistoryMonths, history_properties_month); } diff --git a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs index eece056..c04e2f8 100644 --- a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs @@ -32,48 +32,40 @@ namespace SolarPower.Quartz.Jobs #endregion List powerStationHistoriesHour = new List(); + List pyrheliometerHistoriesHour = new List(); List calcPowerStations = new List(); var DateTimeNow = DateTime.Now; #region step2. 從電站的DB及電站編號找出該電站的控制器 - var count = 0; foreach (var powerStation in powerStations) { - if(count > 0) - { - break; - } - #region step2-1. 取得該電站的當前這小時的歷史資料 - var table_name = String.Format("`{0}`.{1}01_ficstationhistory", powerStation.SiteDB, powerStation.Code); + var calcPowerStation = new PowerStation(); + calcPowerStation.Id = powerStation.Id; + var dateTime = DateTimeNow.AddHours(-1).ToString("yyyy-MM-dd HH"); - dateTime = "2021-06-24 18"; - var history = await powerStationRepository.GetPowerStationHistoryPerHour(dateTime, table_name); + #region step2-1. 取得該電站的當前這小時的歷史資料 + var table_name = String.Format("`{0}`.{1}01_station", powerStation.SiteDB, powerStation.Code); + + var history = await powerStationRepository.GetPowerStationHistoryPerHour(dateTime, table_name); if (history != null) { history.PowerStationId = powerStation.Id; + history.Timestamp = Convert.ToDateTime(history.Timestamp).ToString("yyyy-MM-dd HH:mm:ss"); #region 計算單一電站每小時發電量、發電金額等資料 - var calcPowerStation = new PowerStation(); - calcPowerStation.Id = powerStation.Id; - - calcPowerStation.kwh = history.KWH; #region 發電量 + //每小時發電量(直接填寫 + calcPowerStation.kwh = history.KWH; //今日發電量(直接填寫 calcPowerStation.Today_kWh = history.TodayKWh; //總發電量(直接填寫 calcPowerStation.Total_kWh = history.TotalKWH; #endregion - //TODO - #region 日照度 - //1. 找出該電站所有日照計設備(包還共享 - //2. 透過該DB、col取得到是哪一個sensor - #endregion - #region 發電金額 //發電金額 switch (powerStation.SolarType) @@ -135,16 +127,32 @@ namespace SolarPower.Quartz.Jobs #endregion powerStationHistoriesHour.Add(history); - calcPowerStations.Add(calcPowerStation); } #endregion - count++; + #region step2-2. 取得該電站的當前這小時的日照度歷史資料 + //1. 找出該電站所有日照計設備(包還共享 + var deviceInfos = await powerStationRepository.GetListPyrheliometerByPowerStationId(powerStation.Id, powerStation.SiteDB); + if (deviceInfos != null) + { + //2. 計算該電站所有日照計設的每小時的平均在依照日照計數量平均 + var pyrheliometerHistory = await powerStationRepository.GetPyrheliometerHistoryPerHour(dateTime, deviceInfos); + + if (pyrheliometerHistory != null) + { + calcPowerStation.Today_irradiance = pyrheliometerHistory.Irradiance; + + pyrheliometerHistory.Timestamp = Convert.ToDateTime(pyrheliometerHistory.Timestamp).ToString("yyyy-MM-dd HH:mm:ss"); + pyrheliometerHistoriesHour.Add(pyrheliometerHistory); + } + } + #endregion + + calcPowerStations.Add(calcPowerStation); } #endregion #region step3. 將historiers INSERT 到 power_station_history_hour 資料表 - List history_properties = new List() { "PowerStationId", @@ -163,8 +171,18 @@ namespace SolarPower.Quartz.Jobs await powerStationRepository.AddPowerStationHistory(powerStationHistoriesHour, history_properties); #endregion - //TODO 日照 - #region step4. calcPowerStations UPDATE 到 power_station 資料表 + #region step4. 將Pyrheliometer History INSERT 到 pyrheliometer_history_hour 資料表 + List pyrheliometer_history_properties = new List() + { + "PowerStationId", + "TIMESTAMP", + "Irradiance" + }; + + await powerStationRepository.AddPyrheliometerHistory(pyrheliometerHistoriesHour, pyrheliometer_history_properties); + #endregion + + #region step5. calcPowerStations UPDATE 到 power_station 資料表 List power_station_properties = new List() { "Id", @@ -177,6 +195,7 @@ namespace SolarPower.Quartz.Jobs "today_PR", "today_carbon", "total_carbon", + "today_irradiance" }; await powerStationRepository.UpdateList(calcPowerStations, power_station_properties); diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index 181a1ba..10b1f12 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -1820,8 +1820,19 @@ namespace SolarPower.Repository.Implement try { var sql = $@" - SELECT * FROM {table_name} WHERE DATE_FORMAT(FROM_UNIXTIME(timestamp / 1000), '%Y-%m-%d %H') = @DateTime -"; + SELECT + DATE_FORMAT(FROM_UNIXTIME(timestamp / 1000), '%Y-%m-%d %H') AS TIMESTAMP, + SITEID, + SiteType, + KWH, + TodayKWh, + TotalKWH, + KWHKWP, + PR, + MP, + SolarHour + FROM {table_name} WHERE DATE_FORMAT(FROM_UNIXTIME(timestamp / 1000), '%Y-%m-%d %H') = @DateTime + "; result = await conn.QueryFirstOrDefaultAsync(sql, new { DateTime = dateTime }); } @@ -1833,7 +1844,7 @@ namespace SolarPower.Repository.Implement } } - public async Task GetAvgPowerStationHistory30day(string nowDay, string table_name) + public async Task CalcAvgPowerStationHistory30day(string nowDay, string table_name) { AvgPowerStationHistory result; using (IDbConnection conn = this._databaseHelper.GetConnection()) @@ -2021,7 +2032,7 @@ namespace SolarPower.Repository.Implement } } - public async Task GetPowerStationHistoryMonthDataByPowerStationId(int powerStationId, string month) + public async Task ClacPowerStationHistoryMonthDataByPowerStationId(int powerStationId, string month) { PowerStationHistoryMonth result; using (IDbConnection conn = this._databaseHelper.GetConnection()) @@ -2131,5 +2142,293 @@ namespace SolarPower.Repository.Implement return count; } } + + public async Task> GetListPyrheliometerByPowerStationId(int powerStationId, string db_name) + { + List result; + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + try + { + var sql = $@"SELECT * + FROM {db_name}.device d + WHERE d.PowerStationId = @PowerStationId AND d.`Type` = 'PYR' AND d.Deleted = 0 + UNION + SELECT d.* + FROM {db_name}.sharedevice sd + LEFT JOIN {db_name}.device d ON sd.DeviceId = d.Id + WHERE sd.PowerStationId = @PowerStationId AND d.`Type` = 'PYR' AND d.Deleted = 0 + "; + + result = (await conn.QueryAsync(sql, new { PowerStationId = powerStationId })).ToList(); + } + catch (Exception exception) + { + throw exception; + } + return result; + } + } + + public async Task GetPyrheliometerHistoryPerHour(string dateTime, List deviceInfos) + { + PyrheliometerHistory result; + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + try + { + List sql_per_device = new List(); + + foreach(var device in deviceInfos) + { + var str = @$"SELECT DATE_FORMAT(FROM_UNIXTIME(s.TIMESTAMP/ 1000), '%Y-%m-%d %H') AS TIMESTAMP, s.SITEID, AVG(s.{device.ColName}) AS SENSOR + FROM {device.DBName}.{device.TableName} s + WHERE DATE_FORMAT(FROM_UNIXTIME(s.TIMESTAMP/ 1000), '%Y-%m-%d %H') = @DateTime + GROUP BY DATE_FORMAT(FROM_UNIXTIME(s.TIMESTAMP/ 1000), '%Y-%m-%d %H')"; + + sql_per_device.Add(str); + } + + var sql = @"SELCET TIMESTAMP, AVG(SENSOR) AS Irradiance FROM(" + string.Join(" UNION ", sql_per_device) + @") GORUP BY TIMESTAMP"; + + result = await conn.QueryFirstOrDefaultAsync(sql, new { DateTime = dateTime }); + } + catch (Exception exception) + { + throw exception; + } + return result; + } + } + + public async Task AddPyrheliometerHistory(List entity, List properties) + { + int count; + using (IDbConnection conn = _databaseHelper.GetConnection()) + { + conn.Open(); + using (var trans = conn.BeginTransaction()) + { + try + { + string sql = GenerateInsertQueryWithCustomTable(properties, "pyrheliometer_history_hour"); + + count = await conn.ExecuteAsync(sql, entity, trans); + + trans.Commit(); + } + catch (Exception exception) + { + trans.Rollback(); + throw exception; + } + finally + { + conn.Close(); + } + } + + return count; + } + } + + public async Task CalcAvgPyrheliometerHistory30day(string nowDay, int powerStationId) + { + AvgPyrheliometerHistory result; + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + try + { + var startDay = Convert.ToDateTime(nowDay).AddDays(-30).ToString("yyyy-MM-dd"); + + var sql = $@"SELECT AVG(p.Irradiance) AS AvgIrradiance + FROM pyrheliometer_history_hour p + WHERE DATE_FORMAT(p.TIMESTAMP, '%Y-%m-%d') BETWEEN @StartDay AND @EndDay + AND p.Irradiance != 0 + AND PowerStationId = @PowerStationId + GROUP BY DATE_FORMAT(p.TIMESTAMP, '%Y-%m-%d') + "; + + result = await conn.QueryFirstOrDefaultAsync(sql, new { StartDay = startDay, EndDay = nowDay, PowerStationId = powerStationId }); + } + catch (Exception exception) + { + throw exception; + } + return result; + } + } + + public async Task CalcPyrheliometerHistoryDayDataByPowerStationId(string nowDay, int powerStationId) + { + PyrheliometerHistory result; + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + try + { + var sql = $@"SELECT + PowerStationId, + DATE_FORMAT(p.TIMESTAMP, '%Y-%m-%d'), + AVG(p.Irradiance) AS AvgIrradiance + FROM pyrheliometer_history_hour p + WHERE DATE_FORMAT(p.TIMESTAMP, '%Y-%m-%d') = @NowDay + AND p.Irradiance != 0 + AND PowerStationId = @PowerStationId + GROUP BY DATE_FORMAT(p.TIMESTAMP, '%Y-%m-%d') + "; + + result = await conn.QueryFirstOrDefaultAsync(sql, new { NowDay = nowDay, PowerStationId = powerStationId }); + } + catch (Exception exception) + { + throw exception; + } + return result; + } + } + + public async Task AddPyrheliometerHistoryDayList(List entity, List properties) + { + int count; + using (IDbConnection conn = _databaseHelper.GetConnection()) + { + conn.Open(); + using (var trans = conn.BeginTransaction()) + { + try + { + string sql = GenerateInsertQueryWithCustomTable(properties, "pyrheliometer_history_day"); + + count = await conn.ExecuteAsync(sql, entity, trans); + + trans.Commit(); + } + catch (Exception exception) + { + trans.Rollback(); + throw exception; + } + finally + { + conn.Close(); + } + } + + return count; + } + } + + public async Task CalcPyrheliometerHistoryMonthDataByPowerStationId(string month, int powerStationId) + { + PyrheliometerHistory result; + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + try + { + var sql = $@"SELECT + PowerStationId, + DATE_FORMAT(p.TIMESTAMP, '%Y-%m'), + AVG(p.Irradiance) AS AvgIrradiance + FROM pyrheliometer_history_hour p + WHERE DATE_FORMAT(p.TIMESTAMP, '%Y-%m') = @Month + AND p.Irradiance != 0 + AND PowerStationId = @PowerStationId + GROUP BY DATE_FORMAT(p.TIMESTAMP, '%Y-%m') + "; + + result = await conn.QueryFirstOrDefaultAsync(sql, new { Month = month, PowerStationId = powerStationId }); + } + catch (Exception exception) + { + throw exception; + } + return result; + } + } + + public async Task GetOnePyrheliometerHistoryByMonth(string month, int powerStationId) + { + PyrheliometerHistory result; + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + try + { + var sql = $@"SELECT * FROM pyrheliometer_history_month WHERE DATE_FORMAT(p.TIMESTAMP, '%Y-%m') = @Month AND PowerStationId = @PowerStationId"; + + result = await conn.QueryFirstOrDefaultAsync(sql, new { Month = month, PowerStationId = powerStationId }); + } + catch (Exception exception) + { + throw exception; + } + return result; + } + } + + public async Task AddPyrheliometerHistoryMonthList(List entity, List properties) + { + int count; + using (IDbConnection conn = _databaseHelper.GetConnection()) + { + conn.Open(); + using (var trans = conn.BeginTransaction()) + { + try + { + string sql = GenerateInsertQueryWithCustomTable(properties, "pyrheliometer_history_month"); + + count = await conn.ExecuteAsync(sql, entity, trans); + + trans.Commit(); + } + catch (Exception exception) + { + trans.Rollback(); + throw exception; + } + finally + { + conn.Close(); + } + } + + return count; + } + } + + public async Task UpdatePyrheliometerHistoryMonthList(List entity) + { + int count; + using (IDbConnection conn = _databaseHelper.GetConnection()) + { + conn.Open(); + using (var trans = conn.BeginTransaction()) + { + try + { + string sql = @"UPDATE pyrheliometer_history_month SET + Irradiance=@Irradiance, + WHERE PowerStationId = @PowerStationId + AND TIMESTAMP LIKE CONCAT(@TIMESTAMP, '%') +"; + + count = await conn.ExecuteAsync(sql, entity, trans); + + trans.Commit(); + } + catch (Exception exception) + { + trans.Rollback(); + throw exception; + } + finally + { + conn.Close(); + } + } + + return count; + } + } } } diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index b8960a9..20e31c5 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -27,8 +27,6 @@ namespace SolarPower.Repository.Interface Task> GetOperationPersonnelSelectOptionListAsync(int powerStationId); - - /// /// 透過編號取得,縣市資訊 /// @@ -442,12 +440,12 @@ namespace SolarPower.Repository.Interface Task GetPowerStationHistoryPerHour(string dateTime, string table_name); /// - /// 透過當前日期,取得往前推算30天的平均值 + /// 透過當前日期,計算往前推算30天的平均值 /// /// /// /// - Task GetAvgPowerStationHistory30day(string nowDay, string table_name); + Task CalcAvgPowerStationHistory30day(string nowDay, string table_name); Task AddPowerStationHistory(List entity, List properties); @@ -478,12 +476,12 @@ namespace SolarPower.Repository.Interface Task GetOnePowerStationHistoryByPowerStationIdAndMonth(int powerStationId, string month); /// - /// 透過電站編號、月份,取得該月份資訊 + /// 透過電站編號、月份,計算該月份資訊 /// /// /// /// - Task GetPowerStationHistoryMonthDataByPowerStationId(int powerStationId, string month); + Task ClacPowerStationHistoryMonthDataByPowerStationId(int powerStationId, string month); Task AddPowerStationHistoryMonthList(List entity, List properties); Task UpdatePowerStationHistoryMonthList(List entity); @@ -494,5 +492,17 @@ namespace SolarPower.Repository.Interface /// /// Task> GetPowerstationPyrheliometerAsync(string db_name, int stationId); + + Task> GetListPyrheliometerByPowerStationId(int powerStationId, string db_name); + Task GetPyrheliometerHistoryPerHour(string dateTime, List deviceInfos); + Task AddPyrheliometerHistory(List entity, List properties); + Task CalcAvgPyrheliometerHistory30day(string nowDay, int powerStationId); + Task CalcPyrheliometerHistoryDayDataByPowerStationId(string nowDay, int powerStationId); + Task AddPyrheliometerHistoryDayList(List entity, List properties); + + Task CalcPyrheliometerHistoryMonthDataByPowerStationId(string month, int powerStationId); + Task GetOnePyrheliometerHistoryByMonth(string month, int powerStationId); + Task AddPyrheliometerHistoryMonthList(List entity, List properties); + Task UpdatePyrheliometerHistoryMonthList(List entity); } }