@ -16,6 +16,7 @@ using Myshipping.Application.Service.BookingOrder.Dto;
using Myshipping.Core ;
using Myshipping.Core ;
using Myshipping.Core.Entity ;
using Myshipping.Core.Entity ;
using Myshipping.Core.Service ;
using Myshipping.Core.Service ;
using Newtonsoft.Json.Linq ;
using SqlSugar ;
using SqlSugar ;
using StackExchange.Profiling.Internal ;
using StackExchange.Profiling.Internal ;
using System ;
using System ;
@ -57,6 +58,7 @@ namespace Myshipping.Application
private readonly IServiceWorkFlowBaseService _serviceWorkFlowBaseService ;
private readonly IServiceWorkFlowBaseService _serviceWorkFlowBaseService ;
private readonly IServiceWorkFlowManageService _serviceWorkFlowManageService ;
private readonly IServiceWorkFlowManageService _serviceWorkFlowManageService ;
private readonly IDjyWebsiteAccountConfigService _webAccountConfigService ;
private readonly INamedServiceProvider < IBookingOrderService > _namedBookingOrderServiceProvider ;
private readonly INamedServiceProvider < IBookingOrderService > _namedBookingOrderServiceProvider ;
const string CONST_MAPPING_BC_MODULE_ROUTE = "BC_DOWN_RT" ;
const string CONST_MAPPING_BC_MODULE_ROUTE = "BC_DOWN_RT" ;
@ -81,7 +83,7 @@ namespace Myshipping.Application
SqlSugarRepository < BookingLog > bookinglogRepository , SqlSugarRepository < BookingLogDetail > bookinglogdetailRepository ,
SqlSugarRepository < BookingLog > bookinglogRepository , SqlSugarRepository < BookingLogDetail > bookinglogdetailRepository ,
SqlSugarRepository < BookingRemark > bookingRemarkRepository , SqlSugarRepository < BookingFile > bookingFileRepository ,
SqlSugarRepository < BookingRemark > bookingRemarkRepository , SqlSugarRepository < BookingFile > bookingFileRepository ,
INamedServiceProvider < IBookingOrderService > namedBookingOrderServiceProvider ,
INamedServiceProvider < IBookingOrderService > namedBookingOrderServiceProvider ,
IServiceWorkFlowManageService serviceWorkFlowManageService , SqlSugarRepository < BookingCtnVGM > bookingCtnVGMRepository )
IServiceWorkFlowManageService serviceWorkFlowManageService , SqlSugarRepository < BookingCtnVGM > bookingCtnVGMRepository , IDjyWebsiteAccountConfigService webAccountConfigService )
{
{
_cache = cache ;
_cache = cache ;
_logger = logger ;
_logger = logger ;
@ -105,6 +107,7 @@ namespace Myshipping.Application
_serviceWorkFlowManageService = serviceWorkFlowManageService ;
_serviceWorkFlowManageService = serviceWorkFlowManageService ;
_namedBookingOrderServiceProvider = namedBookingOrderServiceProvider ;
_namedBookingOrderServiceProvider = namedBookingOrderServiceProvider ;
_webAccountConfigService = webAccountConfigService ;
}
}
@ -2589,7 +2592,8 @@ namespace Myshipping.Application
var vgmList = _bookingCtnVGMRepository . AsQueryable ( ) . Where ( t = > t . BILLID = = id ) . ToList ( ) ;
var vgmList = _bookingCtnVGMRepository . AsQueryable ( ) . Where ( t = > t . BILLID = = id ) . ToList ( ) ;
if ( vgmList . Count > 0 )
if ( vgmList . Count > 0 )
list = vgmList . Select ( t = > new BookingCtnVGMDto {
list = vgmList . Select ( t = > new BookingCtnVGMDto
{
id = t . Id ,
id = t . Id ,
cntrNo = t . CNTRNO ,
cntrNo = t . CNTRNO ,
vgmWeight = t . VGM_WEIGHT ,
vgmWeight = t . VGM_WEIGHT ,
@ -2604,6 +2608,173 @@ namespace Myshipping.Application
return list ;
return list ;
}
}
# endregion
# 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 > >
public class DateTimeJsonConverter : System . Text . Json . Serialization . JsonConverter < Nullable < DateTime > >