|
|
@ -2612,9 +2612,25 @@ namespace Myshipping.Application
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 单票正本下载
|
|
|
|
/// 单票正本下载
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public async Task<TaskManageOrderResultDto> DownloadOriginal(long id)
|
|
|
|
[HttpGet("/BookingValueAdded/DownloadOriginal")]
|
|
|
|
|
|
|
|
public async Task<TaskManageOrderResultDto> DownloadOriginal(long id, bool? isCheck)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
const string FileTypeCode = "zhengben";
|
|
|
|
|
|
|
|
const string FileTypeName = "正本";
|
|
|
|
|
|
|
|
|
|
|
|
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
|
|
|
|
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isCheck == true)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (await _bookingFileRepository.IsExistsAsync(x => x.BookingId == id && x.TypeCode == FileTypeCode))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
result.status = -1;
|
|
|
|
|
|
|
|
result.succ = false;
|
|
|
|
|
|
|
|
result.msg = "文件已存在";
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (id < 0)
|
|
|
|
if (id < 0)
|
|
|
@ -2625,24 +2641,26 @@ namespace Myshipping.Application
|
|
|
|
if (order == null)
|
|
|
|
if (order == null)
|
|
|
|
throw Oops.Oh($"订舱信息获取失败(订舱信息不存在或已作废)");
|
|
|
|
throw Oops.Oh($"订舱信息获取失败(订舱信息不存在或已作废)");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result.bno = order.MBLNO;
|
|
|
|
result.bno = order.MBLNO;
|
|
|
|
|
|
|
|
|
|
|
|
var allSysConfig = _cache.GetAllSysConfig().Result;
|
|
|
|
var allSysConfig = _cache.GetAllSysConfig().Result;
|
|
|
|
var url = allSysConfig.FirstOrDefault(x => x.Code == "OriginalServiceUrl")?.Value;
|
|
|
|
var url = allSysConfig.FirstOrDefault(x => x.Code == "DraftDownloadServiceUrl")?.Value;
|
|
|
|
var key = allSysConfig.FirstOrDefault(x => x.Code == "OriginalServiceKey")?.Value;
|
|
|
|
var key = allSysConfig.FirstOrDefault(x => x.Code == "DraftDownloadServiceKey")?.Value;
|
|
|
|
var secret = allSysConfig.FirstOrDefault(x => x.Code == "OriginalServiceSecret")?.Value;
|
|
|
|
var token = allSysConfig.FirstOrDefault(x => x.Code == "DraftDownloadServiceToken")?.Value;
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(url))
|
|
|
|
if (string.IsNullOrWhiteSpace(url))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw Oops.Bah("正本下载服务接口地址未配置,请联系管理员");
|
|
|
|
throw Oops.Bah("单据下载服务接口地址未配置,请联系管理员");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(key))
|
|
|
|
if (string.IsNullOrWhiteSpace(key))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw Oops.Bah("正本下载服务接口Key未配置,请联系管理员");
|
|
|
|
throw Oops.Bah("单据下载服务接口Key未配置,请联系管理员");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(secret))
|
|
|
|
if (string.IsNullOrWhiteSpace(token))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw Oops.Bah("正本下载服务接口Secret未配置,请联系管理员");
|
|
|
|
throw Oops.Bah("单据下载服务接口Token未配置,请联系管理员");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var webAccount = _webAccountConfigService.GetAccountConfig("MSKWeb", UserManager.UserId).Result;
|
|
|
|
var webAccount = _webAccountConfigService.GetAccountConfig("MSKWeb", UserManager.UserId).Result;
|
|
|
@ -2651,6 +2669,10 @@ namespace Myshipping.Application
|
|
|
|
throw Oops.Bah("未配置网站账户,类型:MSKWeb");
|
|
|
|
throw Oops.Bah("未配置网站账户,类型:MSKWeb");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(order.ISSUETYPE))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw Oops.Bah("签单方式为空");
|
|
|
|
|
|
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(order.CARRIERID))
|
|
|
|
if (string.IsNullOrWhiteSpace(order.CARRIERID))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw Oops.Bah("船公司为空");
|
|
|
|
throw Oops.Bah("船公司为空");
|
|
|
@ -2664,7 +2686,7 @@ namespace Myshipping.Application
|
|
|
|
carrierId = (carrierId ?? order.CARRIERID).ToUpper();
|
|
|
|
carrierId = (carrierId ?? order.CARRIERID).ToUpper();
|
|
|
|
if (carrierId != "MSK")
|
|
|
|
if (carrierId != "MSK")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw Oops.Bah($"[{order.CARRIER}]船公司此功能待开发");
|
|
|
|
throw Oops.Bah($"船公司=[{order.CARRIER}]暂不支持正本下载");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 判断签单方式是否符合条件
|
|
|
|
// 判断签单方式是否符合条件
|
|
|
@ -2672,27 +2694,30 @@ namespace Myshipping.Application
|
|
|
|
issueType = issueType ?? order.ISSUETYPE;
|
|
|
|
issueType = issueType ?? order.ISSUETYPE;
|
|
|
|
if (!issueType.Equals("original", StringComparison.OrdinalIgnoreCase))
|
|
|
|
if (!issueType.Equals("original", StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw Oops.Bah("签单方式非[正本下载],无法下载正本");
|
|
|
|
throw Oops.Bah("此单签单方式非[正本下载],无法下载正本");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
url += "";
|
|
|
|
// 实时下载接口
|
|
|
|
|
|
|
|
url += "/documents_server/api/draft/v1/download_realtime";
|
|
|
|
var body = new
|
|
|
|
var body = new
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//user_key = key,
|
|
|
|
web_code = carrierId,
|
|
|
|
//user_secret = secret,
|
|
|
|
|
|
|
|
web_user = webAccount.Account,
|
|
|
|
web_user = webAccount.Account,
|
|
|
|
web_psw = webAccount.Password,
|
|
|
|
web_pwd = webAccount.Password,
|
|
|
|
//web_code = order.CarrierId,
|
|
|
|
bill_no = order.MBLNO,
|
|
|
|
//bno = order.MBLNO
|
|
|
|
consumer_key = key,
|
|
|
|
|
|
|
|
iscontent = false,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
var header = new Dictionary<string, object>()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
{ "Token",token }, { "Content-Type", "application/json" }
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("请求正本下载接口开始,mblno={mblno}, url={url}, body={body}", order.MBLNO, url, body);
|
|
|
|
_logger.LogInformation("请求正本下载接口开始,mblno={mblno}, url={url}, body={body}", order.MBLNO, url, body);
|
|
|
|
DateTime bDate = DateTime.Now;
|
|
|
|
DateTime bDate = DateTime.Now;
|
|
|
|
var rtn = await url.OnClientCreating(client =>
|
|
|
|
var rtn = await url.OnClientCreating(client =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// client 为 HttpClient 对象
|
|
|
|
|
|
|
|
client.Timeout = TimeSpan.FromMinutes(3); // 设置超时时间 3分钟
|
|
|
|
client.Timeout = TimeSpan.FromMinutes(3); // 设置超时时间 3分钟
|
|
|
|
}).SetBody(body).PostAsStringAsync();
|
|
|
|
}).SetBody(body).SetHeaders(header).PostAsStringAsync();
|
|
|
|
|
|
|
|
|
|
|
|
DateTime eDate = DateTime.Now;
|
|
|
|
DateTime eDate = DateTime.Now;
|
|
|
|
TimeSpan ts = eDate.Subtract(bDate);
|
|
|
|
TimeSpan ts = eDate.Subtract(bDate);
|
|
|
@ -2701,76 +2726,77 @@ namespace Myshipping.Application
|
|
|
|
_logger.LogInformation("请求正本下载接口结束,mblno={mblno}, rtn={rtn}, 耗时:{timeDiff}ms", order.MBLNO, rtn, timeDiff);
|
|
|
|
_logger.LogInformation("请求正本下载接口结束,mblno={mblno}, rtn={rtn}, 耗时:{timeDiff}ms", order.MBLNO, rtn, timeDiff);
|
|
|
|
|
|
|
|
|
|
|
|
var jsonRtn = JObject.Parse(rtn);
|
|
|
|
var jsonRtn = JObject.Parse(rtn);
|
|
|
|
if (jsonRtn.GetIntValue("code") == 200)
|
|
|
|
if (jsonRtn.GetIntValue("status") == 1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.LogInformation("请求正本下载接口成功,转存本地,mblno={mblno}", order.MBLNO);
|
|
|
|
_logger.LogInformation("请求正本下载接口成功,转存本地,mblno={mblno}", order.MBLNO);
|
|
|
|
|
|
|
|
|
|
|
|
result.succ = true;
|
|
|
|
var data = jsonRtn.GetJObjectValue("data");
|
|
|
|
result.msg = "正本下载成功";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//string currFilePath = rlt.data.FirstOrDefault().path;
|
|
|
|
// 远程文件路径
|
|
|
|
|
|
|
|
var remoteFilePath = data.GetStringValue("proxy_path");
|
|
|
|
|
|
|
|
// 真实文件名
|
|
|
|
|
|
|
|
var reallyFileName = data.GetStringValue("file_name");
|
|
|
|
|
|
|
|
|
|
|
|
//string fileTypeCode = "bc";
|
|
|
|
// 读取文件保存配置
|
|
|
|
//string fileTypeName = "Booking Confirmation";
|
|
|
|
var fileCfg = App.GetOptions<BookingAttachOptions>();
|
|
|
|
|
|
|
|
|
|
|
|
////读取文件配置
|
|
|
|
string relativePath = $"{fileCfg.relativePath}\\originalfiles\\{order.Id}";
|
|
|
|
//var fileCfg = App.GetOptions<BookingAttachOptions>();
|
|
|
|
string relativeDic = $"{(!string.IsNullOrWhiteSpace(fileCfg.basePath) ? fileCfg.basePath : App.WebHostEnvironment.WebRootPath)}\\{relativePath}";
|
|
|
|
|
|
|
|
|
|
|
|
//string relativePath = $"{fileCfg.relativePath}\\bcfiles\\{bookingOrder.Id}";
|
|
|
|
string fileSavePath = $"{relativeDic}\\{new System.IO.FileInfo(remoteFilePath).Name}";
|
|
|
|
//string filePath = $"{(!string.IsNullOrWhiteSpace(fileCfg.basePath) ? fileCfg.basePath : App.WebHostEnvironment.WebRootPath)}\\{relativePath}";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//string fileFullName = $"{filePath}\\{new System.IO.FileInfo(currFilePath).Name}";
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
relativePath = relativePath.Replace("\\", "/");
|
|
|
|
|
|
|
|
relativeDic = relativeDic.Replace("\\", "/");
|
|
|
|
|
|
|
|
|
|
|
|
//if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
|
|
fileSavePath = fileSavePath.Replace("\\", "/");
|
|
|
|
//{
|
|
|
|
}
|
|
|
|
// relativePath = relativePath.Replace("\\", "/");
|
|
|
|
|
|
|
|
// filePath = filePath.Replace("\\", "/");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// fileFullName = fileFullName.Replace("\\", "/");
|
|
|
|
_logger.LogInformation("mblno={mblno}, 生成文件保存路径完成 路由={relativeDic} 服务器系统={system}", order.MBLNO, relativeDic, RuntimeInformation.OSDescription);
|
|
|
|
//}
|
|
|
|
//预先创建目录
|
|
|
|
|
|
|
|
if (!Directory.Exists(relativeDic))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Directory.CreateDirectory(relativeDic);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//_logger.LogInformation("批次={no} 生成文件保存路径完成 路由={filePath} 服务器系统={system}", batchNo, filePath, RuntimeInformation.OSDescription);
|
|
|
|
var bcStream = await remoteFilePath.GetAsStreamAsync();
|
|
|
|
////预先创建目录
|
|
|
|
|
|
|
|
//if (!Directory.Exists(filePath))
|
|
|
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
// Directory.CreateDirectory(filePath);
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//var bcStream = await currFilePath.GetAsStreamAsync();
|
|
|
|
using (var fileStream = File.Create(fileSavePath))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
await bcStream.CopyToAsync(fileStream);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//using (var fileStream = File.Create(fileFullName))
|
|
|
|
_logger.LogInformation("mblno={mblno} 完成文件保存 filepath={path}", order.MBLNO, fileSavePath);
|
|
|
|
//{
|
|
|
|
|
|
|
|
// await bcStream.CopyToAsync(fileStream);
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//_logger.LogInformation("批次={no} 完成文件保存 filepath={path}", batchNo, fileFullName);
|
|
|
|
string bookFilePath = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
//string bookFilePath = string.Empty;
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bookFilePath = System.Text.RegularExpressions.Regex.Match(fileSavePath, relativePath.Replace("/", "\\/") + ".*").Value;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bookFilePath = System.Text.RegularExpressions.Regex.Match(fileSavePath, relativePath.Replace("\\", "\\\\") + ".*").Value;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
|
|
result.succ = true;
|
|
|
|
//{
|
|
|
|
result.msg = "正本下载成功";
|
|
|
|
// bookFilePath = System.Text.RegularExpressions.Regex.Match(fileFullName, relativePath.Replace("/", "\\/") + ".*").Value;
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
//else
|
|
|
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
// bookFilePath = System.Text.RegularExpressions.Regex.Match(fileFullName, relativePath.Replace("\\", "\\\\") + ".*").Value;
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////这里先写入附件表
|
|
|
|
await _bookingFileRepository.DeleteAsync(x => x.TypeCode == FileTypeCode && x.BookingId == order.Id);
|
|
|
|
//await SaveEDIFile(bookingOrder.Id, bookFilePath, new System.IO.FileInfo(currFilePath).Name,
|
|
|
|
await SaveEDIFile(order.Id, bookFilePath, reallyFileName, FileTypeCode, FileTypeName);
|
|
|
|
// fileTypeCode, fileTypeName);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var msg = jsonRtn.GetStringValue("msg")?.Replace("爬虫", "");
|
|
|
|
var msg = jsonRtn.GetStringValue("message")?.Replace("爬虫", "");
|
|
|
|
_logger.LogInformation("请求正本下载接口失败,mblno={mblno}, 服务返回:{msg}", order.MBLNO, msg);
|
|
|
|
_logger.LogInformation("请求正本下载接口失败,mblno={mblno}, 服务返回:{msg}", order.MBLNO, msg);
|
|
|
|
throw Oops.Bah(msg);
|
|
|
|
throw Oops.Bah(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
result.succ = false;
|
|
|
|
result.succ = false;
|
|
|
|
|
|
|
|
result.status = -2;
|
|
|
|
result.msg = $"正本下载失败,{ex.Message}";
|
|
|
|
result.msg = $"正本下载失败,{ex.Message}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|