1. 每15歸檔加入log
This commit is contained in:
parent
c7651dcd56
commit
b02110c3c5
@ -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<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]);
|
||||
|
||||
|
||||
#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,7 +175,7 @@ namespace SolarPower.Quartz.Jobs
|
||||
|
||||
logger.LogInformation("【CalcInverter15minJob】檢測完成逆變器狀態");
|
||||
}
|
||||
catch(Exception exception)
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError("【CalcInverter15minJob】檢測逆變器狀態失敗 - [Exception] {0}", exception.Message);
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ namespace SolarPower.Services
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//_log.LogError("【SendEmailSMSService】 " + noticeInfo.Recipient_email + "寄送信件失敗");
|
||||
throw ex;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user