新增截止时间发送邮件功能

usertest
jianghaiqing 4 months ago
parent 93b68f598a
commit 0a3e69a136

@ -1432,7 +1432,18 @@ public static class MultiLanguageConst
/// </summary>
[Description("任务主键{0}无法获取业务信息")]
public const string TaskBaseInfoFromTaskIdNull = "TaskBaseInfo_FromTaskId_Null";
/// <summary>
/// 提单号 {0} 检索海运出口订单失败
/// </summary>
[Description("提单号 {0} 检索海运出口订单失败")]
public const string TaskBaseSearchOrderFailMBLNo = "TaskBase_SearchOrderFail_MBLNo";
/// <summary>
/// 提单号 {0} 生成截止时间变更转发邮件正文失败,原因:{1}
/// </summary>
[Description("提单号 {0} 生成截止时间变更转发邮件正文失败,原因:{1}")]
public const string TaskBaseCutDateTransmitGenerateEmailFail = "TaskBase_CutDate_Transmit_GenerateEmailFail";
#endregion

@ -17,6 +17,7 @@
<PackageReference Include="fasterflect" Version="3.0.0" />
<PackageReference Include="GZY.Quartz.MUI" Version="2.6.0" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.14" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.46" />
<PackageReference Include="LanguageExt.Core" Version="4.4.7" />
<PackageReference Include="MailKit" Version="4.6.0" />
<PackageReference Include="Mapster" Version="7.4.0" />

@ -1,5 +1,6 @@
using DS.Module.Core;
using DS.Module.DjyServiceStatus;
using DS.WMS.Core.Op.Dtos;
using DS.WMS.Core.TaskPlat.Dtos;
using System;
using System.Collections.Generic;
@ -26,7 +27,14 @@ namespace DS.WMS.Core.TaskPlat.Interface
/// </summary>
/// <param name="taskPKId">截止时间变更任务主键</param>
/// <returns>返回回执</returns>
Task<DataResult> SearchAndMarkBookingOrder(long taskPKId);
Task<DataResult<SeaExportOrderExtension>> SearchAndMarkBookingOrder(long taskPKId);
/// <summary>
/// 自动更新订单的截单日期并转发
/// </summary>
/// <param name="taskPKId">截止时间变更任务主键</param>
/// <returns>返回回执</returns>
Task<DataResult> AutoUpdateOrderCutDateAndTranmitToCustomer(long taskPKId);
/// <summary>
/// 发送邮件通知给客户

@ -22,6 +22,12 @@ using System.Threading.Tasks;
using Mapster;
using DS.Module.DjyServiceStatus;
using Microsoft.AspNetCore.Identity;
using DS.WMS.Core.Op.Interface;
using Masuit.Tools;
using DS.WMS.Core.Op.Dtos;
using DS.WMS.Core.Sys.Entity;
using HtmlAgilityPack;
using Microsoft.AspNetCore.Mvc;
namespace DS.WMS.Core.TaskPlat.Method
{
@ -34,6 +40,8 @@ namespace DS.WMS.Core.TaskPlat.Method
private readonly ISqlSugarClient db;
private readonly IUser user;
private readonly ISaasDbService saasService;
private readonly ISeaExportService _seaExportService;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public TaskManageCutDateChangeService(IServiceProvider serviceProvider)
@ -42,6 +50,7 @@ namespace DS.WMS.Core.TaskPlat.Method
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
user = _serviceProvider.GetRequiredService<IUser>();
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
_seaExportService = _serviceProvider.GetRequiredService<ISeaExportService>();
}
#region 通过任务主键获取截止时间变更详情
@ -94,8 +103,9 @@ namespace DS.WMS.Core.TaskPlat.Method
/// </summary>
/// <param name="taskPKId">截止时间变更任务主键</param>
/// <returns>返回回执</returns>
public async Task<DataResult> SearchAndMarkBookingOrder(long taskPKId)
public async Task<DataResult<SeaExportOrderExtension>> SearchAndMarkBookingOrder(long taskPKId)
{
SeaExportOrderExtension orderInfo = null;
try
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
@ -106,70 +116,112 @@ namespace DS.WMS.Core.TaskPlat.Method
.Select((a, b) => new { Base = a, Cut = b })
.ToListAsync();
//调取海运出口的检索匹配订单方法
//任务主键{taskPkId}无法获取业务信息
if (queryList.Count == 0)
throw new Exception(string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskBaseInfoFromTaskIdNull)), taskPKId));
//通过船名航次取是主单的订舱记录列表
//var bookingInfo = _bookingOrderRepository.AsQueryable().Filter(null, true).First(a => a.MBLNO == entityInfo.MBL_NO
// && a.IsDeleted == false && (a.ParentId == null || a.ParentId == 0) && a.TenantId == UserManager.TENANT_ID);
string mblNo = queryList.FirstOrDefault().Base.MBL_NO;
var orderRlt = await _seaExportService.SearchOrderInfo(mblNo);
if (!orderRlt.Succeeded)
{
// 提单号 {0} 检索海运出口订单失败
throw new Exception(string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskBaseSearchOrderFailMBLNo)), mblNo));
}
orderInfo = orderRlt.Data;
foreach (var item in queryList.Select(a => a.Cut).ToList())
{
item.BOOKING_ID = orderInfo.currOrder.Id;
item.UpdateTime = DateTime.Now;
item.UpdateBy = long.Parse(user.UserId);
item.UpdateUserName = user.UserName;
tenantDb.Updateable<TaskCutDateChangeInfo>(item).UpdateColumns(x => new
{
x.BOOKING_ID,
x.UpdateTime,
x.UpdateBy,
x.UpdateUserName
}).ExecuteCommand();
var list = tenantDb.Queryable<TaskCutDateChangeDetailInfo>().Where(a => a.P_ID == item.Id).ToList();
if (list != null && list.Count > 0)
{
list.ForEach(async p =>
{
if (p.MBL_NO.Equals(item.MBL_NO, StringComparison.OrdinalIgnoreCase))
{
p.BOOKING_ID = orderInfo.currOrder.Id;
p.UpdateTime = DateTime.Now;
p.UpdateBy = long.Parse(user.UserId);
p.UpdateUserName = user.UserName;
await tenantDb.Updateable<TaskCutDateChangeDetailInfo>(p).UpdateColumns(x => new
{
x.BOOKING_ID,
x.UpdateTime,
x.UpdateBy,
x.UpdateUserName
}).ExecuteCommandAsync();
}
});
}
}
//if (bookingInfo != null)
//{
// entityInfo.BOOKING_ID = bookingInfo.Id;
// entityInfo.UpdatedTime = DateTime.Now;
// entityInfo.UpdatedUserId = UserManager.UserId;
// entityInfo.UpdatedUserName = UserManager.Name;
// await _taskCutDateChangeInfoRepository.AsUpdateable(entityInfo).UpdateColumns(x => new
// {
// x.BOOKING_ID,
// x.UpdatedTime,
// x.UpdatedUserId,
// x.UpdatedUserName
// }).ExecuteCommandAsync();
// var list = _taskCutDateChangeDetailInfoRepository.AsQueryable().Filter(null, true).Where(a => a.P_ID == entityInfo.PK_ID).ToList();
// if (list != null && list.Count > 0)
// {
// list.ForEach(async p =>
// {
// if (p.MBL_NO.Equals(entityInfo.MBL_NO, StringComparison.OrdinalIgnoreCase))
// {
// p.BOOKING_ID = bookingInfo.Id;
// p.UpdatedTime = DateTime.Now;
// p.UpdatedUserId = UserManager.UserId;
// p.UpdatedUserName = UserManager.Name;
// await _taskCutDateChangeDetailInfoRepository.AsUpdateable(p).UpdateColumns(x => new
// {
// x.BOOKING_ID,
// x.UpdatedTime,
// x.UpdatedUserId,
// x.UpdatedUserName
// }).ExecuteCommandAsync();
// }
// });
// }
// result.succ = true;
// result.msg = "检索对应成功";
//}
//else
//{
// result.succ = false;
// result.msg = $"检索对应失败,提单号:{entityInfo.MBL_NO} 没有对应的订舱记录";
//}
}
catch (Exception ex)
{
//result.succ = false;
//result.msg = $"检索失败,原因:{ex.Message}";
Logger.Log(NLog.LogLevel.Info, $"taskPKId={taskPKId} 检索截止时间变更订舱记录 处理异常,原因:{ex.Message}");
//_logger.LogInformation($"taskPKId={taskPKId} 检索截止时间变更订舱记录 处理异常,原因:{ex.Message}");
return DataResult<SeaExportOrderExtension>.FailedData(orderInfo,$"检索失败,原因:{ex.Message}", MultiLanguageConst.Operation_Failed);
}
return null;
return DataResult<SeaExportOrderExtension>.Success(orderInfo);
}
#endregion
#region 自动更新订单的截单日期并转发
/// <summary>
/// 自动更新订单的截单日期并转发
/// </summary>
/// <param name="taskPKId">截止时间变更任务主键</param>
/// <returns>返回回执</returns>
public async Task<DataResult> AutoUpdateOrderCutDateAndTranmitToCustomer(long taskPKId)
{
SeaExportOrderExtension orderInfo = null;
try
{
var queryRlt = await SearchAndMarkBookingOrder(taskPKId);
if (!queryRlt.Succeeded)
{
throw new Exception(queryRlt.Message);
}
orderInfo = queryRlt.Data;
//更新海运出口截单时间
//更新舱位的截单时间
}
catch(Exception ex)
{
Logger.Log(NLog.LogLevel.Info, $"taskPKId={taskPKId} 自动更新订单的截单日期并转发失败异常,原因:{ex.Message}");
return DataResult.Failed( $"自动更新订单的截单日期并转发失败,原因:{ex.Message}", MultiLanguageConst.Operation_Failed);
}
return DataResult.Successed(string.Empty, MultiLanguageConst.OperationSuccess);
}
#endregion
@ -184,5 +236,230 @@ namespace DS.WMS.Core.TaskPlat.Method
return null;
}
#endregion
#region 通过邮件模板生成HTML
/// <summary>
/// 通过邮件模板生成HTML
/// </summary>
/// <param name="model"></param>
/// <param name="bookingOrderList"></param>
/// <param name="filePath"></param>
/// <param name="opUserInfo"></param>
/// <param name="tenantName"></param>
/// <returns></returns>
[NonAction]
private async Task<string> GenerateSendEmailHtml(TaskCutDateChangeInfo model, List<TaskCutDateChangeDetailInfo> rowList, SeaExportRes seaExportRes,
string filePath, SysUser opUserInfo, string tenantName,string fileAbsPath)
{
string result = string.Empty;
string baseHtml = string.Empty;
try
{
//var opt = App.GetOptions<PrintTemplateOptions>();
//var dirAbs = opt.basePath;
//if (string.IsNullOrEmpty(dirAbs))
//{
// dirAbs = App.WebHostEnvironment.WebRootPath;
//}
//var fileAbsPath = Path.Combine(dirAbs, filePath);
//_logger.LogInformation($"查找模板文件:{fileAbsPath}");
//if (!File.Exists(fileAbsPath))
//{
// throw Oops.Bah(BookingErrorCode.BOOK115);
//}
baseHtml = File.ReadAllText(fileAbsPath);
if (opUserInfo != null && !string.IsNullOrWhiteSpace(opUserInfo.UserName))
{
baseHtml = baseHtml.Replace("#opname#", opUserInfo.UserName);
}
else
{
baseHtml = baseHtml.Replace("#opname#", "操作");
}
if (opUserInfo != null && !string.IsNullOrWhiteSpace(opUserInfo.Email))
{
baseHtml = baseHtml.Replace("#opemail#", opUserInfo.Email);
}
else
{
baseHtml = baseHtml.Replace("#opemail#", "");
}
if (opUserInfo != null && !string.IsNullOrWhiteSpace(opUserInfo.Phone))
{
baseHtml = baseHtml.Replace("#optel#", opUserInfo.Phone);
}
else if (opUserInfo != null && !string.IsNullOrWhiteSpace(opUserInfo.Tel))
{
baseHtml = baseHtml.Replace("#optel#", opUserInfo.Tel);
}
else
{
baseHtml = baseHtml.Replace("#optel#", "");
}
if (!string.IsNullOrWhiteSpace(model.MBL_NO))
{
baseHtml = baseHtml.Replace("#BillNo#", model.MBL_NO);
}
else
{
baseHtml = baseHtml.Replace("#BillNo#", "");
}
if (!string.IsNullOrWhiteSpace(model.VESSEL))
{
string s = $"{model.VESSEL}/{model.VOYNO}";
baseHtml = baseHtml.Replace("#VesselVoyno#", s);
}
else
{
baseHtml = baseHtml.Replace("#VesselVoyno#", "");
}
var detailInfo = rowList.FirstOrDefault();
if (detailInfo.SI_CUTOFF.HasValue)
{
baseHtml = baseHtml.Replace("#SICutDate#", detailInfo.SI_CUTOFF.Value.ToString("yyyy-MM-dd HH:mm"));
}
else
{
baseHtml = baseHtml.Replace("#SICutDate#", "");
}
if (detailInfo.VGM_CUT.HasValue)
{
baseHtml = baseHtml.Replace("#VGMCutDate#", detailInfo.VGM_CUT.Value.ToString("yyyy-MM-dd HH:mm"));
}
else
{
baseHtml = baseHtml.Replace("#VGMCutDate#", "");
}
if (detailInfo.CY_CUTOFF.HasValue)
{
baseHtml = baseHtml.Replace("#CYCutDate#", detailInfo.CY_CUTOFF.Value.ToString("yyyy-MM-dd HH:mm"));
}
else
{
baseHtml = baseHtml.Replace("#CYCutDate#", "");
}
if (detailInfo.VOUCHER_CUT_DATE.HasValue)
{
baseHtml = baseHtml.Replace("#VoucherCutDate#", detailInfo.VOUCHER_CUT_DATE.Value.ToString("yyyy-MM-dd HH:mm"));
}
else
{
baseHtml = baseHtml.Replace("#VoucherCutDate#", "");
}
if (detailInfo.CY_OPEN.HasValue)
{
baseHtml = baseHtml.Replace("#CYOpenDate#", detailInfo.CY_OPEN.Value.ToString("yyyy-MM-dd"));
}
else
{
baseHtml = baseHtml.Replace("#CYOpenDate#", "");
}
if (!string.IsNullOrWhiteSpace(detailInfo.REASON))
{
baseHtml = baseHtml.Replace("#Reason#", model.REASON);
}
else
{
baseHtml = baseHtml.Replace("#Reason#", "");
}
if (!string.IsNullOrWhiteSpace(tenantName))
{
baseHtml = baseHtml.Replace("#TenantCompanyName#", tenantName);
}
else
{
baseHtml = baseHtml.Replace("#TenantCompanyName#", "");
}
HtmlDocument html = new HtmlDocument();
html.LoadHtml(baseHtml);
var tableNode = html.DocumentNode.SelectSingleNode(".//table[@id='show-table']");
if (model.PORTLOAD_AREA.Equals("SOUTH_PORT", StringComparison.OrdinalIgnoreCase))
{
if (tableNode != null)
{
StringBuilder tableBuilder = new StringBuilder();
for (int i = 0; i < rowList.Count; i++)
{
tableBuilder.Append($"<tr><td>{rowList[i].MBL_NO}</td><td>{rowList[i].CONTA_NO}</td><td>{rowList[i].LOAD_PORT}</td><td>{(rowList[i].ETB.HasValue ? rowList[i].ETB.Value.ToString("yyyy-MM-dd HH:mm") : "")}</td><td>{(rowList[i].ETD.HasValue ? rowList[i].ETD.Value.ToString("yyyy-MM-dd HH:mm") : "")}</td></tr>");
}
//生成From Vessel的table列表
tableNode.ChildNodes.Add(HtmlNode.CreateNode(tableBuilder.ToString()));
}
}
else
{
var southPNodes = html.DocumentNode.SelectNodes(".//p[@class='south_port']");
foreach (var node in southPNodes)
{
node.Remove();
}
tableNode.RemoveAllChildren();
var colArg = new string[] { "Shipment Number", "Vessel - voyage", "样单截止时间 SI Cut Off", "开港时间 CY Open", "截港时间 CY cut off", "舱单-入港清单截止时间", "MDGF提交截止时间 - 危险品货物", "船代VGM截止时间", "海关放行截止时间(Customs Clearance Deadline)" };
tableNode.ChildNodes.Add(HtmlNode.CreateNode($"<tr><th style=\"text-align: left;\">{(string.Join("</th><th style=\"text-align: left;\">", colArg))}</th></tr>"));
StringBuilder tableBuilder = new StringBuilder();
for (int i = 0; i < rowList.Count; i++)
{
tableBuilder.Append($"<tr><td>{rowList[i].MBL_NO}</td>");
tableBuilder.Append($"<td>{($"{rowList[i].VESSEL}/{rowList[i].VOYNO}")}</td>");
tableBuilder.Append($"<td>{(rowList[i].SI_CUTOFF.HasValue ? rowList[i].SI_CUTOFF.Value.ToString("yyyy-MM-dd HH:mm") : rowList[i].SI_CUTOFF_TXT)}</td>");
tableBuilder.Append($"<td>{(rowList[i].CY_OPEN.HasValue ? rowList[i].CY_OPEN.Value.ToString("yyyy-MM-dd HH:mm") : rowList[i].CY_OPEN_TXT)}</td>");
tableBuilder.Append($"<td>{(rowList[i].CY_CUTOFF.HasValue ? rowList[i].CY_CUTOFF.Value.ToString("yyyy-MM-dd HH:mm") : rowList[i].CY_CUTOFF_TXT)}</td>");
tableBuilder.Append($"<td>{(rowList[i].MANIFEST_CUT.HasValue ? rowList[i].MANIFEST_CUT.Value.ToString("yyyy-MM-dd HH:mm") : rowList[i].MANIFEST_CUT_TXT)}</td>");
tableBuilder.Append($"<td>{(rowList[i].MDGF_CUT.HasValue ? rowList[i].MDGF_CUT.Value.ToString("yyyy-MM-dd HH:mm") : rowList[i].MDGF_CUT_TXT)}</td>");
tableBuilder.Append($"<td>{(rowList[i].VGM_CUT.HasValue ? rowList[i].VGM_CUT.Value.ToString("yyyy-MM-dd HH:mm") : rowList[i].VGM_CUT_TXT)}</td>");
tableBuilder.Append($"<td>{(rowList[i].CLOSING_DATE.HasValue ? rowList[i].CLOSING_DATE.Value.ToString("yyyy-MM-dd HH:mm") : rowList[i].CLOSING_DATE_TXT)}</td>");
tableBuilder.Append("</tr>");
}
//生成From Vessel的table列表
tableNode.ChildNodes.Add(HtmlNode.CreateNode(tableBuilder.ToString()));
}
result = html.DocumentNode.OuterHtml;
}
catch (Exception ex)
{
Logger.Log(NLog.LogLevel.Info, $"生成截止时间变更转发邮件正文失败,原因:{ex.Message}");
//提单号 {0} 生成截止时间变更转发邮件正文失败,原因:{1}
throw new Exception(string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskBaseCutDateTransmitGenerateEmailFail)), model.MBL_NO, ex.Message));
}
return result;
}
#endregion
}
}

Loading…
Cancel
Save