|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
using System.DirectoryServices;
|
|
|
|
|
using DS.Module.Core;
|
|
|
|
|
using DS.Module.Core.Data;
|
|
|
|
|
using DS.Module.PrintModule;
|
|
|
|
@ -9,6 +10,7 @@ using DS.WMS.Core.Op.Entity.TaskInteraction;
|
|
|
|
|
using DS.WMS.Core.Op.Method.TaskInteraction.ActionExecutor;
|
|
|
|
|
using DS.WMS.Core.Op.Method.TaskInteraction.ActionExecutor.Booking;
|
|
|
|
|
using DS.WMS.Core.Sys.Entity;
|
|
|
|
|
using Fasterflect;
|
|
|
|
|
using HtmlAgilityPack;
|
|
|
|
|
using Masuit.Tools;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
@ -36,6 +38,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
|
|
|
|
|
public MailService(IServiceProvider provider) : base(provider)
|
|
|
|
|
{
|
|
|
|
|
config = provider.GetRequiredService<IConfiguration>();
|
|
|
|
|
TenantDb.QueryFilter.Clear<IOrgId>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static async Task<string> RenderTemplateAsync(string name, string templateText, object model, IRazorEngine? razorEngine = null)
|
|
|
|
@ -82,6 +85,9 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
|
|
|
|
|
return DataResult.Failed($"未能获取订单({templateModel.BusinessId})数据");
|
|
|
|
|
|
|
|
|
|
//设置发件人
|
|
|
|
|
if (mailConfig.Sender == null)
|
|
|
|
|
return DataResult.Failed("未设置发件人");
|
|
|
|
|
|
|
|
|
|
long senderId = 0;
|
|
|
|
|
if (mailConfig.Sender.IsSale)
|
|
|
|
|
senderId = order.SaleId;
|
|
|
|
@ -98,28 +104,34 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
|
|
|
|
|
SignatureHtml = x.SignatureHtml
|
|
|
|
|
}).FirstAsync();
|
|
|
|
|
if (templateModel.Sender == null)
|
|
|
|
|
return DataResult.Failed("未设置发件人");
|
|
|
|
|
return DataResult.Failed("邮件模板未设置发件人");
|
|
|
|
|
|
|
|
|
|
var senderConfig = await TenantDb.Queryable<CodeUserEmail>().FirstAsync(x => x.CreateBy == senderId);
|
|
|
|
|
if (senderConfig == null)
|
|
|
|
|
return DataResult.Failed($"发件人用户:{templateModel.Sender.DisplayName} 未设置SMTP发件信息");
|
|
|
|
|
|
|
|
|
|
//设置抄送人
|
|
|
|
|
List<long> ccIds = [];
|
|
|
|
|
List<string> ccList = [];
|
|
|
|
|
if (mailConfig.CC.IsSale)
|
|
|
|
|
ccIds.Add(order.SaleId);
|
|
|
|
|
else if (mailConfig.CC.IsOperator)
|
|
|
|
|
ccIds.Add(order.OperatorId);
|
|
|
|
|
else if (mailConfig.CC.IsCustomerService)
|
|
|
|
|
ccIds.Add(order.CustomerService);
|
|
|
|
|
else if (mailConfig.CC.IsVouchingClerk)
|
|
|
|
|
ccIds.Add(order.Doc);
|
|
|
|
|
|
|
|
|
|
if (ccIds.Count > 0)
|
|
|
|
|
ccList = await Db.Queryable<SysUser>().Where(x => ccIds.Contains(x.Id)).Select(x => x.Email).ToListAsync();
|
|
|
|
|
if (mailConfig.CC != null)
|
|
|
|
|
{
|
|
|
|
|
//设置抄送人
|
|
|
|
|
List<long> ccIds = [];
|
|
|
|
|
if (mailConfig.CC.IsSale)
|
|
|
|
|
ccIds.Add(order.SaleId);
|
|
|
|
|
else if (mailConfig.CC.IsOperator)
|
|
|
|
|
ccIds.Add(order.OperatorId);
|
|
|
|
|
else if (mailConfig.CC.IsCustomerService)
|
|
|
|
|
ccIds.Add(order.CustomerService);
|
|
|
|
|
else if (mailConfig.CC.IsVouchingClerk)
|
|
|
|
|
ccIds.Add(order.Doc);
|
|
|
|
|
|
|
|
|
|
if (ccIds.Count > 0)
|
|
|
|
|
ccList = await Db.Queryable<SysUser>().Where(x => ccIds.Contains(x.Id)).Select(x => x.Email).ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//设置收件人
|
|
|
|
|
if (mailConfig.Receiver == null)
|
|
|
|
|
return DataResult.Failed("邮件模板未设置收件人");
|
|
|
|
|
|
|
|
|
|
List<string> receiverTypes = [];
|
|
|
|
|
if (mailConfig.Receiver.IsCarrier)
|
|
|
|
|
receiverTypes.Add("carrier");
|
|
|
|
@ -185,15 +197,16 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
|
|
|
|
|
string requestUrl = config["TaskMail:FileBaseUrl"] + config["TaskMail:SQLPrint"];
|
|
|
|
|
foreach (var item in mailConfig.Attachments)
|
|
|
|
|
{
|
|
|
|
|
object? obj = PropertyExtensions.GetPropertyValue(templateModel, nameof(MailTemplateModel.Primary), Flags.InstancePublic);
|
|
|
|
|
var req = new OpenPrintReq
|
|
|
|
|
{
|
|
|
|
|
ParamJsonStr = JsonConvert.SerializeObject(templateModel.Primary),
|
|
|
|
|
ParamJsonStr = JsonConvert.SerializeObject(obj),
|
|
|
|
|
PrintType = ((int)FileFormat.PDF).ToString(),
|
|
|
|
|
TemplateId = item.TemplateId,
|
|
|
|
|
TenantId = tenantId
|
|
|
|
|
};
|
|
|
|
|
var reqResult = await Api.PostAsync<PrintResult>(requestUrl, req);
|
|
|
|
|
if (!reqResult.Succeeded)
|
|
|
|
|
if (!reqResult.Data.Succeeded)
|
|
|
|
|
return DataResult.Failed($"未能获取打印API生成的文件,请求地址:{requestUrl}");
|
|
|
|
|
|
|
|
|
|
string url = config["TaskMail:FileBaseUrl"] + @"/PrintTempFile/" + reqResult.Data.Data;
|
|
|
|
|