diff --git a/Myshipping.Application/Service/BookingOrder/BookingMSKAPIService.cs b/Myshipping.Application/Service/BookingOrder/BookingMSKAPIService.cs index 259672e9..23f281a8 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingMSKAPIService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingMSKAPIService.cs @@ -1054,11 +1054,14 @@ 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(); diff --git a/Myshipping.Application/Service/EmailParserServerManage/Dto/EmailParserServerMapper.cs b/Myshipping.Application/Service/EmailParserServerManage/Dto/EmailParserServerMapper.cs index 24adbe9a..0e266445 100644 --- a/Myshipping.Application/Service/EmailParserServerManage/Dto/EmailParserServerMapper.cs +++ b/Myshipping.Application/Service/EmailParserServerManage/Dto/EmailParserServerMapper.cs @@ -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() + .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); } } } diff --git a/Myshipping.Application/Service/EmailParserServerManage/EmailExcuteCodeInjectConfigService.cs b/Myshipping.Application/Service/EmailParserServerManage/EmailExcuteCodeInjectConfigService.cs index fd61724c..3d5f72a3 100644 --- a/Myshipping.Application/Service/EmailParserServerManage/EmailExcuteCodeInjectConfigService.cs +++ b/Myshipping.Application/Service/EmailParserServerManage/EmailExcuteCodeInjectConfigService.cs @@ -153,7 +153,7 @@ namespace Myshipping.Application.Service.EmailParserServerManage if (model == null) throw Oops.Oh($"邮件执行代码注入配置获取失败,邮件执行代码注入配置不存在或已作废", typeof(InvalidOperationException)); - var showModel = model.Adapt(); + var showModel = model.Adapt(); result.succ = true; result.ext = showModel; diff --git a/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs b/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs index b307d180..6022129e 100644 --- a/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs @@ -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 _bookingFileRepository; private readonly SqlSugarRepository _djyUserMailAccount; private readonly SqlSugarRepository _bookingOrderContactRepository; + private readonly SqlSugarRepository _bookingSlotCompareRepository; private readonly IServiceWorkFlowBaseService _serviceWorkFlowBaseService; private readonly IBookingOrderService _bookingOrderService; @@ -85,7 +87,8 @@ namespace Myshipping.Application IBookingOrderService bookingOrderService, ILogger logger, IDjyCustomerService djyCustomerService, IBookingSlotService bookingSlotService, ISysCacheService cache, IBookingValueAddedService bookingValueAddedService, - SqlSugarRepository bookingOrderContactRepository) + SqlSugarRepository bookingOrderContactRepository, + SqlSugarRepository 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 + /// + /// 通过邮件模板生成HTML + /// + /// BC任务详情 + /// 订舱OP详情 + /// 当前租户全称 + /// 返回生成的HTML + public async Task GenerateSendEmailHtmlAmendment(TaskBCInfo taskBCInfo, SysUser opUserInfo, string tenantName) + { + string result = string.Empty; + + /* + 1、加载模板文件,读取HTML + 2、读取main、conta的tr行,替换业务数据 + 3、返回HTML的文本信息。 + */ + try + { + string templatePath = App.Configuration["EmailTemplateFilePath"]; + + var opt = App.GetOptions(); + 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 推送邮件 /// /// 推送邮件 @@ -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 { diff --git a/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs b/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs index 4bc5d27c..062f69d1 100644 --- a/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs @@ -115,6 +115,7 @@ namespace Myshipping.Application private readonly INamedServiceProvider _namedBookingOrderServiceProvider; private readonly INamedServiceProvider _namedRollingNominationServiceProvider; + private readonly INamedServiceProvider _namedTaskManageBCServiceProvider; private readonly IBookingValueAddedService _bookingValueAddedService; const string CONST_WEB_ACCOUNT_TYPE = "CmaWeb"; @@ -164,6 +165,7 @@ namespace Myshipping.Application ISysCacheService cache, ISysDataUserMenu sysDataUserMenuService, INamedServiceProvider namedRollingNominationServiceProvider, + INamedServiceProvider namedTaskManageBCServiceProvider, IBookingValueAddedService bookingValueAddedService, ILogger 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(nameof(TaskManageBCService)); + await name.SyncBookingSlotChange(bcInfo.TASK_ID); } } #endregion