单票正本下载

master
zhangxiaofeng 8 months ago
parent 2f97e87782
commit 834e5bfbdc

@ -12127,7 +12127,10 @@ namespace Myshipping.Application
};
_logger.LogInformation("请求电放提交接口开始mblnos={mblnos}, url={url}, body={body}", mblnos, url, body);
var rtn = await url.SetBody(body).PostAsStringAsync();
var rtn = await url.OnClientCreating(client =>
{
client.Timeout = TimeSpan.FromMinutes(3); // 设置超时时间 3分钟
}).SetBody(body).PostAsStringAsync();
_logger.LogInformation("请求电放提交接口结束rtn={rtn}", rtn);
var jsonRtn = JObject.Parse(rtn);

@ -16,6 +16,7 @@ using Myshipping.Application.Service.BookingOrder.Dto;
using Myshipping.Core;
using Myshipping.Core.Entity;
using Myshipping.Core.Service;
using Newtonsoft.Json.Linq;
using SqlSugar;
using StackExchange.Profiling.Internal;
using System;
@ -57,6 +58,7 @@ namespace Myshipping.Application
private readonly IServiceWorkFlowBaseService _serviceWorkFlowBaseService;
private readonly IServiceWorkFlowManageService _serviceWorkFlowManageService;
private readonly IDjyWebsiteAccountConfigService _webAccountConfigService;
private readonly INamedServiceProvider<IBookingOrderService> _namedBookingOrderServiceProvider;
const string CONST_MAPPING_BC_MODULE_ROUTE = "BC_DOWN_RT";
@ -81,7 +83,7 @@ namespace Myshipping.Application
SqlSugarRepository<BookingLog> bookinglogRepository, SqlSugarRepository<BookingLogDetail> bookinglogdetailRepository,
SqlSugarRepository<BookingRemark> bookingRemarkRepository, SqlSugarRepository<BookingFile> bookingFileRepository,
INamedServiceProvider<IBookingOrderService> namedBookingOrderServiceProvider,
IServiceWorkFlowManageService serviceWorkFlowManageService, SqlSugarRepository<BookingCtnVGM> bookingCtnVGMRepository)
IServiceWorkFlowManageService serviceWorkFlowManageService, SqlSugarRepository<BookingCtnVGM> bookingCtnVGMRepository, IDjyWebsiteAccountConfigService webAccountConfigService)
{
_cache = cache;
_logger = logger;
@ -105,6 +107,7 @@ namespace Myshipping.Application
_serviceWorkFlowManageService = serviceWorkFlowManageService;
_namedBookingOrderServiceProvider = namedBookingOrderServiceProvider;
_webAccountConfigService = webAccountConfigService;
}
@ -1684,7 +1687,7 @@ namespace Myshipping.Application
_logger.LogInformation("批次={no} id={id} templateid={tempid} 开始发送放舱", batchNo
, bookingOrder.Id, model.TemplateId);
//发送放舱
await _bookingOrderService.SendLetterYard(model.BookingOrderId, model.TemplateId);
@ -2583,13 +2586,14 @@ namespace Myshipping.Application
{
List<BookingCtnVGMDto> list = new List<BookingCtnVGMDto>();
if(id < 1)
if (id < 1)
throw Oops.Oh($"订舱ID为空");
var vgmList = _bookingCtnVGMRepository.AsQueryable().Where(t => t.BILLID == id).ToList();
var vgmList = _bookingCtnVGMRepository.AsQueryable().Where(t => t.BILLID == id).ToList();
if (vgmList.Count > 0)
list = vgmList.Select(t => new BookingCtnVGMDto {
list = vgmList.Select(t => new BookingCtnVGMDto
{
id = t.Id,
cntrNo = t.CNTRNO,
vgmWeight = t.VGM_WEIGHT,
@ -2604,6 +2608,173 @@ namespace Myshipping.Application
return list;
}
#endregion
/// <summary>
/// 单票正本下载
/// </summary>
public async Task<TaskManageOrderResultDto> DownloadOriginal(long id)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
if (id < 0)
throw Oops.Oh($"订舱ID为空");
var order = await _bookingOrderRepository.AsQueryable().FirstAsync(a => a.Id == id);
if (order == null)
throw Oops.Oh($"订舱信息获取失败(订舱信息不存在或已作废)");
result.bno = order.MBLNO;
var allSysConfig = _cache.GetAllSysConfig().Result;
var url = allSysConfig.FirstOrDefault(x => x.Code == "OriginalServiceUrl")?.Value;
var key = allSysConfig.FirstOrDefault(x => x.Code == "OriginalServiceKey")?.Value;
var secret = allSysConfig.FirstOrDefault(x => x.Code == "OriginalServiceSecret")?.Value;
if (string.IsNullOrWhiteSpace(url))
{
throw Oops.Bah("正本下载服务接口地址未配置,请联系管理员");
}
if (string.IsNullOrWhiteSpace(key))
{
throw Oops.Bah("正本下载服务接口Key未配置请联系管理员");
}
if (string.IsNullOrWhiteSpace(secret))
{
throw Oops.Bah("正本下载服务接口Secret未配置请联系管理员");
}
var webAccount = _webAccountConfigService.GetAccountConfig("MSKWeb", UserManager.UserId).Result;
if (webAccount == null)
{
throw Oops.Bah("未配置网站账户类型MSKWeb");
}
if (string.IsNullOrWhiteSpace(order.CARRIERID))
{
throw Oops.Bah("船公司为空");
}
var mappingCarrier = _cache.GetAllMappingCarrier().Result;
var mappingIssueType = _cache.GetAllMappingIssueType().Result;
// 判断船公司是否符合条件
string carrierId = mappingCarrier.FirstOrDefault(x => x.Module == "ORIGINAL_DOWN_RT" && x.Code == order.CARRIERID)?.MapCode;
carrierId = (carrierId ?? order.CARRIERID).ToUpper();
if (carrierId != "MSK")
{
throw Oops.Bah($"[{order.CARRIER}]船公司此功能待开发");
}
// 判断签单方式是否符合条件
string issueType = mappingIssueType.FirstOrDefault(x => x.Module == "ORIGINAL_DOWN_RT" && x.Code == order.ISSUETYPE)?.MapCode;
issueType = issueType ?? order.ISSUETYPE;
if (!issueType.Equals("original", StringComparison.OrdinalIgnoreCase))
{
throw Oops.Bah("签单方式非[正本下载],无法下载正本");
}
url += "";
var body = new
{
//user_key = key,
//user_secret = secret,
web_user = webAccount.Account,
web_psw = webAccount.Password,
//web_code = order.CarrierId,
//bno = order.MBLNO
};
_logger.LogInformation("请求正本下载接口开始mblno={mblno}, url={url}, body={body}", order.MBLNO, url, body);
DateTime bDate = DateTime.Now;
var rtn = await url.OnClientCreating(client =>
{
// client 为 HttpClient 对象
client.Timeout = TimeSpan.FromMinutes(3); // 设置超时时间 3分钟
}).SetBody(body).PostAsStringAsync();
DateTime eDate = DateTime.Now;
TimeSpan ts = eDate.Subtract(bDate);
var timeDiff = ts.TotalMilliseconds;
_logger.LogInformation("请求正本下载接口结束mblno={mblno}, rtn={rtn}, 耗时:{timeDiff}ms", order.MBLNO, rtn, timeDiff);
var jsonRtn = JObject.Parse(rtn);
if (jsonRtn.GetIntValue("code") == 200)
{
_logger.LogInformation("请求正本下载接口成功转存本地mblno={mblno}", order.MBLNO);
result.succ = true;
result.msg = "正本下载成功";
//string currFilePath = rlt.data.FirstOrDefault().path;
//string fileTypeCode = "bc";
//string fileTypeName = "Booking Confirmation";
////读取文件配置
//var fileCfg = App.GetOptions<BookingAttachOptions>();
//string relativePath = $"{fileCfg.relativePath}\\bcfiles\\{bookingOrder.Id}";
//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("\\", "/");
// filePath = filePath.Replace("\\", "/");
// fileFullName = fileFullName.Replace("\\", "/");
//}
//_logger.LogInformation("批次={no} 生成文件保存路径完成 路由={filePath} 服务器系统={system}", batchNo, filePath, RuntimeInformation.OSDescription);
////预先创建目录
//if (!Directory.Exists(filePath))
//{
// Directory.CreateDirectory(filePath);
//}
//var bcStream = await currFilePath.GetAsStreamAsync();
//using (var fileStream = File.Create(fileFullName))
//{
// await bcStream.CopyToAsync(fileStream);
//}
//_logger.LogInformation("批次={no} 完成文件保存 filepath={path}", batchNo, fileFullName);
//string bookFilePath = string.Empty;
//if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
//{
// bookFilePath = System.Text.RegularExpressions.Regex.Match(fileFullName, relativePath.Replace("/", "\\/") + ".*").Value;
//}
//else
//{
// bookFilePath = System.Text.RegularExpressions.Regex.Match(fileFullName, relativePath.Replace("\\", "\\\\") + ".*").Value;
//}
////这里先写入附件表
//await SaveEDIFile(bookingOrder.Id, bookFilePath, new System.IO.FileInfo(currFilePath).Name,
// fileTypeCode, fileTypeName);
}
else
{
var msg = jsonRtn.GetStringValue("msg")?.Replace("爬虫", "");
_logger.LogInformation("请求正本下载接口失败mblno={mblno}, 服务返回:{msg}", order.MBLNO, msg);
throw Oops.Bah(msg);
}
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"正本下载失败,{ex.Message}";
}
return result;
}
}
public class DateTimeJsonConverter : System.Text.Json.Serialization.JsonConverter<Nullable<DateTime>>

@ -4,7 +4,7 @@
"DefaultDbType": "MySql",
//
"DefaultDbString": "Data Source=60.209.125.238;Database=booking_hechuan_dev;User ID=root;Password=Djy@Mysql.test;pooling=true;port=32006;sslmode=none;CharSet=utf8mb4;Convert Zero Datetime=True;Allow Zero Datetime=True;",
"DefaultDbString": "Data Source=60.209.125.238;Database=booking_hechuan_dev;User ID=root;Password=Djy@Mysql.test;pooling=true;port=32006;sslmode=none;CharSet=utf8mb4;Convert Zero Datetime=True;Allow Zero Datetime=True;allowPublicKeyRetrieval=true;",
//
//"DefaultDbString": "Data Source=rm-m5e06xxqpa68a68ry5o.mysql.rds.aliyuncs.com;Database=booking_data;User ID=rulesengine_admin;Password=Rule1qaz2wsx!QAZ;pooling=true;port=3306;sslmode=none;CharSet=utf8mb4;Convert Zero Datetime=True;Allow Zero Datetime=True;",

Loading…
Cancel
Save