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
}
diff --git a/Myshipping.Application/EDI/WYEdiHelper.cs b/Myshipping.Application/EDI/WYEdiHelper.cs
index 9508f39d..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)
@@ -615,6 +619,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;
}
diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs
index 257b8abb..81e92e24 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
{
@@ -3263,7 +3269,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()
@@ -3581,20 +3587,44 @@ namespace Myshipping.Application
CancellationTokenSource cts = new CancellationTokenSource();
- //后续发送
- var ftpPostObj = new
+ string host = string.Empty;
+ string port = string.Empty;
+
+ if(ediCfg.SERVERIP.IndexOf(":")>= 0)
{
- host = ediCfg.SERVERIP,
- username = ediCfg.USERNAME,
- pwd = ediCfg.PASSWORD,
- path = ediCfg.FOLDERNAME
- };
+ host = ediCfg.SERVERIP.Split(new char[] { ':'}).FirstOrDefault().Trim();
+ port = ediCfg.SERVERIP.Split(new char[] { ':' }).Last()?.Trim();
+ }
+
+ 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} ,参数:{JSON.Serialize(par)},文件:{filePath}");
- _logger.LogInformation($"准备请求发送ftp:{ftpSpiderUrl} ,参数:{ftpPostObj.ToJsonString()},文件:{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);
@@ -3602,17 +3632,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}");
@@ -3628,6 +3659,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 触发订舱
///
/// 触发订舱
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)