From d7586ff6a079430724c99704ab42b9b6444e90e3 Mon Sep 17 00:00:00 2001 From: "wanling040@gmail.com" Date: Mon, 22 Aug 2022 15:08:13 +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=E5=92=8C=E5=A0=B1=E8=A1=A8=E7=9A=84=E4=BF=A1?= =?UTF-8?q?=E4=BB=B6=EF=BC=8C=E5=AF=84=E4=BB=B6=E4=BA=BA=E7=9A=84=E9=83=A8?= =?UTF-8?q?=E5=88=86=EF=BC=8CFIC=20=E6=94=B9=E7=82=BA=20=E5=85=AC=E5=8F=B8?= =?UTF-8?q?=E5=90=8D=E7=A8=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Quartz/Jobs/SendEmailJob.cs | 10 ++++-- .../Implement/NoticeScheduleRepository.cs | 31 +++++++++++++++++++ .../Interface/INoticeScheduleRepository.cs | 1 + 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/SolarPower/Quartz/Jobs/SendEmailJob.cs b/SolarPower/Quartz/Jobs/SendEmailJob.cs index 25ac79f..0302aa5 100644 --- a/SolarPower/Quartz/Jobs/SendEmailJob.cs +++ b/SolarPower/Quartz/Jobs/SendEmailJob.cs @@ -55,7 +55,10 @@ namespace SolarPower.Quartz.Jobs attachments = notice.Attachment.Split(',').ToList(); } - var result = Send(recipientEmails, notice.Subject, notice.Content, attachments); + var getCompany = noticeScheduleRepository.GetCompanyNameById(notice.Id); + string companyName = getCompany.Result; + + var result = Send(recipientEmails, notice.Subject, notice.Content, attachments, companyName); if (result.CompareTo("成功") == 0) { @@ -96,7 +99,7 @@ namespace SolarPower.Quartz.Jobs } } - private string Send(List recipientEmails, string subject, string content, List attachments) + private string Send(List recipientEmails, string subject, string content, List attachments, string companyName) { var reason = string.Empty; var CanDoSend = true; @@ -105,7 +108,8 @@ 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 = $"FIC 太陽能電站管理系統通知 <{smtp.UserName}>"; + var kkk = companyName + $" 太陽能電站管理系統通知 <{smtp.UserName}>"; MyMail.From = new System.Net.Mail.MailAddress(kkk); //寄件人 foreach (var email in recipientEmails) { diff --git a/SolarPower/Repository/Implement/NoticeScheduleRepository.cs b/SolarPower/Repository/Implement/NoticeScheduleRepository.cs index 034c06c..d008321 100644 --- a/SolarPower/Repository/Implement/NoticeScheduleRepository.cs +++ b/SolarPower/Repository/Implement/NoticeScheduleRepository.cs @@ -160,5 +160,36 @@ namespace SolarPower.Repository.Implement } } } + + public async Task GetCompanyNameById(int noticeId) + { + string result; + using (IDbConnection conn = _databaseHelper.GetConnection()) + { + conn.Open(); + try + { + var sql = @$"select c.Name + from notice_schedule ns + left join user u on ns.UserId = u.id + left join company c on u.CompanyId = c.id + where ns.id = {noticeId}"; + + result = await conn.QueryFirstOrDefaultAsync(sql); + + + } + catch (Exception exception) + { + throw exception; + } + finally + { + conn.Close(); + } + return result; + } + } + } } diff --git a/SolarPower/Repository/Interface/INoticeScheduleRepository.cs b/SolarPower/Repository/Interface/INoticeScheduleRepository.cs index 0b4431e..c4049fc 100644 --- a/SolarPower/Repository/Interface/INoticeScheduleRepository.cs +++ b/SolarPower/Repository/Interface/INoticeScheduleRepository.cs @@ -12,5 +12,6 @@ namespace SolarPower.Repository.Interface Task UpdateList(List noticeSchedules, List properties); Task> GetPowerStationOperationPersonnel(int Userid); Task> GetNoticeTable(NoticeTableSearch info); + Task GetCompanyNameById(int noticeId); } }