From b02110c3c52ec1fc504f9cee6cd4261c5cd72785 Mon Sep 17 00:00:00 2001 From: Kai Date: Thu, 17 Mar 2022 09:40:37 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E6=AF=8F15=E6=AD=B8=E6=AA=94=E5=8A=A0?= =?UTF-8?q?=E5=85=A5log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Quartz/Jobs/CalcInverter15minJob.cs | 79 +++++++++++-------- .../Services/Implement/SendEmailService.cs | 2 +- 2 files changed, 45 insertions(+), 36 deletions(-) diff --git a/SolarPower/Quartz/Jobs/CalcInverter15minJob.cs b/SolarPower/Quartz/Jobs/CalcInverter15minJob.cs index 8b25a1b..f5b8840 100644 --- a/SolarPower/Quartz/Jobs/CalcInverter15minJob.cs +++ b/SolarPower/Quartz/Jobs/CalcInverter15minJob.cs @@ -57,7 +57,7 @@ namespace SolarPower.Quartz.Jobs logger.LogInformation("【CalcInverter15minJob】【開始取得電站資料】"); var powerStations = await powerStationRepository.GetAllAsync(); logger.LogInformation("【CalcInverter15minJob】【取得成功電站資料】"); - logger.LogInformation("【CalcInverter15minJob】【電站資料】 - {0}", System.Text.Json.JsonSerializer.Serialize(powerStations)); + //logger.LogInformation("【CalcInverter15minJob】【電站資料】 - {0}", System.Text.Json.JsonSerializer.Serialize(powerStations)); #endregion List calcInverter15mins = new List(); @@ -75,44 +75,46 @@ namespace SolarPower.Quartz.Jobs //var dateNowTime = string.Format("2021-07-{0} {1}", day_array[i], time_array[j]); - #region step2. 從電站的DB及電站編號找出該電站的控制器 - foreach (var powerStation in powerStations) + #region step2. 從電站的DB及電站編號找出該電站的控制器 + foreach (var powerStation in powerStations) + { + try + { + //取得所有該電站的逆變器 + logger.LogInformation("【CalcInverter15minJob】【開始取得電站[{0}]在{1}的逆變器設備資訊】", powerStation.Code, dateNowTime); + var controllers = await powerStationRepository.GetAllDeviceControllerId(powerStation.Id, powerStation.SiteDB); + var inverters = await powerStationRepository.InverterTable(controllers, powerStation.SiteDB); + var inverterIds = inverters.Where(x => x.Enabled == 1 && x.Status != 0).Select(x => x.InverterId).ToList(); + logger.LogInformation("【CalcInverter15minJob】【取得成功電站[{0}]在{1}的逆變器設備資訊】", powerStation.Code, dateNowTime); + + #region step2-1. 計算該電站逆變器每15min 的值 + var table_name = String.Format("s{1}01_inv", powerStation.SiteDB, powerStation.Code); + var full_table_name = String.Format("`{0}`.`{1}`", powerStation.SiteDB, table_name); + var exist = await powerStationRepository.ExistTable(powerStation.SiteDB, table_name); + + if (!string.IsNullOrEmpty(exist)) { - - //取得所有該電站的逆變器 - logger.LogInformation("【CalcInverter15minJob】【開始取得電站[{0}]在{1}的逆變器設備資訊】", powerStation.Code, dateNowTime); - var controllers = await powerStationRepository.GetAllDeviceControllerId(powerStation.Id, powerStation.SiteDB); - var inverters = await powerStationRepository.InverterTable(controllers, powerStation.SiteDB); - var inverterIds = inverters.Where(x => x.Enabled == 1 && x.Status != 0).Select(x => x.InverterId).ToList(); - logger.LogInformation("【CalcInverter15minJob】【取得成功電站[{0}]在{1}的逆變器設備資訊】", powerStation.Code, dateNowTime); - - #region step2-1. 計算該電站逆變器每15min 的值 - var table_name = String.Format("s{1}01_inv", powerStation.SiteDB, powerStation.Code); - var full_table_name = String.Format("`{0}`.`{1}`", powerStation.SiteDB, table_name); - var exist = await powerStationRepository.ExistTable(powerStation.SiteDB, table_name); - - if (!string.IsNullOrEmpty(exist)) + logger.LogInformation("【CalcInverter15minJob】【開始計算電站[{0}]在{1}的每15分鐘逆變器資訊】", powerStation.Code, dateNowTime); + var calcInverter15min = await powerStationRepository.CalcInverterHisyort15minData(dateNowTime, powerStation.SiteDB, full_table_name, inverterIds); + logger.LogInformation("【CalcInverter15minJob】【計算完成電站[{0}]在{1}的每15分鐘逆變器資訊】", powerStation.Code, dateNowTime); + logger.LogInformation("【CalcInverter15minJob】【計算結果】 - {0}", System.Text.Json.JsonSerializer.Serialize(calcInverter15mins)); + if (calcInverter15min.Count() > 0) { - logger.LogInformation("【CalcInverter15minJob】【開始計算電站[{0}]在{1}的每15分鐘逆變器資訊】", powerStation.Code, dateNowTime); - var calcInverter15min = await powerStationRepository.CalcInverterHisyort15minData(dateNowTime, powerStation.SiteDB, full_table_name, inverterIds); - logger.LogInformation("【CalcInverter15minJob】【計算完成電站[{0}]在{1}的每15分鐘逆變器資訊】", powerStation.Code, dateNowTime); - logger.LogInformation("【CalcInverter15minJob】【計算結果】 - {0}", System.Text.Json.JsonSerializer.Serialize(calcInverter15mins)); - if (calcInverter15min.Count() > 0) + foreach (var inverterHistory in calcInverter15min) { - foreach (var inverterHistory in calcInverter15min) - { - inverterHistory.TIMESTAMP = Convert.ToDateTime(inverterHistory.TIMESTAMP + ":00").ToString("yyyy-MM-dd HH:mm:ss"); - inverterHistory.PowerStationId = powerStation.Id; + inverterHistory.TIMESTAMP = Convert.ToDateTime(inverterHistory.TIMESTAMP + ":00").ToString("yyyy-MM-dd HH:mm:ss"); + inverterHistory.PowerStationId = powerStation.Id; - calcInverter15mins.Add(inverterHistory); - } + calcInverter15mins.Add(inverterHistory); } } - - + } + } + catch (Exception ex) + { + logger.LogError("【CalcInverter15minJob】【電站[{0}]計算失敗】 - {1}", powerStation.Code, ex.ToString()); + } #endregion - - } #endregion @@ -127,7 +129,14 @@ namespace SolarPower.Quartz.Jobs "KWHKWP", }; - await powerStationRepository.AddInverter15minHistory(calcInverter15mins, inverter_history_properties); + try + { + await powerStationRepository.AddInverter15minHistory(calcInverter15mins, inverter_history_properties); + } + catch (Exception ex) + { + logger.LogError("【CalcInverter15minJob】【儲存15分鐘歷史紀錄失敗】 - {0}", ex.ToString()); + } #endregion // } //} @@ -166,11 +175,11 @@ namespace SolarPower.Quartz.Jobs logger.LogInformation("【CalcInverter15minJob】檢測完成逆變器狀態"); } - catch(Exception exception) + catch (Exception exception) { logger.LogError("【CalcInverter15minJob】檢測逆變器狀態失敗 - [Exception] {0}", exception.Message); } - + } catch (Exception exception) { diff --git a/SolarPower/Services/Implement/SendEmailService.cs b/SolarPower/Services/Implement/SendEmailService.cs index 397ad4f..7303192 100644 --- a/SolarPower/Services/Implement/SendEmailService.cs +++ b/SolarPower/Services/Implement/SendEmailService.cs @@ -53,7 +53,7 @@ namespace SolarPower.Services } catch (Exception ex) { - //_log.LogError("【SendEmailSMSService】 " + noticeInfo.Recipient_email + "寄送信件失敗"); + throw ex; return false; }