From eda36a284e12114654b115ea3b44787f46538912 Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Tue, 13 Aug 2024 16:46:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9BC=E8=87=AA=E5=8A=A8=E8=BD=AC?= =?UTF-8?q?=E5=8F=91=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=8B=86=E5=8D=95=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E8=BD=AC=E5=8F=91=20=E8=88=B1=E4=BD=8D=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=9C=BA=E7=AB=99=EF=BC=8C=E7=94=9F=E6=88=90=E8=AE=A2?= =?UTF-8?q?=E8=88=B1=E6=97=B6=E8=87=AA=E5=8A=A8=E5=AF=B9=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entity/BookingSlot/BookingSlotBase.cs | 6 + .../Entity/TaskManagePlat/TaskBCInfo.cs | 5 + .../BookingOrder/BookingOrderService.cs | 13 + .../Service/BookingSlot/BookingSlotService.cs | 13 + .../BookingSlot/Dto/BookingSlotBaseDto.cs | 6 + .../Dtos/BC/DrawModifyBCConfig.cs | 72 +++ .../Dtos/TaskManageOrderBCInfo.cs | 5 + .../Interface/ITaskManageBCService.cs | 3 +- .../TaskManagePlat/TaskManageBCService.cs | 456 +++++++++++++++--- Myshipping.Web.Core/applicationconfig.json | 3 +- ServiceProjectSyncWin/Program.cs | 81 +++- .../ServiceProjectSyncWin.csproj | 2 + 12 files changed, 587 insertions(+), 78 deletions(-) create mode 100644 Myshipping.Application/Service/TaskManagePlat/Dtos/BC/DrawModifyBCConfig.cs diff --git a/Myshipping.Application/Entity/BookingSlot/BookingSlotBase.cs b/Myshipping.Application/Entity/BookingSlot/BookingSlotBase.cs index a3aaec8b..0fd712de 100644 --- a/Myshipping.Application/Entity/BookingSlot/BookingSlotBase.cs +++ b/Myshipping.Application/Entity/BookingSlot/BookingSlotBase.cs @@ -427,5 +427,11 @@ namespace Myshipping.Application /// [Description("舱保类型名称")] public string LOAD_GUARANTEE_FLAG_NAME { get; set; } + + /// + /// 提箱场站 + /// + [Description("提箱场站")] + public string TAKE_CTN_YARD { get; set; } } } \ No newline at end of file diff --git a/Myshipping.Application/Entity/TaskManagePlat/TaskBCInfo.cs b/Myshipping.Application/Entity/TaskManagePlat/TaskBCInfo.cs index 6171558e..a7774fea 100644 --- a/Myshipping.Application/Entity/TaskManagePlat/TaskBCInfo.cs +++ b/Myshipping.Application/Entity/TaskManagePlat/TaskBCInfo.cs @@ -401,5 +401,10 @@ namespace Myshipping.Application /// 船公司航次 /// public string CARRIER_VOYNO { get; set; } + + /// + /// 提箱场站 + /// + public string TAKE_CTN_YARD { get; set; } } } diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index 22d37806..4029d5cd 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -13672,6 +13672,19 @@ namespace Myshipping.Application var currOrder = orderList.FirstOrDefault(a => a.MBLNO == mblNo); + //这里如果是拆票记录,则默认用拆票的第一票作为当前票的对应记录 + if (currOrder == null && orderList.Any(b => b.SPLIT_OR_MERGE_FLAG.HasValue && b.SPLIT_OR_MERGE_FLAG.Value == 1)) + { + var maxChar = orderList.Select(a => + { + var startIndx = a.CUSTNO.Length; + return a.MBLNO.Substring(startIndx); + }).Min(); + + var custNo = orderList.FirstOrDefault().CUSTNO; + currOrder = orderList.FirstOrDefault(a => a.MBLNO == $"{custNo}{maxChar}"); + } + if (currOrder != null) { model.currOrder = currOrder.Adapt(); diff --git a/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs b/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs index 3e7e83a8..c9b4cdd7 100644 --- a/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs +++ b/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs @@ -3223,6 +3223,18 @@ namespace Myshipping.Application ctnInputs = new List() }; + //处理自动对应场站 + if (!string.IsNullOrWhiteSpace(bookingSlotBase.TAKE_CTN_YARD)) + { + var yardInfo = _cache.GetAllCodeYard().GetAwaiter().GetResult().FirstOrDefault(a => a.Code.Equals(bookingSlotBase.TAKE_CTN_YARD)); + + if (yardInfo != null) + { + bkModel.YARDID = yardInfo.Code; + bkModel.YARD = yardInfo.Name; + } + } + // 判断是否为拆票的舱位,如果为拆票,提单号需要加上ABCD... var selectNum = generateModel.CtnList.Sum(x => x.CTNNUM); _logger.LogInformation("根据舱位生成订舱,selectNum:{selectNum}", selectNum); @@ -3594,6 +3606,7 @@ namespace Myshipping.Application [NonAction] public async Task MeasureDiffCautionTask(TaskBCInfoDto bcSrcDto, TaskBCInfoDto bcTargetDto, long slotId) { + return; try { if (bcSrcDto.CarrierId.Equals("MSK", StringComparison.OrdinalIgnoreCase)) diff --git a/Myshipping.Application/Service/BookingSlot/Dto/BookingSlotBaseDto.cs b/Myshipping.Application/Service/BookingSlot/Dto/BookingSlotBaseDto.cs index 1862f3e2..b388c39e 100644 --- a/Myshipping.Application/Service/BookingSlot/Dto/BookingSlotBaseDto.cs +++ b/Myshipping.Application/Service/BookingSlot/Dto/BookingSlotBaseDto.cs @@ -421,6 +421,12 @@ namespace Myshipping.Application.Service.BookingSlot.Dto /// [Description("舱保类型名称")] public string LOAD_GUARANTEE_FLAG_NAME { get; set; } + + /// + /// 提箱场站 + /// + [Description("提箱场站")] + public string TAKE_CTN_YARD { get; set; } } /// diff --git a/Myshipping.Application/Service/TaskManagePlat/Dtos/BC/DrawModifyBCConfig.cs b/Myshipping.Application/Service/TaskManagePlat/Dtos/BC/DrawModifyBCConfig.cs new file mode 100644 index 00000000..ccf28a4b --- /dev/null +++ b/Myshipping.Application/Service/TaskManagePlat/Dtos/BC/DrawModifyBCConfig.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Myshipping.Application.Service +{ + public class DrawModifyBCConfig + { + /// + /// 擦除枚举 + /// + public DrawModifyBCConfigTypeEnum[] drawTypeArg { get; set; } + + /// + /// 原箱数量 + /// + public Nullable origCtnNum { get; set; } + + /// + /// 修改箱数量 + /// + public Nullable newCtnNum { get; set; } + + /// + /// 箱类型 + /// + public string ctnAll { get; set; } + + /// + /// 原提单号 + /// + public string origBillNo { get; set; } + + /// + /// 新提单号 + /// + public string newBillNo { get; set; } + } + + public enum DrawModifyBCConfigTypeEnum + { + /// + /// 标准 + /// + [Description("标准")] + Standard, + /// + /// 擦除更多(展鸿要求) + /// + [Description("擦除更多")] + EraseMore, + /// + /// 手工指定截单时间 + /// + [Description("手工指定截单时间")] + DrawManualSIDate, + /// + /// 分票修改(康乾,主要考虑拆票时箱数量按照拆票显示) + /// + [Description("分票修改")] + SplitBC, + /// + /// 改提单号为分票号 + /// + [Description("改提单号为分票号")] + ChangeToSplitBillNo, + + } +} diff --git a/Myshipping.Application/Service/TaskManagePlat/Dtos/TaskManageOrderBCInfo.cs b/Myshipping.Application/Service/TaskManagePlat/Dtos/TaskManageOrderBCInfo.cs index 12922bb5..167739ec 100644 --- a/Myshipping.Application/Service/TaskManagePlat/Dtos/TaskManageOrderBCInfo.cs +++ b/Myshipping.Application/Service/TaskManagePlat/Dtos/TaskManageOrderBCInfo.cs @@ -396,6 +396,11 @@ namespace Myshipping.Application /// 货物标志 /// public string CARGOID { get; set; } + + /// + /// 提箱场站 + /// + public string TakeCTNYard { get; set; } } diff --git a/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageBCService.cs b/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageBCService.cs index 75c55192..450aa52a 100644 --- a/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageBCService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/Interface/ITaskManageBCService.cs @@ -80,9 +80,10 @@ namespace Myshipping.Application /// 发送邮件 /// /// BC任务主键 + /// 强制订单主键(非必填) /// 是否默认使用用户个人邮箱发送 /// 返回回执 - Task SendEmail(string taskPKId, bool usePersonalEmailSend = false); + Task SendEmail(string taskPKId, Nullable mandatoryBookingId = null, bool usePersonalEmailSend = false); /// /// 获取当前比对结果 diff --git a/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs b/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs index 38593539..f2b5f23b 100644 --- a/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/TaskManageBCService.cs @@ -15,7 +15,9 @@ using Myshipping.Application.ConfigOption; using Myshipping.Application.Entity; using Myshipping.Application.Enum; using Myshipping.Application.Helper; +using Myshipping.Application.Service; using Myshipping.Application.Service.BookingOrder; +using Myshipping.Application.Service.BookingOrder.Dto; using Myshipping.Application.Service.BookingSlot.Dto; using Myshipping.Core; using Myshipping.Core.Entity; @@ -27,6 +29,7 @@ using NPOI.SS.Formula.Functions; using NPOI.Util; using NPOI.XWPF.UserModel; using Org.BouncyCastle.Asn1.Tsp; +using Org.BouncyCastle.Utilities; using RabbitMQ.Client; using SqlSugar; using StackExchange.Profiling.Internal; @@ -890,7 +893,7 @@ namespace Myshipping.Application if (currBCOrder != null && model.IsDirectSend) { //异步推送邮件 - var mailRlt = await GenerateSendEmail(currBCOrder, bcTaskInfo, model.usePersonalEmailSend); + var mailRlt = await GenerateSendEmail(currBCOrder, bcTaskInfo,null, model.usePersonalEmailSend); if (!mailRlt.succ) { @@ -1036,7 +1039,7 @@ namespace Myshipping.Application if (currBCOrder != null && model.IsDirectSend) { //异步推送邮件 - var mailRlt = await GenerateSendEmail(currBCOrder, bcTaskInfo, model.usePersonalEmailSend); + var mailRlt = await GenerateSendEmail(currBCOrder, bcTaskInfo,null, model.usePersonalEmailSend); if (!mailRlt.succ) { @@ -1204,7 +1207,7 @@ namespace Myshipping.Application if (currBCOrder != null && model.IsDirectSend) { //异步推送邮件 - var mailRlt = await GenerateSendEmail(currBCOrder, bcTaskInfo, model.usePersonalEmailSend); + var mailRlt = await GenerateSendEmail(currBCOrder, bcTaskInfo, null, model.usePersonalEmailSend); if (!mailRlt.succ) { @@ -1426,6 +1429,19 @@ namespace Myshipping.Application bkModel.VOYNOINNER = taskBCInfo.CARRIER_VOYNO; } } + + //处理自动对应场站 + if (!string.IsNullOrWhiteSpace(taskBCInfo.TAKE_CTN_YARD)) + { + var yardInfo = _cache.GetAllCodeYard().GetAwaiter().GetResult().FirstOrDefault(a => a.Code.Equals(taskBCInfo.TAKE_CTN_YARD)); + + if (yardInfo != null) + { + bkModel.YARDID = yardInfo.Code; + bkModel.YARD = yardInfo.Name; + } + } + //增加装货港、卸货港的对应 // 解析收货地,得到装货港名称及五字码 if (!string.IsNullOrWhiteSpace(taskBCInfo.PLACERECEIPT)) @@ -1831,7 +1847,7 @@ namespace Myshipping.Application /// 主任务详情 /// 是否默认使用用户个人邮箱发送 /// 返回回执 - private async Task GenerateSendEmail(TaskBCInfo taskBCInfo, TaskBaseInfo bcTaskInfo, bool usePersonalEmailSend = false) + private async Task GenerateSendEmail(TaskBCInfo taskBCInfo, TaskBaseInfo bcTaskInfo, Nullable mandatoryBookingId = null, bool usePersonalEmailSend = false) { TaskManageOrderResultDto result = new TaskManageOrderResultDto(); @@ -1846,9 +1862,21 @@ namespace Myshipping.Application */ //读取订舱数据 - var bookingOrderEntity = _bookingOrderRepository.AsQueryable().Filter(null, true) + BookingOrder bookingOrderEntity = null; + + if(mandatoryBookingId.HasValue && mandatoryBookingId.Value> 0) + { + bookingOrderEntity = _bookingOrderRepository.AsQueryable().Filter(null, true) + .First(a => a.Id == mandatoryBookingId.Value); + } + else + { + bookingOrderEntity = _bookingOrderRepository.AsQueryable().Filter(null, true) .First(a => a.Id == taskBCInfo.BOOKING_ORDER_ID); + } + var ctnList = _bookingCtnRepository.AsQueryable().Filter(null, true) + .Where(a => a.BILLID == mandatoryBookingId.Value).ToList(); if (bookingOrderEntity == null) { @@ -1892,7 +1920,7 @@ namespace Myshipping.Application string opEmail = string.Empty; var bookingContactList = _bookingOrderContactRepository.AsQueryable().Filter(null, true) - .Where(a => a.BookingId == taskBCInfo.BOOKING_ORDER_ID).ToList(); + .Where(a => a.BookingId == bookingOrderEntity.Id).ToList(); if (bookingContactList == null || bookingContactList.Count == 0) { @@ -1956,7 +1984,15 @@ namespace Myshipping.Application if (taskBCInfo.BUSI_TYPE == "BookingAmendment") { - emailHtml = GenerateSendEmailHtmlAmendment(taskBCInfo, opUserInfo, UserManager.TENANT_NAME).GetAwaiter().GetResult(); + if (mandatoryBookingId.HasValue) + { + emailHtml = GenerateSendEmailHtmlAmendment(taskBCInfo, opUserInfo, UserManager.TENANT_NAME, bookingOrderEntity, ctnList).GetAwaiter().GetResult(); + } + else + { + emailHtml = GenerateSendEmailHtmlAmendment(taskBCInfo, opUserInfo, UserManager.TENANT_NAME).GetAwaiter().GetResult(); + } + } else { @@ -1975,18 +2011,19 @@ namespace Myshipping.Application else if (bcTaskInfo.TASK_BASE_TYPE == TaskBaseTypeEnum.BC_MODIFY.ToString()) { //CMA没有变更附件,所以转发邮件时默认用原文件转发 - if(bcTaskInfo.CARRIER_ID.Equals("CMA",StringComparison.OrdinalIgnoreCase)) + if (bcTaskInfo.CARRIER_ID.Equals("CMA", StringComparison.OrdinalIgnoreCase)) { fileInfo = _taskFileRepository.AsQueryable().Filter(null, true).Where(a => a.TASK_PKID == taskBCInfo.TASK_ID && a.FILE_CATEGORY.Contains("BC_MODIFY")) .OrderByDescending(a => a.CreatedTime).First(); } else { + fileInfo = _taskFileRepository.AsQueryable().Filter(null, true).Where(a => a.TASK_PKID == taskBCInfo.TASK_ID && a.FILE_CATEGORY.Contains("BC_MODIFY_NOTICE")) .OrderByDescending(a => a.CreatedTime).First(); + } - - } + } if (fileInfo == null) { @@ -2004,6 +2041,22 @@ namespace Myshipping.Application filePath = Path.Combine(dirAbs, fileInfo.FILE_PATH); + if (mandatoryBookingId.HasValue) + { + //重新取BC文件 + fileInfo = _taskFileRepository.AsQueryable().Filter(null, true).Where(a => a.TASK_PKID == taskBCInfo.TASK_ID && a.FILE_CATEGORY.Contains("BC_MODIFY")) + .OrderByDescending(a => a.CreatedTime).First(); + + filePath = Path.Combine(dirAbs, fileInfo.FILE_PATH); + + var newFilePath = await ReGenerateBAFile(bookingOrderEntity, ctnList, filePath); + + if (!string.IsNullOrWhiteSpace(newFilePath)) + filePath = Path.Combine(dirAbs, newFilePath); + + SaveEDIFile(bookingOrderEntity.Id, filePath, new System.IO.FileInfo(filePath).Name, taskBCInfo.TenantId.Value, + "splitfile", "Booking Confirmation Split").GetAwaiter(); + } EmailApiUserDefinedDto emailApiUserDefinedDto = new EmailApiUserDefinedDto { @@ -2226,8 +2279,11 @@ namespace Myshipping.Application /// BC任务详情 /// 订舱OP详情 /// 当前租户全称 + /// 相关订单详情 + /// 相关订单的集装箱列表 /// 返回生成的HTML - public async Task GenerateSendEmailHtmlAmendment(TaskBCInfo taskBCInfo, SysUser opUserInfo, string tenantName) + public async Task GenerateSendEmailHtmlAmendment(TaskBCInfo taskBCInfo, SysUser opUserInfo, string tenantName, + BookingOrder bookingOrder = null,List ctnList = null) { string result = string.Empty; @@ -2315,11 +2371,56 @@ namespace Myshipping.Application { if (baseTd.Attributes["class"].Value == "billno-val") { - baseTd.InnerHtml = taskBCInfo.MBL_NO; + if (bookingOrder != null) + { + //如果是外港这里需要填正式的提单号 + if (!bookingOrder.CUSTNO.Equals(bookingOrder.HBLNO)) + { + if (!string.IsNullOrWhiteSpace(bookingOrder.PORTLOADID) && bookingOrder.PORTLOADID.Equals("CNTAO", StringComparison.OrdinalIgnoreCase)) + { + baseTd.InnerHtml = bookingOrder.MBLNO; + } + else + { + baseTd.InnerHtml = bookingOrder.HBLNO; + } + } + else + { + baseTd.InnerHtml = bookingOrder.MBLNO; + } + } + else + { + baseTd.InnerHtml = taskBCInfo.MBL_NO; + } } else if (baseTd.Attributes["class"].Value == "takebillno-val") { - baseTd.InnerHtml = taskBCInfo.MBL_NO; + if (bookingOrder != null) + { + //如果是外港这里需要填正式的提单号 + if (!bookingOrder.CUSTNO.Equals(bookingOrder.HBLNO)) + { + if (!string.IsNullOrWhiteSpace(bookingOrder.PORTLOADID) && bookingOrder.PORTLOADID.Equals("CNTAO", StringComparison.OrdinalIgnoreCase)) + { + baseTd.InnerHtml = bookingOrder.HBLNO; + } + else + { + baseTd.InnerHtml = bookingOrder.MBLNO; + } + } + else + { + baseTd.InnerHtml = bookingOrder.MBLNO; + } + } + else + { + baseTd.InnerHtml = taskBCInfo.MBL_NO; + } + //baseTd.InnerHtml = taskBCInfo.MBL_NO; } else if (baseTd.Attributes["class"].Value == "pol-val") { @@ -2331,7 +2432,14 @@ namespace Myshipping.Application } else if (baseTd.Attributes["class"].Value == "ctn-val") { - baseTd.InnerHtml = taskBCInfo.CTN_STAT; + if (ctnList != null && ctnList.Count > 0) + { + baseTd.InnerHtml = string.Join(",", ctnList.GroupBy(a => a.CTNALL).Select(a => $"{a.Key}*{a.Sum(b => b.CTNNUM.HasValue ? b.CTNNUM.Value : 0)}").ToArray()); + } + else + { + baseTd.InnerHtml = taskBCInfo.CTN_STAT; + } } /* else if (baseTd.Attributes["class"].Value == "etd-val") @@ -2597,7 +2705,7 @@ namespace Myshipping.Application /// 是否默认使用用户个人邮箱发送 /// 返回回执 [HttpGet("/TaskManageBC/SendEmail")] - public async Task SendEmail(string taskPKId, bool usePersonalEmailSend = false) + public async Task SendEmail(string taskPKId, Nullable mandatoryBookingId = null, bool usePersonalEmailSend = false ) { if (string.IsNullOrWhiteSpace(taskPKId)) throw Oops.Oh($"BC任务主键不能为空"); @@ -2613,7 +2721,7 @@ namespace Myshipping.Application if (bcOrder == null) throw Oops.Oh($"任务主键{taskPKId}无法获取BC业务信息"); - return await GenerateSendEmail(bcOrder, bcTaskInfo); + return await GenerateSendEmail(bcOrder, bcTaskInfo, mandatoryBookingId); } #endregion @@ -2715,6 +2823,9 @@ namespace Myshipping.Application } } + //这个先取一下与订单的关系 + var searchOrder = await _bookingOrderService.SearchOrderInfo(bcOrder.MBL_NO); + _logger.LogInformation($"taskPKId={taskPKId} 判断是否默认转发邮件 paramConfig={JSON.Serialize(paramConfig)}"); if (!bcOrder.BOOKING_SLOT_ID.HasValue || bcOrder.BOOKING_SLOT_ID.Value == 0) @@ -2790,66 +2901,101 @@ namespace Myshipping.Application } } - //去关联的订舱ID - if(bcOrder.BOOKING_ORDER_ID == null || bcOrder.BOOKING_ORDER_ID.Value == 0) + //如果是拆票需要更新所有的拆票订单,并根据修改BA文件的单号和箱型,自动转发给客户 + if (searchOrder.splitOrMergeFlag == 1) { - var server = _namedBookingSlotServiceProvider.GetService(nameof(BookingSlotService)); - var slotModel = server.SearchBookingSlotWithOrderByNo(bcOrder.MBL_NO, bcOrder.TenantId.Value).GetAwaiter().GetResult(); + var orderIdList = new List { searchOrder.currOrder.Id }; - if (slotModel.HasBookingOrder) + if (searchOrder.otherOrderList.Count > 0) + orderIdList.AddRange(searchOrder.otherOrderList.Select(b => b.Id).ToList()); + + foreach (var bkid in orderIdList) { - bcOrder.BOOKING_ORDER_ID = slotModel.BookingOrderList.FirstOrDefault(); - bcOrder.UpdatedTime = DateTime.Now; - bcOrder.UpdatedUserId = UserManager.UserId; - bcOrder.UpdatedUserName = UserManager.Name; + var currBCOrder = bcOrder.Adapt(); + + currBCOrder.BOOKING_ORDER_ID = bkid; + + await UpdateBookingOrder(currBCOrder, taskPKId, true); - await _taskBCInfoRepository.AsUpdateable(bcOrder).UpdateColumns(it => new + //如果值是ENABLE表示可以自动发送 + if (paramConfig != null && paramConfig.ParaValue.Equals("ENABLE", StringComparison.OrdinalIgnoreCase)) { - it.BOOKING_ORDER_ID, - it.UpdatedTime, - it.UpdatedUserId, - it.UpdatedUserName - }).ExecuteCommandAsync(); - } - } + _logger.LogInformation($"taskPKId={taskPKId} 准备发送邮件"); - if (bcOrder.BOOKING_ORDER_ID != null && bcOrder.BOOKING_ORDER_ID.HasValue && bcOrder.BOOKING_ORDER_ID.Value > 0) - { - await UpdateBookingOrder(bcOrder, taskPKId); + var emailRlt = await SendEmail(taskPKId, bkid); + + _logger.LogInformation($"taskPKId={taskPKId} 发送邮件完成 结果={JSON.Serialize(emailRlt)}"); + + } + else + { + _logger.LogInformation($"taskPKId={taskPKId} 未配置自动发送邮件"); + } + } } else { - _logger.LogInformation($"taskPKId={taskPKId} 更新订舱详情失败没有对应舱位ID"); - } + //去关联的订舱ID + if (bcOrder.BOOKING_ORDER_ID == null || bcOrder.BOOKING_ORDER_ID.Value == 0) + { + var server = _namedBookingSlotServiceProvider.GetService(nameof(BookingSlotService)); + var slotModel = server.SearchBookingSlotWithOrderByNo(bcOrder.MBL_NO, bcOrder.TenantId.Value).GetAwaiter().GetResult(); - //如果值是ENABLE表示可以自动发送 - if (paramConfig != null && paramConfig.ParaValue.Equals("ENABLE", StringComparison.OrdinalIgnoreCase)) - { - _logger.LogInformation($"taskPKId={taskPKId} 准备发送邮件"); + if (slotModel.HasBookingOrder) + { + bcOrder.BOOKING_ORDER_ID = slotModel.BookingOrderList.FirstOrDefault(); + bcOrder.UpdatedTime = DateTime.Now; + bcOrder.UpdatedUserId = UserManager.UserId; + bcOrder.UpdatedUserName = UserManager.Name; + + await _taskBCInfoRepository.AsUpdateable(bcOrder).UpdateColumns(it => new + { + it.BOOKING_ORDER_ID, + it.UpdatedTime, + it.UpdatedUserId, + it.UpdatedUserName + }).ExecuteCommandAsync(); + } + } + + if (bcOrder.BOOKING_ORDER_ID != null && bcOrder.BOOKING_ORDER_ID.HasValue && bcOrder.BOOKING_ORDER_ID.Value > 0) + { + await UpdateBookingOrder(bcOrder, taskPKId); + } + else + { + _logger.LogInformation($"taskPKId={taskPKId} 更新订舱详情失败没有对应舱位ID"); + } - var emailRlt = await SendEmail(taskPKId); + //如果值是ENABLE表示可以自动发送 + if (paramConfig != null && paramConfig.ParaValue.Equals("ENABLE", StringComparison.OrdinalIgnoreCase)) + { + _logger.LogInformation($"taskPKId={taskPKId} 准备发送邮件"); - _logger.LogInformation($"taskPKId={taskPKId} 发送邮件完成 结果={JSON.Serialize(emailRlt)}"); + var emailRlt = await SendEmail(taskPKId); - } - else - { - _logger.LogInformation($"taskPKId={taskPKId} 未配置自动发送邮件"); + _logger.LogInformation($"taskPKId={taskPKId} 发送邮件完成 结果={JSON.Serialize(emailRlt)}"); + + } + else + { + _logger.LogInformation($"taskPKId={taskPKId} 未配置自动发送邮件"); + } } - if (dingdingConfig != null && dingdingConfig.ParaValue.Equals("ENABLE", StringComparison.OrdinalIgnoreCase)) - { - _logger.LogInformation($"taskPKId={taskPKId} 准备发送钉钉消息"); + //if (dingdingConfig != null && dingdingConfig.ParaValue.Equals("ENABLE", StringComparison.OrdinalIgnoreCase)) + //{ + // _logger.LogInformation($"taskPKId={taskPKId} 准备发送钉钉消息"); - var emailRlt = await SendEmail(taskPKId); + // var emailRlt = await SendEmail(taskPKId); - _logger.LogInformation($"taskPKId={taskPKId} 发送钉钉消息完成 结果={JSON.Serialize(emailRlt)}"); + // _logger.LogInformation($"taskPKId={taskPKId} 发送钉钉消息完成 结果={JSON.Serialize(emailRlt)}"); - } - else - { - _logger.LogInformation($"taskPKId={taskPKId} 未配置自动发送邮件"); - } + //} + //else + //{ + // _logger.LogInformation($"taskPKId={taskPKId} 未配置自动发送邮件"); + //} result.succ = true; result.msg = "执行成功"; @@ -2871,7 +3017,7 @@ namespace Myshipping.Application } #endregion - private async Task UpdateBookingOrder(TaskBCInfo bcOrder,string taskPKId) + private async Task UpdateBookingOrder(TaskBCInfo bcOrder, string taskPKId, bool isAvoidUpdateCtn = false) { try { @@ -3053,26 +3199,35 @@ namespace Myshipping.Application bkModel.ChangedFields.Add(nameof(SaveBookingOrderInput.PLACERECEIPT)); bkModel.ChangedFields.Add(nameof(SaveBookingOrderInput.PLACERECEIPTID)); - var taskBCCtnList = _taskBCCTNInfoRepository.AsQueryable().Filter(null, true).Where(a => a.P_ID == bcOrder.PK_ID && a.TenantId == UserManager.TENANT_ID).ToList(); + if (!isAvoidUpdateCtn) + { + var taskBCCtnList = _taskBCCTNInfoRepository.AsQueryable().Filter(null, true).Where(a => a.P_ID == bcOrder.PK_ID && a.TenantId == UserManager.TENANT_ID).ToList(); - var ctnCodeList = _cache.GetAllCodeCtn().GetAwaiter().GetResult().ToList(); + var ctnCodeList = _cache.GetAllCodeCtn().GetAwaiter().GetResult().ToList(); - if (taskBCCtnList.Count > 0) - { - taskBCCtnList.ForEach(t => + if (taskBCCtnList.Count > 0) { - var ctnCode = ctnCodeList.FirstOrDefault(a => !string.IsNullOrWhiteSpace(a.Name) && - a.Name.Equals(t.CTNALL, StringComparison.OrdinalIgnoreCase)); - - BookingCtnDto ctn = new BookingCtnDto + taskBCCtnList.ForEach(t => { - CTNCODE = ctnCode?.Code, - CTNALL = t.CTNALL, - CTNNUM = t.CTNNUM.HasValue ? t.CTNNUM.Value : 1 - }; + var ctnCode = ctnCodeList.FirstOrDefault(a => !string.IsNullOrWhiteSpace(a.Name) && + a.Name.Equals(t.CTNALL, StringComparison.OrdinalIgnoreCase)); - bkModel.ctnInputs.Add(ctn); - }); + BookingCtnDto ctn = new BookingCtnDto + { + CTNCODE = ctnCode?.Code, + CTNALL = t.CTNALL, + CTNNUM = t.CTNNUM.HasValue ? t.CTNNUM.Value : 1 + }; + + bkModel.ctnInputs.Add(ctn); + }); + } + } + else + { + var ctnList = _bookingCtnRepository.AsQueryable().Filter(null, true).Where(a => a.BILLID == bcOrder.BOOKING_ORDER_ID.Value).ToList(); + + bkModel.ctnInputs = ctnList.Select(b => b.Adapt()).ToList(); } var bkRlt = await _bookingOrderService.Save(bkModel); @@ -4099,6 +4254,159 @@ namespace Myshipping.Application return result; } #endregion + + #region 重新获取生成BookingAmendment文件 + /// + /// 重新获取生成BookingAmendment文件 + /// + /// + /// + /// + /// + private async Task ReGenerateBAFile(BookingOrder bookingOrder,List ctnList,string origFilePath) + { + DrawModifyBCConfig mConfig = new DrawModifyBCConfig { + drawTypeArg = new DrawModifyBCConfigTypeEnum[] { DrawModifyBCConfigTypeEnum.ChangeToSplitBillNo,DrawModifyBCConfigTypeEnum.SplitBC }, + origBillNo = bookingOrder.CUSTNO, + newBillNo = bookingOrder.MBLNO, + newCtnNum = ctnList.Sum(a=> a.CTNNUM), + ctnAll = ctnList.FirstOrDefault().CTNALL + }; + + NameValueCollection modifyPar = new NameValueCollection(); + modifyPar.Add("jsonMessage", JSON.Serialize(mConfig)); + + DynameFileInfo dynameFile = null; + + var fileName = Path.GetFileName(origFilePath); + + var fileBytes = File.ReadAllBytes(origFilePath); + + if (fileBytes.Length > 0) + { + dynameFile = new DynameFileInfo + { + FileName = fileName, + FileBytes = fileBytes + }; + } + + string batchNo = IDGen.NextID().ToString(); + + byte[] modifyBytes = ModifyFile(modifyPar, dynameFile).GetAwaiter().GetResult(); + + var noExtensionFileName = Path.GetFileNameWithoutExtension(fileName); + return await FileAttachHelper.SaveFile(bookingOrder.Id.ToString(), modifyBytes, batchNo, noExtensionFileName, + GetFileType(origFilePath), "bcsplitnoticefiles"); + } + #endregion + + #region 获取文件类型 + /// + /// 获取文件类型 + /// + /// 文件完成路径 + /// 返回文件类型枚举 + private PrintFileTypeEnum GetFileType(string fileName) + { + PrintFileTypeEnum fileType = PrintFileTypeEnum.PDF; + + switch (Path.GetExtension(fileName).ToLower()) + { + case ".pdf": + fileType = PrintFileTypeEnum.PDF; + break; + case ".xlsx": + fileType = PrintFileTypeEnum.XLSX; + break; + case ".docx": + fileType = PrintFileTypeEnum.DOCX; + break; + case ".xls": + fileType = PrintFileTypeEnum.XLS; + break; + case ".doc": + fileType = PrintFileTypeEnum.DOC; + break; + } + + return fileType; + } + #endregion + + #region 请求变更BookingAmendment后的文件 + /// + /// 请求变更BookingAmendment后的文件 + /// + /// 请求参数 + /// 文件 + /// 请求类型 + /// 返回回执 + [NonAction] + private async Task ModifyFile(NameValueCollection nameValueCollection, dynamic fileInfo, + string contentType = "application/json") + { + //Stream ms = null; + + byte[] bytes; + var result = string.Empty; + + using (var httpClient = new HttpClient()) + { + try + { + using (var reduceAttach = new MultipartFormDataContent()) + { + string[] allKeys = nameValueCollection.AllKeys; + foreach (string key in allKeys) + { + var dataContent = new ByteArrayContent(Encoding.UTF8.GetBytes(nameValueCollection[key])); + + dataContent.Headers.ContentDisposition = new ContentDispositionHeaderValue($"form-data") + { + Name = key + }; + + reduceAttach.Add(dataContent); + } + + #region 文件参数 + if (fileInfo != null) + { + var Content = new ByteArrayContent(fileInfo.FileBytes); + + //Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data") + //{ + // Name = fileInfo.file.ToString(), + // FileName = fileInfo.fileName.ToString(), + + //}; + + Content.Headers.Add("Content-Type", contentType); + + reduceAttach.Add(Content, "file", HttpUtility.UrlEncode(fileInfo.FileName.ToString())); + } + #endregion + + //httpClient.DefaultRequestHeaders.Add("USER_KEY", App.Configuration["ApiUserKey"]); + //httpClient.DefaultRequestHeaders.Add("USER_SECRET", App.Configuration["ApiUserSecret"]); + //请求 + var response = httpClient.PostAsync(App.Configuration["BookingAmendModifyWebApiUrl"], reduceAttach).Result; + bytes = response.Content.ReadAsByteArrayAsync().GetAwaiter().GetResult(); + } + } + catch (Exception ex) + { + _logger.LogInformation("请求自动变更BookingAmendment文件内容异常,原因:{error}", ex.Message); + + throw Oops.Oh($"请求自动变更BookingAmendment文件内容异常,原因:{ex.Message}"); + + } + + } + return bytes; + } + #endregion } /// diff --git a/Myshipping.Web.Core/applicationconfig.json b/Myshipping.Web.Core/applicationconfig.json index 19a4fa0d..d35c3379 100644 --- a/Myshipping.Web.Core/applicationconfig.json +++ b/Myshipping.Web.Core/applicationconfig.json @@ -141,5 +141,6 @@ "BookingAmendReadWebApiUrl": "http://localhost:5110/api/TaskBookingAmendmentParser/ExcuteBookingAmendmentRead", "SICompareUrl": "http://localhost:5110/api/TaskDraftCompare/ExcuteSISubmittedCompare", "EmailNoticeUrl": "http://47.104.73.97:8801/mail/send", - "EmailNoticeDefaultUser": "jianghaiqing@myshipping.net" + "EmailNoticeDefaultUser": "jianghaiqing@myshipping.net", + "BookingAmendModifyWebApiUrl": "http://localhost:5110/api/TaskBookingAmendmentParser/ModifyBookingAmendmentFile" } \ No newline at end of file diff --git a/ServiceProjectSyncWin/Program.cs b/ServiceProjectSyncWin/Program.cs index 3cdb4e22..114f2b8e 100644 --- a/ServiceProjectSyncWin/Program.cs +++ b/ServiceProjectSyncWin/Program.cs @@ -6,6 +6,7 @@ using Furion.FriendlyException; using Furion.JsonSerialization; using Furion.RemoteRequest.Extensions; using HtmlAgilityPack; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.Extensions.DependencyInjection; @@ -21,7 +22,11 @@ using System.Net.Http.Headers; using System.Text; using System.Text.RegularExpressions; using System.Web; +using RabbitMQ.Client; using static System.Net.Mime.MediaTypeNames; +using RabbitMQ.Client.Events; +using Org.BouncyCastle.Utilities.Bzip2; +using ICSharpCode.SharpZipLib.BZip2; Serve.RunGeneric(additional: services => { @@ -36,7 +41,7 @@ Console.WriteLine("开始准备同步历史服务状态数据"); var service1 = App.GetService(); //service1.SyncServiceProjectRecord(); //service1.SyncServiceProjectRecord5(); -service1.SyncServiceProjectRecord6(); +service1.SyncServiceProjectRecord7(); Console.ReadKey(); public interface ISyncHisRecord @@ -45,7 +50,7 @@ public interface ISyncHisRecord void SyncServiceProjectRecord5(); - void SyncServiceProjectRecord6(); + void SyncServiceProjectRecord7(); //void SyncServiceProjectRecord2(); //void SyncServiceProjectRecord3(); @@ -1299,6 +1304,31 @@ public class SyncHisRecord: ISyncHisRecord,ITransient } + public void SyncServiceProjectRecord7() + { + var factory = new ConnectionFactory + { + Uri = new Uri("amqp://hechuan_booking:hechuan_booking123@47.104.207.5:12567/hechuan_booking"), + }; + + var connection = factory.CreateConnection(); + + var channel = connection.CreateModel(); + + var consumer = new EventingBasicConsumer(channel); + consumer.Received += (model, ea) => + { + var body = ea.Body.ToArray(); + var message = System.Text.Encoding.UTF8.GetString(body); + + var rf = SharpZipLib.Decompress(message); + Console.WriteLine(" [x] Received {0}", message); + }; + channel.BasicConsume(queue: "djy.output.dingcang.ds6.529899258892357", + autoAck: true, + consumer: consumer); + + } public class ForInformationShipmentNotice { /// @@ -2739,4 +2769,51 @@ public static class StringUtilsExtension return inputVal; } + +} + +public class SharpZipLib +{ + + /// + /// 数据压缩 + /// + /// + /// + public static string Compress(string input) + { + string result = string.Empty; + byte[] buffer = Encoding.UTF8.GetBytes(input); + using (MemoryStream outputStream = new MemoryStream()) + { + using (BZip2OutputStream zipStream = new BZip2OutputStream(outputStream)) + { + zipStream.Write(buffer, 0, buffer.Length); + zipStream.Close(); + } + return Convert.ToBase64String(outputStream.ToArray()); + } + } + /// + /// 数据解压缩 + /// + /// + /// + public static string Decompress(string input) + { + string result = string.Empty; + byte[] buffer = Convert.FromBase64String(input); + using (Stream inputStream = new MemoryStream(buffer)) + { + BZip2InputStream zipStream = new BZip2InputStream(inputStream); + + using (StreamReader reader = new StreamReader(zipStream, Encoding.UTF8)) + { + //输出 + result = reader.ReadToEnd(); + } + } + + return result; + } } \ No newline at end of file diff --git a/ServiceProjectSyncWin/ServiceProjectSyncWin.csproj b/ServiceProjectSyncWin/ServiceProjectSyncWin.csproj index 2cbc5e9f..7aa33af3 100644 --- a/ServiceProjectSyncWin/ServiceProjectSyncWin.csproj +++ b/ServiceProjectSyncWin/ServiceProjectSyncWin.csproj @@ -10,7 +10,9 @@ + +