|
|
@ -47,6 +47,9 @@ using Myshipping.Application.EDI.WY;
|
|
|
|
using Myshipping.Application.EDI.YML;
|
|
|
|
using Myshipping.Application.EDI.YML;
|
|
|
|
using Myshipping.Application.EDI.YT;
|
|
|
|
using Myshipping.Application.EDI.YT;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
using FluentFTP;
|
|
|
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
|
|
using Furion.JsonSerialization;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Myshipping.Application
|
|
|
|
namespace Myshipping.Application
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -1798,14 +1801,76 @@ namespace Myshipping.Application
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw Oops.Bah(result.msg);
|
|
|
|
throw Oops.Bah(result.msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//上传FTP
|
|
|
|
|
|
|
|
var sendStatus = await InnerSendBookingOrClosingEDIToFTP(result.extra.ToString(), ftpSet);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result.extra.ToString();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 上传FTP
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="filePath">EDI文件路径</param>
|
|
|
|
|
|
|
|
/// <param name="ediCfg">FTP配置</param>
|
|
|
|
|
|
|
|
/// <returns>true-成功 false-失败</returns>
|
|
|
|
|
|
|
|
private async Task<bool> InnerSendBookingOrClosingEDIToFTP(string filePath, DjyEdiSetting ediCfg)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
CancellationTokenSource cts = new CancellationTokenSource();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var ftpClient = new AsyncFtpClient($"ftp://{ediCfg.SERVERIP}", ediCfg.USERNAME, ediCfg.PASSWORD);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("创建FTP Client");
|
|
|
|
|
|
|
|
if (!ftpClient.IsConnected)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
await ftpClient.Connect();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("FTP Client 连接");
|
|
|
|
|
|
|
|
|
|
|
|
return result.extra.ToString();
|
|
|
|
var setOpts = await ftpClient.Execute("OPTS UTF8 ON", cts.Token);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("FTP Client 设置 OPTS UTF8 ON");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!setOpts.Code.Equals("200") && !setOpts.Code.Equals("202"))
|
|
|
|
|
|
|
|
ftpClient.Encoding = Encoding.GetEncoding("ISO-8859-1");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!File.Exists(filePath))
|
|
|
|
|
|
|
|
throw Oops.Bah($"校验文件完成 file={filePath}");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("读取文件信息");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var fileInfo = new FileInfo(filePath);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string targetPath = $"{ediCfg.FOLDERNAME}/{fileInfo.Name}";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DateTime bDate = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("FTP Client 开始上传");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var uploadRlt = await ftpClient.UploadFile(filePath, targetPath, createRemoteDir: true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DateTime eDate = DateTime.Now;
|
|
|
|
|
|
|
|
TimeSpan ts = eDate.Subtract(bDate);
|
|
|
|
|
|
|
|
var timeDiff = ts.TotalMilliseconds;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"FTP Client 上传完成 上传文件大小:{fileInfo.Length} 用时:{timeDiff}ms.,{JSON.Serialize(uploadRlt)}");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ftpClient.IsConnected)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
await ftpClient.Disconnect();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("FTP Client 断开链接");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ftpClient.Dispose();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("FTP Client 释放完成");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return uploadRlt == FtpStatus.Success;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 触发订舱
|
|
|
|
/// 触发订舱
|
|
|
@ -1831,10 +1896,10 @@ namespace Myshipping.Application
|
|
|
|
if (!string.IsNullOrWhiteSpace(strCheck))
|
|
|
|
if (!string.IsNullOrWhiteSpace(strCheck))
|
|
|
|
throw Oops.Bah($"发送{EDIRouteEnum.PIL.ToString()}校验失败,{strCheck}");
|
|
|
|
throw Oops.Bah($"发送{EDIRouteEnum.PIL.ToString()}校验失败,{strCheck}");
|
|
|
|
|
|
|
|
|
|
|
|
string ediFile = PILEdiHelper.CreateEdiPIL(ediModel);
|
|
|
|
var currRlt = PILEdiHelper.CreateEdiPIL(ediModel);
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
result.succ = true;
|
|
|
|
result.succ = currRlt.succ;
|
|
|
|
result.extra = ediFile;
|
|
|
|
result.extra = currRlt.succ ? currRlt.extra.ToString() : "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ediRouteEnum == EDIRouteEnum.TSL)
|
|
|
|
else if (ediRouteEnum == EDIRouteEnum.TSL)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -1846,20 +1911,26 @@ namespace Myshipping.Application
|
|
|
|
if (!string.IsNullOrWhiteSpace(strCheck))
|
|
|
|
if (!string.IsNullOrWhiteSpace(strCheck))
|
|
|
|
throw Oops.Bah($"发送{EDIRouteEnum.PIL.ToString()}校验失败,{strCheck}");
|
|
|
|
throw Oops.Bah($"发送{EDIRouteEnum.PIL.ToString()}校验失败,{strCheck}");
|
|
|
|
|
|
|
|
|
|
|
|
string ediFile = string.Empty;
|
|
|
|
CommonWebApiResult currRlt = new CommonWebApiResult();
|
|
|
|
|
|
|
|
|
|
|
|
if (model.sendType == "B")
|
|
|
|
if (model.sendType == "B")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ediFile = TSLEdiHelper.CreateEdiTSL(ediModel);
|
|
|
|
currRlt = TSLEdiHelper.CreateEdiTSL(ediModel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (model.sendType == "E")
|
|
|
|
else if (model.sendType == "E")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ediFile = TSLEdiHelper.CreateEdiTSL(ediModel);
|
|
|
|
currRlt = TSLEdiHelper.CreateEdiTSLSI(ediModel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
result.succ = true;
|
|
|
|
result.succ = currRlt.succ;
|
|
|
|
result.extra = ediFile;
|
|
|
|
result.extra = currRlt.succ ? currRlt.extra.ToString() : "";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//鐩存帴鍙戦€佹姤鏂囧埌FTP鏈嶅姟鍣?
|
|
|
|
|
|
|
|
if (model.send)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ediRouteEnum == EDIRouteEnum.WY)
|
|
|
|
else if (ediRouteEnum == EDIRouteEnum.WY)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -1871,11 +1942,11 @@ namespace Myshipping.Application
|
|
|
|
if (!string.IsNullOrWhiteSpace(strCheck))
|
|
|
|
if (!string.IsNullOrWhiteSpace(strCheck))
|
|
|
|
throw Oops.Bah($"发送{EDIRouteEnum.PIL.ToString()}校验失败,{strCheck}");
|
|
|
|
throw Oops.Bah($"发送{EDIRouteEnum.PIL.ToString()}校验失败,{strCheck}");
|
|
|
|
|
|
|
|
|
|
|
|
string ediFile = WYEdiHelper.CreateEdiWY(ediModel);
|
|
|
|
var currRlt = WYEdiHelper.CreateEdiWY(ediModel);
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
result.succ = true;
|
|
|
|
result.succ = currRlt.succ;
|
|
|
|
result.extra = ediFile;
|
|
|
|
result.extra = currRlt.succ ? currRlt.extra.ToString() : "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ediRouteEnum == EDIRouteEnum.YML)
|
|
|
|
else if (ediRouteEnum == EDIRouteEnum.YML)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -1887,20 +1958,20 @@ namespace Myshipping.Application
|
|
|
|
if (!string.IsNullOrWhiteSpace(strCheck))
|
|
|
|
if (!string.IsNullOrWhiteSpace(strCheck))
|
|
|
|
throw Oops.Bah($"发送{EDIRouteEnum.PIL.ToString()}校验失败,{strCheck}");
|
|
|
|
throw Oops.Bah($"发送{EDIRouteEnum.PIL.ToString()}校验失败,{strCheck}");
|
|
|
|
|
|
|
|
|
|
|
|
string ediFile = string.Empty;
|
|
|
|
CommonWebApiResult currRlt = new CommonWebApiResult();
|
|
|
|
|
|
|
|
|
|
|
|
if (model.sendType == "B")
|
|
|
|
if (model.sendType == "B")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ediFile = YMLEdiHelper.CreateEdiYML(ediModel);
|
|
|
|
currRlt = YMLEdiHelper.CreateEdiYML(ediModel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (model.sendType == "E")
|
|
|
|
else if (model.sendType == "E")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ediFile = YMLEdiHelper.CreateEdiYMLSI(ediModel);
|
|
|
|
currRlt = YMLEdiHelper.CreateEdiYMLSI(ediModel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
result.succ = true;
|
|
|
|
result.succ = currRlt.succ;
|
|
|
|
result.extra = ediFile;
|
|
|
|
result.extra = currRlt.succ ? currRlt.extra.ToString() : "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ediRouteEnum == EDIRouteEnum.YT)
|
|
|
|
else if (ediRouteEnum == EDIRouteEnum.YT)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -1912,11 +1983,11 @@ namespace Myshipping.Application
|
|
|
|
if (!string.IsNullOrWhiteSpace(strCheck))
|
|
|
|
if (!string.IsNullOrWhiteSpace(strCheck))
|
|
|
|
throw Oops.Bah($"发送{EDIRouteEnum.PIL.ToString()}校验失败,{strCheck}");
|
|
|
|
throw Oops.Bah($"发送{EDIRouteEnum.PIL.ToString()}校验失败,{strCheck}");
|
|
|
|
|
|
|
|
|
|
|
|
string ediFile = YTEdiHelper.CreateEdiYT(ediModel);
|
|
|
|
CommonWebApiResult currRlt = YTEdiHelper.CreateEdiYT(ediModel);
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
result.succ = true;
|
|
|
|
result.succ = currRlt.succ;
|
|
|
|
result.extra = ediFile;
|
|
|
|
result.extra = currRlt.succ ? currRlt.extra.ToString() : "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
|