From f411cf08a84e5ff20bd86a2fe08708ea0be7b878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B5=87=E6=96=87=E9=BE=99?= Date: Thu, 15 Aug 2024 15:46:29 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E8=88=B1=E5=A7=94=E6=89=98=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ds-wms-service/DS.WMS.Core/DS.WMS.Core.csproj | 2 +- .../DS.WMS.Core/Op/Dtos/SeaExportRes.cs | 4 +- .../TaskInteraction/MailTemplateModel.cs | 49 +++++++- .../SpaceRelease/RelayBCActionExecutor.cs | 3 + .../Op/Method/TaskInteraction/MailService.cs | 83 +++++++------- .../Op/Templates/MailTemplate.cshtml | 35 ------ .../Op/Templates/订舱委托.cshtml | 107 ++++++++++++++++++ 7 files changed, 206 insertions(+), 77 deletions(-) delete mode 100644 ds-wms-service/DS.WMS.Core/Op/Templates/MailTemplate.cshtml create mode 100644 ds-wms-service/DS.WMS.Core/Op/Templates/订舱委托.cshtml diff --git a/ds-wms-service/DS.WMS.Core/DS.WMS.Core.csproj b/ds-wms-service/DS.WMS.Core/DS.WMS.Core.csproj index d488e16e..a7dc4b05 100644 --- a/ds-wms-service/DS.WMS.Core/DS.WMS.Core.csproj +++ b/ds-wms-service/DS.WMS.Core/DS.WMS.Core.csproj @@ -33,7 +33,7 @@ true PreserveNewest - + true PreserveNewest diff --git a/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportRes.cs b/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportRes.cs index eb0e5a3e..f35679c6 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportRes.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportRes.cs @@ -30,6 +30,8 @@ public class SeaExportRes /// public OpBusinessYardRes? YardInfo { get; set; } + + /// /// 主键Id /// @@ -546,7 +548,7 @@ public class SeaExportRes /// public long ForwarderId { get; set; } /// - /// 货代公司 + /// 货代公司(订舱口) /// public string Forwarder { get; set; } diff --git a/ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/MailTemplateModel.cs b/ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/MailTemplateModel.cs index e2ee0ef2..8cee738e 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/MailTemplateModel.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Entity/TaskInteraction/MailTemplateModel.cs @@ -1,4 +1,5 @@ -using System.Dynamic; +using System.Collections.ObjectModel; +using System.Dynamic; namespace DS.WMS.Core.Op.Entity { @@ -22,12 +23,58 @@ namespace DS.WMS.Core.Op.Entity /// public List? FileAttachments { get; set; } + /// + /// 发件人 + /// + public MailSender Sender { get; set; } + + /// + /// 收件人 + /// + public List Receivers { get; set; } + + /// + /// 当前业务联系人 + /// + public string Contacts => Receivers == null ? string.Empty : string.Join(",", Receivers.Select(x => x.DisplayName)); + /// /// 主要数据项 /// public dynamic Primary { get; set; } = new ExpandoObject(); } + public class MailSender + { + /// + /// 显示名称 + /// + public string DisplayName { get; set; } + + /// + /// 邮件地址 + /// + public string MailAddress { get; set; } + + /// + /// 个人签名内容 + /// + public string? SignatureHtml { get; set; } + } + + public class MailReceiver + { + /// + /// 显示名称 + /// + public string DisplayName { get; set; } + + /// + /// 邮件地址 + /// + public string MailAddress { get; set; } + } + /// /// 文件附件 /// diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionExecutor/SpaceRelease/RelayBCActionExecutor.cs b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionExecutor/SpaceRelease/RelayBCActionExecutor.cs index 451516e9..b5ea4b62 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionExecutor/SpaceRelease/RelayBCActionExecutor.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/ActionExecutor/SpaceRelease/RelayBCActionExecutor.cs @@ -2,6 +2,9 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction.ActionExecutor.SpaceRelease { + /// + /// 放舱-转发BC + /// public class RelayBCActionExecutor : DefaultActionExecutor { public override async Task ExecuteAsync(ActionExecutionContext context) diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/MailService.cs b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/MailService.cs index 07b4fedd..430b212b 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/MailService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/MailService.cs @@ -62,22 +62,6 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction ArgumentNullException.ThrowIfNull(mailConfig, nameof(mailConfig)); ArgumentNullException.ThrowIfNull(templateModel, nameof(templateModel)); - string title, content = string.Empty; - var razorEngine = new RazorEngine(); - try - { - string key1 = mailConfig.Id + "-" + nameof(mailConfig.Title); - title = await RenderTemplateAsync(key1, mailConfig.Title, templateModel, razorEngine); - - string key2 = mailConfig.Id + "-" + nameof(mailConfig.Content); - content = await RenderTemplateAsync(key2, mailConfig.Content, templateModel, razorEngine); - } - catch (Exception ex) - { - await ex.LogAsync(Db); - return DataResult.Failed($"渲染邮件模板({mailConfig.Id})时出错,请检查模板是否有语法错误"); - } - var order = await TenantDb.Queryable().Where(x => x.Id == templateModel.BusinessId) .Select(x => new { @@ -108,27 +92,17 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction else if (mailConfig.Sender.IsVouchingClerk) senderId = order.Doc; - var sender = await Db.Queryable().Where(x => x.Id == senderId).Select(x => new { x.UserName, x.SignatureHtml }).FirstAsync(); - if (sender == null) + templateModel.Sender = await Db.Queryable().Where(x => x.Id == senderId).Select(x => new MailSender + { + DisplayName = x.UserName, + SignatureHtml = x.SignatureHtml + }).FirstAsync(); + if (templateModel.Sender == null) return DataResult.Failed("未设置发件人"); var senderConfig = await TenantDb.Queryable().FirstAsync(x => x.CreateBy == senderId); if (senderConfig == null) - return DataResult.Failed($"发件人用户:{sender.UserName} 未设置SMTP发件信息"); - - //插入发件人签名 - var htmlDoc = new HtmlDocument(); - htmlDoc.LoadHtml(content); - var node = htmlDoc.GetElementbyId("sign"); - if (node != null) - node.InnerHtml = sender.SignatureHtml; - - using (StringWriter writer = new()) - { - htmlDoc.Save(writer); - content = writer.ToString(); - writer.Close(); - } + return DataResult.Failed($"发件人用户:{templateModel.Sender.DisplayName} 未设置SMTP发件信息"); //设置抄送人 List ccIds = []; @@ -162,9 +136,39 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction if (mailConfig.Receiver.IsController) receiverTypes.Add("controller"); - var receiverList = await TenantDb.Queryable().Where(x => receiverTypes.Contains(x.CustomerType) + templateModel.Receivers = await TenantDb.Queryable().Where(x => receiverTypes.Contains(x.CustomerType) && x.Email != null && x.Email != string.Empty && x.BusinessId == templateModel.BusinessId && x.BusinessType == templateModel.BusinessType) - .Select(x => new { x.Name, x.Email }).ToListAsync(); + .Select(x => new MailReceiver { DisplayName = x.Name, MailAddress = x.Email }).ToListAsync(); + + string title, content = string.Empty; + var razorEngine = new RazorEngine(); + try + { + string key1 = mailConfig.Id + "-" + nameof(mailConfig.Title); + title = await RenderTemplateAsync(key1, mailConfig.Title, templateModel, razorEngine); + + string key2 = mailConfig.Id + "-" + nameof(mailConfig.Content); + content = await RenderTemplateAsync(key2, mailConfig.Content, templateModel, razorEngine); + } + catch (Exception ex) + { + await ex.LogAsync(Db); + return DataResult.Failed($"渲染邮件模板({mailConfig.Id})时出错,请检查模板是否有语法错误"); + } + + //插入发件人签名 + var htmlDoc = new HtmlDocument(); + htmlDoc.LoadHtml(content); + var node = htmlDoc.GetElementbyId("sign"); + if (node != null) + node.InnerHtml = templateModel.Sender.SignatureHtml; + + using (StringWriter writer = new()) + { + htmlDoc.Save(writer); + content = writer.ToString(); + writer.Close(); + } var attachmentList = mailConfig.Attachments == null ? [] : new List>(mailConfig.Attachments.Count); try @@ -222,13 +226,14 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction } } + string sendTo = string.Join(",", templateModel.Receivers.Select(x => x.MailAddress)); dynamic[] mailParams = [new { - SendTo = string.Join(",", receiverList.Select(x => x.Email)), + SendTo = sendTo, Title = title, Body = content, CCTo = string.Join(",", ccList), - ShowName = senderConfig.ShowName.IsNullOrEmpty() ? sender.UserName : senderConfig.ShowName, + ShowName = senderConfig.ShowName.IsNullOrEmpty() ? templateModel.Sender.DisplayName : senderConfig.ShowName, Account = senderConfig.MailAccount, senderConfig.Password, Server = senderConfig.SmtpServer, @@ -245,11 +250,11 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction if (mailResult.Data.IsSuccessStatusCode) { return DataResult.Successed($"已发邮件(委托单:{order.CustomerNo}),收件人:" - + string.Join(",", receiverList.Select(x => x.Email)) + "发件人:" + senderConfig.MailAccount); + + string.Join(",", sendTo) + "发件人:" + senderConfig.MailAccount); } return DataResult.Failed($"邮件发送失败,API返回状态为:{(int)mailResult.Data.StatusCode} {mailResult.Data.StatusCode}" - + $"(委托单:{order.CustomerNo}),收件人:" + string.Join(",", receiverList.Select(x => x.Email)) + "发件人:" + senderConfig.MailAccount); + + $"(委托单:{order.CustomerNo}),收件人:" + string.Join(",", sendTo) + "发件人:" + senderConfig.MailAccount); } catch (Exception ex) { diff --git a/ds-wms-service/DS.WMS.Core/Op/Templates/MailTemplate.cshtml b/ds-wms-service/DS.WMS.Core/Op/Templates/MailTemplate.cshtml deleted file mode 100644 index 6b1b63d1..00000000 --- a/ds-wms-service/DS.WMS.Core/Op/Templates/MailTemplate.cshtml +++ /dev/null @@ -1,35 +0,0 @@ -@* @model DS.WMS.Core.Op.Entity.MailTemplateModel *@ -@{ - var item = Model.Primary; -} - - - -

测试邮件-@item.MBLNO@item.CustomerNo

- -
- 预计开船日期:@item.ETD - 预计抵达日期:@item.ETA -
-
-
- 订单创建时间:@item.CreateTime.ToString("yyyy年MM月dd日 HH:mm:ss") -
- -
-
-
\ No newline at end of file diff --git a/ds-wms-service/DS.WMS.Core/Op/Templates/订舱委托.cshtml b/ds-wms-service/DS.WMS.Core/Op/Templates/订舱委托.cshtml new file mode 100644 index 00000000..c1150d90 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/Templates/订舱委托.cshtml @@ -0,0 +1,107 @@ +@* @model DS.WMS.Core.Op.Entity.MailTemplateModel *@ +@{ + var item = Model.Primary; +} + + + +*** Auto Email, please reply to all (delete sender Admin)!If only reply to sender, we will not be able to find and deal with it! *** + +Dear @Model.Contacts + +
+ RE: BOOKING - JOB NO. +
+ +请查看附件中的订舱委托,请2小时内先行回复订舱号给我们,并帮忙催促船东尽快放舱,如下信息同订舱委托一致,便于您查阅! + +CARRIER:@item.Carrier +S/Q:XX +ETD : @item.ETD + +POL: @item.LoadPort +POD: @item.DischargePort +FPOD: @item.DeliveryPlace +VOL: XX +Commdity: XX(取中文品名) +HS CODE: @item.HSCode +POD FREE TIME: +REMARK: +(取供应商备注) + + +此票订舱我司对接同事的联系方式如下,任何问题请及时跟我们沟通,谢谢! + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CN NameNameTel No.Mobile/Wechat/QQEmailPosition
邵 芳Candy0532-8068838713375570007 2853083550candy@sunniness.netCooperation
魏涛Wilson0532-8068835313969858993 2853083555ope@sunniness.netOP manager
徐平平Cathy0532-8068835013969662965 2853083551opg@sunniness.netDocument
+ +
+
+ @* Tks + B’rgds + Candy SHAO 邵芳 (此处用当票操作的信息) + General Manager | SUNNINESS LOGISTICS CO.,LTD. + TEL: +86-0532-80688387 |MB./We chat: +86-18866622731|QQ:2853083553 | Email:candy@sunniness.net *@ +
+
+ +@* 此邮件模板是订舱委托推送的邮件模板,在商务订单审核通过后,自动生成,并推送: +1)蓝色是调取系统数据、红色是醒目提醒; +2)订舱委托PDF格式作为附件一起发出 +3)邮件发给订舱代理联系人,抄送我司销售/客服和操作/单证;未勾选推送的订舱代理,仅推送我司干系人! *@ +