From 32df22a687e29dd6d61826493767c391be9dbe36 Mon Sep 17 00:00:00 2001 From: Kai Date: Fri, 27 Aug 2021 09:26:00 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E6=AF=8F=E5=B0=8F=E6=99=82=20=E6=AA=A2?= =?UTF-8?q?=E6=9F=A5DB=20=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Quartz/Jobs/CalcPowerStationJob.cs | 393 ++++++++++-------- 1 file changed, 210 insertions(+), 183 deletions(-) diff --git a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs index 58ac4ad..2a0de14 100644 --- a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs @@ -101,7 +101,11 @@ namespace SolarPower.Quartz.Jobs 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)) + if (string.IsNullOrEmpty(exist)) + { + logger.LogError("【CalcPowerStationJob】【查無電站[0]的s{0}01_station資料表】", powerStation.Code); + } + else { logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime); var history = await powerStationRepository.GetPowerStationHistoryPerHour(dateTime, full_table_name); @@ -219,217 +223,235 @@ namespace SolarPower.Quartz.Jobs #endregion #region step2-2. 取得該電站的當前這小時的設備歷史資料 - logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的設備資訊】", powerStation.Code, dateTime); - PyrheliometerHistory sensorHistory = new PyrheliometerHistory(); - sensorHistory.PowerStationId = powerStation.Id; - sensorHistory.Timestamp = Convert.ToDateTime(dateTime + ":00:00").ToString("yyyy-MM-dd HH:mm:ss"); - - //1. 計算該電站sensor平均值 - 日照計(PYR) - try + var sensoravg_table_name = String.Format("s{1}01_sensoravg", powerStation.SiteDB, powerStation.Code); + var full_sensoravg_table_name = String.Format("`{0}`.`{1}`", powerStation.SiteDB, sensoravg_table_name); + var sensoravg_table_exist = await powerStationRepository.ExistTable(powerStation.SiteDB, sensoravg_table_name); + if (string.IsNullOrEmpty(sensoravg_table_exist)) { - logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的日照計設備資訊】", powerStation.Code, dateTime); - var deviceInfos = await powerStationRepository.GetListPyrheliometerByPowerStationId(powerStation.Id, powerStation.SiteDB); - logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的日照計設備資訊】", powerStation.Code, dateTime); - logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的日照計設備資訊】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(deviceInfos)); - - if (deviceInfos != null && deviceInfos.Count() > 0) - { - logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的日照計的平均值】", powerStation.Code, dateTime); - var pyrheliometerHistory = await powerStationRepository.CalcSensorHistoryPerHour(dateTime, deviceInfos, Convert.ToInt32(SensorTypeEnum.PYR)); - - if (pyrheliometerHistory != null) - { - calcPowerStation.Today_irradiance = pyrheliometerHistory.Irradiance; - - sensorHistory.Irradiance = pyrheliometerHistory.Irradiance; - - //pyrheliometerHistory.Timestamp = Convert.ToDateTime(pyrheliometerHistory.Timestamp + ":00:00").ToString("yyyy-MM-dd HH:mm:ss"); - //pyrheliometerHistory.PowerStationId = powerStation.Id; - //pyrheliometerHistoriesHour.Add(pyrheliometerHistory); - } - logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的日照計的平均值】", powerStation.Code, dateTime); - } + logger.LogError("【CalcPowerStationJob】【查無電站[0]的s{0}01_sensoravg資料表】", powerStation.Code); } - catch (Exception ex) + else { - logger.LogError("【CalcPowerStationJob】【計算失敗電站[{0}]在{1}的日照計的平均值】", powerStation.Code, dateTime); - logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message); - } + logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的設備資訊】", powerStation.Code, dateTime); + PyrheliometerHistory sensorHistory = new PyrheliometerHistory(); + sensorHistory.PowerStationId = powerStation.Id; + sensorHistory.Timestamp = Convert.ToDateTime(dateTime + ":00:00").ToString("yyyy-MM-dd HH:mm:ss"); - //2. 計算該電站sensor平均值 - 模組溫度計(MTR) - try - { - logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的模組溫度計設備資訊】", powerStation.Code, dateTime); - var tempdeviceInfos = await powerStationRepository.GetDeviceListByPowerStationIdAndType(powerStation.Id, "MTR", powerStation.SiteDB); - logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的模組溫度計設備資訊】", powerStation.Code, dateTime); - logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的模組溫度計設備資訊】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(tempdeviceInfos)); - if (tempdeviceInfos != null && tempdeviceInfos.Count() > 0) + //1. 計算該電站sensor平均值 - 日照計(PYR) + try { - logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的模組溫度計的平均值】", powerStation.Code, dateTime); - var tempHistory = await powerStationRepository.CalcSensorHistoryPerHour(dateTime, tempdeviceInfos, Convert.ToInt32(SensorTypeEnum.MTR)); - if (tempHistory != null) + logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的日照計設備資訊】", powerStation.Code, dateTime); + var deviceInfos = await powerStationRepository.GetListPyrheliometerByPowerStationId(powerStation.Id, powerStation.SiteDB); + logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的日照計設備資訊】", powerStation.Code, dateTime); + logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的日照計設備資訊】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(deviceInfos)); + + if (deviceInfos != null && deviceInfos.Count() > 0) { - //tempHistory.Timestamp = Convert.ToDateTime(tempHistory.Timestamp + ":00:00").ToString("yyyy-MM-dd HH:mm:ss"); - //tempHistory.PowerStationId = powerStation.Id; - //TempHistoriesHour.Add(tempHistory); + logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的日照計的平均值】", powerStation.Code, dateTime); + var pyrheliometerHistory = await powerStationRepository.CalcSensorHistoryPerHour(dateTime, deviceInfos, Convert.ToInt32(SensorTypeEnum.PYR)); - sensorHistory.Temperature = tempHistory.Temperature; + if (pyrheliometerHistory != null) + { + calcPowerStation.Today_irradiance = pyrheliometerHistory.Irradiance; - logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的模組溫度計的平均值】", powerStation.Code, dateTime); + sensorHistory.Irradiance = pyrheliometerHistory.Irradiance; + + //pyrheliometerHistory.Timestamp = Convert.ToDateTime(pyrheliometerHistory.Timestamp + ":00:00").ToString("yyyy-MM-dd HH:mm:ss"); + //pyrheliometerHistory.PowerStationId = powerStation.Id; + //pyrheliometerHistoriesHour.Add(pyrheliometerHistory); + } + logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的日照計的平均值】", powerStation.Code, dateTime); } } - } - catch (Exception ex) - { - logger.LogError("【CalcPowerStationJob】【計算失敗電站[{0}]在{1}的模組溫度計的平均值】", powerStation.Code, dateTime); - logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message); - } - - //3. 計算該電站sensor平均值 - 環境溫度計(ETR) - try - { - logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的環境溫度計設備資訊】", powerStation.Code, dateTime); - var ETRdeviceInfos = await powerStationRepository.GetDeviceListByPowerStationIdAndType(powerStation.Id, SensorTypeEnum.ETR.ToString(), powerStation.SiteDB); - logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的環境溫度計設備資訊】", powerStation.Code, dateTime); - logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的環境溫度計設備資訊】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(ETRdeviceInfos)); - if (ETRdeviceInfos != null && ETRdeviceInfos.Count() > 0) + catch (Exception ex) { - logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的環境溫度計的平均值】", powerStation.Code, dateTime); - var ETRHistory = await powerStationRepository.CalcSensorHistoryPerHour(dateTime, ETRdeviceInfos, Convert.ToInt32(SensorTypeEnum.ETR)); - if (ETRHistory != null) + logger.LogError("【CalcPowerStationJob】【計算失敗電站[{0}]在{1}的日照計的平均值】", powerStation.Code, dateTime); + logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message); + } + + //2. 計算該電站sensor平均值 - 模組溫度計(MTR) + try + { + logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的模組溫度計設備資訊】", powerStation.Code, dateTime); + var tempdeviceInfos = await powerStationRepository.GetDeviceListByPowerStationIdAndType(powerStation.Id, "MTR", powerStation.SiteDB); + logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的模組溫度計設備資訊】", powerStation.Code, dateTime); + logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的模組溫度計設備資訊】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(tempdeviceInfos)); + if (tempdeviceInfos != null && tempdeviceInfos.Count() > 0) { - sensorHistory.EnvTemperature = ETRHistory.EnvTemperature; - logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的環境溫度計的平均溫度】", powerStation.Code, dateTime); + logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的模組溫度計的平均值】", powerStation.Code, dateTime); + var tempHistory = await powerStationRepository.CalcSensorHistoryPerHour(dateTime, tempdeviceInfos, Convert.ToInt32(SensorTypeEnum.MTR)); + if (tempHistory != null) + { + //tempHistory.Timestamp = Convert.ToDateTime(tempHistory.Timestamp + ":00:00").ToString("yyyy-MM-dd HH:mm:ss"); + //tempHistory.PowerStationId = powerStation.Id; + //TempHistoriesHour.Add(tempHistory); + + sensorHistory.Temperature = tempHistory.Temperature; + + logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的模組溫度計的平均值】", powerStation.Code, dateTime); + } } } - } - catch (Exception ex) - { - logger.LogError("【CalcPowerStationJob】【計算失敗電站[{0}]在{1}的環境溫度計的平均值】", powerStation.Code, dateTime); - logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message); - } - - //4. 計算該電站 - 環境濕度計(EMM) - try - { - logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的環境濕度計設備資訊】", powerStation.Code, dateTime); - var EMMdeviceInfos = await powerStationRepository.GetDeviceListByPowerStationIdAndType(powerStation.Id, SensorTypeEnum.EMM.ToString(), powerStation.SiteDB); - logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的環境濕度計設備資訊】", powerStation.Code, dateTime); - logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的環境濕度計設備資訊】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(EMMdeviceInfos)); - if (EMMdeviceInfos != null && EMMdeviceInfos.Count() > 0) + catch (Exception ex) { - logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的環境濕度計的平均值】", powerStation.Code, dateTime); - var EMMHistory = await powerStationRepository.CalcSensorHistoryPerHour(dateTime, EMMdeviceInfos, Convert.ToInt32(SensorTypeEnum.EMM)); - if (EMMHistory != null) + logger.LogError("【CalcPowerStationJob】【計算失敗電站[{0}]在{1}的模組溫度計的平均值】", powerStation.Code, dateTime); + logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message); + } + + //3. 計算該電站sensor平均值 - 環境溫度計(ETR) + try + { + logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的環境溫度計設備資訊】", powerStation.Code, dateTime); + var ETRdeviceInfos = await powerStationRepository.GetDeviceListByPowerStationIdAndType(powerStation.Id, SensorTypeEnum.ETR.ToString(), powerStation.SiteDB); + logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的環境溫度計設備資訊】", powerStation.Code, dateTime); + logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的環境溫度計設備資訊】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(ETRdeviceInfos)); + if (ETRdeviceInfos != null && ETRdeviceInfos.Count() > 0) { - sensorHistory.Humidity = EMMHistory.Humidity; - logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的環境濕度計的平均值】", powerStation.Code, dateTime); + logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的環境溫度計的平均值】", powerStation.Code, dateTime); + var ETRHistory = await powerStationRepository.CalcSensorHistoryPerHour(dateTime, ETRdeviceInfos, Convert.ToInt32(SensorTypeEnum.ETR)); + if (ETRHistory != null) + { + sensorHistory.EnvTemperature = ETRHistory.EnvTemperature; + logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的環境溫度計的平均溫度】", powerStation.Code, dateTime); + } } } - } - catch (Exception ex) - { - logger.LogError("【CalcPowerStationJob】【計算失敗電站[{0}]在{1}的環境濕度計的平均值】", powerStation.Code, dateTime); - logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message); - } - - //5. 計算該電站 - 風速計(VAN) - try - { - logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的風速計設備資訊】", powerStation.Code, dateTime); - var VANdeviceInfos = await powerStationRepository.GetDeviceListByPowerStationIdAndType(powerStation.Id, SensorTypeEnum.VAN.ToString(), powerStation.SiteDB); - logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的風速計設備資訊】", powerStation.Code, dateTime); - logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的風速計設備資訊】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(VANdeviceInfos)); - if (VANdeviceInfos != null && VANdeviceInfos.Count() > 0) + catch (Exception ex) { - logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的風速計的平均值】", powerStation.Code, dateTime); - var VANHistory = await powerStationRepository.CalcSensorHistoryPerHour(dateTime, VANdeviceInfos, Convert.ToInt32(SensorTypeEnum.VAN)); - if (VANHistory != null) + logger.LogError("【CalcPowerStationJob】【計算失敗電站[{0}]在{1}的環境溫度計的平均值】", powerStation.Code, dateTime); + logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message); + } + + //4. 計算該電站 - 環境濕度計(EMM) + try + { + logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的環境濕度計設備資訊】", powerStation.Code, dateTime); + var EMMdeviceInfos = await powerStationRepository.GetDeviceListByPowerStationIdAndType(powerStation.Id, SensorTypeEnum.EMM.ToString(), powerStation.SiteDB); + logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的環境濕度計設備資訊】", powerStation.Code, dateTime); + logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的環境濕度計設備資訊】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(EMMdeviceInfos)); + if (EMMdeviceInfos != null && EMMdeviceInfos.Count() > 0) { - sensorHistory.Vane = VANHistory.Vane; - logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的風速計的平均值】", powerStation.Code, dateTime); + logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的環境濕度計的平均值】", powerStation.Code, dateTime); + var EMMHistory = await powerStationRepository.CalcSensorHistoryPerHour(dateTime, EMMdeviceInfos, Convert.ToInt32(SensorTypeEnum.EMM)); + if (EMMHistory != null) + { + sensorHistory.Humidity = EMMHistory.Humidity; + logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的環境濕度計的平均值】", powerStation.Code, dateTime); + } } } - } - catch (Exception ex) - { - logger.LogError("【CalcPowerStationJob】【計算失敗電站[{0}]在{1}的風速計的平均值】", powerStation.Code, dateTime); - logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message); - } - - //5. 計算該電站 - 落塵計(FOM) - try - { - logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的落塵計設備資訊】", powerStation.Code, dateTime); - var FOMdeviceInfos = await powerStationRepository.GetDeviceListByPowerStationIdAndType(powerStation.Id, SensorTypeEnum.FOM.ToString(), powerStation.SiteDB); - logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的落塵計設備資訊】", powerStation.Code, dateTime); - logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的落塵計設備資訊】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(FOMdeviceInfos)); - if (FOMdeviceInfos != null && FOMdeviceInfos.Count() > 0) + catch (Exception ex) { - logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的落塵計的平均%】", powerStation.Code, dateTime); - var FOMHistory = await powerStationRepository.CalcSensorHistoryPerHour(dateTime, FOMdeviceInfos, Convert.ToInt32(SensorTypeEnum.FOM)); - if (FOMHistory != null) + logger.LogError("【CalcPowerStationJob】【計算失敗電站[{0}]在{1}的環境濕度計的平均值】", powerStation.Code, dateTime); + logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message); + } + + //5. 計算該電站 - 風速計(VAN) + try + { + logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的風速計設備資訊】", powerStation.Code, dateTime); + var VANdeviceInfos = await powerStationRepository.GetDeviceListByPowerStationIdAndType(powerStation.Id, SensorTypeEnum.VAN.ToString(), powerStation.SiteDB); + logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的風速計設備資訊】", powerStation.Code, dateTime); + logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的風速計設備資訊】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(VANdeviceInfos)); + if (VANdeviceInfos != null && VANdeviceInfos.Count() > 0) { - sensorHistory.Dust = FOMHistory.Dust; - logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的落塵計的平均值】", powerStation.Code, dateTime); + logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的風速計的平均值】", powerStation.Code, dateTime); + var VANHistory = await powerStationRepository.CalcSensorHistoryPerHour(dateTime, VANdeviceInfos, Convert.ToInt32(SensorTypeEnum.VAN)); + if (VANHistory != null) + { + sensorHistory.Vane = VANHistory.Vane; + logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的風速計的平均值】", powerStation.Code, dateTime); + } } } - } - catch (Exception ex) - { - logger.LogError("【CalcPowerStationJob】【計算失敗電站[{0}]在{1}的落塵計的平均值】", powerStation.Code, dateTime); - logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message); + catch (Exception ex) + { + logger.LogError("【CalcPowerStationJob】【計算失敗電站[{0}]在{1}的風速計的平均值】", powerStation.Code, dateTime); + logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message); + } + + //5. 計算該電站 - 落塵計(FOM) + try + { + logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的落塵計設備資訊】", powerStation.Code, dateTime); + var FOMdeviceInfos = await powerStationRepository.GetDeviceListByPowerStationIdAndType(powerStation.Id, SensorTypeEnum.FOM.ToString(), powerStation.SiteDB); + logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的落塵計設備資訊】", powerStation.Code, dateTime); + logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的落塵計設備資訊】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(FOMdeviceInfos)); + if (FOMdeviceInfos != null && FOMdeviceInfos.Count() > 0) + { + logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的落塵計的平均%】", powerStation.Code, dateTime); + var FOMHistory = await powerStationRepository.CalcSensorHistoryPerHour(dateTime, FOMdeviceInfos, Convert.ToInt32(SensorTypeEnum.FOM)); + if (FOMHistory != null) + { + sensorHistory.Dust = FOMHistory.Dust; + logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的落塵計的平均值】", powerStation.Code, dateTime); + } + } + } + catch (Exception ex) + { + logger.LogError("【CalcPowerStationJob】【計算失敗電站[{0}]在{1}的落塵計的平均值】", powerStation.Code, dateTime); + logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message); + } + + sensorHistoriesHour.Add(sensorHistory); } - sensorHistoriesHour.Add(sensorHistory); calcPowerStations.Add(calcPowerStation); #endregion #region step2-3. 計算該電站所有逆變器每小時值 - try + + var inverter_table_name = String.Format("s{0}01_inv", powerStation.Code); + var full_inverter_table_name = String.Format("`{0}`.`{1}`", powerStation.SiteDB, inverter_table_name); + var inverter_exist = await powerStationRepository.ExistTable(powerStation.SiteDB, inverter_table_name); + if (string.IsNullOrEmpty(inverter_exist)) { - logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的逆變器設備資訊】", powerStation.Code, dateTime); - 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("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的逆變器設備資訊】", powerStation.Code, dateTime); - logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的逆變器設備資訊】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(inverterIds)); - - var inverter_table_name = String.Format("s{0}01_inv", powerStation.Code); - var full_inverter_table_name = String.Format("`{0}`.`{1}`", powerStation.SiteDB, inverter_table_name); - var exist_inverter_table = await powerStationRepository.ExistTable(powerStation.SiteDB, inverter_table_name); - - if (!string.IsNullOrEmpty(exist_inverter_table) && inverterIds != null && inverterIds.Count() > 0) - { - logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的逆變器的資訊】", powerStation.Code, dateTime); - var inverterHistories = await powerStationRepository.CalcInverterHisyortHourData(dateTime, powerStation.SiteDB, full_inverter_table_name, inverterIds); - //取得日照計要找的欄位資訊 - var pyrheliometer = await powerStationRepository.GetFirstPyrheliometerInfo(powerStation.Id, powerStation.SiteDB); - var pyrheliometerValue = await powerStationRepository.GetFirstPyrheliometerValue(dateTime, pyrheliometer.DBName, pyrheliometer.TableName, pyrheliometer.ColName); - foreach (var inverterHistory in inverterHistories) - { - inverterHistory.Irradiance = pyrheliometerValue; - inverterHistory.DC1KW = inverterHistory.DC1W / 1000; - inverterHistory.DC2KW = inverterHistory.DC2W / 1000; - inverterHistory.DC3KW = inverterHistory.DC3W / 1000; - inverterHistory.DC4KW = inverterHistory.DC4W / 1000; - inverterHistory.DC5KW = inverterHistory.DC5W / 1000; - - inverterHistory.DCKW = (inverterHistory.DC1W + inverterHistory.DC2W + inverterHistory.DC3W + inverterHistory.DC4W + inverterHistory.DC5W) / 1000; - inverterHistory.ACKW = (inverterHistory.AC1W + inverterHistory.AC2W + inverterHistory.AC3W) / 1000; - - inverterHistory.TIMESTAMP = Convert.ToDateTime(inverterHistory.TIMESTAMP + ":00:00").ToString("yyyy-MM-dd HH:mm:ss"); - inverterHistory.PowerStationId = powerStation.Id; - - inverterHistoriesHour.Add(inverterHistory); - } - logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的逆變器的資訊】", powerStation.Code, dateTime); - } + logger.LogError("【CalcPowerStationJob】【查無電站[0]的s{0}01_inv資料表】", powerStation.Code); } - catch (Exception ex) + else { - logger.LogError("【CalcPowerStationJob】【計算失敗電站[{0}]在{1}的逆變器的資訊】", powerStation.Code, dateTime); - logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message); + try + { + logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的逆變器設備資訊】", powerStation.Code, dateTime); + 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("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的逆變器設備資訊】", powerStation.Code, dateTime); + logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的逆變器設備資訊】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(inverterIds)); + + if (inverterIds != null && inverterIds.Count() > 0) + { + logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的逆變器的資訊】", powerStation.Code, dateTime); + var inverterHistories = await powerStationRepository.CalcInverterHisyortHourData(dateTime, powerStation.SiteDB, full_inverter_table_name, inverterIds); + //取得日照計要找的欄位資訊 + var pyrheliometer = await powerStationRepository.GetFirstPyrheliometerInfo(powerStation.Id, powerStation.SiteDB); + var pyrheliometerValue = await powerStationRepository.GetFirstPyrheliometerValue(dateTime, pyrheliometer.DBName, pyrheliometer.TableName, pyrheliometer.ColName); + foreach (var inverterHistory in inverterHistories) + { + inverterHistory.Irradiance = pyrheliometerValue; + inverterHistory.DC1KW = inverterHistory.DC1W / 1000; + inverterHistory.DC2KW = inverterHistory.DC2W / 1000; + inverterHistory.DC3KW = inverterHistory.DC3W / 1000; + inverterHistory.DC4KW = inverterHistory.DC4W / 1000; + inverterHistory.DC5KW = inverterHistory.DC5W / 1000; + + inverterHistory.DCKW = (inverterHistory.DC1W + inverterHistory.DC2W + inverterHistory.DC3W + inverterHistory.DC4W + inverterHistory.DC5W) / 1000; + inverterHistory.ACKW = (inverterHistory.AC1W + inverterHistory.AC2W + inverterHistory.AC3W) / 1000; + + inverterHistory.TIMESTAMP = Convert.ToDateTime(inverterHistory.TIMESTAMP + ":00:00").ToString("yyyy-MM-dd HH:mm:ss"); + inverterHistory.PowerStationId = powerStation.Id; + + inverterHistoriesHour.Add(inverterHistory); + } + logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的逆變器的資訊】", powerStation.Code, dateTime); + } + } + catch (Exception ex) + { + logger.LogError("【CalcPowerStationJob】【計算失敗電站[{0}]在{1}的逆變器的資訊】", powerStation.Code, dateTime); + logger.LogError("【CalcPowerStationJob】【失敗原因】- {0}", ex.Message); + } } #endregion @@ -437,13 +459,14 @@ namespace SolarPower.Quartz.Jobs try { - var seneoravg_table_name = String.Format("s{0}01_sensoravg", powerStation.Code); - var full_seneoravg_table_name = String.Format("`{0}`.`{1}`", powerStation.SiteDB, seneoravg_table_name); - var exist_seneoravg_table = await powerStationRepository.ExistTable(powerStation.SiteDB, seneoravg_table_name); - if (!string.IsNullOrEmpty(exist_seneoravg_table)) + //var seneoravg_table_name = String.Format("s{0}01_sensoravg", powerStation.Code); + //var full_seneoravg_table_name = String.Format("`{0}`.`{1}`", powerStation.SiteDB, seneoravg_table_name); + //var exist_seneoravg_table = await powerStationRepository.ExistTable(powerStation.SiteDB, seneoravg_table_name); + + if (!string.IsNullOrEmpty(sensoravg_table_exist)) { logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的sensor avg的資訊】", powerStation.Code, dateTime); - var sensorAvgHistory = await powerStationRepository.CalcSensorAvgHistory(dateTime, full_seneoravg_table_name); + var sensorAvgHistory = await powerStationRepository.CalcSensorAvgHistory(dateTime, full_sensoravg_table_name); logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的sensor avg的資訊】", powerStation.Code, dateTime); if (sensorAvgHistory != null) @@ -468,7 +491,11 @@ namespace SolarPower.Quartz.Jobs var meter_table_name = String.Format("s{0}01_meter", powerStation.Code); var full_meter_table_name = String.Format("`{0}`.`{1}`", powerStation.SiteDB, meter_table_name); var exist_meter_table = await powerStationRepository.ExistTable(powerStation.SiteDB, meter_table_name); - if (!string.IsNullOrEmpty(exist_meter_table)) + if (string.IsNullOrEmpty(exist_meter_table)) + { + logger.LogError("【CalcPowerStationJob】【查無電站[0]的s{0}01_meter資料表】", powerStation.Code); + } + else { logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的meter的資訊】", powerStation.Code, dateTime); var meterHistory = await powerStationRepository.CalcMeterHistory(dateTime, full_meter_table_name);