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); } }