From d2d8fbddf102cce4c91e1d202080cb946269b96d Mon Sep 17 00:00:00 2001 From: "wanling040@gmail.com" Date: Wed, 24 Aug 2022 19:44:08 +0800 Subject: [PATCH] =?UTF-8?q?Email=E6=A0=BC=E5=BC=8F:=20=E7=95=B0=E5=B8=B8?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E3=80=81=E6=97=A5=E5=A0=B1=E8=A1=A8=E3=80=81?= =?UTF-8?q?=E6=9C=88=E5=A0=B1=E8=A1=A8=E3=80=81=E7=B6=9C=E5=90=88=E5=A0=B1?= =?UTF-8?q?=E8=A1=A8=EF=BC=8C=E4=B8=BB=E6=97=A8=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Quartz/Jobs/ExceptionSchedule.cs | 9 +++++++-- SolarPower/Quartz/Jobs/OperationScheduleJob.cs | 17 +++++++++++++---- SolarPower/Quartz/Jobs/SendEmailJob.cs | 11 +++-------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/SolarPower/Quartz/Jobs/ExceptionSchedule.cs b/SolarPower/Quartz/Jobs/ExceptionSchedule.cs index 797a454..9828c3b 100644 --- a/SolarPower/Quartz/Jobs/ExceptionSchedule.cs +++ b/SolarPower/Quartz/Jobs/ExceptionSchedule.cs @@ -72,15 +72,20 @@ namespace SolarPower.Quartz.Jobs { Content += $"當前數值:{Exception.errValue}" + "
"; } - Content += $"發生時間:{Exception.dev_time}"; + //Content += $"發生時間:{Exception.dev_time}"; + string subTime = $",發生時間:{Exception.dev_time}"; + + foreach (var user in UserListWithPowerstation) { + var getCompany = noticeScheduleRepository.GetCompanyNameById(user.Id); + string companyName = getCompany.Result; NoticeSchedule DaySchedule = new NoticeSchedule() { UserId = user.Id, EmailType = 4, RecipientEmail = user.Email, - Subject = "異常通知", + Subject = companyName + "太陽能監控" + Exception.alarmClassName + "-異常通知" + subTime, Content = Content, RecipientName = user.Name, Type = 1, diff --git a/SolarPower/Quartz/Jobs/OperationScheduleJob.cs b/SolarPower/Quartz/Jobs/OperationScheduleJob.cs index 911a475..69bf43b 100644 --- a/SolarPower/Quartz/Jobs/OperationScheduleJob.cs +++ b/SolarPower/Quartz/Jobs/OperationScheduleJob.cs @@ -250,6 +250,9 @@ namespace SolarPower.Quartz.Jobs var stationReportName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(dayexcel, Formatting.Indented)); if (stationReportName != "") { + var getCompany = noticeScheduleRepository.GetCompanyNameById(user.Id); + string companyName = getCompany.Result; + if (user.Email != null && IsValidEmail(user.Email)) { NoticeSchedule DaySchedule = new NoticeSchedule() @@ -257,7 +260,7 @@ namespace SolarPower.Quartz.Jobs UserId = user.Id, EmailType = 0, RecipientEmail = user.Email, - Subject = "日報表", + Subject = companyName + "太陽能監控-日報表", Attachment = stationReportName, RecipientName = user.Name, Type = 1 @@ -290,12 +293,14 @@ namespace SolarPower.Quartz.Jobs var stationMaxReportName = stationReportController.ExportExcelmaxtableBackDownload(JsonConvert.SerializeObject(maxdayexcel, Formatting.Indented)); if (user.Email != null && IsValidEmail(user.Email)) { + var getCompany = noticeScheduleRepository.GetCompanyNameById(user.Id); + string companyName = getCompany.Result; NoticeSchedule MaxSchedule = new NoticeSchedule() { UserId = user.Id, EmailType = 2, RecipientEmail = user.Email, - Subject = "綜合報表", + Subject = companyName + "太陽能監控-綜合報表", Attachment = stationMaxReportName, RecipientName = user.Name, Type = 1 @@ -326,10 +331,12 @@ namespace SolarPower.Quartz.Jobs var stationReportmaxmonthName = stationReportController.ExportExcelBackDownload(JsonConvert.SerializeObject(maxmonthexcel, Formatting.Indented)); if (user.Email != null && IsValidEmail(user.Email)) { + var getCompany = noticeScheduleRepository.GetCompanyNameById(user.Id); + string companyName = getCompany.Result; NoticeSchedule MaxmonthSchedule = new NoticeSchedule() { RecipientEmail = user.Email, - Subject = "綜合報表", + Subject = companyName + "太陽能監控-綜合報表", Attachment = stationReportmaxmonthName, RecipientName = user.Name, Type = 1, @@ -372,10 +379,12 @@ namespace SolarPower.Quartz.Jobs { if (user.Email != null && IsValidEmail(user.Email)) { + var getCompany = noticeScheduleRepository.GetCompanyNameById(user.Id); + string companyName = getCompany.Result; NoticeSchedule MonthSchedule = new NoticeSchedule() { RecipientEmail = user.Email, - Subject = "月報表", + Subject = companyName + "太陽能監控-月報表", Attachment = stationReportmonthName, RecipientName = user.Name, Type = 1, diff --git a/SolarPower/Quartz/Jobs/SendEmailJob.cs b/SolarPower/Quartz/Jobs/SendEmailJob.cs index 0302aa5..33d55d2 100644 --- a/SolarPower/Quartz/Jobs/SendEmailJob.cs +++ b/SolarPower/Quartz/Jobs/SendEmailJob.cs @@ -54,11 +54,7 @@ namespace SolarPower.Quartz.Jobs { attachments = notice.Attachment.Split(',').ToList(); } - - var getCompany = noticeScheduleRepository.GetCompanyNameById(notice.Id); - string companyName = getCompany.Result; - - var result = Send(recipientEmails, notice.Subject, notice.Content, attachments, companyName); + var result = Send(recipientEmails, notice.Subject, notice.Content, attachments); if (result.CompareTo("成功") == 0) { @@ -99,7 +95,7 @@ namespace SolarPower.Quartz.Jobs } } - private string Send(List recipientEmails, string subject, string content, List attachments, string companyName) + private string Send(List recipientEmails, string subject, string content, List attachments) { var reason = string.Empty; var CanDoSend = true; @@ -108,8 +104,7 @@ namespace SolarPower.Quartz.Jobs MyMail.SubjectEncoding = System.Text.Encoding.UTF8;//郵件標題編碼 MyMail.BodyEncoding = System.Text.Encoding.UTF8; //郵件內容編碼 MyMail.IsBodyHtml = true; //是否使用html格式 - //var kkk = $"FIC 太陽能電站管理系統通知 <{smtp.UserName}>"; - var kkk = companyName + $" 太陽能電站管理系統通知 <{smtp.UserName}>"; + var kkk = $"太陽能電站管理系統通知 <{smtp.UserName}>"; MyMail.From = new System.Net.Mail.MailAddress(kkk); //寄件人 foreach (var email in recipientEmails) {