From 91abf2969ea339acb732b92f44cbffbcbba63569 Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Wed, 8 Nov 2023 17:33:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E8=88=B1=E6=96=B9=E6=B3=95=EF=BC=8C?= =?UTF-8?q?=E6=96=B0=E5=A2=9EVOLTA=E5=8F=91=E9=80=81EDI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EDI/Dtos/VOLTAEDIBaseModel.cs | 12 +- Myshipping.Application/Enum/EDIRouteEnum.cs | 6 +- .../BookingOrder/BookingOrderService.cs | 217 +++++++++++++++++- .../BookingOrder/Dto/BookingEDIVOLTAMapper.cs | 41 ++++ .../BookingOrder/IBookingOrderService.cs | 28 +++ 5 files changed, 300 insertions(+), 4 deletions(-) create mode 100644 Myshipping.Application/Service/BookingOrder/Dto/BookingEDIVOLTAMapper.cs diff --git a/Myshipping.Application/EDI/Dtos/VOLTAEDIBaseModel.cs b/Myshipping.Application/EDI/Dtos/VOLTAEDIBaseModel.cs index 9ca2b1fd..69a626cb 100644 --- a/Myshipping.Application/EDI/Dtos/VOLTAEDIBaseModel.cs +++ b/Myshipping.Application/EDI/Dtos/VOLTAEDIBaseModel.cs @@ -16,6 +16,11 @@ namespace Myshipping.Application /// public string BookingId { get; set; } + /// + /// 订舱主键 + /// + public long id { get; set; } + /// /// 发货人名称(必填) /// @@ -149,7 +154,7 @@ namespace Myshipping.Application /// /// 件数 /// - public Nullable Qty { get; set; } + public Nullable Qty { get; set; } /// /// 毛重 @@ -175,5 +180,10 @@ namespace Myshipping.Application /// 包装 /// public string Pkgs { get; set; } + + /// + /// EDI转换包装代码 + /// + public string EdiPkgs { get; set; } } } diff --git a/Myshipping.Application/Enum/EDIRouteEnum.cs b/Myshipping.Application/Enum/EDIRouteEnum.cs index b5c2cd69..3d207807 100644 --- a/Myshipping.Application/Enum/EDIRouteEnum.cs +++ b/Myshipping.Application/Enum/EDIRouteEnum.cs @@ -43,6 +43,10 @@ namespace Myshipping.Application /// /// 玛丽亚娜 /// - MELL + MELL, + /// + /// 沃尔塔航运 + /// + VOL } } diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index a8a84845..19f715e2 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -138,6 +138,8 @@ namespace Myshipping.Application const string CONST_MAPPING_MODULE = "BOOK_OR_CLOSING"; const string CONST_MAPPING_MODULE_ROUTE = "BOOK_OR_CLOSING_RT"; + const string CONST_MAPPING_MODULE_VOLTA = "BOOK_CLOSING_VOLTA"; + private const string PrintRecentListTypeKey = "booking_print_recent_list"; const string CONST_TSL_EDI_URL = "tsl_edi_declare_url"; @@ -5788,6 +5790,10 @@ namespace Myshipping.Application if (ediRouteEnum == EDIRouteEnum.NULL) throw Oops.Bah($"当前船公司没有对应的请求路由配置"); + //这里船公司VOL的单子不能走此通道发送 + if(ediRouteEnum == EDIRouteEnum.VOL) + throw Oops.Bah($"当前船公司VOL不能执行标准发送"); + //集装箱型 var ediCtnList = _cache.GetAllMappingCtn().GetAwaiter().GetResult() .Where(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase) @@ -5798,8 +5804,6 @@ namespace Myshipping.Application .Where(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase) && !string.IsNullOrWhiteSpace(t.CarrierCode) && t.CarrierCode.Equals(order.CARRIERID, StringComparison.OrdinalIgnoreCase)).ToList(); - - //包装基础数据 var basePkgsList = _cache.GetAllCodePackage().GetAwaiter().GetResult(); @@ -9917,5 +9921,214 @@ namespace Myshipping.Application #endregion + #region 检查是否VOLTA并返回初始数据 + /// + /// 检查是否VOLTA并返回初始数据 + /// + /// 请求参数 + /// 返回回执 + [HttpPost("/BookingOrder/CheckAndInitVOLTAEdi")] + public dynamic CheckAndInitVOLTAEdi(BookingOrClosingEDIOrderDto model) + { + CommonWebApiResult result = new CommonWebApiResult(); + + /* + 判断当前单子是否满足执行VOLTA截单流程 + 1、是截单请求 + 2、船公司是VOL。 + 3、提单号开头是(VOL、FCS、REL) + */ + string batchNo = IDGen.NextID().ToString(); + + _logger.LogInformation("批次={no}获取请求VOLTA截单EDI {msg}", batchNo, JSON.Serialize(model)); + + if (!model.sendType.Equals("E", StringComparison.OrdinalIgnoreCase)) + { + throw Oops.Bah("只接受发送类型截单(E)"); + } + + if (model.Id == 0) + throw Oops.Bah("订单Id不能为空"); + + var order = _rep.FirstOrDefault(a => a.Id == model.Id); + + if (order == null) + throw Oops.Bah($"获取订单信息失败"); + + if (order.ParentId.HasValue && order.ParentId.Value > 0) + throw Oops.Bah($"获取当前订单为分单不能生成EDI信息"); + + _logger.LogInformation("批次={no}提取订单信息完成", batchNo); + + if (!order.CARRIERID.Equals("VOL", StringComparison.OrdinalIgnoreCase)) + { + throw Oops.Bah("当前订单的船公司不是VOL(沃尔塔航运)不能发送VOLTA截单EDI"); + } + + if(string.IsNullOrWhiteSpace(order.MBLNO)) + throw Oops.Bah($"提单号不能为空"); + + if (!order.MBLNO.StartsWith("VOL") && !order.MBLNO.StartsWith("FCS") && !order.MBLNO.StartsWith("REL")) + { + throw Oops.Bah($"只支持提单号开头是(VOL、FCS、REL)发送截单"); + } + + //箱信息 + var contaList = _repCtn.AsQueryable().Where(t => t.BILLID == order.Id).ToList(); + + VOLTAEDIBaseModel voltaModel = order.Adapt(); + + #region 拆分收、发、通(名称、地址拆分) + if (!string.IsNullOrWhiteSpace(voltaModel.ShpperName)) + { + string name = voltaModel.ShpperName; + voltaModel.ShpperName = GetShipCneeNotifyDetail(name); + voltaModel.ShpperAddr = GetShipCneeNotifyDetail(name, "addr"); + } + + if (!string.IsNullOrWhiteSpace(voltaModel.ConsigneeName)) + { + string name = voltaModel.ConsigneeName; + voltaModel.ConsigneeName = GetShipCneeNotifyDetail(name); + voltaModel.ConsigneeAddr = GetShipCneeNotifyDetail(name, "addr"); + } + + if (!string.IsNullOrWhiteSpace(voltaModel.NotifyName)) + { + string name = voltaModel.NotifyName; + voltaModel.NotifyName = GetShipCneeNotifyDetail(name); + voltaModel.NotifyAddr = GetShipCneeNotifyDetail(name, "addr"); + } + #endregion + + if (voltaModel != null) + voltaModel.ContaList = contaList.Adapt>(); + + + //还需要翻译箱明细的包装 + + result.succ = true; + result.extra = voltaModel; + + return result; + } + #endregion + + #region 发送VOLTA截单请求 + /// + /// 发送VOLTA截单请求 + /// + /// 请求截单详情 + /// 返回回执 + [HttpPost("/BookingOrder/SendVOLTAEdiSI")] + public async Task SendVOLTAEdiSI(VOLTAEDIBaseModel model) + { + CommonWebApiResult result = new CommonWebApiResult(); + + + + return result; + } + #endregion + + #region 下载VOLTA截单请求报文 + /// + /// 下载VOLTA截单请求报文 + /// + /// 请求截单详情 + /// 返回回执 + [HttpPost("/BookingOrder/DownloadVOLTAEdiSI")] + public async Task DownloadVOLTAEdiSI(VOLTAEDIBaseModel model) + { + var filePath = InnerVOLTAEDI(model).GetAwaiter().GetResult(); + + var fileInfo = new FileInfo(filePath); + + var result = new FileStreamResult(new FileStream(filePath, FileMode.Open), "application/octet-stream") { FileDownloadName = fileInfo.Name }; + return result; + } + #endregion + + #region 生成VOLTA报文(内部方法) + /// + /// 生成VOLTA报文(内部方法) + /// + /// 请求截单详情 + /// 返回回执 + [NonAction] + public async Task InnerVOLTAEDI(VOLTAEDIBaseModel model) + { + CommonWebApiResult result = new CommonWebApiResult(); + + string batchNo = IDGen.NextID().ToString(); + + _logger.LogInformation("批次={no}获取请求VOLTA截单EDI {msg}", batchNo, JSON.Serialize(model)); + + if (model.id == 0) + throw Oops.Bah("订单Id不能为空"); + + var order = _rep.FirstOrDefault(a => a.Id == model.id); + + if (order == null) + throw Oops.Bah($"获取订单信息失败"); + + if (order.ParentId.HasValue && order.ParentId.Value > 0) + throw Oops.Bah($"获取当前订单为分单不能生成EDI信息"); + + _logger.LogInformation("批次={no}提取订单信息完成", batchNo); + + //箱信息 + var contaList = _repCtn.AsQueryable().Where(t => t.BILLID == order.Id).ToList(); + + EDIRouteEnum ediRouteEnum = GetEDIRoute(order.CARRIERID); + + _logger.LogInformation("批次={no} 获取EDI路由完成 路由={route}", batchNo, ediRouteEnum.ToString()); + + if (ediRouteEnum == EDIRouteEnum.NULL) + throw Oops.Bah($"当前船公司没有对应的请求路由配置"); + + return result; + } + #endregion + + #region 提取收、发、通详情 + /// + /// 提取收、发、通详情 + /// + /// 收、发、通信息 + /// 内容定位(name-名称;addr-地址) + /// 返回截取字符 + public string GetShipCneeNotifyDetail(string name,string location = "name") + { + string result = string.Empty; + + try + { + if (location == "name") + { + result = Regex.Match(name, ".*(?=\\n)").Value; + } + else if (location == "addr") + { + string s = Regex.Match(name, ".*(?=\\n)").Value; + + result = name.Replace(s, ""); + + if(Regex.IsMatch(result,"^\\n")) + { + result = Regex.Replace(result, "^\\n", ""); + } + + //result = Regex.Match(name, $"(?<={s}).*").Value; + } + } + catch(Exception ex) + { + _logger.LogInformation($"{nameof(GetShipCneeNotifyDetail)} 提取收、发、通详情异常,原因:{ex.Message}"); + } + + return result; + } + #endregion } } diff --git a/Myshipping.Application/Service/BookingOrder/Dto/BookingEDIVOLTAMapper.cs b/Myshipping.Application/Service/BookingOrder/Dto/BookingEDIVOLTAMapper.cs new file mode 100644 index 00000000..40f13e8f --- /dev/null +++ b/Myshipping.Application/Service/BookingOrder/Dto/BookingEDIVOLTAMapper.cs @@ -0,0 +1,41 @@ +using Mapster; +using Myshipping.Application.Entity; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Myshipping.Application +{ + public class BookingEDIVOLTAMapper : IRegister + { + public void Register(TypeAdapterConfig config) + { + config.ForType() + .Map(dest => dest.id, src => src.Id) + .Map(dest => dest.BookingId, src => src.MBLNO) + .Map(dest => dest.ShpperName, src => src.SHIPPER) + .Map(dest => dest.ConsigneeName, src => src.CONSIGNEE) + .Map(dest => dest.NotifyName, src => src.NOTIFYPARTY) + .Map(dest => dest.PlaceOfOrigin, src => src.PLACERECEIPT) + .Map(dest => dest.LoadPort, src => src.PORTLOAD) + .Map(dest => dest.DischargePort, src => src.PORTDISCHARGE) + .Map(dest => dest.FinalDestination, src => src.DESTINATION) + .Map(dest => dest.PlaceOfDelivery, src => src.PLACEDELIVERY) + .Map(dest => dest.CargoDescription, src => src.DESCRIPTION) + .Map(dest => dest.Marks, src => src.MARKS) + .Map(dest => dest.TotalGWt, src => src.KGS.HasValue ? src.KGS.Value : 0) + .Map(dest => dest.TotalCBM, src => src.CBM.HasValue ? src.CBM.Value : 0); + + + config.ForType() + .Map(dest => dest.ContaNo, src => src.CNTRNO) + .Map(dest => dest.SealNo, src => src.SEALNO) + .Map(dest => dest.Qty, src => src.PKGS.HasValue ? src.PKGS.Value : 0) + .Map(dest => dest.GWt, src => src.KGS.HasValue ? src.KGS.Value : 0) + .Map(dest => dest.CBM, src => src.CBM.HasValue ? src.CBM.Value : 0) + .Map(dest => dest.Pkgs, src => src.KINDPKGS); + } + } +} diff --git a/Myshipping.Application/Service/BookingOrder/IBookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/IBookingOrderService.cs index 3f74b52d..82ac919a 100644 --- a/Myshipping.Application/Service/BookingOrder/IBookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/IBookingOrderService.cs @@ -108,5 +108,33 @@ namespace Myshipping.Application /// 是否默认同步东胜 true-自动同步 false-不自动同步 /// Task SetBookingGoodsStatus(long bookingId, bool isAutoSyncDS = false); + + /// + /// 检查是否VOLTA并返回初始数据 + /// + /// 请求参数 + /// 返回回执 + dynamic CheckAndInitVOLTAEdi(BookingOrClosingEDIOrderDto model); + + /// + /// 发送VOLTA截单请求 + /// + /// 请求截单详情 + /// 返回回执 + Task SendVOLTAEdiSI(VOLTAEDIBaseModel model); + + /// + /// 下载VOLTA截单请求报文 + /// + /// 请求截单详情 + /// 返回回执 + Task DownloadVOLTAEdiSI(VOLTAEDIBaseModel model); + + /// + /// 生成VOLTA报文(内部方法) + /// + /// 请求截单详情 + /// 返回回执 + Task InnerVOLTAEDI(VOLTAEDIBaseModel model); } } \ No newline at end of file