From 6179d549a4577c504937a7900aeb33e1567bc51b Mon Sep 17 00:00:00 2001 From: "wanling040@gmail.com" Date: Thu, 4 Aug 2022 20:29:55 +0800 Subject: [PATCH] =?UTF-8?q?solar=5FApp:=20test=20=E4=BF=AE=E6=94=B9=20irrD?= =?UTF-8?q?ayHour=20In=20TPY?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Quartz/Jobs/CalcPowerStationJob.cs | 54 +++++++++++-------- .../Implement/PowerStationRepository.cs | 5 +- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs index fc7e687..0b6ec0a 100644 --- a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs @@ -44,7 +44,7 @@ namespace SolarPower.Quartz.Jobs if (this.environment.IsDevelopment()) { - dateTime = "2022-06-01 16"; + dateTime = "2022-08-04 18"; } logger.LogInformation("【CalcPowerStationJob】【任務開始】"); @@ -491,6 +491,14 @@ namespace SolarPower.Quartz.Jobs { sensorHistory.IrrDay = TPYHistory.IrrDay; logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的累計日照量的平均值】", powerStation.Code, dateTime); + logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的相減的累計日照量】", powerStation.Code, dateTime); + TPYHistory = await powerStationRepository.CalcIrrDayHourHistoryPerHour(dateTime, powerStation.Id); + if (TPYHistory != null) + { + sensorHistory.IrrDayHour = TPYHistory.IrrDayHour; + logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的相減的累計日照量】", powerStation.Code, dateTime); + } + } } } @@ -501,28 +509,28 @@ namespace SolarPower.Quartz.Jobs } //9. 計算該電站 - 每小時累計日照量(IrrDayHour) - try - { - logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的累計日照量設備資訊】", powerStation.Code, dateTime); - var TPYdeviceInfos = await powerStationRepository.GetDeviceListByPowerStationIdAndType(powerStation.Id, SensorTypeEnum.TPY.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(TPYdeviceInfos)); - if (TPYdeviceInfos != null && TPYdeviceInfos.Count() > 0) - { - logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的相減的累計日照量】", powerStation.Code, dateTime); - var TPYHistory = await powerStationRepository.CalcIrrDayHourHistoryPerHour(dateTime, powerStation.Id); - if (TPYHistory != null) - { - sensorHistory.IrrDayHour = TPYHistory.IrrDayHour; - 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); - } + //try + //{ + // logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的累計日照量設備資訊】", powerStation.Code, dateTime); + // var TPYdeviceInfos = await powerStationRepository.GetDeviceListByPowerStationIdAndType(powerStation.Id, SensorTypeEnum.TPY.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(TPYdeviceInfos)); + // if (TPYdeviceInfos != null && TPYdeviceInfos.Count() > 0) + // { + // logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的相減的累計日照量】", powerStation.Code, dateTime); + // var TPYHistory = await powerStationRepository.CalcIrrDayHourHistoryPerHour(dateTime, powerStation.Id); + // if (TPYHistory != null) + // { + // sensorHistory.IrrDayHour = TPYHistory.IrrDayHour; + // 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); } diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index d3dfe18..c247c1a 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -6433,12 +6433,13 @@ namespace SolarPower.Repository.Implement // where powerstationID = {powerStationId} and LEFT(z.`TIMESTAMP`, 13 ) = '{Convert.ToDateTime(dateTime).ToString("yyyy-MM-dd HH")}' // ) b on a.powerstationID = b.powerstationID and a.`TIMESTAMP` = b.`TIMESTAMP` // Set a.irrdayhour = b.irrdayhour where a.powerstationID = {powerStationId}"; + string d1 = dateTime + ":00:00"; string sql = $@"update sensor_history_hour a join ( select powerstationID, `TIMESTAMP`, irrday - - (select irrday from sensor_history_hour where powerstationID = {powerStationId} and LEFT(`TIMESTAMP`, 13 ) = '{Convert.ToDateTime(dateTime).AddHours(-1).ToString("yyyy-MM-dd HH")}' limit 1) irrdayhour + (select irrday from sensor_history_hour where powerstationID = {powerStationId} and LEFT(`TIMESTAMP`, 13 ) = '{Convert.ToDateTime(d1).AddHours(-1).ToString("yyyy-MM-dd HH")}' limit 1) irrdayhour from sensor_history_hour z - where powerstationID = {powerStationId} and LEFT(z.`TIMESTAMP`, 13 ) = '{(Convert.ToDateTime(dateTime)).ToString("yyyy-MM-dd HH")}' + where powerstationID = {powerStationId} and LEFT(z.`TIMESTAMP`, 13 ) = '{dateTime}' ) b on a.powerstationID = b.powerstationID and a.`TIMESTAMP` = b.`TIMESTAMP` Set a.irrdayhour = case when b.irrdayhour < 0 then 0 else b.irrdayhour end where a.powerstationID = {powerStationId}";