@ -145,7 +145,7 @@ namespace Myshipping.Application
private readonly IServiceWorkFlowManageService _serviceWorkFlowManageService ;
private readonly IDjyUserConfigService _djyUserConfigService ;
private readonly IBookingSlotService bookingSlotService ;
private readonly IBookingValueAddedService bookingValueAddedService ;
private readonly IEventPublisher _publisher ;
private readonly SqlSugarRepository < DjyTenantParamValue > _repTenantParamValue ;
@ -177,7 +177,7 @@ namespace Myshipping.Application
ISysOrgService orgService , SqlSugarRepository < BookingLineOpMgrConfig > repLineOpMgrConfig , SqlSugarRepository < SysEmp > repSysEmp , SqlSugarRepository < BookingAutoYardImport > repAutoYard ,
IServiceWorkFlowManageService serviceWorkFlowManageService , IDjyUserConfigService djyUserConfigService , IEventPublisher publisher , SqlSugarRepository < BookingSlotBase > repSlotBase ,
SqlSugarRepository < BookingSlotAllocation > repSlotAllocation , SqlSugarRepository < BookingSlotAllocationCtn > repSlotAllocationCtn , IBookingSlotService bookingSlotService ,
SqlSugarRepository < BookingGoodsStatusSubscribe > repBookingStatusSubscribe , SqlSugarRepository < DjyTenantParamValue > repTenantParamValue )
SqlSugarRepository < BookingGoodsStatusSubscribe > repBookingStatusSubscribe , SqlSugarRepository < DjyTenantParamValue > repTenantParamValue , IBookingValueAddedService bookingValueAddedService )
{
this . _logger = logger ;
this . _rep = rep ;
@ -231,6 +231,7 @@ namespace Myshipping.Application
this . bookingSlotService = bookingSlotService ;
_repBookingStatusSubscribe = repBookingStatusSubscribe ;
_repTenantParamValue = repTenantParamValue ;
this . bookingValueAddedService = bookingValueAddedService ;
}
#region 主表和箱信息
@ -11910,11 +11911,9 @@ namespace Myshipping.Application
}
}
}
# endregion
#region BC
/// <summary>
/// 接收BC信息更新订舱
/// </summary>
@ -12004,5 +12003,224 @@ namespace Myshipping.Application
CustomerBookingSyncHelper . SendCustomerBookingSync ( ( long ) id , BookingOrderSyncTypeEnum . BC . ToString ( ) ) ;
}
}
# endregion
#region 电放
/// <summary>
/// 船司电放提交
/// </summary>
/// <param name="ids">订舱主键数组</param>
/// <returns>每单的处理提交结果</returns>
[HttpPost("/BookingOrder/SubmitTelex")]
public async Task < List < SubmitTelexResultDto > > SubmitTelex ( [ FromBody ] long [ ] ids )
{
var orderList = await _rep . AsQueryable ( ) . Where ( x = > ids . Contains ( x . Id ) ) . ToListAsync ( ) ;
if ( orderList . Count = = 0 )
{
throw Oops . Bah ( "未找到相应订舱" ) ;
}
var allSysConfig = _cache . GetAllSysConfig ( ) . Result ;
var url = allSysConfig . FirstOrDefault ( x = > x . Code = = "TelexServiceUrl" ) ? . Value ;
var key = allSysConfig . FirstOrDefault ( x = > x . Code = = "TelexServiceKey" ) ? . Value ;
var secret = allSysConfig . FirstOrDefault ( x = > x . Code = = "TelexServiceSecret" ) ? . 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 = _webAccountConfig . GetAccountConfig ( "MSKWeb" , UserManager . UserId ) . Result ;
if ( webAccount = = null )
{
throw Oops . Bah ( "未配置网站账户, 类型: MSKWeb" ) ;
}
var mappingCarrier = _cache . GetAllMappingCarrier ( ) . Result ;
var mappingIssueType = _cache . GetAllMappingIssueType ( ) . Result ;
List < SubmitTelexResultDto > result = new ( ) ;
List < ( long Id , string MBLNO , string CarrierId ) > pushList = new ( ) ;
foreach ( var order in orderList )
{
try
{
if ( string . IsNullOrWhiteSpace ( order . MBLNO ) )
{
result . Add ( new SubmitTelexResultDto ( order . MBLNO , false , "提单号为空" ) ) ;
continue ;
}
if ( string . IsNullOrWhiteSpace ( order . ISSUETYPE ) )
{
result . Add ( new SubmitTelexResultDto ( order . MBLNO , false , "签单方式为空" ) ) ;
continue ;
}
if ( string . IsNullOrWhiteSpace ( order . CARRIERID ) )
{
result . Add ( new SubmitTelexResultDto ( order . MBLNO , false , "船公司为空" ) ) ;
continue ;
}
// 判断船公司是否符合条件
string carrierId = mappingCarrier . FirstOrDefault ( x = > x . Module = = "TelexCheck" & & x . Code = = order . CARRIERID ) ? . MapCode ;
carrierId = ( carrierId ? ? order . CARRIERID ) . ToUpper ( ) ;
if ( carrierId ! = "MSK" )
{
result . Add ( new SubmitTelexResultDto ( order . MBLNO , false , $"[{order.CARRIER}]船公司此功能待开发" ) ) ;
continue ;
}
// 判断签单方式是否符合条件
string issueType = mappingIssueType . FirstOrDefault ( x = > x . Module = = "TelexCheck" & & x . Code = = order . ISSUETYPE ) ? . MapCode ;
issueType = issueType ? ? order . ISSUETYPE ;
if ( ! issueType . Equals ( "telex" , StringComparison . OrdinalIgnoreCase ) )
{
result . Add ( new SubmitTelexResultDto ( order . MBLNO , false , $"签单方式非电放" ) ) ;
continue ;
}
pushList . Add ( ( order . Id , order . MBLNO , carrierId ) ) ;
}
catch ( Exception ex )
{
_logger . LogError ( "请求电放条件判断的过程中发生未知异常, mblno={mblno}, ex={ex}" , order . MBLNO , ex ) ;
result . Add ( new SubmitTelexResultDto ( order . MBLNO , false , $"提交错误:{ex.Message}" ) ) ;
continue ;
}
}
if ( pushList . Count = = 0 )
{
return result ;
}
if ( ids . Length > 1 )
{
url + = "/v1/tasks" ;
var mblnos = string . Concat ( ',' , pushList . Select ( x = > x . MBLNO ) ) ;
try
{
// 提交电放
var data = pushList . Select ( x = > new
{
web_code = x . CarrierId ,
web_user = webAccount . Account ,
web_psw = webAccount . Password ,
bno = x . MBLNO ,
email = UserManager . Email
} ) ;
var body = new
{
user_key = key ,
user_secret = secret ,
data = data
} ;
_logger . LogInformation ( "请求电放提交接口开始, mblnos={mblnos}, url={url}, body={body}" , mblnos , url , body ) ;
var rtn = await url . SetBody ( body ) . PostAsStringAsync ( ) ;
_logger . LogInformation ( "请求电放提交接口结束, rtn={rtn}" , rtn ) ;
var jsonRtn = JObject . Parse ( rtn ) ;
if ( jsonRtn . GetIntValue ( "code" ) = = 200 )
{
_logger . LogInformation ( "请求电放提交接口成功, mblnos={mblnos}" , mblnos ) ;
foreach ( var item in pushList )
{
// 推送 电放已安排 状态
var pushModel = new ModifyServiceProjectStatusDto
{
BookingId = item . Id ,
SourceType = TrackingSourceTypeEnum . MANUAL ,
StatusCodes = new List < ModifyServiceProjectStatusDetailDto > {
new ModifyServiceProjectStatusDetailDto { StatusCode = "DFYAP" } }
} ;
var saveStatusRlt = await bookingValueAddedService . SaveServiceStatus ( pushModel ) ;
_logger . LogInformation ( "请求电放提交接口成功后推送 电放已安排 状态, mblno={mblno}, JSON={json} ,结果={rlt}" ,
item . MBLNO , JSON . Serialize ( pushModel ) , JSON . Serialize ( saveStatusRlt ) ) ;
result . Add ( new SubmitTelexResultDto ( item . MBLNO , true , null ) ) ;
}
}
else
{
var msg = jsonRtn . GetStringValue ( "msg" ) ? . Replace ( "爬虫" , "" ) ;
_logger . LogInformation ( "请求电放提交接口失败, mblnos={mblnos}, 电放服务返回:{msg}" , mblnos , msg ) ;
result . AddRange ( pushList . Select ( x = > new SubmitTelexResultDto ( x . MBLNO , false , $"电放服务返回:{msg}" ) ) ) ;
}
}
catch ( Exception ex )
{
_logger . LogError ( "请求电放服务的过程中发生未知异常, mblnos={mblnos}, ex={ex}" , mblnos , ex ) ;
result . AddRange ( pushList . Select ( x = > new SubmitTelexResultDto ( x . MBLNO , false , $"错误:{ex.Message}" ) ) ) ;
}
}
else
{
url + = "/v1/submit" ;
var order = pushList [ 0 ] ;
try
{
// 提交电放
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 ) ;
var rtn = await url . SetBody ( body ) . PostAsStringAsync ( ) ;
_logger . LogInformation ( "请求电放提交接口结束, mblno={mblno}, rtn={rtn}" , order . MBLNO , rtn ) ;
var jsonRtn = JObject . Parse ( rtn ) ;
if ( jsonRtn . GetIntValue ( "code" ) = = 200 )
{
_logger . LogInformation ( "请求电放提交接口成功, mblno={mblno}" , order . MBLNO ) ;
// 推送 电放已安排 状态
var pushModel = new ModifyServiceProjectStatusDto
{
BookingId = order . Id ,
SourceType = TrackingSourceTypeEnum . MANUAL ,
StatusCodes = new List < ModifyServiceProjectStatusDetailDto > {
new ModifyServiceProjectStatusDetailDto { StatusCode = "DFYAP" } }
} ;
var saveStatusRlt = await bookingValueAddedService . SaveServiceStatus ( pushModel ) ;
_logger . LogInformation ( "请求电放提交接口成功后推送 电放已安排 状态, JSON={json} ,结果={rlt}" , JSON . Serialize ( pushModel ) , JSON . Serialize ( saveStatusRlt ) ) ;
result . Add ( new SubmitTelexResultDto ( order . MBLNO , true , null ) ) ;
}
else
{
var msg = jsonRtn . GetStringValue ( "msg" ) ? . Replace ( "爬虫" , "" ) ;
_logger . LogInformation ( "请求电放提交接口失败, mblno={mblno}, 电放服务返回:{msg}" , order . MBLNO , msg ) ;
result . Add ( new SubmitTelexResultDto ( order . MBLNO , false , $"电放服务返回:{msg}" ) ) ;
}
}
catch ( Exception ex )
{
_logger . LogError ( "请求电放服务的过程中发生未知异常, mblno={mblno}, ex={ex}" , order . MBLNO , ex ) ;
result . Add ( new SubmitTelexResultDto ( order . MBLNO , false , $"错误:{ex.Message}" ) ) ;
}
}
return result ;
}
# endregion
}
}