|
|
|
@ -68,6 +68,8 @@ using NPOI.SS.Formula;
|
|
|
|
|
using NPOI.Util;
|
|
|
|
|
using System.Collections.Specialized;
|
|
|
|
|
using System.Net.Http.Headers;
|
|
|
|
|
using MySqlX.XDevAPI.Common;
|
|
|
|
|
using Ubiety.Dns.Core;
|
|
|
|
|
|
|
|
|
|
namespace Myshipping.Application
|
|
|
|
|
{
|
|
|
|
@ -3214,9 +3216,14 @@ namespace Myshipping.Application
|
|
|
|
|
|
|
|
|
|
var ediModel = new EDIBaseModel();
|
|
|
|
|
|
|
|
|
|
//2023-03-06 修改读取EDI配置方法,所有提取配置必须是已启用的EnableFlag=true,并且要根据SendType匹配发送类型,SendType=""表示使用订舱和截单,SO-订舱 SI-截单
|
|
|
|
|
var ftpSet = _cache.GetAllEdiSetting().GetAwaiter().GetResult()
|
|
|
|
|
.FirstOrDefault(a => a.EDICODE.Equals(ediRouteEnum.ToString(), StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
&& a.TenantId == order.TenantId && !string.IsNullOrWhiteSpace(a.CARRIERID) && a.CARRIERID.Equals(order.CARRIERID, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
&& a.TenantId == order.TenantId && !string.IsNullOrWhiteSpace(a.CARRIERID)
|
|
|
|
|
&& a.CARRIERID.Equals(order.CARRIERID, StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
&& a.EnableFlag
|
|
|
|
|
&& (string.IsNullOrWhiteSpace(a.SendType) ||
|
|
|
|
|
(!string.IsNullOrWhiteSpace(a.SendType) && ((model.sendType == "B" && a.SendType == "SO") ||(model.sendType == "E" && a.SendType == "SI")))));
|
|
|
|
|
|
|
|
|
|
if (ftpSet == null)
|
|
|
|
|
throw Oops.Bah($"获取EDICODE={ediRouteEnum.ToString()}的EDI参数设置失败");
|
|
|
|
@ -3506,7 +3513,22 @@ namespace Myshipping.Application
|
|
|
|
|
DateTime bDate = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
//上传FTP
|
|
|
|
|
var sendStatus = await InnerSendBookingOrClosingEDIToFTP(result.extra.ToString(), ftpSet);
|
|
|
|
|
CommonWebApiResult sendStatus = null;
|
|
|
|
|
|
|
|
|
|
//是订舱并且FTP配置了订舱接收邮箱则触发邮箱发送
|
|
|
|
|
if(!string.IsNullOrWhiteSpace(ftpSet.RECEIVEEMAIL) && model.sendType == "B")
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (!string.IsNullOrWhiteSpace(ftpSet.RECEIVESIEMAIL) && model.sendType == "E")
|
|
|
|
|
{
|
|
|
|
|
//是截单并且FTP配置了截单接收邮箱则触发邮箱发送
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sendStatus = await InnerSendBookingOrClosingEDIToFTP(result.extra.ToString(), ftpSet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DateTime eDate = DateTime.Now;
|
|
|
|
|
TimeSpan ts = eDate.Subtract(bDate);
|
|
|
|
@ -3665,6 +3687,95 @@ namespace Myshipping.Application
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 上传邮件
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 上传邮件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bookingOrder">订舱详情</param>
|
|
|
|
|
/// <param name="filePath">文件路径</param>
|
|
|
|
|
/// <param name="sendType">请求类型</param>
|
|
|
|
|
/// <param name="ediCfg">EDI配置</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
private async Task<CommonWebApiResult> InnerSendBookingOrClosingEDIToEmail(BookingOrder bookingOrder,string filePath,
|
|
|
|
|
string sendType, DjyEdiSetting ediCfg)
|
|
|
|
|
{
|
|
|
|
|
CommonWebApiResult result = new CommonWebApiResult { succ = true };
|
|
|
|
|
|
|
|
|
|
var emailUrl = _cache.GetAllDictData().GetAwaiter().GetResult()
|
|
|
|
|
.FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "email_api_url").Value;
|
|
|
|
|
|
|
|
|
|
EmailApiDto emailApiDto = new EmailApiDto
|
|
|
|
|
{
|
|
|
|
|
SendTo = sendType == "B" ? ediCfg.RECEIVEEMAIL : ediCfg.RECEIVESIEMAIL,
|
|
|
|
|
Title = sendType == "B" ? (bookingOrder.VOYNO + " " + bookingOrder.MBLNO + " IBOOKING") : (bookingOrder.MBLNO + " " + "ESI"),
|
|
|
|
|
Attaches = new List<AttachesInfo>(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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 base64Str = Convert.ToBase64String(heByte);
|
|
|
|
|
|
|
|
|
|
emailApiDto.Attaches.Add(new AttachesInfo {
|
|
|
|
|
AttachName = Path.GetFileName(filePath),
|
|
|
|
|
AttachContent = base64Str
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
string strJoin = System.IO.File.ReadAllText(filePath);
|
|
|
|
|
|
|
|
|
|
DateTime bDate = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
HttpResponseMessage res = null;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
res = await emailUrl.SetBody(emailApiDto, "application/json").PostAsync();
|
|
|
|
|
}
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation($"发送邮件异常:{ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DateTime eDate = DateTime.Now;
|
|
|
|
|
TimeSpan ts = eDate.Subtract(bDate);
|
|
|
|
|
var timeDiff = ts.TotalMilliseconds;
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"邮件上传完成 上传文件大小:{heByte.Length} 用时:{timeDiff}ms.,{strJoin}");
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"发送邮件返回:{JSON.Serialize(res)}");
|
|
|
|
|
|
|
|
|
|
if (res != null && res.StatusCode == System.Net.HttpStatusCode.OK)
|
|
|
|
|
{
|
|
|
|
|
var userResult = await res.Content.ReadAsStringAsync();
|
|
|
|
|
|
|
|
|
|
var respObj = JsonConvert.DeserializeAnonymousType(userResult, new
|
|
|
|
|
{
|
|
|
|
|
Success = false,
|
|
|
|
|
Message = string.Empty,
|
|
|
|
|
Code = -9999,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
result.succ = respObj.Success;
|
|
|
|
|
result.msg = respObj.Message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 转发EDI内部方法
|
|
|
|
|