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参数设置
/// 保存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参数设置准备作废使用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>
@ -141,7 +230,7 @@ namespace Myshipping.Core.Service
{
if (!_cacheService.Exists(CommonConst.CACHE_KEY_DJY_EDI_SETTING))
{
var list = _rep.AsQueryable().Filter(null, true).OrderBy(x=>x.EDINAME).ToList();
var list = _rep.AsQueryable().Filter(null, true).OrderBy(x => x.EDINAME).ToList();
await _cacheService.SetAllEdiSetting(list);
}
}

@ -13,132 +13,136 @@ namespace Myshipping.Core
/// EDI类型代码
/// </summary>
public virtual string EDICODE { get; set; }
/// <summary>
/// EDI类型名称
/// </summary>
public virtual string EDINAME { get; set; }
/// <summary>
/// 服务器IP
/// </summary>
public virtual string SERVERIP { get; set; }
/// <summary>
/// 文件夹
/// </summary>
public virtual string FOLDERNAME { get; set; }
/// <summary>
/// 用户名
/// </summary>
public virtual string USERNAME { get; set; }
/// <summary>
/// 密码
/// </summary>
public virtual string PASSWORD { get; set; }
/// <summary>
/// 发送方代码
/// </summary>
public virtual string SENDCODE { get; set; }
/// <summary>
/// 接收方代码
/// </summary>
public virtual string RECEIVECODE { get; set; }
/// <summary>
/// 发送方名称
/// </summary>
public virtual string SENDNAME { get; set; }
/// <summary>
/// 发送方联系人
/// </summary>
public virtual string SENDATTN { get; set; }
/// <summary>
/// 发送方邮箱
/// </summary>
public virtual string SENDTEL { get; set; }
/// <summary>
/// 发送方电话
/// </summary>
public virtual string SENDEMAIL { get; set; }
/// <summary>
/// 发送方公司代码
/// </summary>
public virtual string SENDCOMPANYCODE { get; set; }
/// <summary>
/// 发送方部门代码
/// </summary>
public virtual string SENDSUBCOMPANYCODE { get; set; }
/// <summary>
/// 船公司代码
/// </summary>
public virtual string CARRIERID { get; set; }
/// <summary>
/// 接收方邮箱
/// </summary>
public virtual string RECEIVEEMAIL { get; set; }
/// <summary>
/// 接收方SI邮箱
/// </summary>
public virtual string RECEIVESIEMAIL { get; set; }
/// <summary>
/// 接收方操作
/// </summary>
public virtual string RECEIVEOP { get; set; }
/// <summary>
/// 接收方销售
/// </summary>
public virtual string RECEIVESALE { get; set; }
/// <summary>
/// 接收方部门
/// </summary>
public virtual string RECEIVEDEPT { get; set; }
/// <summary>
/// 发送人电话
/// </summary>
public virtual string SHIPPERTEL { get; set; }
/// <summary>
/// 收货人电话
/// </summary>
public virtual string CONSIGNEETEL { get; set; }
/// <summary>
/// 通知人电话
/// </summary>
public virtual string NOTIFYPARTYTEL { get; set; }
/// <summary>
/// 是否设置TEL
/// </summary>
public virtual string ISUSETEL { get; set; }
/// <summary>
/// 租户ID
/// </summary>
public virtual long TenantId { get; set; }
/// <summary>
/// 租户名称
/// </summary>
public virtual string TenantName { get; set; }
/// <summary>
/// 发送类型
/// </summary>
public string SendType { get; set; } = string.Empty;
}
/// <summary>
@ -158,7 +162,7 @@ namespace Myshipping.Core
/// </summary>
[Required(ErrorMessage = "主键不能为空")]
public long Id { get; set; }
}
/// <summary>
@ -171,7 +175,7 @@ namespace Myshipping.Core
/// </summary>
[Required(ErrorMessage = "主键不能为空")]
public long Id { get; set; }
}
/// <summary>
@ -183,31 +187,31 @@ namespace Myshipping.Core
/// 主键
/// </summary>
public virtual long Id { get; set; }
/// <summary>
/// EDI类型代码
/// </summary>
public virtual string EDICODE { get; set; }
/// <summary>
/// EDI类型名称
/// </summary>
public virtual string EDINAME { get; set; }
/// <summary>
/// 船公司代码
/// </summary>
public virtual string CARRIERID { get; set; }
/// <summary>
/// 租户ID
/// </summary>
public virtual long TenantId { get; set; }
/// <summary>
/// 租户名称
/// </summary>
public virtual string TenantName { get; set; }
}
}

@ -10,11 +10,14 @@ 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