@ -16,6 +16,7 @@ using Myshipping.Application.Entity;
using Myshipping.Core ;
using Myshipping.Core ;
using Myshipping.Core.Entity ;
using Myshipping.Core.Entity ;
using Myshipping.Core.Service ;
using Myshipping.Core.Service ;
using Org.BouncyCastle.Asn1.X9 ;
using System ;
using System ;
using System.Collections.Generic ;
using System.Collections.Generic ;
using System.Collections.Specialized ;
using System.Collections.Specialized ;
@ -74,31 +75,100 @@ namespace Myshipping.Application
TaskManageExcuteResultDto result = new TaskManageExcuteResultDto ( ) ;
TaskManageExcuteResultDto result = new TaskManageExcuteResultDto ( ) ;
DateTime nowDate = DateTime . Now ;
/ *
/ *
1 、 接 收 报 文 里 的 文 件 信 息 , 优 先 写 入 本 地 文 件 暂 存 。
1 、 接 收 报 文 里 的 文 件 信 息 , 优 先 写 入 本 地 文 件 暂 存 。
2 、 判 断 对 应 的 订 舱 提 单 号 。 如 果 没 有 对 应 的 订 舱 提 单 号 , 则 写 入 任 务 表 失 败 记 录 。
2 、 请 求 解 析 Draft 文 件 解 析 , 并 等 待 解 析 结 果 。
3 、 写 入 任 务 表 。
3 、 判 断 对 应 的 订 舱 提 单 号 。 如 果 没 有 对 应 的 订 舱 提 单 号 , 则 写 入 任 务 表 失 败 记 录 。
4 、 异 步 请 求 格 式 单 比 对 接 口 。
4 、 写 入 任 务 表 。
5 、 接 收 比 对 结 果 更 新 任 务 表 。
5 、 异 步 请 求 格 式 单 比 对 接 口 。
6 、 更 新 订 舱 表 , 并 更 新 状 态 。
6 、 接 收 比 对 结 果 更 新 任 务 表 。
7 、 更 新 订 舱 表 , 并 更 新 状 态 。
* /
* /
try
try
{
{
var model = GetJsonMessageInfo ( jsonData , batchNo ) ;
var model = GetJsonMessageInfo ( jsonData , batchNo ) ;
var bookingOrder = _bookingOrderRepository . AsQueryable ( ) . Filter ( null , true )
TaskDraftCompareMessageInfo readFileMessageInfo = new TaskDraftCompareMessageInfo
. First ( a = > a . MBLNO . Equals ( model . Main . MBlNo ) ) ;
{
Head = new TaskMessageHead
{
GID = batchNo ,
MessageType = "DRAFT_COMPARE" ,
SenderId = App . Configuration [ "RulesEngineSender" ] ,
SenderName = App . Configuration [ "RulesEngineSenderName" ] ,
ReceiverId = "RulesEngine" ,
ReceiverName = "大简云规则引擎" ,
Version = "1.0" ,
RequestDate = nowDate . ToString ( "yyyy-MM-dd HH:mm:ss" ) ,
RequestAction = "Compare" ,
}
} ;
if ( model = = null )
//附件暂存
throw Oops . Oh ( $"提单号{model.Main.MBlNo}无法获取业务信息" ) ;
var fileFullName = await FileAttachHelper . TempSaveWebFile ( model . Head . GID , file , batchNo , CONST_DRAFT_FILE_CODE ) ;
_logger . LogInformation ( "批次={no}获取订舱数据完成" , batchNo ) ;
//Draft文件解析
NameValueCollection par = new NameValueCollection ( ) ;
par . Add ( "jsonMessage" , JSON . Serialize ( readFileMessageInfo ) ) ;
//附件暂存
byte [ ] bytes = file . ToByteArray ( ) ;
var fileFullName = await FileAttachHelper . TempSaveWebFile ( bookingOrder . Id . ToString ( ) , file , batchNo , CONST_DRAFT_FILE_CODE ) ;
DateTime nowDate = DateTime . Now ;
DateTime b Date = DateTime . Now ;
var readResult = await ExcuteReadPDF ( par , new
{
file = "file" ,
fileName = file . FileName ,
fileBytes = bytes
} ) ;
DateTime eDate = DateTime . Now ;
TimeSpan ts = eDate . Subtract ( bDate ) ;
var timeDiff = ts . TotalMilliseconds ;
_logger . LogInformation ( "批次={no} 请求Draft文件解析完成,耗时:{timeDiff}ms. 结果{msg} 报文={message}" , batchNo , timeDiff ,
readResult . succ ? "成功" : "失败" ,
JSON . Serialize ( readResult ) ) ;
if ( ! readResult . succ )
{
_logger . LogInformation ( "批次={no} 请求Draft文件解析失败 原因={reason}" , batchNo , readResult . msg ) ;
throw Oops . Oh ( $"请求Draft文件解析失败 原因={readResult.msg}" ) ;
}
//通过解析提单号匹配订舱的详情
var readModel = JSON . Deserialize < CompareDraftDataInfo > ( JSON . Serialize ( readResult . extra ) ) ;
string billNo = string . Empty ;
if ( ! string . IsNullOrWhiteSpace ( readModel . MasterBlNo ) )
{
billNo = readModel . MasterBlNo ;
}
if ( string . IsNullOrWhiteSpace ( billNo ) )
{
_logger . LogInformation ( "批次={no} 请求Draft文件解析未获取到有效提单号" , batchNo ) ;
throw Oops . Oh ( $"请求Draft文件解析未获取到有效提单号" ) ;
}
var bookingOrder = _bookingOrderRepository . AsQueryable ( ) . Filter ( null , true )
. First ( a = > a . MBLNO . Equals ( billNo ) ) ;
if ( model = = null )
{
_logger . LogInformation ( "批次={no} 提单号{billNo}无法获取业务信息" , batchNo , billNo ) ;
throw Oops . Oh ( $"提单号{billNo}无法获取业务信息" ) ;
}
_logger . LogInformation ( "批次={no}获取订舱数据完成" , batchNo ) ;
TaskDraftCompareMessageInfo msgModel = new TaskDraftCompareMessageInfo {
TaskDraftCompareMessageInfo msgModel = new TaskDraftCompareMessageInfo {
Head = new TaskMessageHead
Head = new TaskMessageHead
{
{
@ -111,11 +181,12 @@ namespace Myshipping.Application
Version = "1.0" ,
Version = "1.0" ,
RequestDate = nowDate . ToString ( "yyyy-MM-dd HH:mm:ss" ) ,
RequestDate = nowDate . ToString ( "yyyy-MM-dd HH:mm:ss" ) ,
RequestAction = "Compare" ,
RequestAction = "Compare" ,
}
} ,
Main = new TaskDraftMessageMainInfo ( )
} ;
} ;
//请求格式单比对接口
//请求格式单比对接口
var mainInfo = bookingOrder . Adapt < TaskDraftMessageMain Info> ( ) ;
var mainInfo = bookingOrder . Adapt < Business Info> ( ) ;
var userInfo = _sysUserRepository . AsQueryable ( ) . First ( a = > a . Id = = bookingOrder . CreatedUserId ) ;
var userInfo = _sysUserRepository . AsQueryable ( ) . First ( a = > a . Id = = bookingOrder . CreatedUserId ) ;
@ -134,34 +205,40 @@ namespace Myshipping.Application
mainInfo . ContaList = contaList . Adapt < List < TaskDraftMessageCtnInfo > > ( ) ;
mainInfo . ContaList = contaList . Adapt < List < TaskDraftMessageCtnInfo > > ( ) ;
}
}
msgModel . Main = mainInfo ;
msgModel . Main . BusinessInfo = mainInfo ;
_logger . LogInformation ( "批次={no} 对应请求报文完成 msg={msg}" , batchNo , JSON . Serialize ( msgModel ) ) ;
//推送Draft比对
DateTime bCompareDate = DateTime . Now ;
NameValueCollection par = new NameValueCollection ( ) ;
var compareResult = await ExcuteDraftCompare ( msgModel ) ;
par . Add ( "jsonMessage" , JSON . Serialize ( msgModel ) ) ;
byte [ ] bytes = file . ToByteArray ( ) ;
DateTime eCompareDate = DateTime . Now ;
TimeSpan tsCompare = bCompareDate . Subtract ( eCompareDate ) ;
var timeDiffCompare = tsCompare . TotalMilliseconds ;
DateTime bDate = DateTime . Now ;
_logger . LogInformation ( "批次={no} 请求Draft比对完成,耗时:{timeDiff}ms. 结果{msg} 报文={message}" , batchNo , timeDiffCompare ,
compareResult . succ ? "成功" : "失败" ,
JSON . Serialize ( compareResult ) ) ;
var compareResult = await ExcuteCompare ( par , new
_logger . LogInformation ( "批次={no} 对应请求报文完成 msg={msg}" , batchNo , JSON . Serialize ( msgModel ) ) ;
{
file = "file" ,
fileName = file . FileName ,
fileBytes = bytes
} ) ;
DateTime eDate = DateTime . Now ;
var entity = _bookingOrderRepository . AsQueryable ( ) . Filter ( null , true )
TimeSpan ts = eDate . Subtract ( bDate ) ;
. First ( a = > a . Id = = bookingOrder . Id ) ;
var timeDiff = ts . TotalMilliseconds ;
entity . LstDraftCompareRlt = compareResult . extra2 . Any ( a = > a . IsDiff ) ? "DIFF" : "" ;
entity . LstDraftCompareDate = nowDate ;
_logger . LogInformation ( "批次={no} 请求完成,耗时:{timeDiff}ms. 结果{msg}" , batchNo , timeDiff , compareResult . succ ? "成功" : "失败" ) ;
//更新订舱相关
await _bookingOrderRepository . AsUpdateable ( entity ) . UpdateColumns ( it = > new
{
it . LstDraftCompareDate ,
it . LstDraftCompareRlt
} ) . ExecuteCommandAsync ( ) ;
//如果确认文件读取成功
//如果确认文件读取成功
var bookFilePath = await FileAttachHelper . MoveFile ( bookingOrder . Id . ToString ( ) , fileFullName , batchNo ) ;
var bookFilePath = await FileAttachHelper . MoveFile ( bookingOrder . Id . ToString ( ) , fileFullName , batchNo ) ;
//new System.IO.FileInfo(bookFilePath).Name
//将格式单附件写入订舱的附件
//将格式单附件写入订舱的附件
await SaveEDIFile ( bookingOrder . Id , bookFilePath , new System . IO . FileInfo ( fileFullName ) . Name , CONST_DRAFT_FILE_CODE , CONST_DRAFT_FILE_NAME ) ;
await SaveEDIFile ( bookingOrder . Id , bookFilePath , new System . IO . FileInfo ( fileFullName ) . Name , CONST_DRAFT_FILE_CODE , CONST_DRAFT_FILE_NAME ) ;
@ -199,16 +276,16 @@ namespace Myshipping.Application
}
}
# endregion
# endregion
#region 请求格式单比对
#region 解析格式单文件
/// <summary>
/// <summary>
/// 请求格式单比对
/// 解析格式单文件
/// </summary>
/// </summary>
/// <param name="nameValueCollection">请求参数</param>
/// <param name="nameValueCollection">请求参数</param>
/// <param name="fileInfo">文件</param>
/// <param name="fileInfo">文件</param>
/// <param name="contentType">请求类型</param>
/// <param name="contentType">请求类型</param>
/// <returns>返回回执</returns>
/// <returns>返回回执</returns>
[NonAction]
[NonAction]
private async Task < TaskManageExcuteResultDto > Excute Compare ( NameValueCollection nameValueCollection , dynamic fileInfo ,
private async Task < TaskManageExcuteResultDto > Excute ReadPDF ( NameValueCollection nameValueCollection , dynamic fileInfo ,
string contentType = "application/json" )
string contentType = "application/json" )
{
{
TaskManageExcuteResultDto model = null ;
TaskManageExcuteResultDto model = null ;
@ -252,7 +329,7 @@ namespace Myshipping.Application
# endregion
# endregion
//请求
//请求
var response = httpClient . PostAsync ( App . Configuration [ "Draft Compare Url"] , reduceAttach ) . Result ;
var response = httpClient . PostAsync ( App . Configuration [ "Draft Read Url"] , reduceAttach ) . Result ;
result = response . Content . ReadAsStringAsync ( ) . Result ;
result = response . Content . ReadAsStringAsync ( ) . Result ;
model = JSON . Deserialize < TaskManageExcuteResultDto > ( result ) ;
model = JSON . Deserialize < TaskManageExcuteResultDto > ( result ) ;
@ -271,6 +348,47 @@ namespace Myshipping.Application
}
}
# endregion
# endregion
#region 请求格式单比对
/// <summary>
/// 请求格式单比对
/// </summary>
/// <param name="info">请求报文</param>
/// <returns></returns>
private async Task < TaskManageExcuteResultDto > ExcuteDraftCompare ( TaskDraftCompareMessageInfo info )
{
TaskManageExcuteResultDto model = null ;
var url = App . Configuration [ "DraftCompareUrl" ] ;
try
{
var res = await url . SetHttpMethod ( HttpMethod . Post )
. SetBody ( JSON . Serialize ( info ) , "application/json" )
. SetContentEncoding ( Encoding . UTF8 )
. PostAsync ( ) ;
_logger . LogInformation ( "批次={no} 对应请求报文完成 res={res}" , info . Head . GID , JSON . Serialize ( res ) ) ;
if ( res . StatusCode = = System . Net . HttpStatusCode . OK )
{
var userResult = await res . Content . ReadAsStringAsync ( ) ;
_logger . LogInformation ( "对应请求报文 userResult={userResult}" , userResult ) ;
model = JSON . Deserialize < TaskManageExcuteResultDto > ( userResult ) ;
}
}
catch ( Exception ex )
{
//写日志
if ( ex is HttpRequestException )
throw Oops . Oh ( 10000002 ) ;
}
return model ;
}
# endregion
#region 异步写入订舱附件表
#region 异步写入订舱附件表
/// <summary>
/// <summary>
/// 异步写入订舱附件表
/// 异步写入订舱附件表
@ -334,7 +452,9 @@ namespace Myshipping.Application
RequestAction = "Compare" ,
RequestAction = "Compare" ,
} ,
} ,
Main = new TaskDraftMessageMainInfo {
Main = new TaskDraftMessageMainInfo {
BusiPKId = bookingId . ToString ( )
BusinessInfo = new BusinessInfo {
BusiPKId = bookingId . ToString ( )
}
}
}
} ;
} ;