新增FTP Client上传EDI文件

booking_auth_dev
jianghaiqing 2 years ago
parent 5fbb48e173
commit 3fedb785cd

@ -610,8 +610,10 @@ namespace Myshipping.Application.EDI.ESL
#endregion #endregion
#region 生成报文(订舱(InttrEdi.filetype=="B"),截单(InttrEdi.filetype=="E")) #region 生成报文(订舱(InttrEdi.filetype=="B"),截单(InttrEdi.filetype=="E"))
public static string CreateEdiESL(MsESLEdiModel InttrEdi) public static CommonWebApiResult CreateEdiESL(MsESLEdiModel InttrEdi)
{ {
CommonWebApiResult result = new CommonWebApiResult { succ = false };
var filetype = "IFTMIN"; var filetype = "IFTMIN";
if (InttrEdi.filetype != "E") filetype = "IFTMBF"; if (InttrEdi.filetype != "E") filetype = "IFTMBF";
@ -1025,7 +1027,9 @@ namespace Myshipping.Application.EDI.ESL
r.Close(); r.Close();
f.Close(); f.Close();
return filename; result.succ = true;
result.extra = filename;
return result;
} }
#endregion #endregion

@ -1,4 +1,5 @@
using Myshipping.Application.EDI.ESL; using Myshipping.Application.EDI.ESL;
using MySqlX.XDevAPI.Common;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@ -653,8 +654,10 @@ namespace Myshipping.Application.EDI.PIL
#endregion #endregion
#region 生成报文(订舱(filetype=="B"),截单(filetype=="E")) #region 生成报文(订舱(filetype=="B"),截单(filetype=="E"))
public static string CreateEdiPIL(EDIBaseModel InttrEdi) public static CommonWebApiResult CreateEdiPIL(EDIBaseModel InttrEdi)
{ {
CommonWebApiResult result = new CommonWebApiResult { succ = false };
var estr = ""; var estr = "";
if (InttrEdi.filetype == "E") if (InttrEdi.filetype == "E")
{ {
@ -1779,7 +1782,9 @@ namespace Myshipping.Application.EDI.PIL
r.Close(); r.Close();
f.Close(); f.Close();
return filename; result.succ = true;
result.extra = filename;
return result;
} }
#endregion #endregion

@ -1,4 +1,5 @@
using Furion.LinqBuilder; using Furion.LinqBuilder;
using MySqlX.XDevAPI.Common;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@ -716,8 +717,10 @@ namespace Myshipping.Application.EDI.TSL
#endregion #endregion
#region 订舱 #region 订舱
public static string CreateEdiTSL(EDIBaseModel InttrEdi) public static CommonWebApiResult CreateEdiTSL(EDIBaseModel InttrEdi)
{ {
CommonWebApiResult result = new CommonWebApiResult { succ = false };
string filename = InttrEdi.filerpath + "\\" + InttrEdi.BSLIST[0].MBLNO + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt"; string filename = InttrEdi.filerpath + "\\" + InttrEdi.BSLIST[0].MBLNO + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt";
//如果是部署linux需要修改路径 //如果是部署linux需要修改路径
@ -1314,13 +1317,17 @@ namespace Myshipping.Application.EDI.TSL
r.Close(); r.Close();
f.Close(); f.Close();
return filename; result.succ = true;
result.extra = filename;
return result;
} }
#endregion #endregion
#region 确认 #region 确认
public static string CreateEdiTSLSI(EDIBaseModel InttrEdi) public static CommonWebApiResult CreateEdiTSLSI(EDIBaseModel InttrEdi)
{ {
CommonWebApiResult result = new CommonWebApiResult { succ = false };
string filename = InttrEdi.filerpath + "\\" + InttrEdi.BSLIST[0].MBLNO + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt"; string filename = InttrEdi.filerpath + "\\" + InttrEdi.BSLIST[0].MBLNO + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt";
if (System.IO.File.Exists(filename)) if (System.IO.File.Exists(filename))
@ -2060,7 +2067,9 @@ namespace Myshipping.Application.EDI.TSL
r.Close(); r.Close();
f.Close(); f.Close();
return filename; result.succ = true;
result.extra = filename;
return result;
} }
#endregion #endregion

@ -618,8 +618,10 @@ namespace Myshipping.Application.EDI.WY
#endregion #endregion
#region 生成报文(订舱(filetype=="B"),截单(filetype=="E")) #region 生成报文(订舱(filetype=="B"),截单(filetype=="E"))
public static string CreateEdiWY(EDIBaseModel InttrEdi) public static CommonWebApiResult CreateEdiWY(EDIBaseModel InttrEdi)
{ {
CommonWebApiResult result = new CommonWebApiResult { succ = false };
var filetype = "IFTMBF"; var filetype = "IFTMBF";
string filename = InttrEdi.filerpath + "\\" + filetype + "_" + InttrEdi.BSLIST[0].MBLNO + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt"; string filename = InttrEdi.filerpath + "\\" + filetype + "_" + InttrEdi.BSLIST[0].MBLNO + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt";
@ -906,7 +908,9 @@ namespace Myshipping.Application.EDI.WY
r.Close(); r.Close();
f.Close(); f.Close();
return filename; result.succ = true;
result.extra = filename;
return result;
} }
#endregion #endregion
} }

@ -5,6 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using MySqlX.XDevAPI.Common;
namespace Myshipping.Application.EDI.YML namespace Myshipping.Application.EDI.YML
{ {
@ -644,8 +645,10 @@ namespace Myshipping.Application.EDI.YML
#endregion #endregion
#region 生成报文(订舱) #region 生成报文(订舱)
public static string CreateEdiYML(EDIBaseModel InttrEdi) public static CommonWebApiResult CreateEdiYML(EDIBaseModel InttrEdi)
{ {
CommonWebApiResult result = new CommonWebApiResult { succ = false };
var filetype = "IFTMBF"; var filetype = "IFTMBF";
string filename = InttrEdi.filerpath + "\\" + filetype + "_" + InttrEdi.BSLIST[0].MBLNO + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt"; string filename = InttrEdi.filerpath + "\\" + filetype + "_" + InttrEdi.BSLIST[0].MBLNO + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt";
@ -968,13 +971,17 @@ namespace Myshipping.Application.EDI.YML
r.Close(); r.Close();
f.Close(); f.Close();
return filename; result.succ = true;
result.extra = filename;
return result;
} }
#endregion #endregion
#region 生成报文(确认) #region 生成报文(确认)
public static string CreateEdiYMLSI(EDIBaseModel InttrEdi) public static CommonWebApiResult CreateEdiYMLSI(EDIBaseModel InttrEdi)
{ {
CommonWebApiResult result = new CommonWebApiResult { succ = false };
string filename = InttrEdi.filerpath + "\\" + InttrEdi.BSLIST[0].MBLNO + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt"; string filename = InttrEdi.filerpath + "\\" + InttrEdi.BSLIST[0].MBLNO + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt";
if (System.IO.File.Exists(filename)) if (System.IO.File.Exists(filename))
@ -1797,7 +1804,9 @@ namespace Myshipping.Application.EDI.YML
r.Close(); r.Close();
f.Close(); f.Close();
return filename; result.succ = true;
result.extra = filename;
return result;
} }
#endregion #endregion

@ -5,6 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using MySqlX.XDevAPI.Common;
namespace Myshipping.Application.EDI.YT namespace Myshipping.Application.EDI.YT
{ {
@ -631,8 +632,10 @@ namespace Myshipping.Application.EDI.YT
#endregion #endregion
#region 生成报文(订舱(filetype=="B"),截单(filetype=="E")) #region 生成报文(订舱(filetype=="B"),截单(filetype=="E"))
public static string CreateEdiYT(EDIBaseModel InttrEdi) public static CommonWebApiResult CreateEdiYT(EDIBaseModel InttrEdi)
{ {
CommonWebApiResult result = new CommonWebApiResult { succ = false };
var filetype = "IFTMIN"; var filetype = "IFTMIN";
if (InttrEdi.filetype != "E") filetype = "IFTMBF"; if (InttrEdi.filetype != "E") filetype = "IFTMBF";
@ -1119,7 +1122,9 @@ namespace Myshipping.Application.EDI.YT
r.Close(); r.Close();
f.Close(); f.Close();
return filename; result.succ = true;
result.extra = filename;
return result;
} }
#endregion #endregion

@ -30,6 +30,10 @@
</Content> </Content>
</ItemGroup> </ItemGroup>
<ItemGroup>
<PackageReference Include="FluentFTP" Version="42.0.1" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Myshipping.Core\Myshipping.Core.csproj" /> <ProjectReference Include="..\Myshipping.Core\Myshipping.Core.csproj" />
</ItemGroup> </ItemGroup>

@ -4757,6 +4757,14 @@
<param name="model">订舱、截单EDI请求</param> <param name="model">订舱、截单EDI请求</param>
<returns>返回回执</returns> <returns>返回回执</returns>
</member> </member>
<member name="M:Myshipping.Application.BookingOrderService.InnerSendBookingOrClosingEDIToFTP(System.String,Myshipping.Core.Entity.DjyEdiSetting)">
<summary>
上传FTP
</summary>
<param name="filePath">EDI文件路径</param>
<param name="ediCfg">FTP配置</param>
<returns>true-成功 false-失败</returns>
</member>
<member name="M:Myshipping.Application.BookingOrderService.InnerSendBookingOrClosingEDI(Myshipping.Application.BookingOrClosingEDIOrderDto,Myshipping.Application.EDIBaseModel,Myshipping.Application.EDIRouteEnum)"> <member name="M:Myshipping.Application.BookingOrderService.InnerSendBookingOrClosingEDI(Myshipping.Application.BookingOrClosingEDIOrderDto,Myshipping.Application.EDIBaseModel,Myshipping.Application.EDIRouteEnum)">
<summary> <summary>
触发订舱 触发订舱

@ -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)

Loading…
Cancel
Save