修改DRAFT 下载

optimize
jianghaiqing 2 years ago
parent 00ed27899a
commit 3b32912048

@ -452,6 +452,24 @@ namespace Myshipping.Application
4
5
*/
if(bookingOrder.CARRIERID.Equals("ESL", StringComparison.OrdinalIgnoreCase))
{
if(string.IsNullOrWhiteSpace(bookingOrder.TMBLNO))
{
if (!string.IsNullOrWhiteSpace(bookingOrder.CUSTNO))
{
result.bno = $"订 {bookingOrder.CUSTNO}";
}
else if (string.IsNullOrWhiteSpace(bookingOrder.MBLNO))
{
result.bno = $"NO.{sortNo}";
}
throw Oops.Bah($"EP号不能为空");
}
}
else
{
if (string.IsNullOrWhiteSpace(bookingOrder.MBLNO))
{
if (!string.IsNullOrWhiteSpace(bookingOrder.CUSTNO))
@ -465,7 +483,7 @@ namespace Myshipping.Application
throw Oops.Bah($"主提单号不能为空");
}
}
var bcOrDraftRouteCfg = _cache.GetAllMappingCarrier().GetAwaiter().GetResult()
.FirstOrDefault(t => t.Module.Equals(CONST_MAPPING_DRAFT_MODULE_ROUTE, StringComparison.OrdinalIgnoreCase)
@ -509,6 +527,42 @@ namespace Myshipping.Application
if (userWebAccountConfig == null)
throw Oops.Oh($" 未配置个人或公司网站账户,网站{webKey}");
string downloadFilePathRlt = string.Empty;
string erroMsg = string.Empty;
if(bcOrDraftRouteCfg.MapCode.Trim().Equals("TSL", StringComparison.OrdinalIgnoreCase))
{
ESLDraftRequestDto requestDto = new ESLDraftRequestDto
{
u = userWebAccountConfig.Account?.Trim(),
p = userWebAccountConfig.Password?.Trim(),
ep_code = bookingOrder.TMBLNO?.Trim().ToUpper(),
};
_logger.LogInformation("批次={no} json={json} 请求Draft远端下载开始", batchNo, JSON.Serialize(requestDto));
DateTime bDate = DateTime.Now;
//开始请求BC
var rlt = await ExcuteESLDraftDownload(bcUrl, requestDto, batchNo);
DateTime eDate = DateTime.Now;
TimeSpan ts = eDate.Subtract(bDate);
var timeDiff = ts.TotalMilliseconds;
_logger.LogInformation("批次={no} result={result} 请求Draft远端下载结束 耗时:{timeDiff}ms. ", batchNo,
JSON.Serialize(rlt), timeDiff);
if (rlt.status == 1)
{
downloadFilePathRlt = rlt.data.api_path;
}
else
{
erroMsg = rlt.message;
}
}
else
{
BCOrDraftRequestDto requestDto = new BCOrDraftRequestDto
{
user_key = App.Configuration["BCOrDraftUserKey"],
@ -533,10 +587,20 @@ namespace Myshipping.Application
JSON.Serialize(rlt), timeDiff);
if (rlt.code == 200)
{
downloadFilePathRlt = rlt.data.FirstOrDefault().path;
}
else
{
erroMsg = rlt.msg;
}
}
if (!string.IsNullOrWhiteSpace(downloadFilePathRlt))
{
_logger.LogInformation("批次={no} 下载文件成功,转存本地", batchNo);
string currFilePath = rlt.data.FirstOrDefault().path;
string currFilePath = downloadFilePathRlt;
string fileTypeCode = "draft";
string fileTypeName = "Draft";
@ -594,7 +658,7 @@ namespace Myshipping.Application
else
{
result.succ = false;
result.msg = $"Draft下载失败原因={rlt.msg}";
result.msg = $"Draft下载失败原因={erroMsg}";
}
}
catch (Exception ex)
@ -705,6 +769,53 @@ namespace Myshipping.Application
}
#endregion
#region ESL Draft请求远端下载
/// <summary>
/// ESL Draft请求远端下载
/// 由于现有的ESL和TSL接口不一致需要提供单独的POST方法
/// </summary>
/// <param name="url">请求URL</param>
/// <param name="info">请求详情</param>
/// <param name="batchNo">批次号</param>
/// <returns>返回结果</returns>
[NonAction]
private async Task<ESLDraftAPIBaseResult> ExcuteESLDraftDownload(string url, ESLDraftRequestDto info, string batchNo)
{
ESLDraftAPIBaseResult 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();
model = JSON.Deserialize<ESLDraftAPIBaseResult>(userResult);
}
}
catch (Exception ex)
{
//写日志
if (ex is HttpRequestException)
throw Oops.Oh(10000002);
}
return model;
}
#endregion
/// <summary>
/// 到港时间更新

Loading…
Cancel
Save