@ -1,4 +1,7 @@
using Furion.DynamicApiController ;
using Furion ;
using Furion.DependencyInjection ;
using Furion.DistributedIDGenerator ;
using Furion.DynamicApiController ;
using Furion.FriendlyException ;
using Furion.JsonSerialization ;
using ICSharpCode.SharpZipLib.Zip ;
@ -6,13 +9,21 @@ using Mapster;
using Microsoft.AspNetCore.Mvc ;
using Microsoft.Extensions.Logging ;
using Myshipping.Application.Entity ;
using Myshipping.Application.Entity.TaskManagePlat ;
using Myshipping.Application.Helper ;
using Myshipping.Application.Service ;
using Myshipping.Core ;
using Myshipping.Core.Service ;
using NPOI.OpenXmlFormats.Dml.Diagram ;
using RabbitMQ.Client ;
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Net.Http ;
using System.Net.Http.Headers ;
using System.Text ;
using System.Threading.Tasks ;
using Yitter.IdGenerator ;
namespace Myshipping.Application
{
@ -20,16 +31,19 @@ namespace Myshipping.Application
/// 截单回执
/// </summary>
[ApiDescriptionSettings("Application", Name = "TaskManageSISubmitted", Order = 10)]
public class TaskManageSISubmittedService : ITaskManageSISubmittedService , IDynamicApiController
public class TaskManageSISubmittedService : ITaskManageSISubmittedService , IDynamicApiController , ITransient
{
private readonly SqlSugarRepository < TaskSISubmitted > _taskSISubmittedRepository ;
private readonly SqlSugarRepository < TaskSISubmittedCtn > _taskSISubmittedCtnRepository ;
private readonly SqlSugarRepository < TaskBaseInfo > _taskBaseRepository ;
private readonly SqlSugarRepository < BookingOrder > _bookingOrderRepository ;
private readonly SqlSugarRepository < BookingCtn > _bookingCtnRepository ;
private readonly SqlSugarRepository < BusinessCompareDiffRecord > _businessCompareDiffRecordRepository ;
private readonly ILogger < TaskManageSISubmittedService > _logger ;
private readonly IBookingValueAddedService _bookingValueAddedService ;
private readonly IDjyTenantParamService _djyTenantParamService ;
private readonly IBookingOrderService _bookingOrderService ;
//租户SI回执是否自动更新订舱
const string CONST_SI_SUBMITTED_DEFAULT_PARAM = "SI_SUBMITTED_AUTO_UPDATE_ORDER" ;
@ -39,7 +53,10 @@ namespace Myshipping.Application
SqlSugarRepository < TaskBaseInfo > taskBaseRepository ,
SqlSugarRepository < BookingOrder > bookingOrderRepository ,
SqlSugarRepository < BusinessCompareDiffRecord > businessCompareDiffRecordRepository ,
IBookingValueAddedService bookingValueAddedService , IDjyTenantParamService djyTenantParamService )
SqlSugarRepository < BookingCtn > bookingCtnRepository ,
SqlSugarRepository < TaskSISubmittedCtn > taskSISubmittedCtnRepository ,
IBookingValueAddedService bookingValueAddedService , IDjyTenantParamService djyTenantParamService ,
IBookingOrderService bookingOrderService )
{
_logger = logger ;
_taskSISubmittedRepository = taskSISubmittedRepository ;
@ -48,6 +65,9 @@ namespace Myshipping.Application
_bookingValueAddedService = bookingValueAddedService ;
_djyTenantParamService = djyTenantParamService ;
_businessCompareDiffRecordRepository = businessCompareDiffRecordRepository ;
_bookingCtnRepository = bookingCtnRepository ;
_taskSISubmittedCtnRepository = taskSISubmittedCtnRepository ;
_bookingOrderService = bookingOrderService ;
}
#region 获取截单回执详情
@ -236,20 +256,22 @@ namespace Myshipping.Application
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto ( ) ;
TaskSISubmitted siSubmitted = null ;
try
{
/ *
1 、 判 断 当 前 租 户 开 启 了 自 动 更 新 订 舱 数 据 ( SI_SUBMITTED_AUTO_UPDATE_ORDER = ENABLE )
2 、 先 与 订 舱 数 据 进 行 比 对 , 记 录 比 对 结 果 。
3 、 更 新 订 舱 详 情
4 、 文 件 挂 到 订 舱 的 附 件 上
* /
var taskBase = _taskBaseRepository . AsQueryable ( ) . First ( a = > a . PK_ID = = taskPkId ) ;
var taskBase = _taskBaseRepository . AsQueryable ( ) . Filter ( null , true ) . First ( a = > a . PK_ID = = taskPkId & & a . TenantId = = UserManager . TENANT_ID ) ;
if ( taskBase = = null )
throw Oops . Oh ( $"任务主键{taskPkId}无法获取业务信息" ) ;
var siSubmitted = _taskSISubmittedRepository . AsQueryable ( ) . Fi rst( a = > a . TASK_ID = = taskBase . PK _ID) ;
siSubmitted = _taskSISubmittedRepository . AsQueryable ( ) . Fi lter( null , true ) . Fi rst( a = > a . TASK_ID = = taskBase . PK _ID & & a . TenantId = = UserManager . TENANT _ID) ;
if ( siSubmitted = = null )
throw Oops . Oh ( $"截单回执主键{taskPkId}无法获取业务信息" ) ;
@ -266,19 +288,399 @@ namespace Myshipping.Application
paramConfig = paramList . FirstOrDefault ( a = > a . ParaCode . Equals ( CONST_SI_SUBMITTED_DEFAULT_PARAM , StringComparison . OrdinalIgnoreCase ) ) ;
}
if ( paramConfig ! = null )
{
//更新前先比对一遍差异
//更新订舱数据
var siCtnList = _taskSISubmittedCtnRepository . AsQueryable ( ) . Filter ( null , true ) . Where ( a = > a . P_PKID = = siSubmitted . PK_ID & & a . TenantId = = UserManager . TENANT_ID ) . ToList ( ) ;
//更新任务的状态
//直接完成SI的回执任务
if ( paramConfig ! = null & & paramConfig . ParaValue . Equals ( "ENABLE" , StringComparison . OrdinalIgnoreCase ) )
{
siSubmitted . IS_SET_AUTO_UPD_BOOKING = true ;
var orderInfo = _bookingOrderRepository . AsQueryable ( ) . Filter ( null , true )
. First ( a = > a . MBLNO = = siSubmitted . MBL_NO & & a . IsDeleted = = false & & a . TenantId = = UserManager . TENANT_ID & & a . ParentId = = 0 ) ;
if ( orderInfo ! = null )
{
siSubmitted . BOOKING_ID = orderInfo . Id ;
var ctnList = _bookingCtnRepository . AsQueryable ( ) . Filter ( null , true )
. Where ( a = > a . BILLID = = orderInfo . Id & & a . IsDeleted = = false & & a . TenantId = = UserManager . TENANT_ID ) . ToList ( ) ;
SIFeedBackCompareDto siSrcDto = orderInfo . Adapt < SIFeedBackCompareDto > ( ) ;
if ( ctnList . Count > 0 )
{
siSrcDto . ContaList = ctnList . Select ( t = > new SIFeedBackCompareContaDto
{
ContaNo = t . CNTRNO ,
SealNo = t . SEALNO ,
ContaType = t . CTNCODE ,
ContaTypeName = t . CTNALL ,
PKGS = t . PKGS . HasValue ? t . PKGS . Value : 0 ,
CBM = t . CBM ,
KGS = t . KGS ,
WeighType = t . WEIGHTYPE = = "累加" ? "ADD" : "ALL" ,
WeighKGS = t . WEIGHKGS
} ) . ToList ( ) ;
}
SIFeedBackCompareDto siTargetDto = siSubmitted . Adapt < SIFeedBackCompareDto > ( ) ;
if ( siCtnList . Count > 0 )
{
siTargetDto . ContaList = siCtnList . Select ( t = > new SIFeedBackCompareContaDto
{
ContaNo = t . CNTRNO ,
SealNo = t . SEALNO ,
ContaType = t . CTNCODE ,
ContaTypeName = t . CTNALL ,
PKGS = t . PKGS . HasValue ? t . PKGS . Value : 0 ,
CBM = t . CBM ,
KGS = t . KGS ,
WeighType = t . WEIGHTYPE ,
WeighKGS = t . WEIGHKGS
} ) . ToList ( ) ;
}
//更新前先比对一遍差异
var compareRlt = await PushCompareSIInfo ( siSrcDto , siTargetDto , orderInfo . Id , taskPkId ) ;
if ( string . IsNullOrWhiteSpace ( compareRlt . Item1 ) )
{
siSubmitted . DIFF_NUM = compareRlt . Item2 ;
}
SaveBookingOrderInput bkModel = null ;
if ( orderInfo ! = null )
{
bkModel = new SaveBookingOrderInput
{
Id = orderInfo . Id ,
ctnInputs = new List < BookingCtnDto > ( ) ,
ChangedFields = new List < string > ( )
} ;
if ( ! string . IsNullOrEmpty ( siSubmitted . ISSUETYPE ) )
{
if ( siSubmitted . ISSUETYPE . Equals ( "seaway" , StringComparison . OrdinalIgnoreCase ) )
{
//bkModel.ISSUETYPE = "seaway";
bkModel . ISSUETYPE = "Seaway Bill" ;
}
else if ( siSubmitted . ISSUETYPE . Equals ( "telex" , StringComparison . OrdinalIgnoreCase ) )
{
//bkModel.ISSUETYPE = "telex";
bkModel . ISSUETYPE = "Telex" ;
}
else if ( siSubmitted . ISSUETYPE . Equals ( "seaway" , StringComparison . OrdinalIgnoreCase ) )
{
//bkModel.ISSUETYPE = "original";
bkModel . ISSUETYPE = "Original" ;
}
bkModel . ChangedFields . Add ( nameof ( SaveBookingOrderInput . ISSUETYPE ) ) ;
//bkModel.ChangedFields.Add(nameof(SaveBookingOrderInput.ISSUETYPE));
}
if ( ! string . IsNullOrEmpty ( siSubmitted . SHIPPER ) )
{
bkModel . SHIPPER = siSubmitted . SHIPPER ;
bkModel . ChangedFields . Add ( nameof ( SaveBookingOrderInput . SHIPPER ) ) ;
}
if ( ! string . IsNullOrEmpty ( siSubmitted . CONSIGNEE ) )
{
bkModel . CONSIGNEE = siSubmitted . CONSIGNEE ;
bkModel . ChangedFields . Add ( nameof ( SaveBookingOrderInput . CONSIGNEE ) ) ;
}
if ( ! string . IsNullOrEmpty ( siSubmitted . NOTIFYPARTY ) )
{
bkModel . NOTIFYPARTY = siSubmitted . NOTIFYPARTY ;
bkModel . ChangedFields . Add ( nameof ( SaveBookingOrderInput . NOTIFYPARTY ) ) ;
}
if ( ! string . IsNullOrEmpty ( siSubmitted . NOTIFYPARTY2 ) )
{
bkModel . NOTIFYPARTY2 = siSubmitted . NOTIFYPARTY2 ;
bkModel . ChangedFields . Add ( nameof ( SaveBookingOrderInput . NOTIFYPARTY2 ) ) ;
}
if ( ! string . IsNullOrEmpty ( siSubmitted . KINDPKGS ) )
{
bkModel . KINDPKGS = siSubmitted . KINDPKGS ;
bkModel . ChangedFields . Add ( nameof ( SaveBookingOrderInput . KINDPKGS ) ) ;
}
if ( ! string . IsNullOrEmpty ( siSubmitted . DESCRIPTION ) )
{
bkModel . DESCRIPTION = siSubmitted . DESCRIPTION ;
bkModel . ChangedFields . Add ( nameof ( SaveBookingOrderInput . DESCRIPTION ) ) ;
}
if ( ! string . IsNullOrEmpty ( siSubmitted . HSCODE ) )
{
bkModel . HSCODE = siSubmitted . HSCODE ;
bkModel . ChangedFields . Add ( nameof ( SaveBookingOrderInput . HSCODE ) ) ;
}
}
if ( ctnList . Count > 0 )
{
List < BookingCtn > oddCtnList = new List < BookingCtn > ( ) ;
foreach ( var ctn in ctnList )
{
if ( ! string . IsNullOrWhiteSpace ( ctn . CTNCODE ) & & string . IsNullOrWhiteSpace ( ctn . CNTRNO ) & & ctn . CTNNUM . HasValue & & ctn . CTNNUM . Value > 1 )
{
for ( int i = 0 ; i < ctn . CTNNUM . Value - 1 ; i + + )
{
oddCtnList . Add ( new BookingCtn
{
BILLID = orderInfo . Id ,
IsDeleted = false ,
CreatedTime = DateTime . Now ,
UpdatedTime = DateTime . Now ,
CreatedUserId = ctn . CreatedUserId ,
CreatedUserName = ctn . CreatedUserName ,
CTNCODE = ctn . CTNCODE ,
CTNALL = ctn . CTNALL ,
} ) ;
}
ctn . CTNNUM = 1 ;
}
}
if ( oddCtnList . Count > 0 )
{
ctnList . AddRange ( oddCtnList ) ;
}
}
if ( siCtnList . Count > 0 )
{
siCtnList . ForEach ( x = >
{
var ctn = ctnList . FirstOrDefault ( a = > ! string . IsNullOrWhiteSpace ( x . CNTRNO ) & & ! string . IsNullOrWhiteSpace ( a . CNTRNO )
& & a . CNTRNO . Equals ( x . CNTRNO , StringComparison . OrdinalIgnoreCase ) ) ;
if ( ctn ! = null )
{
ctn . CTNCODE = x . CTNCODE ;
ctn . CTNALL = x . CTNALL ;
ctn . CTNNUM = 1 ;
ctn . SEALNO = x . SEALNO ;
ctn . PKGS = x . PKGS ;
ctn . KGS = x . KGS ;
ctn . WEIGHTYPE = x . WEIGHTYPE ;
ctn . WEIGHKGS = x . WEIGHKGS ;
ctn . CBM = x . CBM ;
ctn . REMARK + = "SI Add" ;
ctn . TenantId = UserManager . TENANT_ID ;
ctn . CreatedTime = DateTime . Now ;
ctn . CreatedUserId = UserManager . UserId ;
ctn . CreatedUserName = UserManager . Name ;
if ( x . WEIGHKGS . HasValue & & x . KGS . HasValue )
ctn . TAREWEIGHT = x . WEIGHKGS . Value - x . KGS . Value ;
}
else
{
ctn = ctnList . FirstOrDefault ( a = > a . CTNCODE = = x . CTNCODE & & string . IsNullOrWhiteSpace ( a . CNTRNO ) ) ;
if ( ctn ! = null )
{
ctn . CNTRNO = x . CNTRNO ;
ctn . CTNCODE = x . CTNCODE ;
ctn . CTNALL = x . CTNALL ;
ctn . CTNNUM = 1 ;
ctn . SEALNO = x . SEALNO ;
ctn . PKGS = x . PKGS ;
ctn . KGS = x . KGS ;
ctn . WEIGHTYPE = x . WEIGHTYPE ;
ctn . WEIGHKGS = x . WEIGHKGS ;
ctn . CBM = x . CBM ;
ctn . REMARK + = "SI Add" ;
ctn . TenantId = UserManager . TENANT_ID ;
ctn . CreatedTime = DateTime . Now ;
ctn . CreatedUserId = UserManager . UserId ;
ctn . CreatedUserName = UserManager . Name ;
if ( x . WEIGHKGS . HasValue & & x . KGS . HasValue )
ctn . TAREWEIGHT = x . WEIGHKGS . Value - x . KGS . Value ;
}
else
{
ctn = ctnList . FirstOrDefault ( a = > a . CTNALL = = x . CTNALL & & string . IsNullOrWhiteSpace ( a . CNTRNO ) ) ;
if ( ctn ! = null )
{
ctn . CNTRNO = x . CNTRNO ;
ctn . CTNCODE = x . CTNCODE ;
ctn . CTNALL = x . CTNALL ;
ctn . CTNNUM = 1 ;
ctn . SEALNO = x . SEALNO ;
ctn . PKGS = x . PKGS ;
ctn . KGS = x . KGS ;
ctn . WEIGHTYPE = x . WEIGHTYPE ;
ctn . WEIGHKGS = x . WEIGHKGS ;
ctn . CBM = x . CBM ;
ctn . REMARK + = "SI Add" ;
ctn . TenantId = UserManager . TENANT_ID ;
ctn . CreatedTime = DateTime . Now ;
ctn . CreatedUserId = UserManager . UserId ;
ctn . CreatedUserName = UserManager . Name ;
if ( x . WEIGHKGS . HasValue & & x . KGS . HasValue )
ctn . TAREWEIGHT = x . WEIGHKGS . Value - x . KGS . Value ;
}
else
{
ctnList . Add ( new BookingCtn
{
BILLID = orderInfo . Id ,
IsDeleted = false ,
CreatedTime = DateTime . Now ,
UpdatedTime = DateTime . Now ,
CreatedUserId = UserManager . UserId ,
CreatedUserName = UserManager . Name ,
TenantId = UserManager . TENANT_ID ,
CNTRNO = x . CNTRNO ,
CTNCODE = x . CTNCODE ,
CTNALL = x . CTNALL ,
CTNNUM = 1 ,
SEALNO = x . SEALNO ,
PKGS = x . PKGS ,
KGS = x . KGS ,
WEIGHTYPE = x . WEIGHTYPE ,
WEIGHKGS = x . WEIGHKGS ,
CBM = x . CBM ,
REMARK = "SI Add" ,
} ) ;
}
}
}
} ) ;
if ( ctnList . Any ( t = > t . REMARK . IndexOf ( "SI Add" ) < 0 ) )
ctnList . ForEach ( t = > { if ( t . REMARK . IndexOf ( "SI Add" ) < 0 ) ctnList . Remove ( t ) ; } ) ;
}
//更新订舱数据
var bkRlt = await _bookingOrderService . Save ( bkModel ) ;
if ( bkRlt . Id > 0 )
{
siSubmitted . PROCESS_STATUS = "SUCC" ;
siSubmitted . PROCESS_DATE = DateTime . Now ;
siSubmitted . IS_UPDATE_BOOKING = true ;
siSubmitted . UPDATE_BOOKING_DATE = DateTime . Now ;
//直接完成SI的回执任务
if ( taskBase . IS_PUBLIC = = 1 )
{
//更新任务的状态
taskBase . IS_PUBLIC = 0 ;
taskBase . IS_COMPLETE = 1 ;
taskBase . COMPLETE_DEAL = "AUTO" ;
taskBase . COMPLETE_DEAL_NAME = "自动" ;
taskBase . COMPLETE_DATE = DateTime . Now ;
if ( ! string . IsNullOrWhiteSpace ( orderInfo . OP ) )
{
taskBase . RealUserId = long . Parse ( orderInfo . OPID ) ;
taskBase . RealUserName = orderInfo . OP ;
taskBase . UpdatedTime = DateTime . Now ;
taskBase . UpdatedUserId = long . Parse ( orderInfo . OPID ) ;
taskBase . UpdatedUserName = orderInfo . OP ;
}
else
{
taskBase . RealUserId = orderInfo . CreatedUserId . Value ;
taskBase . RealUserName = orderInfo . CreatedUserName ;
taskBase . UpdatedTime = DateTime . Now ;
taskBase . UpdatedUserId = orderInfo . CreatedUserId . Value ;
taskBase . UpdatedUserName = orderInfo . CreatedUserName ;
}
//更新任务台,将当前任务变更为个人任务
await _taskBaseRepository . AsUpdateable ( taskBase ) . UpdateColumns ( it = > new {
it . IS_PUBLIC ,
it . RealUserId ,
it . RealUserName ,
it . UpdatedTime ,
it . UpdatedUserId ,
it . UpdatedUserName
} ) . ExecuteCommandAsync ( ) ;
}
else
{
taskBase . IS_COMPLETE = 1 ;
taskBase . COMPLETE_DEAL = "AUTO" ;
taskBase . COMPLETE_DEAL_NAME = "自动" ;
taskBase . COMPLETE_DATE = DateTime . Now ;
if ( ! string . IsNullOrWhiteSpace ( orderInfo . OP ) )
{
taskBase . RealUserId = long . Parse ( orderInfo . OPID ) ;
taskBase . RealUserName = orderInfo . OP ;
taskBase . UpdatedTime = DateTime . Now ;
taskBase . UpdatedUserId = long . Parse ( orderInfo . OPID ) ;
taskBase . UpdatedUserName = orderInfo . OP ;
}
else
{
taskBase . RealUserId = orderInfo . CreatedUserId . Value ;
taskBase . RealUserName = orderInfo . CreatedUserName ;
taskBase . UpdatedTime = DateTime . Now ;
taskBase . UpdatedUserId = orderInfo . CreatedUserId . Value ;
taskBase . UpdatedUserName = orderInfo . CreatedUserName ;
}
//更新任务台,将当前任务变更为个人任务
await _taskBaseRepository . AsUpdateable ( taskBase ) . UpdateColumns ( it = > new {
it . IS_PUBLIC ,
it . RealUserId ,
it . RealUserName ,
it . UpdatedTime ,
it . UpdatedUserId ,
it . UpdatedUserName
} ) . ExecuteCommandAsync ( ) ;
}
}
else
{
siSubmitted . PROCESS_STATUS = "FAILURE" ;
siSubmitted . PROCESS_DATE = DateTime . Now ;
siSubmitted . PROCESS_RESULT = "更新订舱信息失败" ;
siSubmitted . UPDATE_BOOKING_DATE = DateTime . Now ;
}
}
else
{
result . succ = false ;
result . msg = $"提单号{siSubmitted.MBL_NO} 检索订舱数据失败" ;
}
}
else
{
result . succ = false ;
result . msg = "当前租户没开通自动( SI回执是否自动更新订舱) " ;
siSubmitted . IS_SET_AUTO_UPD_BOOKING = false ;
}
}
catch ( Exception ex )
@ -287,8 +689,268 @@ namespace Myshipping.Application
result . msg = ex . Message ;
}
if ( ! result . succ & & siSubmitted ! = null )
{
siSubmitted . PROCESS_STATUS = "FAILURE" ;
siSubmitted . PROCESS_DATE = DateTime . Now ;
if ( result . msg . Length > 500 )
{
siSubmitted . PROCESS_RESULT = result . msg . Substring ( 0 , 500 ) ;
}
else
{
siSubmitted . PROCESS_RESULT = result . msg ;
}
await _taskSISubmittedRepository . AsUpdateable ( siSubmitted ) . UpdateColumns ( x = > new
{
x . PROCESS_DATE ,
x . PROCESS_STATUS ,
x . PROCESS_RESULT ,
x . IS_SET_AUTO_UPD_BOOKING
} ) . ExecuteCommandAsync ( ) ;
}
return result ;
}
# endregion
/// <summary>
/// 获取SI反馈信息
/// </summary>
/// <param name="taskPKId">任务主键</param>
/// <returns>返回结果</returns>
[HttpGet("/TaskManageSISubmitted/GetSIFeedBackInfo")]
public async Task < TaskSISubmittedShowDto > GetSIFeedBackInfo ( string taskPKId )
{
TaskSISubmittedShowDto dto = new TaskSISubmittedShowDto ( ) ;
var taskBase = _taskBaseRepository . AsQueryable ( ) . First ( a = > a . PK_ID = = taskPKId ) ;
if ( taskBase = = null )
throw Oops . Oh ( $"任务主键{taskPKId}无法获取业务信息" ) ;
var siSubmitted = _taskSISubmittedRepository . AsQueryable ( ) . First ( a = > a . TASK_ID = = taskBase . PK_ID ) ;
if ( siSubmitted = = null )
throw Oops . Oh ( $"截单回执主键{taskPKId}无法获取业务信息" ) ;
var bookOrderList = _bookingOrderRepository . AsQueryable ( ) . Filter ( null , true )
. InnerJoin < BookingCtn > ( ( bk , ctn ) = > bk . Id = = ctn . BILLID )
. Where ( ( bk , ctn ) = > bk . Id = = siSubmitted . BOOKING_ID . Value & & bk . TenantId = = UserManager . TENANT_ID )
. Select ( ( bk , ctn ) = > new { bk = bk , ctn = ctn } ) . ToList ( ) ;
var orderInfo = bookOrderList . FirstOrDefault ( ) . bk ;
//var siFeedBackList = _taskSISubmittedRepository.EntityContext.Queryable<TaskSISubmitted>()
// .InnerJoin<TaskSISubmittedCtn>((si, ctn) => si.PK_ID == ctn.P_PKID)
// .Where((si, ctn) => si.TASK_PKID == model.TaskId && si.TenantId == UserManager.TENANT_ID)
// .Select((si, ctn) => new { si = si, ctn = ctn }).ToList();
//if (siFeedBackList.Count == 0)
// throw Oops.Oh($"SI反馈信息不存在");
//var siFeedBackInfo = siFeedBackList.FirstOrDefault().si;
//var resultInfo = siFeedBackInfo.Adapt<TaskSIFeedBackResultBusiDto>();
//resultInfo.ContaList = siFeedBackList.Select(t => t.ctn.Adapt<TaskSIFeedBackResultContaDto>()).ToList();
//model.BusiInfo = resultInfo;
//if (orderInfo != null)
//{
// //订舱
// model.BookingOrder = orderInfo.Adapt<TaskBookingOrderDto>();
//}
////进行数据比对确认差异字段KEY
//var mainDiff = await InnerCompareMainInfoDiff(orderInfo, siFeedBackInfo);
//model.SICompareOrderKeyList = mainDiff;
//var contaDiff = await InnerCompareContaInfoDiff(bookOrderList.Select(t => t.ctn).ToList(),
// siFeedBackList.Select(t => t.ctn).ToList());
//model.SICompareOrderContaKeyList = contaDiff;
return dto ;
}
#region 推送BC变更比对
/// <summary>
/// 推送BC变更比对sysUser
/// </summary>
/// <param name="siSrcDto">订舱详情</param>
/// <param name="siTargetDto">SI截单详情</param>
/// <param name="bookingId">订舱主键</param>
/// <param name="taskPKId">任务ID</param>
/// <returns></returns>
[NonAction]
public async Task < Tuple < string , int > > PushCompareSIInfo ( SIFeedBackCompareDto siSrcDto , SIFeedBackCompareDto siTargetDto , long bookingId , string taskPKId )
{
string result = string . Empty ;
int diffNum = 0 ;
string batchNo = IDGen . NextID ( ) . ToString ( ) ;
DateTime bDate = DateTime . Now ;
var compareResult = await ExcuteCompare ( siSrcDto , siTargetDto ) ;
DateTime eDate = DateTime . Now ;
TimeSpan ts = eDate . Subtract ( bDate ) ;
var timeDiff = ts . TotalMilliseconds ;
if ( compareResult ! = null )
{
_logger . LogInformation ( "批次={no} 请求完成,耗时:{timeDiff}ms. 结果{msg}" , batchNo , timeDiff , compareResult . succ ? "成功" : "失败" ) ;
if ( ! compareResult . succ )
{
result = $"比对失败,原因:{compareResult.msg}" ;
}
}
if ( compareResult ! = null )
{
DateTime nowDate = DateTime . Now ;
var hisInfo = _businessCompareDiffRecordRepository . AsQueryable ( ) . Filter ( null , true ) . First ( a = >
a . BUSI_ID = = bookingId . ToString ( ) & & a . TASK_ID = = taskPKId ) ;
if ( hisInfo = = null )
{
BusinessCompareDiffRecord entity = new BusinessCompareDiffRecord
{
BUSI_ID = bookingId . ToString ( ) ,
TASK_ID = taskPKId ,
BUSI_TYPE = "SI_SUBMITTED" ,
COMPARE_DIFF_NUM = compareResult . extra . IsExistsDiff ? compareResult . extra . ShowDetailList . Count : 0 ,
CreatedTime = nowDate ,
UpdatedTime = nowDate ,
CreatedUserId = UserManager . UserId ,
CreatedUserName = UserManager . Name ,
UpdatedUserId = UserManager . UserId ,
UpdatedUserName = UserManager . Name ,
COMPARE_TYPE = "SI_MODIFY" ,
COMPARE_RLT = JSON . Serialize ( compareResult . extra . ShowDetailList ) ,
} ;
await _businessCompareDiffRecordRepository . InsertAsync ( entity ) ;
}
else
{
hisInfo . COMPARE_DIFF_NUM = compareResult . extra . IsExistsDiff ? compareResult . extra . ShowDetailList . Count : 0 ;
hisInfo . UpdatedTime = nowDate ;
hisInfo . UpdatedUserId = UserManager . UserId ;
hisInfo . UpdatedUserName = UserManager . Name ;
hisInfo . COMPARE_RLT = JSON . Serialize ( compareResult . extra . ShowDetailList ) ;
await _businessCompareDiffRecordRepository . AsUpdateable ( hisInfo ) . UpdateColumns ( it = >
new
{
it . COMPARE_DIFF_NUM ,
it . COMPARE_RLT ,
it . UpdatedTime ,
it . UpdatedUserId ,
it . UpdatedUserName
} ) . ExecuteCommandAsync ( ) ;
}
if ( compareResult . extra . ShowDetailList = = null | | compareResult . extra . ShowDetailList . Count = = 0 )
{
result = $"比对失败,没有比对出差异" ;
new EmailNoticeHelper ( ) . SendEmailNotice ( $"MBLNO={siSrcDto.MblNo} SI 回执比对差异失败, 比对结果为0" , $"MBLNO={siSrcDto.MblNo} SI 回执比对差异失败, 比对结果为0" , App . Configuration [ "EmailNoticeDefaultUser" ] . GetUserEmailList ( ) ) ;
}
else
{
diffNum = compareResult . extra . ShowDetailList . Count ;
}
}
else
{
result = $"比对失败,未获取到比对结果" ;
new EmailNoticeHelper ( ) . SendEmailNotice ( $"MBLNO={siSrcDto.MblNo} SI 回执比对差异失败,未获取到比对结果" , $"MBLNO={siSrcDto.MblNo} SI 回执比对差异失败,未获取到比对结果" , App . Configuration [ "EmailNoticeDefaultUser" ] . GetUserEmailList ( ) ) ;
}
return new Tuple < string , int > ( result , diffNum ) ;
}
# endregion
#region 请求BC比对
/// <summary>
/// 请求SI比对
/// </summary>
/// <param name="siSrcDto">订舱详情</param>
/// <param name="siTargetDto">SI截单详情</param>
/// <returns>返回回执</returns>
[NonAction]
public async Task < TaskManageExcuteResultDto > ExcuteCompare ( SIFeedBackCompareDto siSrcDto , SIFeedBackCompareDto siTargetDto )
{
TaskManageExcuteResultDto model = null ;
/ *
1 、 读 取 配 置 文 件 中 的 规 则 引 擎 URL
2 、 填 充 请 求 的 类 , 并 生 成 JSON 报 文
3 、 POST 请 求 接 口 , 并 记 录 回 执 。
4 、 返 回 信 息 。
* /
var url = App . Configuration [ "SICompareUrl" ] ;
using ( var httpClient = new HttpClient ( ) )
{
try
{
using ( var reduceAttach = new MultipartFormDataContent ( ) )
{
var dataContent = new ByteArrayContent ( Encoding . UTF8 . GetBytes ( JSON . Serialize ( siSrcDto ) ) ) ;
dataContent . Headers . ContentDisposition = new ContentDispositionHeaderValue ( $"form-data" )
{
Name = "srcJson"
} ;
reduceAttach . Add ( dataContent ) ;
var dataContent2 = new ByteArrayContent ( Encoding . UTF8 . GetBytes ( JSON . Serialize ( siTargetDto ) ) ) ;
dataContent2 . Headers . ContentDisposition = new ContentDispositionHeaderValue ( $"form-data" )
{
Name = "destJson"
} ;
reduceAttach . Add ( dataContent2 ) ;
//请求
var response = httpClient . PostAsync ( url , reduceAttach ) . Result ;
var result = response . Content . ReadAsStringAsync ( ) . Result ;
model = JSON . Deserialize < TaskManageExcuteResultDto > ( result ) ;
}
}
catch ( Exception ex )
{
_logger . LogInformation ( "推送SI比对异常, 原因: {error}" , ex . Message ) ;
throw Oops . Oh ( $"推送SI比对异常, 原因: {ex.Message}" ) ;
}
}
return model ;
}
# endregion
}
}