This commit is contained in:
b110212000 2021-09-03 17:45:12 +08:00
commit 11e20f30b9
4 changed files with 394 additions and 317 deletions

View File

@ -1,6 +1,8 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Quartz;
using solarApp.Service;
using SolarPower.Models;
using SolarPower.Models.PowerStation;
using SolarPower.Repository.Interface;
@ -21,8 +23,16 @@ namespace SolarPower.Quartz.Jobs
private readonly INoticeScheduleRepository noticeScheduleRepository;
private readonly IStationReportRepository stationReportRepository;
private readonly IOperationRepository operationRepository;
private readonly IConfiguration Configuration;
public CalcAvgPowerStationJob(ILogger<CalcAvgPowerStationJob> logger, IPowerStationRepository powerStationRepository, IUserRepository userRepository, INoticeScheduleRepository noticeScheduleRepository, IStationReportRepository stationReportRepository,IOperationRepository operationRepository)
public CalcAvgPowerStationJob(
ILogger<CalcAvgPowerStationJob> logger,
IPowerStationRepository powerStationRepository,
IUserRepository userRepository,
INoticeScheduleRepository noticeScheduleRepository,
IStationReportRepository stationReportRepository,
IOperationRepository operationRepository,
IConfiguration Configuration)
{
this.logger = logger;
this.powerStationRepository = powerStationRepository;
@ -30,6 +40,7 @@ namespace SolarPower.Quartz.Jobs
this.noticeScheduleRepository = noticeScheduleRepository;
this.stationReportRepository = stationReportRepository;
this.operationRepository = operationRepository;
this.Configuration = Configuration;
}
public async Task Execute(IJobExecutionContext context)
@ -377,79 +388,79 @@ namespace SolarPower.Quartz.Jobs
}
#endregion
#region step2-2.
if (!string.IsNullOrEmpty(exist))
{
//電站資訊
logger.LogInformation("【CalcAvgPowerStationJob】【開始取得電站[{0}]在{1}的所有值的總和】", powerStation.Code, dateNowDay);
var historyDay = await powerStationRepository.GetLastOnePowerStationHistoryByDay(dateNowDay, full_table_name);
logger.LogInformation("【CalcAvgPowerStationJob】【取得成功電站[{0}]在{1}的所有值的總和】", powerStation.Code, dateNowDay);
logger.LogInformation("【CalcAvgPowerStationJob】【電站[{0}]在{1}的所有值的總和】 - {2}", powerStation.Code, dateNowDay, System.Text.Json.JsonSerializer.Serialize(historyDay));
var moneyandcarbon = await powerStationRepository.GetMoneyAndCarbonWithHistoryHour(powerStation.Id, dateNowDay, 1);
var lastmoneyhistory = await powerStationRepository.GetLastMoneyAndCarbonInHour(powerStation.Id, 1, "");
if (historyDay != null)
{
historyDay.PowerStationId = powerStation.Id;
historyDay.CARBON = moneyandcarbon.CARBON;
historyDay.MONEY = moneyandcarbon.MONEY;
//historyDay.TODAYCARBON = lastmoneyhistory.TODAYCARBON;
//historyDay.TODAYMONEY = lastmoneyhistory.TODAYMONEY ;
if (lastmoneyhistory != null)
{
historyDay.TOTALCARBON = lastmoneyhistory.TOTALCARBON + moneyandcarbon.CARBON;
historyDay.TOTALMONEY = lastmoneyhistory.TOTALMONEY + moneyandcarbon.MONEY;
}
else
{
historyDay.TOTALCARBON = moneyandcarbon.CARBON;
historyDay.TOTALMONEY = moneyandcarbon.MONEY;
}
//#region step2-2. 計算該電站昨天的所有值總
//if (!string.IsNullOrEmpty(exist))
//{
// //電站資訊
// logger.LogInformation("【CalcAvgPowerStationJob】【開始取得電站[{0}]在{1}的所有值的總和】", powerStation.Code, dateNowDay);
// var historyDay = await powerStationRepository.GetLastOnePowerStationHistoryByDay(dateNowDay, full_table_name);
// logger.LogInformation("【CalcAvgPowerStationJob】【取得成功電站[{0}]在{1}的所有值的總和】", powerStation.Code, dateNowDay);
// logger.LogInformation("【CalcAvgPowerStationJob】【電站[{0}]在{1}的所有值的總和】 - {2}", powerStation.Code, dateNowDay, System.Text.Json.JsonSerializer.Serialize(historyDay));
// var moneyandcarbon = await powerStationRepository.GetMoneyAndCarbonWithHistoryHour(powerStation.Id, dateNowDay, 1);
// var lastmoneyhistory = await powerStationRepository.GetLastMoneyAndCarbonInHour(powerStation.Id, 1, "");
// if (historyDay != null)
// {
// historyDay.PowerStationId = powerStation.Id;
// historyDay.CARBON = moneyandcarbon.CARBON;
// historyDay.MONEY = moneyandcarbon.MONEY;
// //historyDay.TODAYCARBON = lastmoneyhistory.TODAYCARBON;
// //historyDay.TODAYMONEY = lastmoneyhistory.TODAYMONEY ;
// if (lastmoneyhistory != null)
// {
// historyDay.TOTALCARBON = lastmoneyhistory.TOTALCARBON + moneyandcarbon.CARBON;
// historyDay.TOTALMONEY = lastmoneyhistory.TOTALMONEY + moneyandcarbon.MONEY;
// }
// else
// {
// historyDay.TOTALCARBON = moneyandcarbon.CARBON;
// historyDay.TOTALMONEY = moneyandcarbon.MONEY;
// }
//日期轉換
historyDay.Timestamp = Convert.ToDateTime(historyDay.Timestamp + ":00:00").ToString("yyyy-MM-dd");
powerStationHistoryDays.Add(historyDay);
}
}
// //日期轉換
// historyDay.Timestamp = Convert.ToDateTime(historyDay.Timestamp + ":00:00").ToString("yyyy-MM-dd");
// powerStationHistoryDays.Add(historyDay);
// }
//}
//日照計、溫度
logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}的日照計所有值的平均】", powerStation.Code, dateNowDay);
var pyrheliometerHistorDay = await powerStationRepository.CalcPyrheliometerHistoryDayDataByPowerStationId(dateNowDay, powerStation.Id);
logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}的日照計所有值的平均】", powerStation.Code, dateNowDay);
if (pyrheliometerHistorDay != null)
{
pyrheliometerHistoryDays.Add(pyrheliometerHistorDay);
}
////日照計、溫度
//logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}的日照計所有值的平均】", powerStation.Code, dateNowDay);
//var pyrheliometerHistorDay = await powerStationRepository.CalcPyrheliometerHistoryDayDataByPowerStationId(dateNowDay, powerStation.Id);
//logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}的日照計所有值的平均】", powerStation.Code, dateNowDay);
//if (pyrheliometerHistorDay != null)
//{
// pyrheliometerHistoryDays.Add(pyrheliometerHistorDay);
//}
//逆變器
logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}的逆變器所有值的平均】", powerStation.Code, dateNowDay);
var inverterHistoriesDay = await powerStationRepository.CalcInverterHistoryDayDataByPowerStationId(dateNowDay, powerStation.SiteDB, powerStation.Id);
logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}的逆變器所有值的平均】", powerStation.Code, dateNowDay);
if (inverterHistoriesDay != null && inverterHistoriesDay.Count() > 0)
{
foreach (var inverterHistoryDay in inverterHistoriesDay)
{
inverterHistoryDay.DC1KW = inverterHistoryDay.DC1W / 1000;
inverterHistoryDay.DC2KW = inverterHistoryDay.DC2W / 1000;
inverterHistoryDay.DC3KW = inverterHistoryDay.DC3W / 1000;
inverterHistoryDay.DC4KW = inverterHistoryDay.DC4W / 1000;
inverterHistoryDay.DC5KW = inverterHistoryDay.DC5W / 1000;
////逆變器
//logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}的逆變器所有值的平均】", powerStation.Code, dateNowDay);
//var inverterHistoriesDay = await powerStationRepository.CalcInverterHistoryDayDataByPowerStationId(dateNowDay, powerStation.SiteDB, powerStation.Id);
//logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}的逆變器所有值的平均】", powerStation.Code, dateNowDay);
//if (inverterHistoriesDay != null && inverterHistoriesDay.Count() > 0)
//{
// foreach (var inverterHistoryDay in inverterHistoriesDay)
// {
// inverterHistoryDay.DC1KW = inverterHistoryDay.DC1W / 1000;
// inverterHistoryDay.DC2KW = inverterHistoryDay.DC2W / 1000;
// inverterHistoryDay.DC3KW = inverterHistoryDay.DC3W / 1000;
// inverterHistoryDay.DC4KW = inverterHistoryDay.DC4W / 1000;
// inverterHistoryDay.DC5KW = inverterHistoryDay.DC5W / 1000;
inverterHistoryDay.DCKW = (inverterHistoryDay.DC1W + inverterHistoryDay.DC2W + inverterHistoryDay.DC3W + inverterHistoryDay.DC4W + inverterHistoryDay.DC5W) / 1000;
inverterHistoryDay.ACKW = (inverterHistoryDay.AC1W + inverterHistoryDay.AC2W + inverterHistoryDay.AC3W) / 1000;
// inverterHistoryDay.DCKW = (inverterHistoryDay.DC1W + inverterHistoryDay.DC2W + inverterHistoryDay.DC3W + inverterHistoryDay.DC4W + inverterHistoryDay.DC5W) / 1000;
// inverterHistoryDay.ACKW = (inverterHistoryDay.AC1W + inverterHistoryDay.AC2W + inverterHistoryDay.AC3W) / 1000;
allofInverterHistorDays.Add(inverterHistoryDay);
}
}
//sensor avg
logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}的Sensor Avg table所有值的平均】", powerStation.Code, dateNowDay);
var sensorAvgHistoryDay = await powerStationRepository.CalcSensorAvgDayDataByPowerStationId(dateNowDay, powerStation.Id);
logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}的Sensor Avg table所有值的平均】", powerStation.Code, dateNowDay);
if (sensorAvgHistoryDay != null)
{
sensorAvgHistoryDays.Add(sensorAvgHistoryDay);
}
// allofInverterHistorDays.Add(inverterHistoryDay);
// }
//}
////sensor avg
//logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}的Sensor Avg table所有值的平均】", powerStation.Code, dateNowDay);
//var sensorAvgHistoryDay = await powerStationRepository.CalcSensorAvgDayDataByPowerStationId(dateNowDay, powerStation.Id);
//logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}的Sensor Avg table所有值的平均】", powerStation.Code, dateNowDay);
//if (sensorAvgHistoryDay != null)
//{
// sensorAvgHistoryDays.Add(sensorAvgHistoryDay);
//}
//meter
////meter
logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}的meter_hour所有值的平均】", powerStation.Code, dateNowDay);
var meterHistoriesDay = await powerStationRepository.CalcMeterDayDataByPowerStationId(dateNowDay, powerStation.Id);
logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}的meter_hour所有值的平均】", powerStation.Code, dateNowDay);
@ -457,7 +468,7 @@ namespace SolarPower.Quartz.Jobs
{
meterHistoriesDays.AddRange(meterHistoriesDay);
}
#endregion
//#endregion
}
#endregion
@ -476,287 +487,287 @@ namespace SolarPower.Quartz.Jobs
#region step4. insert資料表
//每日 - 電站歷史資料
List<string> history_properties_day = new List<string>()
{
"PowerStationId",
"TIMESTAMP",
"SITEID",
"SITETYPE",
"TODAYKWH",
"TOTALKWH",
"KWHKWP",
"PR",
"MP",
"SolarHour",
"MONEY",
"CARBON",
"TOTALMONEY",
"TOTALCARBON"
};
await powerStationRepository.AddPowerStationHistoryDayList(powerStationHistoryDays, history_properties_day);
//List<string> history_properties_day = new List<string>()
//{
// "PowerStationId",
// "TIMESTAMP",
// "SITEID",
// "SITETYPE",
// "TODAYKWH",
// "TOTALKWH",
// "KWHKWP",
// "PR",
// "MP",
// "SolarHour",
// "MONEY",
// "CARBON",
// "TOTALMONEY",
// "TOTALCARBON"
//};
//await powerStationRepository.AddPowerStationHistoryDayList(powerStationHistoryDays, history_properties_day);
//每日 - 日照溫度歷史資料
await powerStationRepository.AddPyrheliometerHistoryDayList(pyrheliometerHistoryDays, pyrheliometer_history_properties);
////每日 - 日照溫度歷史資料
//await powerStationRepository.AddPyrheliometerHistoryDayList(pyrheliometerHistoryDays, pyrheliometer_history_properties);
//每日 - 逆變器歷史資料
await powerStationRepository.AddInverterHistoryDayList(allofInverterHistorDays, inverter_history_properties);
////每日 - 逆變器歷史資料
//await powerStationRepository.AddInverterHistoryDayList(allofInverterHistorDays, inverter_history_properties);
//每日 - sensor avg
await powerStationRepository.AddSensorAvgHistoryDayList(sensorAvgHistoryDays, sensoravg_history_properties);
////每日 - sensor avg
//await powerStationRepository.AddSensorAvgHistoryDayList(sensorAvgHistoryDays, sensoravg_history_properties);
//每日 - meter
await powerStationRepository.AddMeterHistoryDayList(meterHistoriesDays, meter_history_properties);
#endregion
#region step5.
foreach (var powerStation in powerStations)
{
//電站該月份的歷史資料
logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}月份的歷史資料總和】", powerStation.Code, dateNowMonth);
var exist_history = await powerStationRepository.GetOnePowerStationHistoryByPowerStationIdAndMonth(powerStation.Id, dateNowMonth);
if (exist_history == null)
{ //新增
var historyMonth = await powerStationRepository.ClacPowerStationHistoryMonthDataByPowerStationId(powerStation.Id, dateNowMonth);
var moneyandcarbonMon = await powerStationRepository.GetMoneyAndCarbonWithHistoryHour(powerStation.Id, dateNowMonth, 0);
var lastmoneyhistorymonth = await powerStationRepository.GetLastMoneyAndCarbonInHour(powerStation.Id, 2, "");
if (historyMonth != null)
{
historyMonth.Timestamp = Convert.ToDateTime(historyMonth.Timestamp).ToString("yyyy-MM-dd");
historyMonth.MONEY = moneyandcarbonMon.MONEY;
historyMonth.CARBON = moneyandcarbonMon.CARBON;
if (lastmoneyhistorymonth != null)
{
historyMonth.TOTALCARBON = lastmoneyhistorymonth.TOTALCARBON + moneyandcarbonMon.CARBON;
historyMonth.TOTALMONEY = lastmoneyhistorymonth.TOTALMONEY + moneyandcarbonMon.MONEY;
}
else
{
historyMonth.TOTALCARBON = moneyandcarbonMon.CARBON;
historyMonth.TOTALMONEY = moneyandcarbonMon.MONEY;
}
//foreach (var powerStation in powerStations)
//{
// //電站該月份的歷史資料
// logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}月份的歷史資料總和】", powerStation.Code, dateNowMonth);
// var exist_history = await powerStationRepository.GetOnePowerStationHistoryByPowerStationIdAndMonth(powerStation.Id, dateNowMonth);
// if (exist_history == null)
// { //新增
// var historyMonth = await powerStationRepository.ClacPowerStationHistoryMonthDataByPowerStationId(powerStation.Id, dateNowMonth);
// var moneyandcarbonMon = await powerStationRepository.GetMoneyAndCarbonWithHistoryHour(powerStation.Id, dateNowMonth, 0);
// var lastmoneyhistorymonth = await powerStationRepository.GetLastMoneyAndCarbonInHour(powerStation.Id, 2, "");
// if (historyMonth != null)
// {
// historyMonth.Timestamp = Convert.ToDateTime(historyMonth.Timestamp).ToString("yyyy-MM-dd");
// historyMonth.MONEY = moneyandcarbonMon.MONEY;
// historyMonth.CARBON = moneyandcarbonMon.CARBON;
// if (lastmoneyhistorymonth != null)
// {
// historyMonth.TOTALCARBON = lastmoneyhistorymonth.TOTALCARBON + moneyandcarbonMon.CARBON;
// historyMonth.TOTALMONEY = lastmoneyhistorymonth.TOTALMONEY + moneyandcarbonMon.MONEY;
// }
// else
// {
// historyMonth.TOTALCARBON = moneyandcarbonMon.CARBON;
// historyMonth.TOTALMONEY = moneyandcarbonMon.MONEY;
// }
insertPowerStationHistoryMonths.Add(historyMonth);
}
logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}月份的歷史資料總和】", powerStation.Code, dateNowMonth);
}
else
{ //修改
var historyMonth = await powerStationRepository.ClacPowerStationHistoryMonthDataByPowerStationId(powerStation.Id, dateNowMonth);
var moneyandcarbonMon = await powerStationRepository.GetMoneyAndCarbonWithHistoryHour(powerStation.Id, dateNowMonth, 0);
var lastmoneyhistorymonth = await powerStationRepository.GetLastMoneyAndCarbonInHour(powerStation.Id, 2, "");
if (historyMonth != null)
{
historyMonth.MONEY = historyMonth.MONEY + moneyandcarbonMon.MONEY;
historyMonth.CARBON = historyMonth.CARBON + moneyandcarbonMon.CARBON;
if (lastmoneyhistorymonth != null)
{
historyMonth.TOTALCARBON = lastmoneyhistorymonth.TOTALCARBON + moneyandcarbonMon.CARBON;
historyMonth.TOTALMONEY = lastmoneyhistorymonth.TOTALMONEY + moneyandcarbonMon.MONEY;
}
else
{
historyMonth.TOTALCARBON = moneyandcarbonMon.CARBON;
historyMonth.TOTALMONEY = moneyandcarbonMon.MONEY;
}
updatePowerStationHistoryMonths.Add(historyMonth);
}
logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}月份的歷史資料總和】", powerStation.Code, dateNowMonth);
}
// insertPowerStationHistoryMonths.Add(historyMonth);
// }
// logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}月份的歷史資料總和】", powerStation.Code, dateNowMonth);
// }
// else
// { //修改
// var historyMonth = await powerStationRepository.ClacPowerStationHistoryMonthDataByPowerStationId(powerStation.Id, dateNowMonth);
// var moneyandcarbonMon = await powerStationRepository.GetMoneyAndCarbonWithHistoryHour(powerStation.Id, dateNowMonth, 0);
// var lastmoneyhistorymonth = await powerStationRepository.GetLastMoneyAndCarbonInHour(powerStation.Id, 2, "");
// if (historyMonth != null)
// {
// historyMonth.MONEY = historyMonth.MONEY + moneyandcarbonMon.MONEY;
// historyMonth.CARBON = historyMonth.CARBON + moneyandcarbonMon.CARBON;
// if (lastmoneyhistorymonth != null)
// {
// historyMonth.TOTALCARBON = lastmoneyhistorymonth.TOTALCARBON + moneyandcarbonMon.CARBON;
// historyMonth.TOTALMONEY = lastmoneyhistorymonth.TOTALMONEY + moneyandcarbonMon.MONEY;
// }
// else
// {
// historyMonth.TOTALCARBON = moneyandcarbonMon.CARBON;
// historyMonth.TOTALMONEY = moneyandcarbonMon.MONEY;
// }
// updatePowerStationHistoryMonths.Add(historyMonth);
// }
// logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}月份的歷史資料總和】", powerStation.Code, dateNowMonth);
// }
//電站該月份的的日照度歷史資料
logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}月份的日照度歷史資料】", powerStation.Code, dateNowMonth);
var exist_pyrheliometer_history = await powerStationRepository.GetOnePyrheliometerHistoryByMonth(dateNowMonth, powerStation.Id);
if (exist_pyrheliometer_history == null)
{ //新增
var pyrheliometerHistoryMonth = await powerStationRepository.CalcPyrheliometerHistoryMonthDataByPowerStationId(dateNowMonth, powerStation.Id);
if (pyrheliometerHistoryMonth != null)
{
pyrheliometerHistoryMonth.Timestamp = Convert.ToDateTime(pyrheliometerHistoryMonth.Timestamp).ToString("yyyy-MM-dd");
insertPyrheliometerHistoryMonths.Add(pyrheliometerHistoryMonth);
}
logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}月份的日照度歷史資料】", powerStation.Code, dateNowMonth);
}
else
{ //修改
var pyrheliometerHistoryMonth = await powerStationRepository.CalcPyrheliometerHistoryMonthDataByPowerStationId(dateNowMonth, powerStation.Id);
if (pyrheliometerHistoryMonth != null)
{
updatePyrheliometerHistoryMonths.Add(pyrheliometerHistoryMonth);
}
logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}月份的日照度歷史資料】", powerStation.Code, dateNowMonth);
}
// //電站該月份的的日照度歷史資料
// logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}月份的日照度歷史資料】", powerStation.Code, dateNowMonth);
// var exist_pyrheliometer_history = await powerStationRepository.GetOnePyrheliometerHistoryByMonth(dateNowMonth, powerStation.Id);
// if (exist_pyrheliometer_history == null)
// { //新增
// var pyrheliometerHistoryMonth = await powerStationRepository.CalcPyrheliometerHistoryMonthDataByPowerStationId(dateNowMonth, powerStation.Id);
// if (pyrheliometerHistoryMonth != null)
// {
// pyrheliometerHistoryMonth.Timestamp = Convert.ToDateTime(pyrheliometerHistoryMonth.Timestamp).ToString("yyyy-MM-dd");
// insertPyrheliometerHistoryMonths.Add(pyrheliometerHistoryMonth);
// }
// logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}月份的日照度歷史資料】", powerStation.Code, dateNowMonth);
// }
// else
// { //修改
// var pyrheliometerHistoryMonth = await powerStationRepository.CalcPyrheliometerHistoryMonthDataByPowerStationId(dateNowMonth, powerStation.Id);
// if (pyrheliometerHistoryMonth != null)
// {
// updatePyrheliometerHistoryMonths.Add(pyrheliometerHistoryMonth);
// }
// logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}月份的日照度歷史資料】", powerStation.Code, dateNowMonth);
// }
//電站該月份的的逆變器歷史資料
logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}月份的逆變器歷史資料】", powerStation.Code, dateNowMonth);
var exist_inverter_histories = await powerStationRepository.GetInverterHistoryByPowerStationIdAndMonth(dateNowMonth, powerStation.Id);
if (exist_inverter_histories.Count == 0)
{ //新增
var inverterHistoriesMonth = await powerStationRepository.CalcInverterHistoryMonthDataByPowerStationId(dateNowMonth, powerStation.SiteDB, powerStation.Id);
if (inverterHistoriesMonth.Count > 0)
{
foreach (var inverterHistoryMonth in inverterHistoriesMonth)
{
inverterHistoryMonth.DC1KW = inverterHistoryMonth.DC1W / 1000;
inverterHistoryMonth.DC2KW = inverterHistoryMonth.DC2W / 1000;
inverterHistoryMonth.DC3KW = inverterHistoryMonth.DC3W / 1000;
inverterHistoryMonth.DC4KW = inverterHistoryMonth.DC4W / 1000;
inverterHistoryMonth.DC5KW = inverterHistoryMonth.DC5W / 1000;
// //電站該月份的的逆變器歷史資料
// logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}月份的逆變器歷史資料】", powerStation.Code, dateNowMonth);
// var exist_inverter_histories = await powerStationRepository.GetInverterHistoryByPowerStationIdAndMonth(dateNowMonth, powerStation.Id);
// if (exist_inverter_histories.Count == 0)
// { //新增
// var inverterHistoriesMonth = await powerStationRepository.CalcInverterHistoryMonthDataByPowerStationId(dateNowMonth, powerStation.SiteDB, powerStation.Id);
// if (inverterHistoriesMonth.Count > 0)
// {
// foreach (var inverterHistoryMonth in inverterHistoriesMonth)
// {
// inverterHistoryMonth.DC1KW = inverterHistoryMonth.DC1W / 1000;
// inverterHistoryMonth.DC2KW = inverterHistoryMonth.DC2W / 1000;
// inverterHistoryMonth.DC3KW = inverterHistoryMonth.DC3W / 1000;
// inverterHistoryMonth.DC4KW = inverterHistoryMonth.DC4W / 1000;
// inverterHistoryMonth.DC5KW = inverterHistoryMonth.DC5W / 1000;
inverterHistoryMonth.DCKW = (inverterHistoryMonth.DC1W + inverterHistoryMonth.DC2W + inverterHistoryMonth.DC3W + inverterHistoryMonth.DC4W + inverterHistoryMonth.DC5W) / 1000;
inverterHistoryMonth.ACKW = (inverterHistoryMonth.AC1W + inverterHistoryMonth.AC2W + inverterHistoryMonth.AC3W) / 1000;
// inverterHistoryMonth.DCKW = (inverterHistoryMonth.DC1W + inverterHistoryMonth.DC2W + inverterHistoryMonth.DC3W + inverterHistoryMonth.DC4W + inverterHistoryMonth.DC5W) / 1000;
// inverterHistoryMonth.ACKW = (inverterHistoryMonth.AC1W + inverterHistoryMonth.AC2W + inverterHistoryMonth.AC3W) / 1000;
inverterHistoryMonth.TIMESTAMP = Convert.ToDateTime(inverterHistoryMonth.TIMESTAMP).ToString("yyyy-MM-dd");
insertInverterHistoryMonths.Add(inverterHistoryMonth);
}
}
logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}月份的逆變器歷史資料】", powerStation.Code, dateNowMonth);
}
else
{ //修改
var inverterHistoriesMonth = await powerStationRepository.CalcInverterHistoryMonthDataByPowerStationId(dateNowMonth, powerStation.SiteDB, powerStation.Id);
if (inverterHistoriesMonth.Count > 0)
{
foreach (var inverterHistoryMonth in inverterHistoriesMonth)
{
inverterHistoryMonth.DC1KW = inverterHistoryMonth.DC1W / 1000;
inverterHistoryMonth.DC2KW = inverterHistoryMonth.DC2W / 1000;
inverterHistoryMonth.DC3KW = inverterHistoryMonth.DC3W / 1000;
inverterHistoryMonth.DC4KW = inverterHistoryMonth.DC4W / 1000;
inverterHistoryMonth.DC5KW = inverterHistoryMonth.DC5W / 1000;
// inverterHistoryMonth.TIMESTAMP = Convert.ToDateTime(inverterHistoryMonth.TIMESTAMP).ToString("yyyy-MM-dd");
// insertInverterHistoryMonths.Add(inverterHistoryMonth);
// }
// }
// logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}月份的逆變器歷史資料】", powerStation.Code, dateNowMonth);
// }
// else
// { //修改
// var inverterHistoriesMonth = await powerStationRepository.CalcInverterHistoryMonthDataByPowerStationId(dateNowMonth, powerStation.SiteDB, powerStation.Id);
// if (inverterHistoriesMonth.Count > 0)
// {
// foreach (var inverterHistoryMonth in inverterHistoriesMonth)
// {
// inverterHistoryMonth.DC1KW = inverterHistoryMonth.DC1W / 1000;
// inverterHistoryMonth.DC2KW = inverterHistoryMonth.DC2W / 1000;
// inverterHistoryMonth.DC3KW = inverterHistoryMonth.DC3W / 1000;
// inverterHistoryMonth.DC4KW = inverterHistoryMonth.DC4W / 1000;
// inverterHistoryMonth.DC5KW = inverterHistoryMonth.DC5W / 1000;
inverterHistoryMonth.DCKW = (inverterHistoryMonth.DC1W + inverterHistoryMonth.DC2W + inverterHistoryMonth.DC3W + inverterHistoryMonth.DC4W + inverterHistoryMonth.DC5W) / 1000;
inverterHistoryMonth.ACKW = (inverterHistoryMonth.AC1W + inverterHistoryMonth.AC2W + inverterHistoryMonth.AC3W) / 1000;
// inverterHistoryMonth.DCKW = (inverterHistoryMonth.DC1W + inverterHistoryMonth.DC2W + inverterHistoryMonth.DC3W + inverterHistoryMonth.DC4W + inverterHistoryMonth.DC5W) / 1000;
// inverterHistoryMonth.ACKW = (inverterHistoryMonth.AC1W + inverterHistoryMonth.AC2W + inverterHistoryMonth.AC3W) / 1000;
inverterHistoryMonth.TIMESTAMP = Convert.ToDateTime(inverterHistoryMonth.TIMESTAMP).ToString("yyyy-MM-dd");
updateInverterHistoryMonths.Add(inverterHistoryMonth);
}
}
logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}月份的逆變器歷史資料】", powerStation.Code, dateNowMonth);
}
// inverterHistoryMonth.TIMESTAMP = Convert.ToDateTime(inverterHistoryMonth.TIMESTAMP).ToString("yyyy-MM-dd");
// updateInverterHistoryMonths.Add(inverterHistoryMonth);
// }
// }
// logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}月份的逆變器歷史資料】", powerStation.Code, dateNowMonth);
// }
//電站該月份的的sensoravg歷史資料
logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}月份的Sensor Avg table所有值的平均資料】", powerStation.Code, dateNowMonth);
var exist_sensoravg_history = await powerStationRepository.GetSensorAvgHistoryByPowerStationIdAndMonth(dateNowMonth, powerStation.Id);
if (exist_sensoravg_history == null)
{ //新增
var sensorAvgHistoryMonth = await powerStationRepository.CalcSensorAvgHistoryMonthDataByPowerStationId(dateNowMonth, powerStation.Id);
if (sensorAvgHistoryMonth != null)
{
sensorAvgHistoryMonth.TIMESTAMP = Convert.ToDateTime(sensorAvgHistoryMonth.TIMESTAMP).ToString("yyyy-MM-dd");
insertSensorAvgHistoryMonths.Add(sensorAvgHistoryMonth);
}
logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}月份的Sensor Avg table所有值的平均資料】", powerStation.Code, dateNowMonth);
}
else
{ //修改
var sensorAvgHistoryMonth = await powerStationRepository.CalcSensorAvgHistoryMonthDataByPowerStationId(dateNowMonth, powerStation.Id);
if (sensorAvgHistoryMonth != null)
{
sensorAvgHistoryMonth.TIMESTAMP = Convert.ToDateTime(sensorAvgHistoryMonth.TIMESTAMP).ToString("yyyy-MM-dd");
updateSensorAvgHistoryMonths.Add(sensorAvgHistoryMonth);
}
logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}月份的Sensor Avg table所有值的平均資料】", powerStation.Code, dateNowMonth);
}
// //電站該月份的的sensoravg歷史資料
// logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}月份的Sensor Avg table所有值的平均資料】", powerStation.Code, dateNowMonth);
// var exist_sensoravg_history = await powerStationRepository.GetSensorAvgHistoryByPowerStationIdAndMonth(dateNowMonth, powerStation.Id);
// if (exist_sensoravg_history == null)
// { //新增
// var sensorAvgHistoryMonth = await powerStationRepository.CalcSensorAvgHistoryMonthDataByPowerStationId(dateNowMonth, powerStation.Id);
// if (sensorAvgHistoryMonth != null)
// {
// sensorAvgHistoryMonth.TIMESTAMP = Convert.ToDateTime(sensorAvgHistoryMonth.TIMESTAMP).ToString("yyyy-MM-dd");
// insertSensorAvgHistoryMonths.Add(sensorAvgHistoryMonth);
// }
// logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}月份的Sensor Avg table所有值的平均資料】", powerStation.Code, dateNowMonth);
// }
// else
// { //修改
// var sensorAvgHistoryMonth = await powerStationRepository.CalcSensorAvgHistoryMonthDataByPowerStationId(dateNowMonth, powerStation.Id);
// if (sensorAvgHistoryMonth != null)
// {
// sensorAvgHistoryMonth.TIMESTAMP = Convert.ToDateTime(sensorAvgHistoryMonth.TIMESTAMP).ToString("yyyy-MM-dd");
// updateSensorAvgHistoryMonths.Add(sensorAvgHistoryMonth);
// }
// logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}月份的Sensor Avg table所有值的平均資料】", powerStation.Code, dateNowMonth);
// }
//電站該月份的的meter歷史資料
logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}月份的meter table所有值的平均資料】", powerStation.Code, dateNowMonth);
var exist_meter_history = await powerStationRepository.GetMeterHistoryByPowerStationIdAndMonth(dateNowMonth, powerStation.Id);
if (exist_meter_history.Count() == 0)
{ //新增
var meterHistoriesMonth = await powerStationRepository.CalcMeterHistoryMonthDataByPowerStationId(dateNowMonth, powerStation.Id);
if (meterHistoriesMonth != null && meterHistoriesMonth.Count() > 0)
{
foreach (var meterHistoryMonth in meterHistoriesMonth)
{
meterHistoryMonth.TIMESTAMP = Convert.ToDateTime(meterHistoryMonth.TIMESTAMP).ToString("yyyy-MM-dd");
insertmeterHistoryMonths.Add(meterHistoryMonth);
}
}
logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}月份的meter table所有值的平均資料】", powerStation.Code, dateNowMonth);
}
else
{ //修改
var meterHistoriesMonth = await powerStationRepository.CalcMeterHistoryMonthDataByPowerStationId(dateNowMonth, powerStation.Id);
if (meterHistoriesMonth != null && meterHistoriesMonth.Count() > 0)
{
foreach (var meterHistoryMonth in meterHistoriesMonth)
{
meterHistoryMonth.TIMESTAMP = Convert.ToDateTime(meterHistoryMonth.TIMESTAMP).ToString("yyyy-MM-dd");
updatemeterHistoryMonths.Add(meterHistoryMonth);
}
}
logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}月份的meter table所有值的平均資料】", powerStation.Code, dateNowMonth);
}
}
// //電站該月份的的meter歷史資料
// logger.LogInformation("【CalcAvgPowerStationJob】【開始計算電站[{0}]在{1}月份的meter table所有值的平均資料】", powerStation.Code, dateNowMonth);
// var exist_meter_history = await powerStationRepository.GetMeterHistoryByPowerStationIdAndMonth(dateNowMonth, powerStation.Id);
// if (exist_meter_history.Count() == 0)
// { //新增
// var meterHistoriesMonth = await powerStationRepository.CalcMeterHistoryMonthDataByPowerStationId(dateNowMonth, powerStation.Id);
// if (meterHistoriesMonth != null && meterHistoriesMonth.Count() > 0)
// {
// foreach (var meterHistoryMonth in meterHistoriesMonth)
// {
// meterHistoryMonth.TIMESTAMP = Convert.ToDateTime(meterHistoryMonth.TIMESTAMP).ToString("yyyy-MM-dd");
// insertmeterHistoryMonths.Add(meterHistoryMonth);
// }
// }
// logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}月份的meter table所有值的平均資料】", powerStation.Code, dateNowMonth);
// }
// else
// { //修改
// var meterHistoriesMonth = await powerStationRepository.CalcMeterHistoryMonthDataByPowerStationId(dateNowMonth, powerStation.Id);
// if (meterHistoriesMonth != null && meterHistoriesMonth.Count() > 0)
// {
// foreach (var meterHistoryMonth in meterHistoriesMonth)
// {
// meterHistoryMonth.TIMESTAMP = Convert.ToDateTime(meterHistoryMonth.TIMESTAMP).ToString("yyyy-MM-dd");
// updatemeterHistoryMonths.Add(meterHistoryMonth);
// }
// }
// logger.LogInformation("【CalcAvgPowerStationJob】【計算完成電站[{0}]在{1}月份的meter table所有值的平均資料】", powerStation.Code, dateNowMonth);
// }
//}
#endregion
//每月
List<string> history_properties_month = new List<string>()
{
"PowerStationId",
"TIMESTAMP",
"SITEID",
"SITETYPE",
"MonthKWh",
"TOTALKWH",
"KWHKWP",
"PR",
"MP",
"SolarHour",
"MONEY",
"CARBON",
"TOTALMONEY",
"TOTALCARBON"
};
//List<string> history_properties_month = new List<string>()
//{
// "PowerStationId",
// "TIMESTAMP",
// "SITEID",
// "SITETYPE",
// "MonthKWh",
// "TOTALKWH",
// "KWHKWP",
// "PR",
// "MP",
// "SolarHour",
// "MONEY",
// "CARBON",
// "TOTALMONEY",
// "TOTALCARBON"
//};
if (insertPowerStationHistoryMonths.Count > 0)
{
await powerStationRepository.AddPowerStationHistoryMonthList(insertPowerStationHistoryMonths, history_properties_month);
}
//if (insertPowerStationHistoryMonths.Count > 0)
//{
// await powerStationRepository.AddPowerStationHistoryMonthList(insertPowerStationHistoryMonths, history_properties_month);
//}
if (updatePowerStationHistoryMonths.Count > 0)
{
await powerStationRepository.UpdatePowerStationHistoryMonthList(updatePowerStationHistoryMonths);
}
//if (updatePowerStationHistoryMonths.Count > 0)
//{
// await powerStationRepository.UpdatePowerStationHistoryMonthList(updatePowerStationHistoryMonths);
//}
#region step5. insert or update
//每月
if (insertPyrheliometerHistoryMonths.Count > 0)
{
await powerStationRepository.AddPyrheliometerHistoryMonthList(insertPyrheliometerHistoryMonths, pyrheliometer_history_properties);
}
//if (insertPyrheliometerHistoryMonths.Count > 0)
//{
// await powerStationRepository.AddPyrheliometerHistoryMonthList(insertPyrheliometerHistoryMonths, pyrheliometer_history_properties);
//}
if (updatePyrheliometerHistoryMonths.Count > 0)
{
await powerStationRepository.UpdatePyrheliometerHistoryMonthList(updatePyrheliometerHistoryMonths);
}
//if (updatePyrheliometerHistoryMonths.Count > 0)
//{
// await powerStationRepository.UpdatePyrheliometerHistoryMonthList(updatePyrheliometerHistoryMonths);
//}
#endregion
#region step6. insert or update
//每月
if (insertInverterHistoryMonths.Count > 0)
{
await powerStationRepository.AddInverterHistoryMonthList(insertInverterHistoryMonths, inverter_history_properties);
}
//if (insertInverterHistoryMonths.Count > 0)
//{
// await powerStationRepository.AddInverterHistoryMonthList(insertInverterHistoryMonths, inverter_history_properties);
//}
if (updateInverterHistoryMonths.Count > 0)
{
await powerStationRepository.UpdateInverterHistoryMonthList(updateInverterHistoryMonths);
}
//if (updateInverterHistoryMonths.Count > 0)
//{
// await powerStationRepository.UpdateInverterHistoryMonthList(updateInverterHistoryMonths);
//}
#endregion
#region step7. Sensor Avg資料insert or update
//每月
if (insertSensorAvgHistoryMonths.Count > 0)
{
await powerStationRepository.AddSensorAvgHistoryMonthList(insertSensorAvgHistoryMonths, sensoravg_history_properties);
}
//if (insertSensorAvgHistoryMonths.Count > 0)
//{
// await powerStationRepository.AddSensorAvgHistoryMonthList(insertSensorAvgHistoryMonths, sensoravg_history_properties);
//}
if (updateSensorAvgHistoryMonths.Count > 0)
{
await powerStationRepository.UpdateSensorAvgHistoryMonthList(updateSensorAvgHistoryMonths);
}
//if (updateSensorAvgHistoryMonths.Count > 0)
//{
// await powerStationRepository.UpdateSensorAvgHistoryMonthList(updateSensorAvgHistoryMonths);
//}
#endregion
#region step8. meter資料insert or update
@ -772,13 +783,66 @@ namespace SolarPower.Quartz.Jobs
}
#endregion
#region
var gobackDay = this.Configuration.GetValue<int>("GoBackDay"); //回推天數
var start_date = DateTimeNow.AddDays(-1 * gobackDay);
var end_date = DateTimeNow.AddDays(-1);
logger.LogInformation("【CalcAvgPowerStationJob】【開始補償機制】");
procSensorSvc sensorSvc = new procSensorSvc();
procInvSvc invSvc = new procInvSvc();
procStationSvc siteSvc = new procStationSvc();
foreach (var powerStation in powerStations)
{
foreach (DateTime day in EachDay(start_date, end_date))
{
var day_str = day.ToString("yyyy-MM-dd");
try
{
logger.LogInformation("【CalcAvgPowerStationJob】【開始執行電站[{0}]在{1}的Sensor補償機制】", powerStation.Code, day_str);
sensorSvc.archiveData(powerStation.Code, day_str);
logger.LogInformation("【CalcAvgPowerStationJob】【執行完成電站[{0}]在{1}的Sensor補償機制】", powerStation.Code, day_str);
}
catch (Exception exception)
{
logger.LogInformation("【CalcAvgPowerStationJob】【執行失敗電站[{0}]在{1}的Sensor補償機制】", powerStation.Code, day_str);
logger.LogError("【CalcAvgPowerStationJob】[Exception] - {0}", exception.Message);
logger.LogError("【CalcAvgPowerStationJob】[InnerException] - {0}", exception.InnerException.Message);
}
try
{
logger.LogInformation("【CalcAvgPowerStationJob】【開始執行電站[{0}]在{1}的Inverter補償機制】", powerStation.Code, day_str);
invSvc.archiveData(powerStation.Code, day_str);
logger.LogInformation("【CalcAvgPowerStationJob】【執行完成電站[{0}]在{1}的Inverter補償機制】", powerStation.Code, day_str);
}
catch (Exception exception)
{
logger.LogInformation("【CalcAvgPowerStationJob】【執行失敗電站[{0}]在{1}的Inverter補償機制】", powerStation.Code, day_str);
logger.LogError("【CalcAvgPowerStationJob】[Exception] - {0}", exception.Message);
logger.LogError("【CalcAvgPowerStationJob】[InnerException] - {0}", exception.InnerException.Message);
}
try
{
logger.LogInformation("【CalcAvgPowerStationJob】【開始執行電站[{0}]在{1}的Site補償機制】", powerStation.Code, day_str);
siteSvc.archiveData(powerStation.Code, day_str);
logger.LogInformation("【CalcAvgPowerStationJob】【執行完成電站[{0}]在{1}的Site補償機制】", powerStation.Code, day_str);
}
catch (Exception exception)
{
logger.LogInformation("【CalcAvgPowerStationJob】【執行失敗電站[{0}]在{1}的Site補償機制】", powerStation.Code, day_str);
logger.LogError("【CalcAvgPowerStationJob】[Exception] - {0}", exception.Message);
logger.LogError("【CalcAvgPowerStationJob】[InnerException] - {0}", exception.InnerException.Message);
}
}
}
#endregion
#region
var users = userRepository.GetAllAsync();
foreach (var user in users.Result)
{
List<OperationPersonnel> powerstations = new List<OperationPersonnel>();
powerstations = await noticeScheduleRepository.GetPowerStationOperationPersonnel(user.Id);
if (powerstations.Count == 0)
@ -951,5 +1015,11 @@ namespace SolarPower.Quartz.Jobs
logger.LogError("【CalcAvgPowerStationJob】[InnerException] - {0}", exception.InnerException.Message);
}
}
public IEnumerable<DateTime> EachDay(DateTime from, DateTime thru)
{
for (var day = from.Date; day.Date <= thru.Date; day = day.AddDays(1))
yield return day;
}
}
}

View File

@ -24,9 +24,9 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.78" />
<PackageReference Include="Dapper" Version="2.0.90" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.17" />
<PackageReference Include="MySql.Data" Version="8.0.24" />
<PackageReference Include="MySql.Data" Version="8.0.26" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NPOI" Version="2.5.3" />
<PackageReference Include="Quartz" Version="3.3.2" />
@ -182,4 +182,8 @@
<None Include="wwwroot\webfonts\summernote.woff2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\solarApp\solarApp.csproj" />
</ItemGroup>
</Project>

View File

@ -7,6 +7,7 @@
}
},
"LoginExpireMinute": 60, //()
"GoBackDay": 3, //(())
"DBConfig": {
"Server": "MVgHWzR3rGDgD57TUoFunA==",
"port": "r4AoXMUDodcQjIzofGNCcg==",

View File

@ -4,5 +4,7 @@
<connectionStrings>
<add name="mySql" connectionString="server=60.251.164.103;user=webuser;Database=solar_master;Port=11306;password=FICadmin99;charset='utf8';pooling=true;sslmode=none;" providerName="MySql.Data.MySqlClient" />
<!--<add name="mySql" connectionString="server=localhost;user=root;Database=solar_master;Port=3306;password=zxcvb123;charset='utf8';pooling=true;sslmode=none;" providerName="MySql.Data.MySqlClient" />-->
<!-- kai -->
<!--<add name="mySql" connectionString="server=210.61.91.43;port=10068;user=idafenweb;Database=solar_power_test;Port=3306;password=P@ssw0rd;charset='utf8';pooling=true;sslmode=none;" providerName="MySql.Data.MySqlClient" />-->
</connectionStrings>
</configuration>