From aa41a56952975180a13e46b18302b32baab542b1 Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Fri, 3 Mar 2023 15:39:12 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9PIL=20EDI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Myshipping.Application/EDI/PILEdiHelper.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Myshipping.Application/EDI/PILEdiHelper.cs b/Myshipping.Application/EDI/PILEdiHelper.cs index e4cd942e..02d3a739 100644 --- a/Myshipping.Application/EDI/PILEdiHelper.cs +++ b/Myshipping.Application/EDI/PILEdiHelper.cs @@ -360,6 +360,11 @@ namespace Myshipping.Application.EDI.PIL if (string.IsNullOrEmpty(InttrEdi.RECEIVECODE)) { error = error + "
接收方代码不能为空"; } + //2023-03-03 确认需要增加货代名称不能为空,这里对比东胜是填的订舱代理名称,这里需要人工填写 + if (string.IsNullOrEmpty(InttrEdi.ForWarderName)) + { error = error + "
货代称呼不能为空"; } + + //if (InttrEdi.filetype == "B") //{ // if (InttrEdi.UseForWarderCode) @@ -1759,7 +1764,7 @@ namespace Myshipping.Application.EDI.PIL } tempstr += GetSpaceStr("", 4);//5//Department Code//M//X(4)//19//22//webCSM Department Code (eg SG00) (out from webCSM only)//部门代码//webcsm部门代码(如sg00)(从webcsm只) tempstr += GetSpaceStr("", 3);//6//Booking Agent Code//M//X(3)//23//25//webCSM Booking Agent Code (eg SIN)//订舱代理代码//webcsm订舱代理代码(如犯罪) - if (bill.ISSUETYPE.ToString().Trim().ToUpper() == "WAYBILL") + if (bill.ISSUETYPE.ToString().Trim().ToUpper() == "WAYBILL" || bill.ISSUETYPE.ToString().Trim().ToUpper() == "SEAWAY BILL") { tempstr += GetSpaceStr("W", 1);//7//BOL Type//M//X(1)//26//26//N-Nominal, G-Negotiable, S-Switch, W-Waybill, M-Memo//公司类型//n-nominal,g-negotiable,S-开关,w-waybill,m-memo } From a4e6ff64572ec7fa1207bdec39702f79083d270b Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Fri, 3 Mar 2023 16:32:35 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9WY=20EDI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Myshipping.Application/EDI/WYEdiHelper.cs | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Myshipping.Application/EDI/WYEdiHelper.cs b/Myshipping.Application/EDI/WYEdiHelper.cs index 9508f39d..64d7d968 100644 --- a/Myshipping.Application/EDI/WYEdiHelper.cs +++ b/Myshipping.Application/EDI/WYEdiHelper.cs @@ -615,6 +615,33 @@ namespace Myshipping.Application.EDI.WY } + //2023-03-03 经过测试东胜的EDI根据付费方式,区分 到付-需要填到付地点不能填预付地点,预付只能填预付地点不能填到付地点 + //跟韩工确认增加判断 + if (!string.IsNullOrWhiteSpace(headData.BLFRT) && headData.BLFRT.IndexOf("PREPAID") >= 0) + { + if (string.IsNullOrWhiteSpace(headData.PREPARDAT)) + { + error = error + "
提单号:" + headData.MBLNO + " 付费方式是预付,预付地点不能为空"; + } + + if (!string.IsNullOrWhiteSpace(headData.PAYABLEAT)) + { + error = error + "
提单号:" + headData.MBLNO + " 付费方式是预付,到付地点不能填写"; + } + } + else if (!string.IsNullOrWhiteSpace(headData.BLFRT) && headData.BLFRT.IndexOf("COLLECT") >= 0) + { + if (string.IsNullOrWhiteSpace(headData.PAYABLEAT)) + { + error = error + "
提单号:" + headData.MBLNO + " 付费方式是到付,到付地点不能为空"; + } + + if (!string.IsNullOrWhiteSpace(headData.PREPARDAT)) + { + error = error + "
提单号:" + headData.MBLNO + " 付费方式是到付,预付地点不能填写"; + } + } + } return error; } From a63093832f9507dd613982e830d2340c4e914cda Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Fri, 3 Mar 2023 17:02:30 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9WY=20EDI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Myshipping.Application/EDI/WYEdiHelper.cs | 4 ++++ .../Service/BookingOrder/Dto/BookingEDIMapper.cs | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Myshipping.Application/EDI/WYEdiHelper.cs b/Myshipping.Application/EDI/WYEdiHelper.cs index 64d7d968..1f8ee914 100644 --- a/Myshipping.Application/EDI/WYEdiHelper.cs +++ b/Myshipping.Application/EDI/WYEdiHelper.cs @@ -301,6 +301,10 @@ namespace Myshipping.Application.EDI.WY if (string.IsNullOrEmpty(InttrEdi.RECEIVECODE)) { error = error + "
接收方代码不能为空"; } + //2023-03-03 确认需要增加货代名称不能为空,这里对比东胜是填的订舱代理名称,这里需要人工填写 + if (string.IsNullOrEmpty(InttrEdi.ForWarderName)) + { error = error + "
货代称呼不能为空"; } + //if (InttrEdi.filetype == "B") //{ // if (InttrEdi.UseForWarderCode) diff --git a/Myshipping.Application/Service/BookingOrder/Dto/BookingEDIMapper.cs b/Myshipping.Application/Service/BookingOrder/Dto/BookingEDIMapper.cs index 85c34898..2488f0dd 100644 --- a/Myshipping.Application/Service/BookingOrder/Dto/BookingEDIMapper.cs +++ b/Myshipping.Application/Service/BookingOrder/Dto/BookingEDIMapper.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; namespace Myshipping.Application @@ -64,7 +65,9 @@ namespace Myshipping.Application .Map(dest => dest.ISCONTAINERSOC, src => src.ISCONTAINERSOC) .Map(dest => dest.FREIGHTPAYER, src => src.FREIGHTPAYER) .Map(dest => dest.PLACEDELIVERYID, src => src.PLACEDELIVERYID) - .Map(dest => dest.PLACEDELIVERY, src => src.PLACEDELIVERY); + .Map(dest => dest.PLACEDELIVERY, src => src.PLACEDELIVERY) + .Map(dest => dest.CARRIER, src => src.CARRIER); + config.ForType() .Map(dest => dest.CTNNUM, src => src.CTNNUM.HasValue? src.CTNNUM.Value:0) From 4ef20fa5a5db3ac894f0b0b4a5e5675459c01b5d Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Fri, 3 Mar 2023 18:03:41 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9FTP=20=E8=AE=BF=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/BookingOrder/BookingOrderService.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index 1823f0af..de1df513 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -3048,7 +3048,7 @@ namespace Myshipping.Application var primaryModel = order.Adapt(); //起运港是CNTAO并且船公司是太平需要判断场站EDI - if (order.PORTLOADID == "CNTAO" && ediRouteEnum == EDIRouteEnum.PIL) + if ((order.PORTLOADID == "CNTAO" && ediRouteEnum == EDIRouteEnum.PIL) || ediRouteEnum == EDIRouteEnum.WY) { //场站 var ediYardList = _cache.GetAllMappingYard().GetAwaiter().GetResult() @@ -3366,10 +3366,20 @@ namespace Myshipping.Application CancellationTokenSource cts = new CancellationTokenSource(); + string host = string.Empty; + string port = string.Empty; + + if(ediCfg.SERVERIP.IndexOf(":")>= 0) + { + host = ediCfg.SERVERIP.Split(new char[] { ':'}).FirstOrDefault().Trim(); + port = ediCfg.SERVERIP.Split(new char[] { ':' }).Last()?.Trim(); + } + //后续发送 var ftpPostObj = new { - host = ediCfg.SERVERIP, + host = host, + port = port, username = ediCfg.USERNAME, pwd = ediCfg.PASSWORD, path = ediCfg.FOLDERNAME From 5f09dfd877654b87def62ebc44ecac3281769612 Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Mon, 6 Mar 2023 11:51:54 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9EDI=E7=9A=84=E5=8F=91?= =?UTF-8?q?=E9=80=81=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BookingOrder/BookingOrderService.cs | 125 +++++++++++++++--- 1 file changed, 108 insertions(+), 17 deletions(-) diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index de1df513..cd48c330 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -62,6 +62,12 @@ using Myshipping.Application.EDI.ESL; using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using NPOI.SS.Formula.Functions; +using NPOI.HPSF; +using MimeKit; +using NPOI.SS.Formula; +using NPOI.Util; +using System.Collections.Specialized; +using System.Net.Http.Headers; namespace Myshipping.Application { @@ -3375,21 +3381,35 @@ namespace Myshipping.Application port = ediCfg.SERVERIP.Split(new char[] { ':' }).Last()?.Trim(); } - //后续发送 - var ftpPostObj = new - { - host = host, - port = port, - username = ediCfg.USERNAME, - pwd = ediCfg.PASSWORD, - path = ediCfg.FOLDERNAME - }; + NameValueCollection par = new NameValueCollection(); + par.Add("host", host); + par.Add("port", port); + par.Add("username", ediCfg.USERNAME); + par.Add("pwd", ediCfg.PASSWORD); + par.Add("path", ediCfg.FOLDERNAME); var ftpSpiderUrl = _cache.GetAllDictData().GetAwaiter().GetResult().FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "booking_edi_ftp_server").Value; - var fileInfo = new FileInfo(filePath); + //var fileInfo = new FileInfo(filePath); - _logger.LogInformation($"准备请求发送ftp:{ftpSpiderUrl} ,参数:{ftpPostObj.ToJsonString()},文件:{filePath}"); + _logger.LogInformation($"准备请求发送ftp:{ftpSpiderUrl} ,参数:{JSON.Serialize(par)},文件:{filePath}"); + + + System.IO.FileStream file = new System.IO.FileStream(filePath, FileMode.Open, FileAccess.Read); + int SplitSize = 5242880;//5M分片长度 + int index = 1; //序号 第几片 + long StartPosition = 5242880 * (index - 1); + long lastLens = file.Length - StartPosition;//真不知道怎么起命了,就这样吧 + if (lastLens < 5242880) + { + SplitSize = (int)lastLens; + } + byte[] heByte = new byte[SplitSize]; + file.Seek(StartPosition, SeekOrigin.Begin); + //第一个参数是 起始位置 + file.Read(heByte, 0, SplitSize); + //第三个参数是 读取长度(剩余长度) + file.Close(); string strJoin = System.IO.File.ReadAllText(filePath); @@ -3397,17 +3417,18 @@ namespace Myshipping.Application _logger.LogInformation("FTP 开始上传"); - var res = await ftpSpiderUrl - .SetContentType("multipart/form-data") - .SetBody(ftpPostObj) - .SetBodyBytes(("file", Encoding.UTF8.GetBytes(strJoin), fileInfo.Name)) - .PostAsStringAsync(); + var res = TransmitFtpFile(ftpSpiderUrl, par, new + { + file = "file", + fileName = Path.GetFileName(filePath), + fileBytes = heByte + }); DateTime eDate = DateTime.Now; TimeSpan ts = eDate.Subtract(bDate); var timeDiff = ts.TotalMilliseconds; - _logger.LogInformation($"FTP 上传完成 上传文件大小:{fileInfo.Length} 用时:{timeDiff}ms.,{strJoin}"); + _logger.LogInformation($"FTP 上传完成 上传文件大小:{heByte.Length} 用时:{timeDiff}ms.,{strJoin}"); _logger.LogInformation($"发送ftp返回:{res}"); @@ -3423,6 +3444,76 @@ namespace Myshipping.Application } #endregion + #region + /// + /// 转发EDI内部方法 + /// + /// 请求接口地址 + /// 键值对参数 + /// 文件信息 + /// 默认 application/json + /// 返回结果 + private static string TransmitFtpFile(string requestUrl, NameValueCollection nameValueCollection, dynamic fileInfo, + string contentType = "application/json") + { + 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, fileInfo.file.ToString(), HttpUtility.UrlEncode(fileInfo.fileName.ToString())); + } + #endregion + + //请求 + var response = httpClient.PostAsync(requestUrl, reduceAttach).Result; + result = response.Content.ReadAsStringAsync().Result; + } + } + catch (Exception ex) + { + result = JSON.Serialize(new + { + message = $"{nameof(TransmitFtpFile)} 转发EDI内部方法异常,原因:{ex.Message}", + status = 0 + }); + } + + } + return result; + } + #endregion + #region 触发订舱 /// /// 触发订舱