1. 每15歸檔加入log

This commit is contained in:
Kai 2022-03-17 09:40:37 +08:00
parent c7651dcd56
commit b02110c3c5
2 changed files with 45 additions and 36 deletions

View File

@ -57,7 +57,7 @@ namespace SolarPower.Quartz.Jobs
logger.LogInformation("【CalcInverter15minJob】【開始取得電站資料】"); logger.LogInformation("【CalcInverter15minJob】【開始取得電站資料】");
var powerStations = await powerStationRepository.GetAllAsync(); var powerStations = await powerStationRepository.GetAllAsync();
logger.LogInformation("【CalcInverter15minJob】【取得成功電站資料】"); logger.LogInformation("【CalcInverter15minJob】【取得成功電站資料】");
logger.LogInformation("【CalcInverter15minJob】【電站資料】 - {0}", System.Text.Json.JsonSerializer.Serialize(powerStations)); //logger.LogInformation("【CalcInverter15minJob】【電站資料】 - {0}", System.Text.Json.JsonSerializer.Serialize(powerStations));
#endregion #endregion
List<InverterHistory> calcInverter15mins = new List<InverterHistory>(); List<InverterHistory> calcInverter15mins = new List<InverterHistory>();
@ -75,44 +75,46 @@ namespace SolarPower.Quartz.Jobs
//var dateNowTime = string.Format("2021-07-{0} {1}", day_array[i], time_array[j]); //var dateNowTime = string.Format("2021-07-{0} {1}", day_array[i], time_array[j]);
#region step2. DB及電站編號找出該電站的控制器 #region step2. DB及電站編號找出該電站的控制器
foreach (var powerStation in powerStations) 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}的每15分鐘逆變器資訊】", powerStation.Code, dateNowTime);
//取得所有該電站的逆變器 var calcInverter15min = await powerStationRepository.CalcInverterHisyort15minData(dateNowTime, powerStation.SiteDB, full_table_name, inverterIds);
logger.LogInformation("【CalcInverter15minJob】【開始取得電站[{0}]在{1}的逆變器設備資訊】", powerStation.Code, dateNowTime); logger.LogInformation("【CalcInverter15minJob】【計算完成電站[{0}]在{1}的每15分鐘逆變器資訊】", powerStation.Code, dateNowTime);
var controllers = await powerStationRepository.GetAllDeviceControllerId(powerStation.Id, powerStation.SiteDB); logger.LogInformation("【CalcInverter15minJob】【計算結果】 - {0}", System.Text.Json.JsonSerializer.Serialize(calcInverter15mins));
var inverters = await powerStationRepository.InverterTable(controllers, powerStation.SiteDB); if (calcInverter15min.Count() > 0)
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); foreach (var inverterHistory in calcInverter15min)
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) 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
} }
#endregion #endregion
@ -127,7 +129,14 @@ namespace SolarPower.Quartz.Jobs
"KWHKWP", "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 #endregion
// } // }
//} //}
@ -166,7 +175,7 @@ namespace SolarPower.Quartz.Jobs
logger.LogInformation("【CalcInverter15minJob】檢測完成逆變器狀態"); logger.LogInformation("【CalcInverter15minJob】檢測完成逆變器狀態");
} }
catch(Exception exception) catch (Exception exception)
{ {
logger.LogError("【CalcInverter15minJob】檢測逆變器狀態失敗 - [Exception] {0}", exception.Message); logger.LogError("【CalcInverter15minJob】檢測逆變器狀態失敗 - [Exception] {0}", exception.Message);
} }

View File

@ -53,7 +53,7 @@ namespace SolarPower.Services
} }
catch (Exception ex) catch (Exception ex)
{ {
//_log.LogError("【SendEmailSMSService】 " + noticeInfo.Recipient_email + "寄送信件失敗"); throw ex;
return false; return false;
} }