diff --git a/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs index aff119a..06398f5 100644 --- a/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs @@ -8,6 +8,7 @@ using SolarPower.Models.PowerStation; using SolarPower.Repository.Interface; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Net.Http; using System.Threading.Tasks; @@ -870,40 +871,83 @@ namespace SolarPower.Quartz.Jobs #region 寄送日月報 var users = userRepository.GetAllAsync(); + var ttt = new List() { + "s506488@gmail.com", + "cesarliuc@gmail.com" + }; foreach (var user in users.Result) { - List powerstations = new List(); - powerstations = await noticeScheduleRepository.GetPowerStationOperationPersonnel(user.Id); - if (powerstations.Count == 0) + try { - continue; - } - List sentdaypowerstations = powerstations.Where(x => x.EmailDayReport == 1).Select(a => new Excelpowerstation { Name = a.Name, Value = a.PowerStationId.ToString() }).ToList(); - List sentMaxpowerstations = powerstations.Where(x => x.EmailComplexReport == 1).Select(a => new Excelpowerstation { Name = a.Name, Value = a.PowerStationId.ToString() }).ToList(); + logger.LogInformation("【CalcAvgPowerStationJob】【開始產生使用者[{0}({1})]的日月報】", user.Account, user.Name); - Controllers.StationReportController stationReportController = new Controllers.StationReportController(powerStationRepository, stationReportRepository); - //日報表 - if (sentdaypowerstations.Count != 0) - { - Excel dayexcel = new Excel() + List powerstations = new List(); + powerstations = await noticeScheduleRepository.GetPowerStationOperationPersonnel(user.Id); + if (powerstations.Count == 0) { - 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 != "") + continue; + } + List sentdaypowerstations = powerstations.Where(x => x.EmailDayReport == 1).Select(a => new Excelpowerstation { Name = a.Name, Value = a.PowerStationId.ToString() }).ToList(); + List 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) { - NoticeSchedule DaySchedule = new NoticeSchedule() + 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 properties = new List() + { + "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 = 0, + EmailType = 2, RecipientEmail = user.Email, - Subject = "日報表", - Attachment = stationReportName, + Subject = "綜合報表", + Attachment = stationMaxReportName, RecipientName = user.Name, Type = 1 }; @@ -917,120 +961,100 @@ namespace SolarPower.Quartz.Jobs "RecipientName", "Type" }; - await noticeScheduleRepository.AddOneAsync(DaySchedule, properties); + 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 properties2 = new List() + { + "UserId", + "EmailType", + "RecipientEmail", + "Subject", + "Attachment", + "RecipientName", + "Type" + }; + await noticeScheduleRepository.AddOneAsync(MaxmonthSchedule, properties2); + } + } - } - //綜合報表 每日 - 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 properties = new List() - { - "UserId", - "EmailType", - "RecipientEmail", - "Subject", - "Attachment", - "RecipientName", - "Type" - }; - await noticeScheduleRepository.AddOneAsync(MaxSchedule, properties); if (DateTime.Now.ToString("dd") == "01") { - Select_table2 maxmonthexcel = new Select_table2() + List sentmonthpowerstations = powerstations.Where(x => x.EmailMonthReport == 1).Select(a => new Excelpowerstation { Name = a.Name, Value = a.PowerStationId.ToString() }).ToList(); + if (sentmonthpowerstations.Count == 0) { - FormType = 0, - PowerStation = sentMaxpowerstations, - SearchType = 0, + break; + } + Excel monthexcel = new Excel() + { + FormType = 1, + PowerStation = sentmonthpowerstations, + SearchType = 2, Time = DateTime.Now.AddDays(-1).ToString("yyyy-MM"), Userid = user.Id }; - var stationReportmaxmonthName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(maxmonthexcel, Formatting.Indented)); - NoticeSchedule MaxmonthSchedule = new NoticeSchedule() + var stationReportmonthName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(monthexcel, Formatting.Indented)); + if (stationReportmonthName != "") { - RecipientEmail = user.Email, - Subject = "綜合報表", - Attachment = stationReportmaxmonthName, - RecipientName = user.Name, - Type = 1, - UserId = user.Id, - EmailType = 2 - }; - List properties2 = new List() - { - "UserId", - "EmailType", - "RecipientEmail", - "Subject", - "Attachment", - "RecipientName", - "Type" - }; - await noticeScheduleRepository.AddOneAsync(MaxmonthSchedule, properties2); + NoticeSchedule MonthSchedule = new NoticeSchedule() + { + RecipientEmail = user.Email, + Subject = "月報表", + Attachment = stationReportmonthName, + RecipientName = user.Name, + Type = 1, + UserId = user.Id, + EmailType = 1 + }; + List properties2 = new List() + { + "UserId", + "EmailType", + "RecipientEmail", + "Subject", + "Attachment", + "RecipientName", + "Type" + }; + await noticeScheduleRepository.AddOneAsync(MonthSchedule, properties2); + } + } + logger.LogInformation("【CalcAvgPowerStationJob】【產生完成使用者[{0}({1})]的日月報】", user.Account, user.Name); } - - if (DateTime.Now.ToString("dd") == "01") + catch (Exception exception) { - List sentmonthpowerstations = powerstations.Where(x => x.EmailMonthReport == 1).Select(a => new Excelpowerstation { Name = a.Name, Value = a.PowerStationId.ToString() }).ToList(); - if (sentmonthpowerstations.Count == 0) + logger.LogError("【CalcAvgPowerStationJob】【產生失敗使用者[{0}({1})]的日月報】", user.Account, user.Name); + logger.LogError("【CalcAvgPowerStationJob】[Exception] - {0}", exception.Message); + if (exception.InnerException != null) { - 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 properties2 = new List() - { - "UserId", - "EmailType", - "RecipientEmail", - "Subject", - "Attachment", - "RecipientName", - "Type" - }; - await noticeScheduleRepository.AddOneAsync(MonthSchedule, properties2); + logger.LogError("【CalcAvgPowerStationJob】[InnerException] - {0}", exception.InnerException.Message); } + var line = new StackTrace(exception, true).GetFrame(0).GetFileLineNumber(); + logger.LogError("【CalcAvgPowerStationJob】[錯誤行數] - {0}", line); } } diff --git a/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml b/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml index 8b784e3..50841ca 100644 --- a/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml +++ b/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml @@ -2744,9 +2744,15 @@ return; } $("#Invertercard-Name").html(rel.data.name); - $("#Invertercard-kwh").html(rel.data.kwh); - $("#Invertercard-money").html(rel.data.today_Money.toFixed()); - $("#Invertercard-pr").html(rel.data.today_PR); + $("#Invertercard-kwh").html(rel.data.kwh.toFixed(2)); + @if (ViewBag.myUser.Role.Auths.Contains("ShowMoney")) + { + + $("#Invertercard-money").html(rel.data.today_Money.toFixed()); + + } + $("#Invertercard-Capacity").html(rel.data.generatingCapacity.toFixed(3)); + $("#Invertercard-pr").html(rel.data.today_PR.toFixed(2)); var str = "
" + "
" $('#prbar').remove(); @@ -2764,9 +2770,9 @@ break; } $("#Invertercard-type").html(TypeName); - var time = new Date(rel.data.createdAt); - $("#Invertercard-date").html(time.getMonth() + "/" + time.getDate() + " " + time.getHours() + ":" + time.getMinutes()); - + @*var time = new Date(rel.data.createdAt); + $("#Invertercard-date").html(time.getMonth() + "/" + time.getDate() + " " + time.getHours() + ":" + time.getMinutes());*@ + $("#Invertercard-date").html(rel.data.electricityMeterAt); var urlPath = "../upload/power_station/" + rel.data.id + "/" + rel.data.mainDisplay; var xmlhttp; diff --git a/SolarPower/Views/StationOverview/_InverterInfo.cshtml b/SolarPower/Views/StationOverview/_InverterInfo.cshtml index 3918e43..a1f5b9f 100644 --- a/SolarPower/Views/StationOverview/_InverterInfo.cshtml +++ b/SolarPower/Views/StationOverview/_InverterInfo.cshtml @@ -6,25 +6,43 @@
...
-

新竹巨城站

-

+

新竹巨城站

+
+

27°C

+
-

發電量

-

185 kWh

-

27°C

+
+

發電量

+

0.00 kWh

+
+ @if (ViewBag.myUser.Role.Auths.Contains("ShowMoney")) + { +
+ @*

發電金額

*@ +

0 NT

+
+ }
-

發電金額

-

2,5840 NT

-

自建躉售

+
+

裝置容量

+

0.00 kWp

+
+
+

自建躉售

+
-

PR值

-

90 %

-

17:50:36

+
+

PR值

+

0 %

+
+
+

06-30 17:50

+
@@ -32,7 +50,6 @@
    -