1. 修改電站交叉分析
This commit is contained in:
parent
a16468f22c
commit
5676df94dd
@ -74,7 +74,7 @@ namespace SolarPower.Controllers
|
||||
temp.Add(powerStation);
|
||||
foreach (var device in psName_Group)
|
||||
{
|
||||
if(!string.IsNullOrEmpty(device.DeviceId))
|
||||
if (!string.IsNullOrEmpty(device.DeviceId))
|
||||
{
|
||||
temp.Add(device);
|
||||
}
|
||||
@ -114,13 +114,17 @@ namespace SolarPower.Controllers
|
||||
Dictionary<int, List<Device>> deviceDic = new Dictionary<int, List<Device>>();
|
||||
List<StationIdWithMeterIds> meterDic = new List<StationIdWithMeterIds>();
|
||||
List<int> selected_powerStationIds = new List<int>();
|
||||
|
||||
List<PowerStationHistory> powerStationHistories = new List<PowerStationHistory>();
|
||||
List<MeterHistory> meterHistories = new List<MeterHistory>();
|
||||
|
||||
foreach (var psId_Group in device_powerStationId_Group)
|
||||
{
|
||||
var powerStation = await powerStationRepository.GetOneAsync(psId_Group.Key);
|
||||
|
||||
//區分電站總覽or設備
|
||||
var temp_psIds = psId_Group.Where(x => x.DeviceType == "PWS").Select(x => Convert.ToInt32(x.DeviceId)).ToList();
|
||||
if(temp_psIds.Count() > 0)
|
||||
if (temp_psIds.Count() > 0)
|
||||
{
|
||||
selected_powerStationIds.AddRange(temp_psIds);
|
||||
}
|
||||
@ -170,13 +174,39 @@ namespace SolarPower.Controllers
|
||||
|
||||
var XAxis = new List<string>();
|
||||
|
||||
#region 電站資料
|
||||
//針對x軸先進行處理,並同時抓取資料
|
||||
if (selected_powerStationIds.Count() > 0)
|
||||
{
|
||||
var powerStationHistories = await powerStationRepository.GetPowerStationHistory(post.SelectedDate, post.SearchType, selected_powerStationIds);
|
||||
powerStationHistories = await powerStationRepository.GetPowerStationHistory(post.SelectedDate, post.SearchType, selected_powerStationIds);
|
||||
|
||||
XAxis.AddRange(powerStationHistories.Select(x => x.Timestamp).Distinct().ToList());
|
||||
}
|
||||
if (meterDic.Count() > 0)
|
||||
{
|
||||
meterHistories = await powerStationRepository.GetMeterHistory(post.SelectedDate, post.SearchType, meterDic);
|
||||
|
||||
XAxis.AddRange(meterHistories.Select(x => x.TIMESTAMP).Distinct().ToList());
|
||||
}
|
||||
if (deviceDic.Count > 0)
|
||||
{
|
||||
foreach (var devices in deviceDic)
|
||||
{
|
||||
var result = await powerStationRepository.GetSensorAvgByDevices(post.SelectedDate, post.SearchType, devices.Value);
|
||||
|
||||
foreach (var rows in result)
|
||||
{
|
||||
var fields = rows as IDictionary<string, object>;
|
||||
XAxis.Add(fields["TIMESTAMP"].ToString());
|
||||
}
|
||||
|
||||
}
|
||||
XAxis = XAxis.Distinct().ToList();
|
||||
}
|
||||
XAxis.Sort();
|
||||
|
||||
#region 電站資料
|
||||
if (powerStationHistories.Count() > 0)
|
||||
{
|
||||
var powerStationHistories_Id_Group = powerStationHistories.GroupBy(x => x.PowerStationId).ToList();
|
||||
|
||||
foreach (var item in powerStationHistories_Id_Group)
|
||||
@ -189,9 +219,11 @@ namespace SolarPower.Controllers
|
||||
Irradiance.Name = string.Format("{0}:{1}", powerStation.Name, analysisDevice.MultipleYaxes["Irradiance"]);
|
||||
Irradiance.YaxesKey = "Irradiance";
|
||||
Irradiance.Values = new List<double>();
|
||||
foreach (var history in temp_item)
|
||||
foreach (var xa in XAxis)
|
||||
{
|
||||
if (XAxis.IndexOf(history.Timestamp) > -1)
|
||||
var history = temp_item.Where(x => xa == x.Timestamp).FirstOrDefault();
|
||||
|
||||
if (history != null)
|
||||
{
|
||||
Irradiance.Values.Add(history.Irradiance);
|
||||
}
|
||||
@ -206,11 +238,13 @@ namespace SolarPower.Controllers
|
||||
KWH.Name = string.Format("{0}:{1}", powerStation.Name, analysisDevice.MultipleYaxes["KWH"]);
|
||||
KWH.YaxesKey = "KWH";
|
||||
KWH.Values = new List<double>();
|
||||
foreach (var history in temp_item)
|
||||
foreach (var xa in XAxis)
|
||||
{
|
||||
if (XAxis.IndexOf(history.Timestamp) > -1)
|
||||
var history = temp_item.Where(x => xa == x.Timestamp).FirstOrDefault();
|
||||
|
||||
if (history != null)
|
||||
{
|
||||
KWH.Values.Add(Math.Round(history.KWH, 2));
|
||||
KWH.Values.Add(history.KWH);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -223,9 +257,11 @@ namespace SolarPower.Controllers
|
||||
solarHour.Name = string.Format("{0}:{1}", powerStation.Name, analysisDevice.MultipleYaxes["SolarHour"]);
|
||||
solarHour.YaxesKey = "SolarHour";
|
||||
solarHour.Values = new List<double>();
|
||||
foreach (var history in temp_item)
|
||||
foreach (var xa in XAxis)
|
||||
{
|
||||
if (XAxis.IndexOf(history.Timestamp) > -1)
|
||||
var history = temp_item.Where(x => xa == x.Timestamp).FirstOrDefault();
|
||||
|
||||
if (history != null)
|
||||
{
|
||||
solarHour.Values.Add(Math.Round(history.SolarHour, 2));
|
||||
}
|
||||
@ -240,9 +276,11 @@ namespace SolarPower.Controllers
|
||||
KWHKWP.Name = string.Format("{0}:{1}", powerStation.Name, analysisDevice.MultipleYaxes["KWHKWP"]);
|
||||
KWHKWP.YaxesKey = "KWHKWP";
|
||||
KWHKWP.Values = new List<double>();
|
||||
foreach (var history in temp_item)
|
||||
foreach (var xa in XAxis)
|
||||
{
|
||||
if (XAxis.IndexOf(history.Timestamp) > -1)
|
||||
var history = temp_item.Where(x => xa == x.Timestamp).FirstOrDefault();
|
||||
|
||||
if (history != null)
|
||||
{
|
||||
KWHKWP.Values.Add(Math.Round(history.KWHKWP, 2));
|
||||
}
|
||||
@ -257,9 +295,11 @@ namespace SolarPower.Controllers
|
||||
PR.Name = string.Format("{0}:{1}", powerStation.Name, analysisDevice.MultipleYaxes["PR"]);
|
||||
PR.YaxesKey = "PR";
|
||||
PR.Values = new List<double>();
|
||||
foreach (var history in temp_item)
|
||||
foreach (var xa in XAxis)
|
||||
{
|
||||
if (XAxis.IndexOf(history.Timestamp) > -1)
|
||||
var history = temp_item.Where(x => xa == x.Timestamp).FirstOrDefault();
|
||||
|
||||
if (history != null)
|
||||
{
|
||||
PR.Values.Add(Math.Round(history.PR, 2));
|
||||
}
|
||||
@ -274,9 +314,11 @@ namespace SolarPower.Controllers
|
||||
modelTemperature.Name = string.Format("{0}:{1}", powerStation.Name, analysisDevice.MultipleYaxes["Temperature"]);
|
||||
modelTemperature.YaxesKey = "Temperature";
|
||||
modelTemperature.Values = new List<double>();
|
||||
foreach (var history in temp_item)
|
||||
foreach (var xa in XAxis)
|
||||
{
|
||||
if (XAxis.IndexOf(history.Timestamp) > -1)
|
||||
var history = temp_item.Where(x => xa == x.Timestamp).FirstOrDefault();
|
||||
|
||||
if (history != null)
|
||||
{
|
||||
modelTemperature.Values.Add(Math.Round(history.Temperature, 2));
|
||||
}
|
||||
@ -291,12 +333,8 @@ namespace SolarPower.Controllers
|
||||
#endregion
|
||||
|
||||
#region 電錶資料
|
||||
if (meterDic.Count() > 0)
|
||||
if (meterHistories.Count() > 0)
|
||||
{
|
||||
var meterHistories = await powerStationRepository.GetMeterHistory(post.SelectedDate, post.SearchType, meterDic);
|
||||
|
||||
XAxis.AddRange(meterHistories.Select(x => x.TIMESTAMP).Distinct().ToList());
|
||||
|
||||
var meterHistories_Id_Group = meterHistories.GroupBy(x => x.METERID).ToList();
|
||||
|
||||
foreach (var item in meterHistories_Id_Group)
|
||||
@ -307,9 +345,11 @@ namespace SolarPower.Controllers
|
||||
OUTPUT_KWH.Name = string.Format("{0}:{1}", item.Key, analysisDevice.MultipleYaxes["OUTPUT_KWH"]);
|
||||
OUTPUT_KWH.YaxesKey = "OUTPUT_KWH";
|
||||
OUTPUT_KWH.Values = new List<double>();
|
||||
foreach (var history in temp_item)
|
||||
foreach (var xa in XAxis)
|
||||
{
|
||||
if (XAxis.IndexOf(history.TIMESTAMP) > -1)
|
||||
var history = temp_item.Where(x => xa == x.TIMESTAMP).FirstOrDefault();
|
||||
|
||||
if (history != null)
|
||||
{
|
||||
OUTPUT_KWH.Values.Add(Math.Round(history.OUTPUT_KWH, 2));
|
||||
}
|
||||
@ -324,9 +364,11 @@ namespace SolarPower.Controllers
|
||||
INPUT_KWH.Name = string.Format("{0}:{1}", item.Key, analysisDevice.MultipleYaxes["INPUT_KWH"]);
|
||||
INPUT_KWH.YaxesKey = "INPUT_KWH";
|
||||
INPUT_KWH.Values = new List<double>();
|
||||
foreach (var history in temp_item)
|
||||
foreach (var xa in XAxis)
|
||||
{
|
||||
if (XAxis.IndexOf(history.TIMESTAMP) > -1)
|
||||
var history = temp_item.Where(x => xa == x.TIMESTAMP).FirstOrDefault();
|
||||
|
||||
if (history != null)
|
||||
{
|
||||
INPUT_KWH.Values.Add(Math.Round(history.INPUT_KWH, 2));
|
||||
}
|
||||
@ -341,9 +383,11 @@ namespace SolarPower.Controllers
|
||||
V_AB.Name = string.Format("{0}:{1}", item.Key, analysisDevice.MultipleYaxes["V_AB"]);
|
||||
V_AB.YaxesKey = "V_AB";
|
||||
V_AB.Values = new List<double>();
|
||||
foreach (var history in temp_item)
|
||||
foreach (var xa in XAxis)
|
||||
{
|
||||
if (XAxis.IndexOf(history.TIMESTAMP) > -1)
|
||||
var history = temp_item.Where(x => xa == x.TIMESTAMP).FirstOrDefault();
|
||||
|
||||
if (history != null)
|
||||
{
|
||||
V_AB.Values.Add(Math.Round(history.V_AB, 2));
|
||||
}
|
||||
@ -358,9 +402,11 @@ namespace SolarPower.Controllers
|
||||
V_BC.Name = string.Format("{0}:{1}", item.Key, analysisDevice.MultipleYaxes["V_BC"]);
|
||||
V_BC.YaxesKey = "V_BC";
|
||||
V_BC.Values = new List<double>();
|
||||
foreach (var history in temp_item)
|
||||
foreach (var xa in XAxis)
|
||||
{
|
||||
if (XAxis.IndexOf(history.TIMESTAMP) > -1)
|
||||
var history = temp_item.Where(x => xa == x.TIMESTAMP).FirstOrDefault();
|
||||
|
||||
if (history != null)
|
||||
{
|
||||
V_BC.Values.Add(Math.Round(history.V_BC, 2));
|
||||
}
|
||||
@ -375,9 +421,11 @@ namespace SolarPower.Controllers
|
||||
V_CA.Name = string.Format("{0}:{1}", item.Key, analysisDevice.MultipleYaxes["V_BC"]);
|
||||
V_CA.YaxesKey = "V_CA";
|
||||
V_CA.Values = new List<double>();
|
||||
foreach (var history in temp_item)
|
||||
foreach (var xa in XAxis)
|
||||
{
|
||||
if (XAxis.IndexOf(history.TIMESTAMP) > -1)
|
||||
var history = temp_item.Where(x => xa == x.TIMESTAMP).FirstOrDefault();
|
||||
|
||||
if (history != null)
|
||||
{
|
||||
V_CA.Values.Add(Math.Round(history.V_CA, 2));
|
||||
}
|
||||
@ -392,9 +440,11 @@ namespace SolarPower.Controllers
|
||||
I_A.Name = string.Format("{0}:{1}", item.Key, analysisDevice.MultipleYaxes["I_A"]);
|
||||
I_A.YaxesKey = "I_A";
|
||||
I_A.Values = new List<double>();
|
||||
foreach (var history in temp_item)
|
||||
foreach (var xa in XAxis)
|
||||
{
|
||||
if (XAxis.IndexOf(history.TIMESTAMP) > -1)
|
||||
var history = temp_item.Where(x => xa == x.TIMESTAMP).FirstOrDefault();
|
||||
|
||||
if (history != null)
|
||||
{
|
||||
I_A.Values.Add(Math.Round(history.I_A, 2));
|
||||
}
|
||||
@ -409,9 +459,11 @@ namespace SolarPower.Controllers
|
||||
I_B.Name = string.Format("{0}:{1}", item.Key, analysisDevice.MultipleYaxes["I_B"]);
|
||||
I_B.YaxesKey = "I_B";
|
||||
I_B.Values = new List<double>();
|
||||
foreach (var history in temp_item)
|
||||
foreach (var xa in XAxis)
|
||||
{
|
||||
if (XAxis.IndexOf(history.TIMESTAMP) > -1)
|
||||
var history = temp_item.Where(x => xa == x.TIMESTAMP).FirstOrDefault();
|
||||
|
||||
if (history != null)
|
||||
{
|
||||
I_B.Values.Add(Math.Round(history.I_B, 2));
|
||||
}
|
||||
@ -426,9 +478,11 @@ namespace SolarPower.Controllers
|
||||
I_C.Name = string.Format("{0}:{1}", item.Key, analysisDevice.MultipleYaxes["I_C"]);
|
||||
I_C.YaxesKey = "I_C";
|
||||
I_C.Values = new List<double>();
|
||||
foreach (var history in temp_item)
|
||||
foreach (var xa in XAxis)
|
||||
{
|
||||
if (XAxis.IndexOf(history.TIMESTAMP) > -1)
|
||||
var history = temp_item.Where(x => xa == x.TIMESTAMP).FirstOrDefault();
|
||||
|
||||
if (history != null)
|
||||
{
|
||||
I_C.Values.Add(Math.Round(history.I_C, 2));
|
||||
}
|
||||
@ -443,9 +497,11 @@ namespace SolarPower.Controllers
|
||||
P.Name = string.Format("{0}:{1}", item.Key, analysisDevice.MultipleYaxes["P"]);
|
||||
P.YaxesKey = "P";
|
||||
P.Values = new List<double>();
|
||||
foreach (var history in temp_item)
|
||||
foreach (var xa in XAxis)
|
||||
{
|
||||
if (XAxis.IndexOf(history.TIMESTAMP) > -1)
|
||||
var history = temp_item.Where(x => xa == x.TIMESTAMP).FirstOrDefault();
|
||||
|
||||
if (history != null)
|
||||
{
|
||||
P.Values.Add(Math.Round(history.P, 2));
|
||||
}
|
||||
@ -460,9 +516,11 @@ namespace SolarPower.Controllers
|
||||
F.Name = string.Format("{0}:{1}", item.Key, analysisDevice.MultipleYaxes["F"]);
|
||||
F.YaxesKey = "F";
|
||||
F.Values = new List<double>();
|
||||
foreach (var history in temp_item)
|
||||
foreach (var xa in XAxis)
|
||||
{
|
||||
if (XAxis.IndexOf(history.TIMESTAMP) > -1)
|
||||
var history = temp_item.Where(x => xa == x.TIMESTAMP).FirstOrDefault();
|
||||
|
||||
if (history != null)
|
||||
{
|
||||
F.Values.Add(Math.Round(history.F, 2));
|
||||
}
|
||||
@ -483,13 +541,7 @@ namespace SolarPower.Controllers
|
||||
{
|
||||
var result = await powerStationRepository.GetSensorAvgByDevices(post.SelectedDate, post.SearchType, devices.Value);
|
||||
|
||||
foreach (var rows in result)
|
||||
{
|
||||
var fields = rows as IDictionary<string, object>;
|
||||
XAxis.Add(fields["TIMESTAMP"].ToString());
|
||||
}
|
||||
|
||||
|
||||
var powerStation = await powerStationRepository.GetOneAsync(devices.Key);
|
||||
foreach (var device in devices.Value)
|
||||
{
|
||||
DeviceHistoryInfo deviceHistoryInfo = new DeviceHistoryInfo();
|
||||
@ -525,7 +577,7 @@ namespace SolarPower.Controllers
|
||||
suffix = string.Empty;
|
||||
break;
|
||||
}
|
||||
deviceHistoryInfo.Name = string.Format("{0}:{1}", device.Name, suffix);
|
||||
deviceHistoryInfo.Name = string.Format("{0}:{1}({2})", powerStation.Name, device.Name, suffix);
|
||||
deviceHistoryInfo.YaxesKey = YaxesKey;
|
||||
deviceHistoryInfo.Values = new List<double>();
|
||||
foreach (var rows in result)
|
||||
|
||||
@ -869,196 +869,7 @@ namespace SolarPower.Quartz.Jobs
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【執行完成補償機制】");
|
||||
#endregion
|
||||
|
||||
#region 寄送日月報
|
||||
var users = userRepository.GetAllAsync();
|
||||
var ttt = new List<string>() {
|
||||
"s506488@gmail.com",
|
||||
"cesarliuc@gmail.com"
|
||||
};
|
||||
|
||||
foreach (var user in users.Result)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【開始產生使用者[{0}({1})]的日月報】", user.Account, user.Name);
|
||||
|
||||
List<OperationPersonnel> powerstations = new List<OperationPersonnel>();
|
||||
powerstations = await noticeScheduleRepository.GetPowerStationOperationPersonnel(user.Id);
|
||||
if (powerstations.Count == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
List<Excelpowerstation> sentdaypowerstations = powerstations.Where(x => x.EmailDayReport == 1).Select(a => new Excelpowerstation { Name = a.Name, Value = a.PowerStationId.ToString() }).ToList();
|
||||
List<Excelpowerstation> sentMaxpowerstations = powerstations.Where(x => x.EmailComplexReport == 1).Select(a => new Excelpowerstation { Name = a.Name, Value = a.PowerStationId.ToString() }).ToList();
|
||||
|
||||
Controllers.StationReportController stationReportController = new Controllers.StationReportController(powerStationRepository, stationReportRepository);
|
||||
//日報表
|
||||
if (sentdaypowerstations.Count != 0)
|
||||
{
|
||||
Excel dayexcel = new Excel()
|
||||
{
|
||||
FormType = 0,
|
||||
PowerStation = sentdaypowerstations,
|
||||
SearchType = 0,
|
||||
Time = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"),
|
||||
Userid = user.Id
|
||||
};
|
||||
var stationReportName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(dayexcel, Formatting.Indented));
|
||||
if (stationReportName != "")
|
||||
{
|
||||
NoticeSchedule DaySchedule = new NoticeSchedule()
|
||||
{
|
||||
UserId = user.Id,
|
||||
EmailType = 0,
|
||||
RecipientEmail = user.Email,
|
||||
Subject = "日報表",
|
||||
Attachment = stationReportName,
|
||||
RecipientName = user.Name,
|
||||
Type = 1
|
||||
};
|
||||
List<string> properties = new List<string>()
|
||||
{
|
||||
"UserId",
|
||||
"EmailType",
|
||||
"RecipientEmail",
|
||||
"Subject",
|
||||
"Attachment",
|
||||
"RecipientName",
|
||||
"Type"
|
||||
};
|
||||
await noticeScheduleRepository.AddOneAsync(DaySchedule, properties);
|
||||
}
|
||||
}
|
||||
//綜合報表 每日
|
||||
if (sentMaxpowerstations.Count != 0)
|
||||
{
|
||||
Select_table2 maxdayexcel = new Select_table2()
|
||||
{
|
||||
FormType = 0,
|
||||
PowerStation = sentMaxpowerstations,
|
||||
SearchType = 0,
|
||||
Time = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"),
|
||||
Userid = user.Id
|
||||
};
|
||||
var stationMaxReportName = stationReportController.ExportExcelmaxtableBackDownload(JsonConvert.SerializeObject(maxdayexcel, Formatting.Indented));
|
||||
NoticeSchedule MaxSchedule = new NoticeSchedule()
|
||||
{
|
||||
UserId = user.Id,
|
||||
EmailType = 2,
|
||||
RecipientEmail = user.Email,
|
||||
Subject = "綜合報表",
|
||||
Attachment = stationMaxReportName,
|
||||
RecipientName = user.Name,
|
||||
Type = 1
|
||||
};
|
||||
List<string> properties = new List<string>()
|
||||
{
|
||||
"UserId",
|
||||
"EmailType",
|
||||
"RecipientEmail",
|
||||
"Subject",
|
||||
"Attachment",
|
||||
"RecipientName",
|
||||
"Type"
|
||||
};
|
||||
await noticeScheduleRepository.AddOneAsync(MaxSchedule, properties);
|
||||
|
||||
if (DateTime.Now.ToString("dd") == "01")
|
||||
{
|
||||
Select_table2 maxmonthexcel = new Select_table2()
|
||||
{
|
||||
FormType = 0,
|
||||
PowerStation = sentMaxpowerstations,
|
||||
SearchType = 0,
|
||||
Time = DateTime.Now.AddDays(-1).ToString("yyyy-MM"),
|
||||
Userid = user.Id
|
||||
};
|
||||
var stationReportmaxmonthName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(maxmonthexcel, Formatting.Indented));
|
||||
NoticeSchedule MaxmonthSchedule = new NoticeSchedule()
|
||||
{
|
||||
RecipientEmail = user.Email,
|
||||
Subject = "綜合報表",
|
||||
Attachment = stationReportmaxmonthName,
|
||||
RecipientName = user.Name,
|
||||
Type = 1,
|
||||
UserId = user.Id,
|
||||
EmailType = 2
|
||||
};
|
||||
List<string> properties2 = new List<string>()
|
||||
{
|
||||
"UserId",
|
||||
"EmailType",
|
||||
"RecipientEmail",
|
||||
"Subject",
|
||||
"Attachment",
|
||||
"RecipientName",
|
||||
"Type"
|
||||
};
|
||||
await noticeScheduleRepository.AddOneAsync(MaxmonthSchedule, properties2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (DateTime.Now.ToString("dd") == "01")
|
||||
{
|
||||
List<Excelpowerstation> sentmonthpowerstations = powerstations.Where(x => x.EmailMonthReport == 1).Select(a => new Excelpowerstation { Name = a.Name, Value = a.PowerStationId.ToString() }).ToList();
|
||||
if (sentmonthpowerstations.Count == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
Excel monthexcel = new Excel()
|
||||
{
|
||||
FormType = 1,
|
||||
PowerStation = sentmonthpowerstations,
|
||||
SearchType = 2,
|
||||
Time = DateTime.Now.AddDays(-1).ToString("yyyy-MM"),
|
||||
Userid = user.Id
|
||||
};
|
||||
var stationReportmonthName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(monthexcel, Formatting.Indented));
|
||||
if (stationReportmonthName != "")
|
||||
{
|
||||
NoticeSchedule MonthSchedule = new NoticeSchedule()
|
||||
{
|
||||
RecipientEmail = user.Email,
|
||||
Subject = "月報表",
|
||||
Attachment = stationReportmonthName,
|
||||
RecipientName = user.Name,
|
||||
Type = 1,
|
||||
UserId = user.Id,
|
||||
EmailType = 1
|
||||
};
|
||||
List<string> properties2 = new List<string>()
|
||||
{
|
||||
"UserId",
|
||||
"EmailType",
|
||||
"RecipientEmail",
|
||||
"Subject",
|
||||
"Attachment",
|
||||
"RecipientName",
|
||||
"Type"
|
||||
};
|
||||
await noticeScheduleRepository.AddOneAsync(MonthSchedule, properties2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【產生完成使用者[{0}({1})]的日月報】", user.Account, user.Name);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError("【CalcAvgPowerStationJob】【產生失敗使用者[{0}({1})]的日月報】", user.Account, user.Name);
|
||||
logger.LogError("【CalcAvgPowerStationJob】[Exception] - {0}", exception.Message);
|
||||
if (exception.InnerException != null)
|
||||
{
|
||||
logger.LogError("【CalcAvgPowerStationJob】[InnerException] - {0}", exception.InnerException.Message);
|
||||
}
|
||||
|
||||
var line = new StackTrace(exception, true).GetFrame(0).GetFileLineNumber();
|
||||
logger.LogError("【CalcAvgPowerStationJob】[錯誤行數] - {0}", line);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
logger.LogInformation("【CalcAvgPowerStationJob】【任務完成】");
|
||||
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Quartz;
|
||||
using SolarPower.Models;
|
||||
using SolarPower.Repository.Interface;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@ -15,11 +17,24 @@ namespace SolarPower.Quartz.Jobs
|
||||
{
|
||||
private readonly ILogger<OperationScheduleJob> logger;
|
||||
private IOperationRepository operationRepository;
|
||||
private readonly IPowerStationRepository powerStationRepository;
|
||||
private readonly IUserRepository userRepository;
|
||||
private readonly INoticeScheduleRepository noticeScheduleRepository;
|
||||
private readonly IStationReportRepository stationReportRepository;
|
||||
|
||||
public OperationScheduleJob(ILogger<OperationScheduleJob> logger, IOperationRepository operationRepository)
|
||||
public OperationScheduleJob(ILogger<OperationScheduleJob> logger,
|
||||
IOperationRepository operationRepository,
|
||||
IPowerStationRepository powerStationRepository,
|
||||
IUserRepository userRepository,
|
||||
INoticeScheduleRepository noticeScheduleRepository,
|
||||
IStationReportRepository stationReportRepository)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.operationRepository = operationRepository;
|
||||
this.powerStationRepository = powerStationRepository;
|
||||
this.userRepository = userRepository;
|
||||
this.noticeScheduleRepository = noticeScheduleRepository;
|
||||
this.stationReportRepository = stationReportRepository;
|
||||
}
|
||||
|
||||
public async Task Execute(IJobExecutionContext context)
|
||||
@ -180,6 +195,197 @@ namespace SolarPower.Quartz.Jobs
|
||||
|
||||
|
||||
}
|
||||
|
||||
#region 寄送日月報
|
||||
var users = userRepository.GetAllAsync();
|
||||
var ttt = new List<string>() {
|
||||
"s506488@gmail.com",
|
||||
"cesarliuc@gmail.com"
|
||||
};
|
||||
|
||||
foreach (var user in users.Result)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.LogInformation("【OperationScheduleJob】【開始產生使用者[{0}({1})]的日月報】", user.Account, user.Name);
|
||||
|
||||
List<OperationPersonnel> powerstations = new List<OperationPersonnel>();
|
||||
powerstations = await noticeScheduleRepository.GetPowerStationOperationPersonnel(user.Id);
|
||||
if (powerstations.Count == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
List<Excelpowerstation> sentdaypowerstations = powerstations.Where(x => x.EmailDayReport == 1).Select(a => new Excelpowerstation { Name = a.Name, Value = a.PowerStationId.ToString() }).ToList();
|
||||
List<Excelpowerstation> sentMaxpowerstations = powerstations.Where(x => x.EmailComplexReport == 1).Select(a => new Excelpowerstation { Name = a.Name, Value = a.PowerStationId.ToString() }).ToList();
|
||||
|
||||
Controllers.StationReportController stationReportController = new Controllers.StationReportController(powerStationRepository, stationReportRepository);
|
||||
//日報表
|
||||
if (sentdaypowerstations.Count != 0)
|
||||
{
|
||||
Excel dayexcel = new Excel()
|
||||
{
|
||||
FormType = 0,
|
||||
PowerStation = sentdaypowerstations,
|
||||
SearchType = 0,
|
||||
Time = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"),
|
||||
Userid = user.Id
|
||||
};
|
||||
var stationReportName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(dayexcel, Formatting.Indented));
|
||||
if (stationReportName != "")
|
||||
{
|
||||
NoticeSchedule DaySchedule = new NoticeSchedule()
|
||||
{
|
||||
UserId = user.Id,
|
||||
EmailType = 0,
|
||||
RecipientEmail = user.Email,
|
||||
Subject = "日報表",
|
||||
Attachment = stationReportName,
|
||||
RecipientName = user.Name,
|
||||
Type = 1
|
||||
};
|
||||
List<string> properties = new List<string>()
|
||||
{
|
||||
"UserId",
|
||||
"EmailType",
|
||||
"RecipientEmail",
|
||||
"Subject",
|
||||
"Attachment",
|
||||
"RecipientName",
|
||||
"Type"
|
||||
};
|
||||
await noticeScheduleRepository.AddOneAsync(DaySchedule, properties);
|
||||
}
|
||||
}
|
||||
//綜合報表 每日
|
||||
if (sentMaxpowerstations.Count != 0)
|
||||
{
|
||||
Select_table2 maxdayexcel = new Select_table2()
|
||||
{
|
||||
FormType = 0,
|
||||
PowerStation = sentMaxpowerstations,
|
||||
SearchType = 0,
|
||||
Time = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"),
|
||||
Userid = user.Id
|
||||
};
|
||||
var stationMaxReportName = stationReportController.ExportExcelmaxtableBackDownload(JsonConvert.SerializeObject(maxdayexcel, Formatting.Indented));
|
||||
NoticeSchedule MaxSchedule = new NoticeSchedule()
|
||||
{
|
||||
UserId = user.Id,
|
||||
EmailType = 2,
|
||||
RecipientEmail = user.Email,
|
||||
Subject = "綜合報表",
|
||||
Attachment = stationMaxReportName,
|
||||
RecipientName = user.Name,
|
||||
Type = 1
|
||||
};
|
||||
List<string> properties = new List<string>()
|
||||
{
|
||||
"UserId",
|
||||
"EmailType",
|
||||
"RecipientEmail",
|
||||
"Subject",
|
||||
"Attachment",
|
||||
"RecipientName",
|
||||
"Type"
|
||||
};
|
||||
await noticeScheduleRepository.AddOneAsync(MaxSchedule, properties);
|
||||
|
||||
if (DateTime.Now.ToString("dd") == "01")
|
||||
{
|
||||
Select_table2 maxmonthexcel = new Select_table2()
|
||||
{
|
||||
FormType = 0,
|
||||
PowerStation = sentMaxpowerstations,
|
||||
SearchType = 0,
|
||||
Time = DateTime.Now.AddDays(-1).ToString("yyyy-MM"),
|
||||
Userid = user.Id
|
||||
};
|
||||
var stationReportmaxmonthName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(maxmonthexcel, Formatting.Indented));
|
||||
NoticeSchedule MaxmonthSchedule = new NoticeSchedule()
|
||||
{
|
||||
RecipientEmail = user.Email,
|
||||
Subject = "綜合報表",
|
||||
Attachment = stationReportmaxmonthName,
|
||||
RecipientName = user.Name,
|
||||
Type = 1,
|
||||
UserId = user.Id,
|
||||
EmailType = 2
|
||||
};
|
||||
List<string> properties2 = new List<string>()
|
||||
{
|
||||
"UserId",
|
||||
"EmailType",
|
||||
"RecipientEmail",
|
||||
"Subject",
|
||||
"Attachment",
|
||||
"RecipientName",
|
||||
"Type"
|
||||
};
|
||||
await noticeScheduleRepository.AddOneAsync(MaxmonthSchedule, properties2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (DateTime.Now.ToString("dd") == "01")
|
||||
{
|
||||
List<Excelpowerstation> sentmonthpowerstations = powerstations.Where(x => x.EmailMonthReport == 1).Select(a => new Excelpowerstation { Name = a.Name, Value = a.PowerStationId.ToString() }).ToList();
|
||||
if (sentmonthpowerstations.Count == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
Excel monthexcel = new Excel()
|
||||
{
|
||||
FormType = 1,
|
||||
PowerStation = sentmonthpowerstations,
|
||||
SearchType = 2,
|
||||
Time = DateTime.Now.AddDays(-1).ToString("yyyy-MM"),
|
||||
Userid = user.Id
|
||||
};
|
||||
var stationReportmonthName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(monthexcel, Formatting.Indented));
|
||||
if (stationReportmonthName != "")
|
||||
{
|
||||
NoticeSchedule MonthSchedule = new NoticeSchedule()
|
||||
{
|
||||
RecipientEmail = user.Email,
|
||||
Subject = "月報表",
|
||||
Attachment = stationReportmonthName,
|
||||
RecipientName = user.Name,
|
||||
Type = 1,
|
||||
UserId = user.Id,
|
||||
EmailType = 1
|
||||
};
|
||||
List<string> properties2 = new List<string>()
|
||||
{
|
||||
"UserId",
|
||||
"EmailType",
|
||||
"RecipientEmail",
|
||||
"Subject",
|
||||
"Attachment",
|
||||
"RecipientName",
|
||||
"Type"
|
||||
};
|
||||
await noticeScheduleRepository.AddOneAsync(MonthSchedule, properties2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
logger.LogInformation("【OperationScheduleJob】【產生完成使用者[{0}({1})]的日月報】", user.Account, user.Name);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError("【OperationScheduleJob】【產生失敗使用者[{0}({1})]的日月報】", user.Account, user.Name);
|
||||
logger.LogError("【OperationScheduleJob】[Exception] - {0}", exception.Message);
|
||||
if (exception.InnerException != null)
|
||||
{
|
||||
logger.LogError("【OperationScheduleJob】[InnerException] - {0}", exception.InnerException.Message);
|
||||
}
|
||||
|
||||
var line = new StackTrace(exception, true).GetFrame(0).GetFileLineNumber();
|
||||
logger.LogError("【OperationScheduleJob】[錯誤行數] - {0}", line);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
|
||||
@ -67,7 +67,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="pr-3">
|
||||
<button type="button" class="btn btn-secondary waves-effect waves-themed" onclick="GetAnalysisStationInfo()">查詢</button>
|
||||
<button type="button" class="btn btn-secondary waves-effect waves-themed" id="btn-analysis-stationinfo" onclick="GetAnalysisStationInfo()">查詢</button>
|
||||
@*<button type="button" class="btn btn-secondary waves-effect waves-themed" onclick="DataBackFill()">回填</button>*@
|
||||
</div>
|
||||
</div>
|
||||
@ -625,6 +625,13 @@
|
||||
DeviceIdInfos: selected_device
|
||||
}
|
||||
|
||||
if (selected_device.length <= 0) {
|
||||
toast_warning("請至少選擇一設備");
|
||||
return;
|
||||
}
|
||||
|
||||
$("#btn-analysis-stationinfo").html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>').attr("disabled", true);
|
||||
|
||||
$.post(url, send_data, function (rel) {
|
||||
if (rel.code != "0000") {
|
||||
toast_error(rel.msg);
|
||||
@ -641,6 +648,9 @@
|
||||
|
||||
$('input[name="compare_col[]"]').trigger('change');
|
||||
|
||||
ReloadHighCharts()
|
||||
$("#btn-analysis-stationinfo").html('查詢').attr("disabled", false);
|
||||
|
||||
}, 'json');
|
||||
}
|
||||
|
||||
@ -710,9 +720,7 @@
|
||||
height: 600,
|
||||
animation: false
|
||||
},
|
||||
title: {
|
||||
text: '交叉分析圖表'
|
||||
},
|
||||
title: false,
|
||||
tooltip: {
|
||||
formatter: function () {
|
||||
return '<b>' + this.series.name + '</b><br>' +
|
||||
|
||||
Loading…
Reference in New Issue
Block a user