修改TSL EDI 和车队检索

optimize
jianghaiqing 2 years ago
parent b80d785587
commit d9ffa460e3

@ -1339,9 +1339,9 @@ namespace Myshipping.Application.EDI.TSL
if (bill.CARGOID == "R") if (bill.CARGOID == "R")
{ {
if (string.IsNullOrWhiteSpace(bill.REEFERF)) if (!string.IsNullOrWhiteSpace(bill.REEFERF))
r.WriteLine("MEA+AAE+AAS+CBM:" + bill.REEFERF + "'"); r.WriteLine("MEA+AAE+AAS+CBM:" + bill.REEFERF + "'");
if (string.IsNullOrWhiteSpace(bill.HUMIDITY)) if (!string.IsNullOrWhiteSpace(bill.HUMIDITY))
r.WriteLine("MEA+AAE+AAO+HMD:" + bill.HUMIDITY + "'"); r.WriteLine("MEA+AAE+AAO+HMD:" + bill.HUMIDITY + "'");
r.WriteLine("TMP+2+" + bill.TEMPSET + ":CEL'"); r.WriteLine("TMP+2+" + bill.TEMPSET + ":CEL'");
icount = icount + 2; icount = icount + 2;

@ -169,10 +169,10 @@ namespace Myshipping.Application
if (bcOrDraftRouteCfg == null) if (bcOrDraftRouteCfg == null)
{ {
_logger.LogInformation("提单号【{mbl}】根据订舱的船公司代码{ca} 提取船公司映射失败", _logger.LogInformation("提单号{mbl} 根据订舱的船公司代码{ca} 提取船公司映射失败",
bookingOrder.MBLNO, bookingOrder.CARRIERID); bookingOrder.MBLNO, bookingOrder.CARRIERID);
throw Oops.Bah("提单号={mbl} 船公司={ca} 未配置BC和DRAFT下载路由请联系管理员配置", bookingOrder.MBLNO, bookingOrder.CARRIERID); throw Oops.Oh("提单号={0} 船公司={1} 未配置BC和DRAFT下载路由请联系管理员配置", bookingOrder.MBLNO, bookingOrder.CARRIERID);
} }
string urlKey = string.Format(CONST_FORMAT_BC_URL, bcOrDraftRouteCfg.MapCode.ToLower()); string urlKey = string.Format(CONST_FORMAT_BC_URL, bcOrDraftRouteCfg.MapCode.ToLower());
@ -180,23 +180,28 @@ namespace Myshipping.Application
var bcUrl = _cache.GetAllDictData().GetAwaiter().GetResult() var bcUrl = _cache.GetAllDictData().GetAwaiter().GetResult()
.FirstOrDefault(x => x.TypeCode == "url_set" && x.Code.Equals(urlKey, StringComparison.OrdinalIgnoreCase))?.Value; .FirstOrDefault(x => x.TypeCode == "url_set" && x.Code.Equals(urlKey, StringComparison.OrdinalIgnoreCase))?.Value;
_logger.LogInformation("提单号【{mbl}】根据订舱的船公司代码{ca} 提取BC下载URL完成结果={rlt}", _logger.LogInformation("提单号{mbl} 根据订舱的船公司代码{ca} 提取BC下载URL完成结果={rlt}",
bookingOrder.MBLNO, bookingOrder.CARRIERID, bcUrl); bookingOrder.MBLNO, bookingOrder.CARRIERID, bcUrl);
if (string.IsNullOrWhiteSpace(bcUrl)) if (string.IsNullOrWhiteSpace(bcUrl))
{ {
_logger.LogInformation("提单号【{mbl}】根据订舱的船公司代码{ca} 提取BC下载URL失败未取到配置key={key}", _logger.LogInformation("提单号{0} 根据订舱的船公司代码{1} 提取BC下载URL失败未取到配置key={key}",
bookingOrder.MBLNO, bookingOrder.CARRIERID, urlKey);
throw Oops.Oh("提单号{0} 根据订舱的船公司代码{1} 提取BC下载URL失败未取到配置key={key}",
bookingOrder.MBLNO, bookingOrder.CARRIERID, urlKey); bookingOrder.MBLNO, bookingOrder.CARRIERID, urlKey);
} }
string webKey = string.Format(CONST_FORMAT_WEB, bcOrDraftRouteCfg.MapCode.ToLower());
//获取个人对应的账户,这里GetAccountConfig逻辑优先取个人个人没有配置取公司对应配置 //获取个人对应的账户,这里GetAccountConfig逻辑优先取个人个人没有配置取公司对应配置
var userWebAccountConfig = _webAccountConfig.GetAccountConfig(CONST_FORMAT_WEB, UserManager.UserId).GetAwaiter() var userWebAccountConfig = _webAccountConfig.GetAccountConfig(webKey, UserManager.UserId).GetAwaiter()
.GetResult(); .GetResult();
_logger.LogInformation("批次={no} 获取获取网站的账户完成result={Num}", batchNo, JSON.Serialize(userWebAccountConfig)); _logger.LogInformation("批次={no} 获取获取网站的账户完成result={Num}", batchNo, JSON.Serialize(userWebAccountConfig));
if (userWebAccountConfig == null) if (userWebAccountConfig == null)
throw Oops.Bah($"个人/公司网站【{CONST_FORMAT_WEB}】获取失败,请维护个人/公司网站账户信息"); throw Oops.Oh($"个人/公司网站【{webKey}】获取失败,请维护个人/公司网站账户信息");
BCOrDraftRequestDto requestDto = new BCOrDraftRequestDto BCOrDraftRequestDto requestDto = new BCOrDraftRequestDto
{ {
@ -357,20 +362,20 @@ namespace Myshipping.Application
foreach (var bk in list) foreach (var bk in list)
{ {
taskList.Add(InnerDownloadBookingConfirm(bk, batchNo)); taskList.Add(InnerDownloadDraft(bk, batchNo));
} }
Task.WaitAll(taskList.ToArray()); Task.WaitAll(taskList.ToArray());
result.succ = true; result.succ = true;
result.msg = "批量下载BC成功"; result.msg = "下载Draft成功";
var downResultList = taskList.Select(x => x.Result).ToList(); var downResultList = taskList.Select(x => x.Result).ToList();
if (downResultList.Any(x => !x.succ)) if (downResultList.Any(x => !x.succ))
{ {
result.succ = false; result.succ = false;
result.msg = "BC下载失败"; result.msg = "Draft下载失败";
} }
else else
{ {
@ -397,7 +402,7 @@ namespace Myshipping.Application
catch (Exception ex) catch (Exception ex)
{ {
result.succ = false; result.succ = false;
result.msg = $"批量下载Draft异常原因{ex.Message}"; result.msg = $"下载Draft异常原因{ex.Message}";
} }
return result; return result;
@ -429,15 +434,15 @@ namespace Myshipping.Application
.FirstOrDefault(t => t.Module.Equals(CONST_MAPPING_CARRIER_MODULE_ROUTE, StringComparison.OrdinalIgnoreCase) .FirstOrDefault(t => t.Module.Equals(CONST_MAPPING_CARRIER_MODULE_ROUTE, StringComparison.OrdinalIgnoreCase)
&& t.Code.Equals(bookingOrder.CARRIERID?.Trim(), StringComparison.OrdinalIgnoreCase)); && t.Code.Equals(bookingOrder.CARRIERID?.Trim(), StringComparison.OrdinalIgnoreCase));
_logger.LogInformation("提单号【{mbl}】根据订舱的船公司代码{ca} 提取船公司映射完成,结果={rlt}", _logger.LogInformation("提单号{mbl} 根据订舱的船公司代码{ca} 提取船公司映射完成,结果={rlt}",
bookingOrder.MBLNO, bookingOrder.CARRIERID, bcOrDraftRouteCfg); bookingOrder.MBLNO, bookingOrder.CARRIERID, bcOrDraftRouteCfg);
if (bcOrDraftRouteCfg == null) if (bcOrDraftRouteCfg == null)
{ {
_logger.LogInformation("提单号【{mbl}】根据订舱的船公司代码{ca} 提取船公司映射失败", _logger.LogInformation("提单号{0} 根据订舱的船公司代码{1} 提取船公司映射失败",
bookingOrder.MBLNO, bookingOrder.CARRIERID); bookingOrder.MBLNO, bookingOrder.CARRIERID);
throw Oops.Bah("提单号={mbl} 船公司={ca} 未配置BC和DRAFT下载路由请联系管理员配置", bookingOrder.MBLNO, bookingOrder.CARRIERID); throw Oops.Oh("提单号={0} 船公司={1} 未配置BC和DRAFT下载路由请联系管理员配置", bookingOrder.MBLNO, bookingOrder.CARRIERID);
} }
string urlKey = string.Format(CONST_FORMAT_DRAFT_URL, bcOrDraftRouteCfg.MapCode.ToLower()); string urlKey = string.Format(CONST_FORMAT_DRAFT_URL, bcOrDraftRouteCfg.MapCode.ToLower());
@ -445,26 +450,28 @@ namespace Myshipping.Application
var bcUrl = _cache.GetAllDictData().GetAwaiter().GetResult() var bcUrl = _cache.GetAllDictData().GetAwaiter().GetResult()
.FirstOrDefault(x => x.TypeCode == "url_set" && x.Code.Equals(urlKey, StringComparison.OrdinalIgnoreCase))?.Value; .FirstOrDefault(x => x.TypeCode == "url_set" && x.Code.Equals(urlKey, StringComparison.OrdinalIgnoreCase))?.Value;
_logger.LogInformation("提单号【{mbl}】根据订舱的船公司代码{ca} 提取DRAFT下载URL完成结果={rlt}", _logger.LogInformation("提单号{mbl} 根据订舱的船公司代码{ca} 提取DRAFT下载URL完成结果={rlt}",
bookingOrder.MBLNO, bookingOrder.CARRIERID, bcUrl); bookingOrder.MBLNO, bookingOrder.CARRIERID, bcUrl);
if (string.IsNullOrWhiteSpace(bcUrl)) if (string.IsNullOrWhiteSpace(bcUrl))
{ {
_logger.LogInformation("提单号【{mbl}】根据订舱的船公司代码{ca} 提取BC下载URL失败未取到配置key={key}", _logger.LogInformation("提单号{0} 根据订舱的船公司代码{1} 提取BC下载URL失败未取到配置key={key}",
bookingOrder.MBLNO, bookingOrder.CARRIERID, urlKey); bookingOrder.MBLNO, bookingOrder.CARRIERID, urlKey);
}
string accountTypeCode = string.Empty; throw Oops.Oh("提单号{0} 根据订舱的船公司代码{1} 提取BC下载URL失败未取到配置key={key}",
bookingOrder.MBLNO, bookingOrder.CARRIERID, urlKey);
}
string webKey = string.Format(CONST_FORMAT_WEB, bcOrDraftRouteCfg.MapCode.ToLower());
//获取个人对应的账户,这里GetAccountConfig逻辑优先取个人个人没有配置取公司对应配置 //获取个人对应的账户,这里GetAccountConfig逻辑优先取个人个人没有配置取公司对应配置
var userWebAccountConfig = _webAccountConfig.GetAccountConfig(CONST_FORMAT_WEB, UserManager.UserId).GetAwaiter() var userWebAccountConfig = _webAccountConfig.GetAccountConfig(webKey, UserManager.UserId).GetAwaiter()
.GetResult(); .GetResult();
_logger.LogInformation("批次={no} 获取获取网站的账户完成result={Num}", batchNo, JSON.Serialize(userWebAccountConfig)); _logger.LogInformation("批次={no} 获取获取网站的账户完成result={Num}", batchNo, JSON.Serialize(userWebAccountConfig));
if (userWebAccountConfig == null) if (userWebAccountConfig == null)
throw Oops.Bah($"个人/公司网站【{CONST_FORMAT_WEB}】获取失败,请维护个人/公司网站账户信息"); throw Oops.Oh($"个人/公司网站【{webKey}】获取失败,请维护个人/公司网站账户信息");
BCOrDraftRequestDto requestDto = new BCOrDraftRequestDto BCOrDraftRequestDto requestDto = new BCOrDraftRequestDto
{ {
@ -480,7 +487,7 @@ namespace Myshipping.Application
DateTime bDate = DateTime.Now; DateTime bDate = DateTime.Now;
//开始请求BC //开始请求BC
var rlt = await ExcuteBCDownload(bcUrl, requestDto, batchNo); var rlt = await ExcuteDraftDownload(bcUrl, requestDto, batchNo);
DateTime eDate = DateTime.Now; DateTime eDate = DateTime.Now;
TimeSpan ts = eDate.Subtract(bDate); TimeSpan ts = eDate.Subtract(bDate);
@ -495,13 +502,13 @@ namespace Myshipping.Application
string currFilePath = rlt.data.path; string currFilePath = rlt.data.path;
string fileTypeCode = "bc"; string fileTypeCode = "draft";
string fileTypeName = "Booking Confirmation"; string fileTypeName = "Draft";
//读取文件配置 //读取文件配置
var fileCfg = App.GetOptions<BookingAttachOptions>(); var fileCfg = App.GetOptions<BookingAttachOptions>();
string relativePath = $"{fileCfg.relativePath}\\bcfiles\\{bookingOrder.Id}"; string relativePath = $"{fileCfg.relativePath}\\draftfiles\\{bookingOrder.Id}";
string filePath = $"{(!string.IsNullOrWhiteSpace(fileCfg.basePath) ? fileCfg.basePath : App.WebHostEnvironment.WebRootPath)}\\{relativePath}"; string filePath = $"{(!string.IsNullOrWhiteSpace(fileCfg.basePath) ? fileCfg.basePath : App.WebHostEnvironment.WebRootPath)}\\{relativePath}";
string fileFullName = $"{filePath}\\{new System.IO.FileInfo(currFilePath).Name}"; string fileFullName = $"{filePath}\\{new System.IO.FileInfo(currFilePath).Name}";
@ -546,36 +553,85 @@ namespace Myshipping.Application
fileTypeCode, fileTypeName); fileTypeCode, fileTypeName);
result.succ = true; result.succ = true;
result.msg = "BC下载成功"; result.msg = "Draft下载成功";
} }
else else
{ {
result.succ = false; result.succ = false;
result.msg = $"BC下载失败,原因={rlt.msg}"; result.msg = $"Draft下载失败,原因={rlt.msg}";
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
result.succ = false; result.succ = false;
result.msg = $"BC下载失败,原因:{ex.Message}"; result.msg = $"Draft下载失败,原因:{ex.Message}";
} }
return result; return result;
} }
#endregion #endregion
#region 请求远端下载 #region BC请求远端下载
/// <summary>
/// BC请求远端下载
/// </summary>
/// <param name="url">请求URL</param>
/// <param name="info">请求详情</param>
/// <param name="batchNo">批次号</param>
/// <returns>返回结果</returns>
[NonAction]
private async Task<BCAPIBaseResult> ExcuteBCDownload(string url, BCOrDraftRequestDto info, string batchNo)
{
BCAPIBaseResult model = null;
/*
1JSON
2POST
3
*/
try
{
_logger.LogInformation("批次={no} 对应请求报文 request={res}", batchNo, JSON.Serialize(info));
var res = await url.SetHttpMethod(HttpMethod.Post)
.SetBody(JSON.Serialize(info), "application/json")
.SetContentEncoding(Encoding.UTF8)
.PostAsync();
_logger.LogInformation("批次={no} 对应请求报文完成 res={res}", batchNo, JSON.Serialize(res));
if (res.StatusCode == System.Net.HttpStatusCode.OK)
{
var userResult = await res.Content.ReadAsStringAsync();
System.Text.Json.JsonSerializerOptions jsonOptions = new JsonSerializerOptions();
jsonOptions.Converters.Add(new DateTimeJsonConverter("yyyy-MM-dd HH:mm:ss"));
model = JSON.Deserialize<BCAPIBaseResult>(userResult, jsonOptions);
}
}
catch (Exception ex)
{
//写日志
if (ex is HttpRequestException)
throw Oops.Oh(10000002);
}
return model;
}
#endregion
#region Draft请求远端下载
/// <summary> /// <summary>
/// 请求远端下载 /// Draft请求远端下载
/// </summary> /// </summary>
/// <param name="url">请求URL</param> /// <param name="url">请求URL</param>
/// <param name="info">请求详情</param> /// <param name="info">请求详情</param>
/// <param name="batchNo">批次号</param> /// <param name="batchNo">批次号</param>
/// <returns>返回结果</returns> /// <returns>返回结果</returns>
[NonAction] [NonAction]
private async Task<BCAPIBaseResult<BCAPIBaseDataParse>> ExcuteBCDownload(string url, BCOrDraftRequestDto info, string batchNo) private async Task<DraftAPIBaseResult> ExcuteDraftDownload(string url, BCOrDraftRequestDto info, string batchNo)
{ {
BCAPIBaseResult<BCAPIBaseDataParse> model = null; DraftAPIBaseResult model = null;
/* /*
1JSON 1JSON
2POST 2POST
@ -599,7 +655,7 @@ namespace Myshipping.Application
System.Text.Json.JsonSerializerOptions jsonOptions = new JsonSerializerOptions(); System.Text.Json.JsonSerializerOptions jsonOptions = new JsonSerializerOptions();
jsonOptions.Converters.Add(new DateTimeJsonConverter("yyyy-MM-dd HH:mm:ss")); jsonOptions.Converters.Add(new DateTimeJsonConverter("yyyy-MM-dd HH:mm:ss"));
model = JSON.Deserialize<BCAPIBaseResult<BCAPIBaseDataParse>>(userResult, jsonOptions); model = JSON.Deserialize<DraftAPIBaseResult>(userResult, jsonOptions);
} }
} }
catch (Exception ex) catch (Exception ex)

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Myshipping.Application namespace Myshipping.Application
{ {
public class BCAPIBaseResult<T> public class BCAPIBaseResult
{ {
/// <summary> /// <summary>
/// 回执代码 /// 回执代码
@ -21,20 +21,23 @@ namespace Myshipping.Application
/// <summary> /// <summary>
/// 数据集 /// 数据集
/// </summary> /// </summary>
public BCAPIBaseData<T> data { get; set; } public BCAPIBaseData data { get; set; }
} }
public class BCAPIBaseData<T> public class BCOrDraftAPIBaseData
{ {
/// <summary> /// <summary>
/// 文件下载路径 /// 文件下载路径
/// </summary> /// </summary>
public string path { get; set; } public string path { get; set; }
}
public class BCAPIBaseData : BCOrDraftAPIBaseData
{
/// <summary> /// <summary>
/// 解析详情 /// 解析详情
/// </summary> /// </summary>
public T parse { get; set; } public BCAPIBaseDataParse parse { get; set; }
} }
public class BCAPIBaseDataParse public class BCAPIBaseDataParse
@ -73,5 +76,25 @@ namespace Myshipping.Application
public List<BCReadModel> BCList { get; set; } public List<BCReadModel> BCList { get; set; }
} }
public class DraftAPIBaseResult
{
/// <summary>
/// 回执代码
/// </summary>
public int code { get; set; }
/// <summary>
/// 提示信息
/// </summary>
public string msg { get; set; }
/// <summary>
/// 数据集
/// </summary>
public DraftAPIBaseData data { get; set; }
}
public class DraftAPIBaseData : BCOrDraftAPIBaseData
{
}
} }

@ -14,6 +14,7 @@ using Microsoft.Extensions.Logging;
using System; using System;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using NPOI.Util; using NPOI.Util;
using StackExchange.Profiling.Internal;
namespace Myshipping.Core.Service namespace Myshipping.Core.Service
{ {
@ -221,19 +222,13 @@ namespace Myshipping.Core.Service
try try
{ {
string sqlWhere = "1=1";
if (!string.IsNullOrWhiteSpace(queryItem)) var entityList = await _rep.AsQueryable()
{ .WhereIF(!string.IsNullOrWhiteSpace(queryItem), x =>
sqlWhere += $" and (CodeName like '%{queryItem.Trim()}%' or ShortName like '%{queryItem.Trim()}%' or FullName like '%{queryItem.Trim()}%')"; x.CodeName.Contains(queryItem)|| x.ShortName.Contains(queryItem) || x.FullName.Contains(queryItem))
} .WhereIF(queryType.Length > 0, x =>
x.PropString.Contains(queryType.FirstOrDefault()))
if (queryType.Length > 0) .Take(top).OrderBy(a => a.FullName)
{
sqlWhere += $" and PropString REGEXP '" + string.Join("|", queryType) + "'";
}
var entityList = await _rep.AsQueryable().Where(sqlWhere).Take(top).OrderBy(a => a.FullName)
.ToListAsync(); .ToListAsync();
if (entityList.Count > 0) if (entityList.Count > 0)

Loading…
Cancel
Save