wet 2 years ago
commit 8a03945837

@ -360,6 +360,11 @@ namespace Myshipping.Application.EDI.PIL
if (string.IsNullOrEmpty(InttrEdi.RECEIVECODE)) if (string.IsNullOrEmpty(InttrEdi.RECEIVECODE))
{ error = error + "<br />接收方代码不能为空"; } { error = error + "<br />接收方代码不能为空"; }
//2023-03-03 确认需要增加货代名称不能为空,这里对比东胜是填的订舱代理名称,这里需要人工填写
if (string.IsNullOrEmpty(InttrEdi.ForWarderName))
{ error = error + "<br />货代称呼不能为空"; }
//if (InttrEdi.filetype == "B") //if (InttrEdi.filetype == "B")
//{ //{
// if (InttrEdi.UseForWarderCode) // 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("", 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订舱代理代码如犯罪 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-nominalg-negotiableS-开关w-waybillm-memo tempstr += GetSpaceStr("W", 1);//7//BOL Type//M//X(1)//26//26//N-Nominal, G-Negotiable, S-Switch, W-Waybill, M-Memo//公司类型//n-nominalg-negotiableS-开关w-waybillm-memo
} }

@ -301,6 +301,10 @@ namespace Myshipping.Application.EDI.WY
if (string.IsNullOrEmpty(InttrEdi.RECEIVECODE)) if (string.IsNullOrEmpty(InttrEdi.RECEIVECODE))
{ error = error + "<br />接收方代码不能为空"; } { error = error + "<br />接收方代码不能为空"; }
//2023-03-03 确认需要增加货代名称不能为空,这里对比东胜是填的订舱代理名称,这里需要人工填写
if (string.IsNullOrEmpty(InttrEdi.ForWarderName))
{ error = error + "<br />货代称呼不能为空"; }
//if (InttrEdi.filetype == "B") //if (InttrEdi.filetype == "B")
//{ //{
// if (InttrEdi.UseForWarderCode) // 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 + "<br />提单号:" + headData.MBLNO + " 付费方式是预付,预付地点不能为空";
}
if (!string.IsNullOrWhiteSpace(headData.PAYABLEAT))
{
error = error + "<br />提单号:" + headData.MBLNO + " 付费方式是预付,到付地点不能填写";
}
}
else if (!string.IsNullOrWhiteSpace(headData.BLFRT) && headData.BLFRT.IndexOf("COLLECT") >= 0)
{
if (string.IsNullOrWhiteSpace(headData.PAYABLEAT))
{
error = error + "<br />提单号:" + headData.MBLNO + " 付费方式是到付,到付地点不能为空";
}
if (!string.IsNullOrWhiteSpace(headData.PREPARDAT))
{
error = error + "<br />提单号:" + headData.MBLNO + " 付费方式是到付,预付地点不能填写";
}
}
} }
return error; return error;
} }

@ -62,6 +62,12 @@ using Myshipping.Application.EDI.ESL;
using NPOI.HSSF.UserModel; using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel; using NPOI.SS.UserModel;
using NPOI.SS.Formula.Functions; 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 namespace Myshipping.Application
{ {
@ -3263,7 +3269,7 @@ namespace Myshipping.Application
var primaryModel = order.Adapt<MsOpSeaeEDIBaseModel>(); var primaryModel = order.Adapt<MsOpSeaeEDIBaseModel>();
//起运港是CNTAO并且船公司是太平需要判断场站EDI //起运港是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() var ediYardList = _cache.GetAllMappingYard().GetAwaiter().GetResult()
@ -3581,20 +3587,44 @@ namespace Myshipping.Application
CancellationTokenSource cts = new CancellationTokenSource(); CancellationTokenSource cts = new CancellationTokenSource();
//后续发送 string host = string.Empty;
var ftpPostObj = new string port = string.Empty;
if(ediCfg.SERVERIP.IndexOf(":")>= 0)
{ {
host = ediCfg.SERVERIP, host = ediCfg.SERVERIP.Split(new char[] { ':'}).FirstOrDefault().Trim();
username = ediCfg.USERNAME, port = ediCfg.SERVERIP.Split(new char[] { ':' }).Last()?.Trim();
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 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); string strJoin = System.IO.File.ReadAllText(filePath);
@ -3602,17 +3632,18 @@ namespace Myshipping.Application
_logger.LogInformation("FTP 开始上传"); _logger.LogInformation("FTP 开始上传");
var res = await ftpSpiderUrl var res = TransmitFtpFile(ftpSpiderUrl, par, new
.SetContentType("multipart/form-data") {
.SetBody(ftpPostObj) file = "file",
.SetBodyBytes(("file", Encoding.UTF8.GetBytes(strJoin), fileInfo.Name)) fileName = Path.GetFileName(filePath),
.PostAsStringAsync(); fileBytes = heByte
});
DateTime eDate = DateTime.Now; DateTime eDate = DateTime.Now;
TimeSpan ts = eDate.Subtract(bDate); TimeSpan ts = eDate.Subtract(bDate);
var timeDiff = ts.TotalMilliseconds; var timeDiff = ts.TotalMilliseconds;
_logger.LogInformation($"FTP 上传完成 上传文件大小:{fileInfo.Length} 用时:{timeDiff}ms.,{strJoin}"); _logger.LogInformation($"FTP 上传完成 上传文件大小:{heByte.Length} 用时:{timeDiff}ms.,{strJoin}");
_logger.LogInformation($"发送ftp返回{res}"); _logger.LogInformation($"发送ftp返回{res}");
@ -3628,6 +3659,76 @@ namespace Myshipping.Application
} }
#endregion #endregion
#region
/// <summary>
/// 转发EDI内部方法
/// </summary>
/// <param name="requestUrl">请求接口地址</param>
/// <param name="nameValueCollection">键值对参数</param>
/// <param name="fileInfo">文件信息</param>
/// <param name="contentType">默认 application/json</param>
/// <returns>返回结果</returns>
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 触发订舱 #region 触发订舱
/// <summary> /// <summary>
/// 触发订舱 /// 触发订舱

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Myshipping.Application namespace Myshipping.Application
@ -64,7 +65,9 @@ namespace Myshipping.Application
.Map(dest => dest.ISCONTAINERSOC, src => src.ISCONTAINERSOC) .Map(dest => dest.ISCONTAINERSOC, src => src.ISCONTAINERSOC)
.Map(dest => dest.FREIGHTPAYER, src => src.FREIGHTPAYER) .Map(dest => dest.FREIGHTPAYER, src => src.FREIGHTPAYER)
.Map(dest => dest.PLACEDELIVERYID, src => src.PLACEDELIVERYID) .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<BookingCtn, MsOpSeaeCtnEDIBaseModel>() config.ForType<BookingCtn, MsOpSeaeCtnEDIBaseModel>()
.Map(dest => dest.CTNNUM, src => src.CTNNUM.HasValue? src.CTNNUM.Value:0) .Map(dest => dest.CTNNUM, src => src.CTNNUM.HasValue? src.CTNNUM.Value:0)

Loading…
Cancel
Save