douhandong 1 month ago
commit a92a0e5666

@ -43,4 +43,9 @@ public class CodePortSelectRes
/// 助记码
/// </summary>
public string PinYinCode { get; set; }
/// <summary>
/// 国家名称
/// </summary>
public string CountryEnName { get; set; } = "";
}

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -106,5 +107,31 @@ namespace DS.WMS.Core.Op.Dtos
/// 录入人
/// </summary>
public string CreateByName { get; set; }
/// <summary>
/// 国内发货人 t_info_client CUSTNAME
/// </summary>
[Description("国内发货人Id")]
public long? ShipperCnId { get; set; }
/// <summary>
/// 国内发货人 t_info_client CUSTNAME
/// </summary>
[Description("国内发货人")]
public string ShipperCn { get; set; }
/// <summary>
/// 发货人 t_info_client CUSTNAME
/// </summary>
[Description("发货人")]
public string Shipper { get; set; }
/// <summary>
/// 收货人 t_info_client CUSTNAME
/// </summary>
[Description("收货人")]
public string Consignee { get; set; }
/// <summary>
/// 通知人 t_info_client CUSTNAME
/// </summary>
[Description("通知人")]
public string NotifyParty { get; set; }
}
}

@ -433,5 +433,21 @@ namespace DS.WMS.Core.Op.Dtos
/// </summary>
[Description("提单确认人邮箱")]
public string BLConfirmationEmail { get; set; }
/// <summary>
/// 发货人 t_info_client CUSTNAME
/// </summary>
[Description("发货人")]
public string Shipper { get; set; }
/// <summary>
/// 收货人 t_info_client CUSTNAME
/// </summary>
[Description("收货人")]
public string Consignee { get; set; }
/// <summary>
/// 通知人 t_info_client CUSTNAME
/// </summary>
[Description("通知人")]
public string NotifyParty { get; set; }
}
}

@ -439,5 +439,21 @@ namespace DS.WMS.Core.Op.Dtos
/// </summary>
[Description("提单确认人邮箱")]
public string BLConfirmationEmail { get; set; }
/// <summary>
/// 发货人 t_info_client CUSTNAME
/// </summary>
[Description("发货人")]
public string Shipper { get; set; }
/// <summary>
/// 收货人 t_info_client CUSTNAME
/// </summary>
[Description("收货人")]
public string Consignee { get; set; }
/// <summary>
/// 通知人 t_info_client CUSTNAME
/// </summary>
[Description("通知人")]
public string NotifyParty { get; set; }
}
}

@ -506,4 +506,23 @@ public class SeaExportBillManage : BaseOrgModel<long>
[Description("提单确认人邮箱")]
[SqlSugar.SugarColumn(ColumnDescription = "提单确认人邮箱", IsNullable = true, Length = 100)]
public string BLConfirmationEmail { get; set; }
/// <summary>
/// 发货人 t_info_client CUSTNAME
/// </summary>
[Description("发货人")]
[SqlSugar.SugarColumn(ColumnDescription = "发货人", IsNullable = true, Length = 100)]
public string Shipper { get; set; }
/// <summary>
/// 收货人 t_info_client CUSTNAME
/// </summary>
[Description("收货人")]
[SqlSugar.SugarColumn(ColumnDescription = "收货人", IsNullable = true, Length = 100)]
public string Consignee { get; set; }
/// <summary>
/// 通知人 t_info_client CUSTNAME
/// </summary>
[Description("通知人")]
[SqlSugar.SugarColumn(ColumnDescription = "通知人", IsNullable = true, Length = 100)]
public string NotifyParty { get; set; }
}

@ -228,21 +228,28 @@ namespace DS.WMS.Core.Op.Method
var temp = new SeaExportBillManage()
{
BusinessId = long.Parse(req.Id),
ShipperContent = item.ShipperContent,
ShipperCode = item.ShipperCode,
ShipperCountry = item.ShipperCountry,
ShipperEmail = item.ShipperEmail,
ShipperTel = item.ShipperTel,
ShipperId = item.ShipperId,
Shipper = item.Shipper,
ConsigneeContent = item.ConsigneeContent,
ConsigneeCode = item.ConsigneeCode,
ConsigneeCountry = item.ConsigneeCountry,
ConsigneeEmail = item.ConsigneeEmail,
ConsigneeTel = item.ConsigneeTel,
ConsigneeId = item.ConsigneeId,
Consignee = item.Consignee,
NotifyPartyContent = item.NotifyPartyContent,
NotifyPartyCode = item.NotifyPartyCode,
NotifyPartyCountry = item.NotifyPartyCountry,
NotifyPartyEmail = item.NotifyPartyEmail,
NotifyPartyTel = item.NotifyPartyTel,
NotifyPartyId = item.NotifyPartyId,
NotifyParty = item.NotifyParty,
Marks = item.Marks,
Description = item.Description,
};

@ -1385,7 +1385,7 @@ public class ClientCommonService : IClientCommonService
PinYinCode = a.ShortName + "(" + a.CodeName + ")",
}
)
.MergeTable()
.ClearFilter<ISharedOrgId>().MergeTable()
.Mapper(it =>
{
it.UserIds = tenantDb.Queryable<InfoClientStakeholder>().Where(c => c.StartDate <= DateTime.Now && c.EndDate >= DateTime.Now && c.ClientId == it.Id).Select(n => n.CreateBy).ToList();

@ -1107,12 +1107,13 @@ public class CommonService : ICommonService
public async Task<DataResult<List<CodePortSelectRes>>> GetClientPortSelectList(string queryKey = "")
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var list = await tenantDb.Queryable<CodePort>()
.Where(x => x.Status == StatusEnum.Enable)
.WhereIF(!string.IsNullOrEmpty(queryKey), x => x.PortName.Contains(queryKey) || x.CnName.Contains(queryKey) || x.EdiCode.Contains(queryKey))
.Select(x => new CodePortSelectRes()
var list = await tenantDb.Queryable<CodePort>().Where(a => a.Status == StatusEnum.Enable)
.LeftJoin<CodeCountry>((a, b) => a.CountryId == b.Id)
.WhereIF(!string.IsNullOrEmpty(queryKey), (a, b) => a.PortName.Contains(queryKey) || a.CnName.Contains(queryKey) || a.EdiCode.Contains(queryKey))
.Select((a, b) => new CodePortSelectRes()
{
PinYinCode = !String.IsNullOrEmpty(x.EdiCode) ? x.EdiCode + "/" + x.PortName : x.PortName,
PinYinCode = !String.IsNullOrEmpty(a.EdiCode) ? a.EdiCode + "/" + a.PortName : a.PortName,
CountryEnName = b.CountryEnName
}, true)
.Take(20)
.WithCache(SqlSugarCacheConst.Port + user.TenantId, SqlSugarCacheConst.CacheDurationInSeconds)

@ -0,0 +1,35 @@
using DS.WMS.Core.Op.Entity;
namespace DS.WMS.Core.TaskInteraction.Dtos
{
/// <summary>
/// 数据获取上下文
/// </summary>
public class DataFetchContext
{
/// <summary>
/// 服务提供程序
/// </summary>
public IServiceProvider ServiceProvider { get; internal set; }
/// <summary>
/// 业务ID
/// </summary>
public long? BusinessId { get; internal set; }
/// <summary>
/// 业务类型
/// </summary>
public BusinessType? BusinessType { get; internal set; }
/// <summary>
/// 邮件配置内容
/// </summary>
public string? Content { get; internal set; }
/// <summary>
/// 数据对象
/// </summary>
public dynamic? Data { get; set; }
}
}

@ -3,39 +3,50 @@
namespace DS.WMS.Core.TaskInteraction.Dtos
{
/// <summary>
/// 邮件模板模型
/// 邮件模板模型基类
/// </summary>
public class MailTemplateModel
public class MailTemplateModelBase
{
/// <summary>
/// 业务ID
/// 附件
/// </summary>
public long BusinessId { get; set; }
public List<FileAttachment>? FileAttachments { get; set; }
/// <summary>
/// 业务ID
/// 发件人
/// </summary>
public BusinessType BusinessType { get; set; } = BusinessType.OceanShippingExport;
public MailSender? Sender { get; set; }
/// <summary>
/// 发送附件
/// 收件人
/// </summary>
public List<FileAttachment>? FileAttachments { get; set; }
public List<MailReceiver> Receivers { get; set; } = [];
/// <summary>
/// 发件人
/// 收件人姓名
/// </summary>
public MailSender Sender { get; set; }
public string Contacts => Receivers == null ? string.Empty : string.Join(",", Receivers.Select(x => x.DisplayName));
/// <summary>
/// 收件人
/// 主要数据项
/// </summary>
public List<MailReceiver> Receivers { get; set; }
public dynamic? Primary { get; protected internal set; }
}
/// <summary>
/// 邮件模板业务模型
/// </summary>
public class MailTemplateModel : MailTemplateModelBase
{
/// <summary>
/// 收件人姓名
/// 业务ID
/// </summary>
public string Contacts => Receivers == null ? string.Empty : string.Join(",", Receivers.Select(x => x.DisplayName));
public long BusinessId { get; set; }
/// <summary>
/// 业务类型
/// </summary>
public BusinessType? BusinessType { get; set; }
/// <summary>
/// 销售
@ -72,17 +83,15 @@ namespace DS.WMS.Core.TaskInteraction.Dtos
/// </summary>
public string? CustomerName { get; set; }
/// <summary>
/// 主要数据项
/// </summary>
public dynamic? Primary { get; protected internal set; }
/// <summary>
/// 箱型价格列表
/// </summary>
public List<BusinessCtnPrice>? CtnPriceList { get; set; }
}
/// <summary>
/// 发件人
/// </summary>
public class MailSender
{
/// <summary>
@ -106,6 +115,9 @@ namespace DS.WMS.Core.TaskInteraction.Dtos
public string? SignatureHtml { get; set; }
}
/// <summary>
/// 收件人
/// </summary>
public class MailReceiver
{
/// <summary>
@ -206,27 +218,4 @@ namespace DS.WMS.Core.TaskInteraction.Dtos
Primary = primary;
}
}
/// <summary>
/// 邮件模板模型
/// </summary>
/// <typeparam name="T1">主要数据类型</typeparam>
/// <typeparam name="T2">次要数据类型</typeparam>
public class MailTemplateModel<T1, T2> : MailTemplateModel<T1>
{
/// <summary>
/// 次要数据项
/// </summary>
public T2 Secondary { get; internal set; }
/// <summary>
/// 初始化
/// </summary>
/// <param name="primary">主数据</param>
/// <param name="secondary">主数据</param>
public MailTemplateModel(T1 primary, T2 secondary) : base(primary)
{
Secondary = secondary;
}
}
}

@ -76,10 +76,10 @@ namespace DS.WMS.Core.TaskInteraction.Entity
Fixed = 1,
/// <summary>
/// SQL
/// 数据库
/// </summary>
[Description("SQL")]
SQL = 2,
[Description("数据库")]
Database = 2,
/// <summary>
/// 网络

@ -40,6 +40,12 @@ namespace DS.WMS.Core.TaskInteraction.Entity
[SugarColumn(ColumnDescription = "客户名称", Length = 200, IsNullable = true)]
public string? CustomerName { get; set; }
/// <summary>
/// 是否业务邮件
/// </summary>
[SugarColumn(ColumnDescription = "是否业务邮件")]
public bool IsBusiness { get; set; }
/// <summary>
/// 数据源提供程序ID
/// </summary>

@ -0,0 +1,17 @@
using DS.WMS.Core.TaskInteraction.Dtos;
namespace DS.WMS.Core.TaskInteraction.Interface
{
/// <summary>
/// 用于邮件模板的数据提供程序
/// </summary>
public interface IDataProvider
{
/// <summary>
/// 获取数据
/// </summary>
/// <param name="context">上下文</param>
/// <returns></returns>
Task FetchDataAsync(DataFetchContext context);
}
}

@ -10,23 +10,23 @@ namespace DS.WMS.Core.TaskInteraction.Interface
/// </summary>
public interface ITaskMailService
{
/// <summary>
/// 渲染模板
/// </summary>
/// <param name="docType">单据类型</param>
/// <param name="bsId">业务ID</param>
/// <param name="businessType">业务类型</param>
/// <returns></returns>
Task<DataResult<string>> RenderTemplateAsync(DocumentType docType, long bsId, BusinessType businessType);
///// <summary>
///// 渲染模板
///// </summary>
///// <param name="docType">单据类型</param>
///// <param name="bsId">业务ID</param>
///// <param name="businessType">业务类型</param>
///// <returns></returns>
//Task<DataResult<string>> RenderTemplateAsync(DocumentType docType, long bsId, BusinessType businessType);
/// <summary>
/// 获取邮件内容
/// </summary>
/// <param name="docType">单据类型</param>
/// <param name="templateName">邮件模板名称</param>
/// <param name="customerNO">委托编号</param>
/// <returns></returns>
Task<DataResult<Tuple<string, string>>> GetMailContentAsync(string customerNO, DocumentType docType, string? templateName = null);
///// <summary>
///// 获取邮件内容
///// </summary>
///// <param name="docType">单据类型</param>
///// <param name="templateName">邮件模板名称</param>
///// <param name="customerNO">委托编号</param>
///// <returns></returns>
//Task<DataResult<Tuple<string, string>>> GetMailContentAsync(string customerNO, DocumentType docType, string? templateName = null);
/// <summary>
/// 获取分页列表

@ -59,7 +59,7 @@ namespace DS.WMS.Core.TaskInteraction.Method.ActionExecutor.Booking
}
MailGenerator mailService = new(context.ServiceProvider);
var model = await mailService.GetTemplateModelAsync(context.ActionManager, context.TaskInfo.BusinessId, context.TaskInfo.BusinessType);
var model = await mailService.GetBusinessModelAsync(mailConfig, context.TaskInfo.BusinessId, context.TaskInfo.BusinessType, context.ActionManager);
if (model.Primary == null)
{
await LogService.WriteLogAsync(context.TaskInfo, $"未能获取Id={context.TaskInfo.BusinessId} {context.TaskInfo.BusinessType.GetDescription()}的订单数据");

@ -52,7 +52,7 @@ namespace DS.WMS.Core.TaskInteraction.Method.ActionExecutor
}
MailGenerator mailService = new(context.ServiceProvider);
var model = await mailService.GetTemplateModelAsync(context.ActionManager, context.TaskInfo.BusinessId, context.TaskInfo.BusinessType);
var model = await mailService.GetBusinessModelAsync(mailConfig, context.TaskInfo.BusinessId, context.TaskInfo.BusinessType, context.ActionManager);
if (model.Primary == null)
{
await logService.WriteLogAsync(context.TaskInfo, $"未能获取Id={context.TaskInfo.BusinessId} {context.TaskInfo.BusinessType.GetDescription()}的订单数据");

@ -73,7 +73,7 @@ namespace DS.WMS.Core.TaskInteraction.Method.ActionExecutor.SpaceRelease
}
MailGenerator mailService = new MailGenerator(context.ServiceProvider);
var model = await mailService.GetTemplateModelAsync(context.ActionManager, context.TaskInfo.BusinessId, context.TaskInfo.BusinessType);
var model = await mailService.GetBusinessModelAsync(mailConfig, context.TaskInfo.BusinessId, context.TaskInfo.BusinessType, context.ActionManager);
if (model.Primary == null)
{
await logService.WriteLogAsync(context.TaskInfo, $"未能获取Id={context.TaskInfo.BusinessId} {context.TaskInfo.BusinessType.GetDescription()}的订单数据");

@ -0,0 +1,34 @@
using DS.WMS.Core.TaskInteraction.Dtos;
using DS.WMS.Core.TaskInteraction.Interface;
using SqlSugar;
namespace DS.WMS.Core.TaskInteraction.Method.DataProvider
{
/// <summary>
/// 默认数据库提供程序
/// </summary>
public class DefaultDatabaseProvider : ServiceBase, IDataProvider
{
/// <summary>
/// 初始化
/// </summary>
/// <param name="provider"></param>
public DefaultDatabaseProvider(IServiceProvider provider) : base(provider)
{
}
/// <summary>
/// 执行数据库查询
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public async Task FetchDataAsync(DataFetchContext context)
{
SugarParameter[] sugarParams = [
new SugarParameter(nameof(context.BusinessId), context.BusinessId, System.Data.DbType.Int64),
new SugarParameter(nameof(context.BusinessType), context.BusinessType, System.Data.DbType.Int32),
];
context.Data = await TenantDb.Ado.SqlQueryAsync<dynamic>(context.Content, sugarParams);
}
}
}

@ -11,6 +11,7 @@ using DS.WMS.Core.TaskInteraction.Dtos;
using DS.WMS.Core.TaskInteraction.Entity;
using DS.WMS.Core.TaskInteraction.Interface;
using DS.WMS.Core.TaskInteraction.Method.ActionExecutor;
using DS.WMS.Core.TaskInteraction.Method.DataProvider;
using Fasterflect;
using HtmlAgilityPack;
using Masuit.Tools;
@ -22,7 +23,7 @@ using RazorEngineCore;
namespace DS.WMS.Core.TaskInteraction.Method
{
/// <summary>
/// 业务邮件发送服务
/// 邮件模板发送
/// </summary>
public class MailGenerator : ServiceBase
{
@ -61,22 +62,68 @@ namespace DS.WMS.Core.TaskInteraction.Method
/// <summary>
/// 根据业务ID和类型获取模板所需数据
/// </summary>
/// <param name="actionManager"></param>
///<param name="taskMail">邮件配置</param>
/// <param name="bsId">业务ID</param>
/// <param name="businessType">业务类型</param>
/// <param name="bsType">业务类型</param>
/// <param name="actionManager"></param>
/// <returns></returns>
public async Task<MailTemplateModel> GetTemplateModelAsync(IActionManagerService actionManager,
long bsId, BusinessType? businessType = null)
public async Task<MailTemplateModel> GetBusinessModelAsync(BusinessTaskMail taskMail,
long bsId, BusinessType? bsType = null, IActionManagerService? actionManager = null)
{
ArgumentNullException.ThrowIfNull(actionManager, nameof(actionManager));
ArgumentNullException.ThrowIfNull(taskMail, nameof(taskMail));
MailTemplateModel model = new()
{
BusinessId = bsId,
BusinessType = businessType.GetValueOrDefault(),
Primary = await actionManager.GetBusinessDataAsync(bsId, businessType.GetValueOrDefault())
BusinessType = bsType
};
if (taskMail.Provider == null)
{
actionManager ??= ServiceProvider.GetRequiredService<IActionManagerService>();
model.Primary = await actionManager.GetBusinessDataAsync(bsId, bsType.GetValueOrDefault());
}
else
{
IDataProvider? dataProvider = null;
switch (taskMail.Provider.Type)
{
case DataProviderType.Custom:
if (string.IsNullOrEmpty(taskMail.Provider.TypeName))
return model;
var type = Type.GetType(taskMail.Provider.TypeName, true);
dataProvider = ConstructorExtensions.CreateInstance(type, [ServiceProvider]) as IDataProvider;
dataProvider ??= ConstructorExtensions.CreateInstance(type) as IDataProvider;
break;
case DataProviderType.Fixed:
model.Primary = JsonConvert.DeserializeObject<dynamic>(taskMail.Content!);
break;
case DataProviderType.Database:
dataProvider = new DefaultDatabaseProvider(ServiceProvider);
break;
case DataProviderType.Network:
break;
}
if (dataProvider != null)
{
DataFetchContext context = new()
{
ServiceProvider = ServiceProvider,
BusinessId = bsId,
BusinessType = bsType,
Content = taskMail.Content,
};
await dataProvider.FetchDataAsync(context);
model.Primary = context.Data;
}
}
if (model.Primary == null)
return model;
@ -171,7 +218,7 @@ namespace DS.WMS.Core.TaskInteraction.Method
}
/// <summary>
/// 根据配置发送邮件
/// 根据模板配置发送邮件
/// </summary>
/// <param name="mailConfig">邮件配置</param>
/// <param name="templateModel">模板数据</param>
@ -335,8 +382,8 @@ namespace DS.WMS.Core.TaskInteraction.Method
return DataResult.Failed($"未能获取打印API生成的文件请求地址{requestUrl}");
string url = config["TaskMail:FileBaseUrl"] + @"/PrintTempFile/" + reqResult.Data.Data;
var fileResult = await Api.SendRequestAsync(HttpMethod.Get, url);
if (!fileResult.IsSuccessStatusCode)
var response = await Api.SendRequestAsync(HttpMethod.Get, url);
if (!response.IsSuccessStatusCode)
return DataResult.Failed($"未能获取打印API生成的文件附件地址{url}");
string? fileName = Path.GetFileName(reqResult.Data.Data);
@ -356,7 +403,7 @@ namespace DS.WMS.Core.TaskInteraction.Method
fileName = fileName + "." + item.FileType.Value.ToString().ToLowerInvariant();
}
var byteArray = await fileResult.Content.ReadAsByteArrayAsync();
var byteArray = await response.Content.ReadAsByteArrayAsync();
string base64Str = Convert.ToBase64String(byteArray);
attachmentList.Add(new Tuple<string, string>(fileName, base64Str));
}

@ -1,7 +1,6 @@
using DS.Module.Core;
using DS.Module.Core.Data;
using DS.Module.Core.Extensions;
using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.TaskInteraction.Entity;
using DS.WMS.Core.TaskInteraction.Interface;
using Microsoft.Extensions.DependencyInjection;
@ -26,54 +25,54 @@ namespace DS.WMS.Core.TaskInteraction.Method
mailService = new(provider);
}
/// <summary>
/// 渲染模板
/// </summary>
/// <param name="docType">单据类型</param>
/// <param name="bsId">业务ID</param>
/// <param name="businessType">业务类型</param>
/// <returns></returns>
public async Task<DataResult<string>> RenderTemplateAsync(DocumentType docType, long bsId, BusinessType businessType)
{
var taskMail = await TenantDb.Queryable<BusinessTaskMail>()
.Where(x => x.DocumentType == docType).OrderByDescending(x => x.CreateTime).FirstAsync();
if (taskMail == null)
return DataResult<string>.FailedWithDesc(MultiLanguageConst.EmptyData);
if (string.IsNullOrEmpty(taskMail.Content))
return DataResult<string>.Success(taskMail.Content);
var model = await mailService.GetTemplateModelAsync(actionService.Value, bsId, BusinessType.OceanShippingExport);
if (model.Primary == null)
return DataResult<string>.FailedWithDesc(MultiLanguageConst.EmptyData);
string content = await MailGenerator.RenderTemplateAsync(taskMail.Content, model);
return DataResult<string>.Success(content);
}
/// <summary>
/// 获取邮件内容
/// </summary>
/// <param name="docType">单据类型</param>
/// <param name="templateName">邮件模板名称</param>
/// <param name="customerNO">委托编号</param>
/// <returns></returns>
public async Task<DataResult<Tuple<string, string>>> GetMailContentAsync(string customerNO, DocumentType docType, string? templateName = null)
{
var taskMail = await TenantDb.Queryable<BusinessTaskMail>()
.Where(x => x.DocumentType == docType || x.Name == templateName).OrderByDescending(x => x.CreateTime).FirstAsync();
if (taskMail == null)
return DataResult<Tuple<string, string>>.FailedWithDesc(MultiLanguageConst.EmptyData);
var bsId = await TenantDb.Queryable<SeaExport>().Where(x => x.CustomerNo.Contains(customerNO)).Select(x => x.Id).FirstAsync();
var model = await mailService.GetTemplateModelAsync(actionService.Value, bsId, BusinessType.OceanShippingExport);
string title = await MailGenerator.RenderTemplateAsync(taskMail.Title, model);
string content = await MailGenerator.RenderTemplateAsync(taskMail.Content, model);
return DataResult<Tuple<string, string>>.Success(new Tuple<string, string>(title, content));
}
///// <summary>
///// 渲染模板
///// </summary>
///// <param name="docType">单据类型</param>
///// <param name="bsId">业务ID</param>
///// <param name="businessType">业务类型</param>
///// <returns></returns>
//public async Task<DataResult<string>> RenderTemplateAsync(DocumentType docType, long bsId, BusinessType businessType)
//{
// var taskMail = await TenantDb.Queryable<BusinessTaskMail>()
// .Where(x => x.DocumentType == docType).OrderByDescending(x => x.CreateTime).FirstAsync();
// if (taskMail == null)
// return DataResult<string>.FailedWithDesc(MultiLanguageConst.EmptyData);
// if (string.IsNullOrEmpty(taskMail.Content))
// return DataResult<string>.Success(taskMail.Content);
// var model = await mailService.GetTemplateModelAsync(actionService.Value, bsId, BusinessType.OceanShippingExport);
// if (model.Primary == null)
// return DataResult<string>.FailedWithDesc(MultiLanguageConst.EmptyData);
// string content = await BizMailGenerator.RenderTemplateAsync(taskMail.Content, model);
// return DataResult<string>.Success(content);
//}
///// <summary>
///// 获取邮件内容
///// </summary>
///// <param name="docType">单据类型</param>
///// <param name="templateName">邮件模板名称</param>
///// <param name="customerNO">委托编号</param>
///// <returns></returns>
//public async Task<DataResult<Tuple<string, string>>> GetMailContentAsync(string customerNO, DocumentType docType, string? templateName = null)
//{
// var taskMail = await TenantDb.Queryable<BusinessTaskMail>()
// .Where(x => x.DocumentType == docType || x.Name == templateName).OrderByDescending(x => x.CreateTime).FirstAsync();
// if (taskMail == null)
// return DataResult<Tuple<string, string>>.FailedWithDesc(MultiLanguageConst.EmptyData);
// var bsId = await TenantDb.Queryable<SeaExport>().Where(x => x.CustomerNo.Contains(customerNO)).Select(x => x.Id).FirstAsync();
// var model = await mailService.GetTemplateModelAsync(actionService.Value, bsId, BusinessType.OceanShippingExport);
// string title = await BizMailGenerator.RenderTemplateAsync(taskMail.Title, model);
// string content = await BizMailGenerator.RenderTemplateAsync(taskMail.Content, model);
// return DataResult<Tuple<string, string>>.Success(new Tuple<string, string>(title, content));
//}
/// <summary>
/// 获取分页列表

@ -24,48 +24,48 @@ namespace DS.WMS.OpApi.Controllers
this.service = service;
}
/// <summary>
/// 渲染模板
/// </summary>
/// <param name="docType">单据类型</param>
/// <param name="bsId">业务ID</param>
/// <param name="businessType">业务类型</param>
/// <returns></returns>
[HttpGet, Route("RenderTemplate")]
public async Task<DataResult<string>> RenderTemplateAsync(DocumentType docType, long bsId, BusinessType businessType)
{
return await service.RenderTemplateAsync(docType, bsId, businessType);
}
///// <summary>
///// 渲染模板
///// </summary>
///// <param name="docType">单据类型</param>
///// <param name="bsId">业务ID</param>
///// <param name="businessType">业务类型</param>
///// <returns></returns>
//[HttpGet, Route("RenderTemplate")]
//public async Task<DataResult<string>> RenderTemplateAsync(DocumentType docType, long bsId, BusinessType businessType)
//{
// return await service.RenderTemplateAsync(docType, bsId, businessType);
//}
/// <summary>
/// 预览邮件模板
/// </summary>
/// <param name="host"></param>
/// <param name="customerNO">委托编号</param>
/// <param name="docType">单据类型</param>
/// <param name="templateName">模板自定义名称</param>
/// <returns></returns>
[HttpGet, Route("Preview")]
public async Task<IActionResult> PreviewAsync([FromServices] IHostEnvironment host, string customerNO, DocumentType docType, string? templateName = null)
{
var result = await service.GetMailContentAsync(customerNO, docType, templateName);
if (!result.Succeeded)
return Content(result.Message);
///// <summary>
///// 预览邮件模板
///// </summary>
///// <param name="host"></param>
///// <param name="customerNO">委托编号</param>
///// <param name="docType">单据类型</param>
///// <param name="templateName">模板自定义名称</param>
///// <returns></returns>
//[HttpGet, Route("Preview")]
//public async Task<IActionResult> PreviewAsync([FromServices] IHostEnvironment host, string customerNO, DocumentType docType, string? templateName = null)
//{
// var result = await service.GetMailContentAsync(customerNO, docType, templateName);
// if (!result.Succeeded)
// return Content(result.Message);
//string dir = Path.Combine(host.ContentRootPath, "wwwroot", "content-preview");
//if (!Directory.Exists(dir))
// Directory.CreateDirectory(dir);
// //string dir = Path.Combine(host.ContentRootPath, "wwwroot", "content-preview");
// //if (!Directory.Exists(dir))
// // Directory.CreateDirectory(dir);
//string path = Path.Combine(dir, customerNO + ".htm");
//FileStream fs = new FileStream(path, FileMode.Create);
//StreamWriter writer = new StreamWriter(fs, Encoding.UTF8);
//await writer.WriteAsync(result.Data.Item2);
//await fs.FlushAsync();
// //string path = Path.Combine(dir, customerNO + ".htm");
// //FileStream fs = new FileStream(path, FileMode.Create);
// //StreamWriter writer = new StreamWriter(fs, Encoding.UTF8);
// //await writer.WriteAsync(result.Data.Item2);
// //await fs.FlushAsync();
//return PhysicalFile(path, "application/octet-stream");
// //return PhysicalFile(path, "application/octet-stream");
return File(Encoding.UTF8.GetBytes(result.Data.Item2), "application/octet-stream", customerNO + ".htm");
}
// return File(Encoding.UTF8.GetBytes(result.Data.Item2), "application/octet-stream", customerNO + ".htm");
//}
/// <summary>
/// 获取分页列表
@ -103,6 +103,7 @@ namespace DS.WMS.OpApi.Controllers
if (taskMail.Sender == null)
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskMailSenderNotNull));
taskMail.IsBusiness = true;
return await service.EditAsync(taskMail);
}

Loading…
Cancel
Save