修改邮件配置

master
jianghaiqing 9 months ago
parent 2a8d71478d
commit 35667637de

@ -1054,12 +1054,15 @@ namespace Myshipping.Application.Service.BookingOrder
if (oldInfo == null)
throw Oops.Oh("订舱数据不存在或已作废");
if (isSendApi)
if (oldInfo.STATUS == "SUCC")
{
if(oldInfo.STATUS == "SUCC")
if(isSendApi)
throw Oops.Oh("订舱数据已发送成功,不能重复发送");
throw Oops.Oh("订舱数据已发送成功,不能修改");
}
BookingDeliveryRecord entity = model.Adapt<BookingDeliveryRecord>();
entity.Id = model.id.Value;

@ -149,6 +149,14 @@ namespace Myshipping.Application
.Map(dest => dest.INJECT_FULLNAME, src => src.InjectFullName)
.Map(dest => dest.CreatedTime, src => src.CreatedTime)
.Map(dest => dest.UpdatedTime, src => src.UpdatedTime);
config.ForType<EmailExcuteCodeInjectConfigInfo, EmailExcuteCodeInjectConfigDto>()
.Map(dest => dest.GID, src => src.GID)
.Map(dest => dest.InjectCode, src => src.INJECT_CODE)
.Map(dest => dest.InjectName, src => src.INJECT_NAME)
.Map(dest => dest.InjectFullName, src => src.INJECT_FULLNAME)
.Map(dest => dest.CreatedTime, src => src.CreatedTime)
.Map(dest => dest.UpdatedTime, src => src.UpdatedTime);
}
}
}

@ -153,7 +153,7 @@ namespace Myshipping.Application.Service.EmailParserServerManage
if (model == null)
throw Oops.Oh($"邮件执行代码注入配置获取失败,邮件执行代码注入配置不存在或已作废", typeof(InvalidOperationException));
var showModel = model.Adapt<EmailExcuteCodeInjectConfigInfo>();
var showModel = model.Adapt<EmailExcuteCodeInjectConfigDto>();
result.succ = true;
result.ext = showModel;

@ -20,6 +20,7 @@ using Newtonsoft.Json;
using Npoi.Mapper;
using NPOI.HPSF;
using NPOI.SS.Formula.Functions;
using Org.BouncyCastle.Asn1.Tsp;
using RabbitMQ.Client;
using SqlSugar;
using StackExchange.Profiling.Internal;
@ -59,6 +60,7 @@ namespace Myshipping.Application
private readonly SqlSugarRepository<BookingFile> _bookingFileRepository;
private readonly SqlSugarRepository<DjyUserMailAccount> _djyUserMailAccount;
private readonly SqlSugarRepository<BookingOrderContact> _bookingOrderContactRepository;
private readonly SqlSugarRepository<BookingSlotCompare> _bookingSlotCompareRepository;
private readonly IServiceWorkFlowBaseService _serviceWorkFlowBaseService;
private readonly IBookingOrderService _bookingOrderService;
@ -85,7 +87,8 @@ namespace Myshipping.Application
IBookingOrderService bookingOrderService, ILogger<TaskManageBCService> logger,
IDjyCustomerService djyCustomerService,
IBookingSlotService bookingSlotService, ISysCacheService cache, IBookingValueAddedService bookingValueAddedService,
SqlSugarRepository<BookingOrderContact> bookingOrderContactRepository)
SqlSugarRepository<BookingOrderContact> bookingOrderContactRepository,
SqlSugarRepository<BookingSlotCompare> bookingSlotCompareRepository)
{
_taskBaseRepository = taskBaseRepository;
_taskBCInfoRepository = taskBCInfoRepository;
@ -103,6 +106,7 @@ namespace Myshipping.Application
_djyCustomerService = djyCustomerService;
_djyUserMailAccount = djyUserMailAccount;
_bookingOrderContactRepository = bookingOrderContactRepository;
_bookingSlotCompareRepository = bookingSlotCompareRepository;
_logger = logger;
}
@ -1031,6 +1035,8 @@ namespace Myshipping.Application
id = await _bookingSlotService.InnerApiReceive(slotModel, dynameFile, dynameNoticeFile);
}
catch (Exception ex)
{
@ -1450,17 +1456,18 @@ namespace Myshipping.Application
string emailTitle = $"Booking Confirmation : {taskBCInfo.MBL_NO}";
if (taskBCInfo.BUSI_TYPE == "BookingAmendment")
{
emailTitle = $"【变更】Booking Amendment : {taskBCInfo.MBL_NO}";
}
string filePath = string.Empty;
SysUser opUserInfo = null;
if(!string.IsNullOrWhiteSpace(bookingOrderEntity.OPID) && Regex.IsMatch(bookingOrderEntity.OPID,"[0-9]+"))
if (!string.IsNullOrWhiteSpace(bookingOrderEntity.OPID) && Regex.IsMatch(bookingOrderEntity.OPID, "[0-9]+"))
opUserInfo = _sysUserRepository.AsQueryable().First(u => u.Id == long.Parse(bookingOrderEntity.OPID));
if (taskBCInfo.BUSI_TYPE == "BookingAmendment")
{
emailTitle = $"【变更】Booking Amendment : {taskBCInfo.MBL_NO}";
}
//读取邮件模板并填充数据
string emailHtml = GenerateSendEmailHtml(taskBCInfo, opUserInfo,UserManager.TENANT_NAME).GetAwaiter().GetResult();
@ -1671,6 +1678,156 @@ namespace Myshipping.Application
}
#endregion
#region 通过邮件模板生成HTML
/// <summary>
/// 通过邮件模板生成HTML
/// </summary>
/// <param name="taskBCInfo">BC任务详情</param>
/// <param name="opUserInfo">订舱OP详情</param>
/// <param name="tenantName">当前租户全称</param>
/// <returns>返回生成的HTML</returns>
public async Task<string> GenerateSendEmailHtmlAmendment(TaskBCInfo taskBCInfo, SysUser opUserInfo, string tenantName)
{
string result = string.Empty;
/*
1HTML
2maincontatr
3HTML
*/
try
{
string templatePath = App.Configuration["EmailTemplateFilePath"];
var opt = App.GetOptions<BookingAttachOptions>();
var dirAbs = opt.basePath;
if (string.IsNullOrEmpty(dirAbs))
{
dirAbs = App.WebHostEnvironment.WebRootPath;
}
templatePath = $"{dirAbs}{templatePath}\\BCModifyEmailTemplate.html";
string baseHtml = File.ReadAllText(templatePath);
if (string.IsNullOrWhiteSpace(baseHtml))
throw Oops.Oh($"读取邮件模板失败");
if (opUserInfo != null && !string.IsNullOrWhiteSpace(opUserInfo.Name))
{
baseHtml = baseHtml.Replace("#opname#", opUserInfo.Name);
}
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.Tel))
{
baseHtml = baseHtml.Replace("#optel#", opUserInfo.Tel);
}
else
{
baseHtml = baseHtml.Replace("#optel#", "");
}
HtmlDocument html = new HtmlDocument();
html.LoadHtml(baseHtml);
HtmlNode baseTable = html.DocumentNode.SelectNodes("//table[@class='base-table']").FirstOrDefault();
if (baseTable == null)
throw Oops.Oh($"读取邮件模板格式错误定位base-table失败");
var baseTrList = baseTable.SelectNodes(".//tr");
foreach (var baseTr in baseTrList)
{
var tdList = baseTr.SelectNodes(".//td");
foreach (var baseTd in tdList)
{
if (baseTd.Attributes["class"].Value == "billno-val")
{
baseTd.InnerHtml = taskBCInfo.MBL_NO;
}
else if (baseTd.Attributes["class"].Value == "takebillno-val")
{
baseTd.InnerHtml = taskBCInfo.MBL_NO;
}
else if (baseTd.Attributes["class"].Value == "pol-val")
{
baseTd.InnerHtml = taskBCInfo.PLACERECEIPT;
}
else if (baseTd.Attributes["class"].Value == "pod-val")
{
baseTd.InnerHtml = taskBCInfo.PLACEDELIVERY;
}
else if (baseTd.Attributes["class"].Value == "ctn-val")
{
baseTd.InnerHtml = taskBCInfo.CTN_STAT;
}
else if (baseTd.Attributes["class"].Value == "etd-val")
{
if (taskBCInfo.ETD.HasValue)
{
baseTd.InnerHtml = taskBCInfo.ETD.Value.ToString("yyyy-MM-dd");
}
}
else if (baseTd.Attributes["class"].Value == "eta-val")
{
if (taskBCInfo.ETA.HasValue)
{
baseTd.InnerHtml = taskBCInfo.ETA.Value.ToString("yyyy-MM-dd");
}
}
}
}
var noreplyTr = html.DocumentNode.SelectNodes("//tr[@class='email-noreply']").FirstOrDefault();
if (noreplyTr != null)
{
var currTd = noreplyTr.SelectNodes(".//td").FirstOrDefault();
if (currTd != null)
{
var currPList = currTd.SelectNodes(".//p");
foreach (var baseP in currPList)
{
if (baseP.Attributes["class"].Value == "notice-comp-val")
{
baseP.InnerHtml = tenantName;
}
}
}
}
result = html.DocumentNode.OuterHtml;
}
catch (Exception ex)
{
_logger.LogInformation($"通过邮件模板生成HTML异常原因={ex.Message}");
throw ex;
}
return result;
}
#endregion
#region 推送邮件
/// <summary>
/// 推送邮件
@ -1842,7 +1999,16 @@ namespace Myshipping.Application
//推送舱位
var bookingSlotId = GenerateBookingSlot(bcOrder, bcCtnList, fileList,"update").GetAwaiter().GetResult();
//检索是否有差异
var compareResult = _bookingSlotCompareRepository.AsQueryable().Filter(null, true)
.Where(x => x.SLOT_ID == bookingSlotId && x.IsDeleted == false && x.TenantId ==
bcOrder.TenantId).OrderByDescending(a=>a.CreatedTime).First();
if(compareResult != null && compareResult.COMPARE_DIFF_NUM > 0)
{
//准备推送邮件
await GenerateSendEmail(bcOrder);
}
}
else
{

@ -115,6 +115,7 @@ namespace Myshipping.Application
private readonly INamedServiceProvider<IBookingOrderService> _namedBookingOrderServiceProvider;
private readonly INamedServiceProvider<ITaskManageRollingNominationService> _namedRollingNominationServiceProvider;
private readonly INamedServiceProvider<ITaskManageBCService> _namedTaskManageBCServiceProvider;
private readonly IBookingValueAddedService _bookingValueAddedService;
const string CONST_WEB_ACCOUNT_TYPE = "CmaWeb";
@ -164,6 +165,7 @@ namespace Myshipping.Application
ISysCacheService cache,
ISysDataUserMenu sysDataUserMenuService,
INamedServiceProvider<ITaskManageRollingNominationService> namedRollingNominationServiceProvider,
INamedServiceProvider<ITaskManageBCService> namedTaskManageBCServiceProvider,
IBookingValueAddedService bookingValueAddedService,
ILogger<BookingOrderService> logger)
{
@ -202,6 +204,7 @@ namespace Myshipping.Application
_namedBookingOrderServiceProvider = namedBookingOrderServiceProvider;
_namedRollingNominationServiceProvider = namedRollingNominationServiceProvider;
_bookingValueAddedService = bookingValueAddedService;
_namedTaskManageBCServiceProvider = namedTaskManageBCServiceProvider;
_sysDataUserMenuService = sysDataUserMenuService;
@ -754,7 +757,10 @@ namespace Myshipping.Application
if (info.Main.TaskType == TaskBaseTypeEnum.BC_MODIFY)
{
var name = _namedTaskManageBCServiceProvider
.GetService<ITransient>(nameof(TaskManageBCService));
await name.SyncBookingSlotChange(bcInfo.TASK_ID);
}
}
#endregion

Loading…
Cancel
Save