wet 2 years ago
commit f6c5b10058

File diff suppressed because it is too large Load Diff

@ -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内部方法

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Myshipping.Application
{
public class EmailApiDto
{
public string SendTo { get; set; }
//public string CCTo { get; set; }
public string Title { get; set; }
public string Body { get; set; }
//public string ShowName { get; set; }
public string SmtpConfig { get; set; } = "SERVICE";
//public string Account { get; set; }
//public string Password { get; set; }
//public string Server { get; set; }
//public string Port { get; set; }
//public string UseSSL { get; set; }
public bool isCallback { get; set; } = false;
public List<AttachesInfo> Attaches { get; set; }
}
public class AttachesInfo
{
public string AttachName { get; set; }
public string AttachContent { get; set; }
}
}

@ -111,5 +111,13 @@ namespace Myshipping.Core.Entity
/// 租户名称
/// </summary>
public string TenantName { get; set; }
/// <summary>
/// 发送类型
/// </summary>
public string SendType { get; set; }
/// <summary>
/// 启用标志
/// </summary>
public bool EnableFlag { get; set; } = true;
}
}

@ -2034,6 +2034,16 @@
租户名称
</summary>
</member>
<member name="P:Myshipping.Core.Entity.DjyEdiSetting.SendType">
<summary>
发送类型
</summary>
</member>
<member name="P:Myshipping.Core.Entity.DjyEdiSetting.EnableFlag">
<summary>
启用标志
</summary>
</member>
<member name="T:Myshipping.Core.Entity.DjyTenantConfig">
<summary>
@ -10766,18 +10776,32 @@
</member>
<member name="M:Myshipping.Core.Service.DjyEdiSettingService.Add(Myshipping.Core.AddDjyEdiSettingInput)">
<summary>
增加EDI参数设置
增加EDI参数设置准备作废使用save接口代替
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="M:Myshipping.Core.Service.DjyEdiSettingService.Save(Myshipping.Core.UpdateDjyEdiSettingInput)">
<summary>
保存EDI参数设置
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="M:Myshipping.Core.Service.DjyEdiSettingService.Update(Myshipping.Core.UpdateDjyEdiSettingInput)">
<summary>
更新EDI参数设置
更新EDI参数设置准备作废使用save接口代替
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="M:Myshipping.Core.Service.DjyEdiSettingService.SetEnable(System.Int64)">
<summary>
设置启用启用后同船司、同发送类型的其他EDI通道会被取消启用
</summary>
<param name="id"></param>
<returns></returns>
</member>
<member name="M:Myshipping.Core.Service.DjyEdiSettingService.Delete(Myshipping.Core.GetDjyEdiSettingInput)">
<summary>
删除EDI参数设置
@ -15474,6 +15498,11 @@
租户名称
</summary>
</member>
<member name="P:Myshipping.Core.DjyEdiSettingInput.SendType">
<summary>
发送类型
</summary>
</member>
<member name="T:Myshipping.Core.AddDjyEdiSettingInput">
<summary>
EDI参数设置新增输入参数

@ -49,7 +49,7 @@ namespace Myshipping.Core.Service
}
/// <summary>
/// 增加EDI参数设置
/// 增加EDI参数设置准备作废使用save接口代替
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
@ -58,20 +58,80 @@ namespace Myshipping.Core.Service
{
var cc = _rep.AsQueryable()
.Filter(null, true)
.Count(x => x.EDICODE == input.EDICODE && x.TenantId == input.TenantId && x.CARRIERID == input.CARRIERID);
.Count(x => x.EDICODE == input.EDICODE && x.TenantId == input.TenantId && x.CARRIERID == input.CARRIERID && x.SendType == input.SendType);
if (cc > 0)
{
throw Oops.Bah($"该租户({input.TenantName})已存在相同类型({input.EDICODE}相同船司({input.CARRIERID})的参数设置");
throw Oops.Bah($"该租户({input.TenantName})已存在相同类型({input.EDICODE}相同船司({input.CARRIERID})、相同发送类型({input.SendType})的参数设置");
}
var entity = input.Adapt<DjyEdiSetting>();
await _rep.InsertAsync(entity);
await CacheData();
return entity.Id;
}
/// <summary>
/// 保存EDI参数设置
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/DjyEdiSetting/save")]
public async Task<long> Save(UpdateDjyEdiSettingInput input)
{
DjyEdiSetting entity = null;
if (input.Id == 0) //新增
{
var cc = _rep.AsQueryable()
.Filter(null, true)
.Count(x => x.EDICODE == input.EDICODE && x.TenantId == input.TenantId && x.CARRIERID == input.CARRIERID && x.SendType == input.SendType);
if (cc > 0)
{
throw Oops.Bah($"该租户({input.TenantName})已存在相同类型({input.EDICODE})、相同船司({input.CARRIERID})、相同发送类型({input.SendType})的参数设置");
}
entity = input.Adapt<DjyEdiSetting>();
await _rep.InsertAsync(entity);
//其他同船司、同发送类型的都禁用
var otherList = _rep.Where(x => x.TenantId == input.TenantId && x.CARRIERID == input.CARRIERID && x.Id != entity.Id).ToList();
foreach (var item in otherList)
{
item.EnableFlag = false;
await _rep.UpdateAsync(item);
}
}
else
{
entity = _rep.AsQueryable()
.Filter(null, true)
.First(x => x.Id == input.Id);
if (entity == null)
{
throw Oops.Bah($"未找到数据");
}
var cc = _rep.AsQueryable().Filter(null, true)
.Count(x => x.EDICODE == input.EDICODE && x.TenantId == input.TenantId && x.CARRIERID == input.CARRIERID && x.SendType == input.SendType && x.Id != input.Id);
if (cc > 0)
{
throw Oops.Bah($"该租户({input.TenantName})已存在相同类型({input.EDICODE})、相同船司({input.CARRIERID})、相同发送类型({input.SendType})的参数设置");
}
entity = input.Adapt(entity);
await _rep.UpdateAsync(entity);
}
await CacheData();
return entity.Id;
}
/// <summary>
/// 更新EDI参数设置
/// 更新EDI参数设置准备作废使用save接口代替
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
@ -87,10 +147,10 @@ namespace Myshipping.Core.Service
}
var cc = _rep.AsQueryable().Filter(null, true)
.Count(x => x.EDICODE == input.EDICODE && x.TenantId == input.TenantId && x.CARRIERID == input.CARRIERID && x.Id != input.Id);
.Count(x => x.EDICODE == input.EDICODE && x.TenantId == input.TenantId && x.CARRIERID == input.CARRIERID && x.SendType == input.SendType && x.Id != input.Id);
if (cc > 0)
{
throw Oops.Bah($"该租户({input.TenantName})已存在相同类型({input.EDICODE}相同船司({input.CARRIERID})的参数设置");
throw Oops.Bah($"该租户({input.TenantName})已存在相同类型({input.EDICODE}相同船司({input.CARRIERID})、相同发送类型({input.SendType})的参数设置");
}
entity = input.Adapt(entity);
@ -100,6 +160,35 @@ namespace Myshipping.Core.Service
return entity.Id;
}
/// <summary>
/// 设置启用启用后同船司、同发送类型的其他EDI通道会被取消启用
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpPost("/DjyEdiSetting/SetEnable")]
public async Task SetEnable(long id)
{
var entity = _rep.AsQueryable()
.Filter(null, true)
.First(x => x.Id == id);
if (entity == null)
{
throw Oops.Bah($"未找到数据");
}
entity.EnableFlag = true;
await _rep.UpdateAsync(entity);
//其他同船司、同发送类型的都禁用
var otherList = _rep.Where(x => x.TenantId == entity.TenantId && x.CARRIERID == entity.CARRIERID && x.Id != entity.Id).ToList();
foreach (var item in otherList)
{
item.EnableFlag = false;
await _rep.UpdateAsync(item);
}
}
/// <summary>
/// 删除EDI参数设置
/// </summary>

@ -138,6 +138,10 @@ namespace Myshipping.Core
/// 租户名称
/// </summary>
public virtual string TenantName { get; set; }
/// <summary>
/// 发送类型
/// </summary>
public string SendType { get; set; } = string.Empty;
}

@ -10,10 +10,13 @@ namespace Myshipping.Core.Service
Task<dynamic> Page([FromQuery] QueryDjyEdiSettingInput input);
Task<long> Add(AddDjyEdiSettingInput input);
Task<long> Update(UpdateDjyEdiSettingInput input);
Task<long> Save(UpdateDjyEdiSettingInput input);
Task Delete(GetDjyEdiSettingInput input);
Task<DjyEdiSetting> Get([FromQuery] GetDjyEdiSettingInput input);
//Task<dynamic> List([FromQuery] QueryDjyEdiSettingInput input);
Task SetEnable(long id);
Task CacheData(bool flag);
}

Loading…
Cancel
Save