|
|
|
@ -169,10 +169,10 @@ namespace Myshipping.Application
|
|
|
|
|
|
|
|
|
|
if (bcOrDraftRouteCfg == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("提单号【{mbl}】根据订舱的船公司代码{ca} 提取船公司映射失败",
|
|
|
|
|
_logger.LogInformation("提单号{mbl} 根据订舱的船公司代码{ca} 提取船公司映射失败",
|
|
|
|
|
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());
|
|
|
|
@ -180,23 +180,28 @@ namespace Myshipping.Application
|
|
|
|
|
var bcUrl = _cache.GetAllDictData().GetAwaiter().GetResult()
|
|
|
|
|
.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);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string webKey = string.Format(CONST_FORMAT_WEB, bcOrDraftRouteCfg.MapCode.ToLower());
|
|
|
|
|
|
|
|
|
|
//获取个人对应的账户,这里GetAccountConfig逻辑优先取个人,个人没有配置取公司对应配置
|
|
|
|
|
var userWebAccountConfig = _webAccountConfig.GetAccountConfig(CONST_FORMAT_WEB, UserManager.UserId).GetAwaiter()
|
|
|
|
|
var userWebAccountConfig = _webAccountConfig.GetAccountConfig(webKey, UserManager.UserId).GetAwaiter()
|
|
|
|
|
.GetResult();
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("批次={no} 获取获取网站的账户完成,result={Num}", batchNo, JSON.Serialize(userWebAccountConfig));
|
|
|
|
|
|
|
|
|
|
if (userWebAccountConfig == null)
|
|
|
|
|
throw Oops.Bah($"个人/公司网站【{CONST_FORMAT_WEB}】获取失败,请维护个人/公司网站账户信息");
|
|
|
|
|
throw Oops.Oh($"个人/公司网站【{webKey}】获取失败,请维护个人/公司网站账户信息");
|
|
|
|
|
|
|
|
|
|
BCOrDraftRequestDto requestDto = new BCOrDraftRequestDto
|
|
|
|
|
{
|
|
|
|
@ -357,20 +362,20 @@ namespace Myshipping.Application
|
|
|
|
|
|
|
|
|
|
foreach (var bk in list)
|
|
|
|
|
{
|
|
|
|
|
taskList.Add(InnerDownloadBookingConfirm(bk, batchNo));
|
|
|
|
|
taskList.Add(InnerDownloadDraft(bk, batchNo));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Task.WaitAll(taskList.ToArray());
|
|
|
|
|
|
|
|
|
|
result.succ = true;
|
|
|
|
|
result.msg = "批量下载BC成功";
|
|
|
|
|
result.msg = "下载Draft成功";
|
|
|
|
|
|
|
|
|
|
var downResultList = taskList.Select(x => x.Result).ToList();
|
|
|
|
|
|
|
|
|
|
if (downResultList.Any(x => !x.succ))
|
|
|
|
|
{
|
|
|
|
|
result.succ = false;
|
|
|
|
|
result.msg = "BC下载失败";
|
|
|
|
|
result.msg = "Draft下载失败";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
@ -397,7 +402,7 @@ namespace Myshipping.Application
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
result.succ = false;
|
|
|
|
|
result.msg = $"批量下载Draft异常,原因:{ex.Message}";
|
|
|
|
|
result.msg = $"下载Draft异常,原因:{ex.Message}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
@ -429,15 +434,15 @@ namespace Myshipping.Application
|
|
|
|
|
.FirstOrDefault(t => t.Module.Equals(CONST_MAPPING_CARRIER_MODULE_ROUTE, 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);
|
|
|
|
|
|
|
|
|
|
if (bcOrDraftRouteCfg == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("提单号【{mbl}】根据订舱的船公司代码{ca} 提取船公司映射失败",
|
|
|
|
|
_logger.LogInformation("提单号{0} 根据订舱的船公司代码{1} 提取船公司映射失败",
|
|
|
|
|
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());
|
|
|
|
@ -445,26 +450,28 @@ namespace Myshipping.Application
|
|
|
|
|
var bcUrl = _cache.GetAllDictData().GetAwaiter().GetResult()
|
|
|
|
|
.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);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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逻辑优先取个人,个人没有配置取公司对应配置
|
|
|
|
|
var userWebAccountConfig = _webAccountConfig.GetAccountConfig(CONST_FORMAT_WEB, UserManager.UserId).GetAwaiter()
|
|
|
|
|
var userWebAccountConfig = _webAccountConfig.GetAccountConfig(webKey, UserManager.UserId).GetAwaiter()
|
|
|
|
|
.GetResult();
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("批次={no} 获取获取网站的账户完成,result={Num}", batchNo, JSON.Serialize(userWebAccountConfig));
|
|
|
|
|
|
|
|
|
|
if (userWebAccountConfig == null)
|
|
|
|
|
throw Oops.Bah($"个人/公司网站【{CONST_FORMAT_WEB}】获取失败,请维护个人/公司网站账户信息");
|
|
|
|
|
throw Oops.Oh($"个人/公司网站【{webKey}】获取失败,请维护个人/公司网站账户信息");
|
|
|
|
|
|
|
|
|
|
BCOrDraftRequestDto requestDto = new BCOrDraftRequestDto
|
|
|
|
|
{
|
|
|
|
@ -480,7 +487,7 @@ namespace Myshipping.Application
|
|
|
|
|
|
|
|
|
|
DateTime bDate = DateTime.Now;
|
|
|
|
|
//开始请求BC
|
|
|
|
|
var rlt = await ExcuteBCDownload(bcUrl, requestDto, batchNo);
|
|
|
|
|
var rlt = await ExcuteDraftDownload(bcUrl, requestDto, batchNo);
|
|
|
|
|
|
|
|
|
|
DateTime eDate = DateTime.Now;
|
|
|
|
|
TimeSpan ts = eDate.Subtract(bDate);
|
|
|
|
@ -495,13 +502,13 @@ namespace Myshipping.Application
|
|
|
|
|
|
|
|
|
|
string currFilePath = rlt.data.path;
|
|
|
|
|
|
|
|
|
|
string fileTypeCode = "bc";
|
|
|
|
|
string fileTypeName = "Booking Confirmation";
|
|
|
|
|
string fileTypeCode = "draft";
|
|
|
|
|
string fileTypeName = "Draft";
|
|
|
|
|
|
|
|
|
|
//读取文件配置
|
|
|
|
|
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 fileFullName = $"{filePath}\\{new System.IO.FileInfo(currFilePath).Name}";
|
|
|
|
@ -546,36 +553,85 @@ namespace Myshipping.Application
|
|
|
|
|
fileTypeCode, fileTypeName);
|
|
|
|
|
|
|
|
|
|
result.succ = true;
|
|
|
|
|
result.msg = "BC下载成功";
|
|
|
|
|
result.msg = "Draft下载成功";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result.succ = false;
|
|
|
|
|
result.msg = $"BC下载失败,原因={rlt.msg}";
|
|
|
|
|
result.msg = $"Draft下载失败,原因={rlt.msg}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
result.succ = false;
|
|
|
|
|
result.msg = $"BC下载失败,原因:{ex.Message}";
|
|
|
|
|
result.msg = $"Draft下载失败,原因:{ex.Message}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
#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;
|
|
|
|
|
/*
|
|
|
|
|
1、填充请求的类,并生成JSON报文
|
|
|
|
|
2、POST请求接口,并记录回执。
|
|
|
|
|
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>
|
|
|
|
|
/// 请求远端下载
|
|
|
|
|
/// Draft请求远端下载
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="url">请求URL</param>
|
|
|
|
|
/// <param name="info">请求详情</param>
|
|
|
|
|
/// <param name="batchNo">批次号</param>
|
|
|
|
|
/// <returns>返回结果</returns>
|
|
|
|
|
[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;
|
|
|
|
|
/*
|
|
|
|
|
1、填充请求的类,并生成JSON报文
|
|
|
|
|
2、POST请求接口,并记录回执。
|
|
|
|
@ -599,7 +655,7 @@ namespace Myshipping.Application
|
|
|
|
|
System.Text.Json.JsonSerializerOptions jsonOptions = new JsonSerializerOptions();
|
|
|
|
|
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)
|
|
|
|
|