diff --git a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs index b62c84c..e6fa27e 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 = "2021-08-16 09"; + dateTime = "2021-11-02 10"; } logger.LogInformation("【CalcPowerStationJob】【任務開始】"); @@ -107,12 +107,18 @@ namespace SolarPower.Quartz.Jobs { logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime); var history = await powerStationRepository.GetPowerStationHistoryPerHour(dateTime, full_table_name); - logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime); - logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的每小時歷史資料】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(history)); - var lastmoneyhistorybyhour = await powerStationRepository.GetLastMoneyAndCarbonInHour(powerStation.Id, 0, dateTime); + // 當前用不到 + // var lastmoneyhistorybyhour = await powerStationRepository.GetLastMoneyAndCarbonInHour(powerStation.Id, 0, dateTime); - if (history != null) + if (history == null) { + logger.LogWarning("【CalcPowerStationJob】【查無電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime); + } + else + { + logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime); + logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的每小時歷史資料】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(history)); + logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime); history.PowerStationId = powerStation.Id; history.Timestamp = Convert.ToDateTime(history.Timestamp + ":00:00").ToString("yyyy-MM-dd HH:mm:ss"); @@ -303,8 +309,12 @@ namespace SolarPower.Quartz.Jobs //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); + } + else + { + logger.LogWarning("【CalcPowerStationJob】【查無結果電站[{0}]在{1}的日照計的平均值】", powerStation.Code, dateTime); } - logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的日照計的平均值】", powerStation.Code, dateTime); } } catch (Exception ex) @@ -334,6 +344,10 @@ namespace SolarPower.Quartz.Jobs logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的模組溫度計的平均值】", powerStation.Code, dateTime); } + else + { + logger.LogWarning("【CalcPowerStationJob】【查無結果電站[{0}]在{1}的模組溫度計的平均值】", powerStation.Code, dateTime); + } } } catch (Exception ex) diff --git a/solarApp/Program.cs b/solarApp/Program.cs index 782bb0f..4533ef9 100644 --- a/solarApp/Program.cs +++ b/solarApp/Program.cs @@ -1,3 +1,4 @@ +using Serilog; using System; using System.Collections.Generic; using System.Linq; @@ -14,12 +15,22 @@ namespace solarApp [STAThread] static void Main() { + Log.Logger = new LoggerConfiguration() + .MinimumLevel.Verbose() // ]w̧Cܼh w]: Information + .WriteTo.File("Logs/solarApp/log-.log", + rollingInterval: RollingInterval.Day, // CѤ@ɮ + outputTemplate: "{Timestamp:HH:mm:ss} [{Level:u5}] {Message:lj}{NewLine}{Exception}" + ) // Xɮ ɦWd: log-20211005.log + .CreateLogger(); + Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //Application.Run(new fmExcel()); Application.Run(new fmArchive()); //Application.Run(new fmMain()); + + Log.CloseAndFlush(); } } } diff --git a/solarApp/Service/procInvSvc.cs b/solarApp/Service/procInvSvc.cs index e8ebfc7..5c5cf89 100644 --- a/solarApp/Service/procInvSvc.cs +++ b/solarApp/Service/procInvSvc.cs @@ -6,6 +6,7 @@ using Dapper; using solarApp.Model; using System.Configuration; using System.Threading.Tasks; +using Serilog; namespace solarApp.Service { @@ -116,6 +117,7 @@ namespace solarApp.Service string ss = @"SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY,',''));"; conn.Execute(ss); + Log.Information("開始執行[{0}]在{1}逆變器15min補償", _siteID, _date1); #region 15 min string sql = @" INSERT INTO solar_master.inverter_history_15min( PowerStationId, TIMESTAMP, INVERTERID, KWH, TODAYKWH, KWHKWP) @@ -146,10 +148,12 @@ namespace solarApp.Service group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H') , inverterid ) a join " + _siteDB + @".inverter b on a.inverterid = b.inverterid"; var ds = conn.Execute(sql, new { date1 = _date1, PowerStationID = _powerStationID }); + + Log.Information("執行完成[{0}]在{1}逆變器15min補償", _siteID, _date1); #endregion #region hour - sql = @" + sql = @" insert into solar_master.inverter_history_hour (PowerStationId, INVERTERID, TIMESTAMP, Irradiance, AC1V, AC1A, AC1W, AC1F, AC1WH, AC2V, AC2A, AC2W, AC2F, AC2WH, AC3V, AC3A, AC3W, AC3F, AC3WH, DC1V, DC1A, DC1W, DC1WH, DC2V, DC2A, DC2W, DC2WH, DC3V, DC3A, DC3W, DC3WH, DC4V, DC4A, DC4W, DC4WH, DC5V, DC5A, DC5W, DC5WH, PR, RA1, RA2, RA3, RA4, RA5, DCKW, ACKW, KWH, TODAYKWH, TOTALKWH, KWHKWP) diff --git a/solarApp/solarApp.csproj b/solarApp/solarApp.csproj index dcee98b..c75fd44 100644 --- a/solarApp/solarApp.csproj +++ b/solarApp/solarApp.csproj @@ -21,6 +21,8 @@ + + \ No newline at end of file