diff --git a/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs b/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs index 4c891c57..a495b45c 100644 --- a/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs +++ b/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs @@ -1432,7 +1432,18 @@ public static class MultiLanguageConst /// [Description("任务主键{0}无法获取业务信息")] public const string TaskBaseInfoFromTaskIdNull = "TaskBaseInfo_FromTaskId_Null"; - + + /// + /// 提单号 {0} 检索海运出口订单失败 + /// + [Description("提单号 {0} 检索海运出口订单失败")] + public const string TaskBaseSearchOrderFailMBLNo = "TaskBase_SearchOrderFail_MBLNo"; + + /// + /// 提单号 {0} 生成截止时间变更转发邮件正文失败,原因:{1} + /// + [Description("提单号 {0} 生成截止时间变更转发邮件正文失败,原因:{1}")] + public const string TaskBaseCutDateTransmitGenerateEmailFail = "TaskBase_CutDate_Transmit_GenerateEmailFail"; #endregion diff --git a/ds-wms-service/DS.Module.Nuget/DS.Module.Nuget.csproj b/ds-wms-service/DS.Module.Nuget/DS.Module.Nuget.csproj index 2ad8e2c7..d171a11a 100644 --- a/ds-wms-service/DS.Module.Nuget/DS.Module.Nuget.csproj +++ b/ds-wms-service/DS.Module.Nuget/DS.Module.Nuget.csproj @@ -17,6 +17,7 @@ + diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/CutDateChange/ITaskManageCutDateChangeService.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/CutDateChange/ITaskManageCutDateChangeService.cs index 57a018f8..b65a72cb 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/CutDateChange/ITaskManageCutDateChangeService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/CutDateChange/ITaskManageCutDateChangeService.cs @@ -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 /// /// 截止时间变更任务主键 /// 返回回执 - Task SearchAndMarkBookingOrder(long taskPKId); + Task> SearchAndMarkBookingOrder(long taskPKId); + + /// + /// 自动更新订单的截单日期并转发 + /// + /// 截止时间变更任务主键 + /// 返回回执 + Task AutoUpdateOrderCutDateAndTranmitToCustomer(long taskPKId); /// /// 发送邮件通知给客户 diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/CutDateChange/TaskManageCutDateChangeService.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/CutDateChange/TaskManageCutDateChangeService.cs index 7d186253..2177d109 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/CutDateChange/TaskManageCutDateChangeService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/CutDateChange/TaskManageCutDateChangeService.cs @@ -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(); user = _serviceProvider.GetRequiredService(); saasService = _serviceProvider.GetRequiredService(); + _seaExportService = _serviceProvider.GetRequiredService(); } #region 通过任务主键获取截止时间变更详情 @@ -94,8 +103,9 @@ namespace DS.WMS.Core.TaskPlat.Method /// /// 截止时间变更任务主键 /// 返回回执 - public async Task SearchAndMarkBookingOrder(long taskPKId) + public async Task> 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(item).UpdateColumns(x => new + { + x.BOOKING_ID, + x.UpdateTime, + x.UpdateBy, + x.UpdateUserName + }).ExecuteCommand(); + + var list = tenantDb.Queryable().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(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.FailedData(orderInfo,$"检索失败,原因:{ex.Message}", MultiLanguageConst.Operation_Failed); } - return null; + return DataResult.Success(orderInfo); + } + #endregion + + #region 自动更新订单的截单日期并转发 + /// + /// 自动更新订单的截单日期并转发 + /// + /// 截止时间变更任务主键 + /// 返回回执 + public async Task 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 + /// + /// 通过邮件模板生成HTML + /// + /// + /// + /// + /// + /// + /// + [NonAction] + private async Task GenerateSendEmailHtml(TaskCutDateChangeInfo model, List rowList, SeaExportRes seaExportRes, + string filePath, SysUser opUserInfo, string tenantName,string fileAbsPath) + { + string result = string.Empty; + string baseHtml = string.Empty; + + try + { + //var opt = App.GetOptions(); + //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($"{rowList[i].MBL_NO}{rowList[i].CONTA_NO}{rowList[i].LOAD_PORT}{(rowList[i].ETB.HasValue ? rowList[i].ETB.Value.ToString("yyyy-MM-dd HH:mm") : "")}{(rowList[i].ETD.HasValue ? rowList[i].ETD.Value.ToString("yyyy-MM-dd HH:mm") : "")}"); + } + + //生成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($"{(string.Join("", colArg))}")); + + StringBuilder tableBuilder = new StringBuilder(); + + for (int i = 0; i < rowList.Count; i++) + { + tableBuilder.Append($"{rowList[i].MBL_NO}"); + tableBuilder.Append($"{($"{rowList[i].VESSEL}/{rowList[i].VOYNO}")}"); + tableBuilder.Append($"{(rowList[i].SI_CUTOFF.HasValue ? rowList[i].SI_CUTOFF.Value.ToString("yyyy-MM-dd HH:mm") : rowList[i].SI_CUTOFF_TXT)}"); + tableBuilder.Append($"{(rowList[i].CY_OPEN.HasValue ? rowList[i].CY_OPEN.Value.ToString("yyyy-MM-dd HH:mm") : rowList[i].CY_OPEN_TXT)}"); + tableBuilder.Append($"{(rowList[i].CY_CUTOFF.HasValue ? rowList[i].CY_CUTOFF.Value.ToString("yyyy-MM-dd HH:mm") : rowList[i].CY_CUTOFF_TXT)}"); + tableBuilder.Append($"{(rowList[i].MANIFEST_CUT.HasValue ? rowList[i].MANIFEST_CUT.Value.ToString("yyyy-MM-dd HH:mm") : rowList[i].MANIFEST_CUT_TXT)}"); + tableBuilder.Append($"{(rowList[i].MDGF_CUT.HasValue ? rowList[i].MDGF_CUT.Value.ToString("yyyy-MM-dd HH:mm") : rowList[i].MDGF_CUT_TXT)}"); + tableBuilder.Append($"{(rowList[i].VGM_CUT.HasValue ? rowList[i].VGM_CUT.Value.ToString("yyyy-MM-dd HH:mm") : rowList[i].VGM_CUT_TXT)}"); + tableBuilder.Append($"{(rowList[i].CLOSING_DATE.HasValue ? rowList[i].CLOSING_DATE.Value.ToString("yyyy-MM-dd HH:mm") : rowList[i].CLOSING_DATE_TXT)}"); + + tableBuilder.Append(""); + } + + //生成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 } }