@ -24,6 +24,11 @@ using Org.BouncyCastle.Crypto;
using Yitter.IdGenerator ;
using MySqlX.XDevAPI.Common ;
using NPOI.OpenXmlFormats.Wordprocessing ;
using Newtonsoft.Json ;
using StackExchange.Profiling.Internal ;
using SqlSugar ;
using static Aliyun . OSS . Model . InventoryConfigurationModel ;
using System.Threading ;
namespace Myshipping.Application.Service.BookingOrder
{
@ -35,6 +40,8 @@ namespace Myshipping.Application.Service.BookingOrder
{
private readonly SqlSugarRepository < BookingDeliveryRecord > _bookingDeliveryRecordRep ;
private readonly SqlSugarRepository < BookingDeliveryRecordCtn > _bookingDeliveryRecordCtnRep ;
private readonly SqlSugarRepository < BookingDeliveryRecordShipSchedule > _bookingDeliveryRecordShipScheduleRep ;
private readonly ISysCacheService _cache ;
private readonly IDjyWebsiteAccountConfigService _webAccountConfig ;
private readonly ILogger < BookingMSKAPIService > _logger ;
@ -48,7 +55,7 @@ namespace Myshipping.Application.Service.BookingOrder
public BookingMSKAPIService ( ILogger < BookingMSKAPIService > logger , ISysCacheService cache ,
IDjyWebsiteAccountConfigService webAccountConfig , SqlSugarRepository < BookingDeliveryRecord > bookingDeliveryRecordRep ,
ISysDataUserMenu sysDataUserMenuService ,
SqlSugarRepository < BookingDeliveryRecordCtn > bookingDeliveryRecordCtnRep )
SqlSugarRepository < BookingDeliveryRecordCtn > bookingDeliveryRecordCtnRep , SqlSugarRepository < BookingDeliveryRecordShipSchedule > bookingDeliveryRecordShipScheduleRep )
{
_logger = logger ;
_cache = cache ;
@ -56,6 +63,7 @@ namespace Myshipping.Application.Service.BookingOrder
_bookingDeliveryRecordRep = bookingDeliveryRecordRep ;
_bookingDeliveryRecordCtnRep = bookingDeliveryRecordCtnRep ;
_sysDataUserMenuService = sysDataUserMenuService ;
_bookingDeliveryRecordShipScheduleRep = bookingDeliveryRecordShipScheduleRep ;
}
#region 检索海运船期详情
@ -173,11 +181,12 @@ namespace Myshipping.Application.Service.BookingOrder
queryInfo . stuffingVolume = model . stuffingVolume ;
}
MSKAPISearchPoint2PointScheduleResultDto resultInfo = null ;
var jsonBody = Newtonsoft . Json . JsonConvert . SerializeObject ( queryInfo ) ;
var jsonBody = Newtonsoft . Json . JsonConvert . SerializeObject ( queryInfo , Formatting . Indented , new JsonSerializerSettings
{
NullValueHandling = NullValueHandling . Ignore
} ) ;
var rlt = await queryUrl . SetBody ( jsonBody )
. PostAsStringAsync ( ) ;
@ -203,80 +212,264 @@ namespace Myshipping.Application.Service.BookingOrder
if ( resultInfo ! = null & & resultInfo . code = = 200
& & resultInfo . data ! = null & & resultInfo . data . Count > 0 )
{
resultInfo . data . ForEach ( a = >
resultInfo . data . ForEach ( t = >
{
a . transportSchedules . ForEach ( b = >
t . transportSchedules . ForEach ( a = >
{
a . originGeoId = model . carrierCollectionOriginGeoID ;
a . originUnLocCode = model . collectionOriginUNLocationCode ;
a . originRegionName = model . collectionOriginUNRegionName ;
a . originCityName = model . collectionOriginCityName ;
a . originCountryName = model . collectionOriginCountryName ;
a . destinationGeoId = model . carrierDeliveryDestinationGeoID ;
a . destinationUnLocCode = model . deliveryDestinationUNLocationCode ;
a . destinationRegionName = model . deliveryDestinationUNRegionName ;
a . destinationCityName = model . deliveryDestinationCityName ;
a . destinationCountryName = model . deliveryDestinationCountryName ;
CacheShipSailingSchedule ( a ) . GetAwaiter ( ) . GetResult ( ) ;
} ) ;
var currList = t . transportSchedules . Select ( a = >
{
SearchShipSailingScheduleResultDto info = new SearchShipSailingScheduleResultDto
return GetShipScheduleShow ( a ) ;
} ) . ToList ( ) ;
if ( currList . Count > 0 )
list . AddRange ( currList ) ;
} ) ;
}
}
catch ( Exception ex )
{
carrierProductId = a . carrierProductId ,
carrierProductSequenceId = a . carrierProductSequenceId ,
ETD = b . departureDateTime ,
ATD = b . arrivalDateTime ,
vesselOperatorCarrierCode = b . vesselOperatorCarrierCode
_logger . LogError ( $"检索海运船期详情异常, req={JSON.Serialize(model)} 原因:{ex.Message}" ) ;
throw Oops . Bah ( $"检索海运船期详情失败,{ex.Message}" ) ;
}
return list ;
}
# endregion
#region 组织返回船期数据
/// <summary>
/// 组织返回船期数据
/// </summary>
/// <param name="model">查询的船期详情</param>
/// <returns>返回显示的船期数据</returns>
private SearchShipSailingScheduleResultDto GetShipScheduleShow ( MSKAPISearchTransportSchedules model )
{
SearchShipSailingScheduleResultDto showDto = new SearchShipSailingScheduleResultDto
{
PId = model . PId ,
MD5 = model . MD5 ,
orignCarrierCityGeoID = model . originGeoId ,
orignUNLocationCode = model . originUnLocCode ,
orignCityName = model . originCityName ,
originRegionName = model . originRegionName ,
originCountryName = model . originCountryName ,
deliveryCarrierCityGeoID = model . destinationGeoId ,
deliveryUNLocationCode = model . destinationUnLocCode ,
deliveryCityName = model . destinationCityName ,
deliveryRegionName = model . destinationRegionName ,
deliveryCountryName = model . destinationCountryName ,
vesselName = model . firstDepartureVessel . vesselName ,
carrierDepartureVoyageNumber = model . transportLegs . FirstOrDefault ( ) . transport . carrierDepartureVoyageNumber ,
Legs = new List < MSKAPISPOTScheduleRateResultShowLegsDto > ( )
} ;
if ( b . departureDateTime . HasValue & & b . arrivalDateTime . HasValue )
//ETD
if ( model . departureDateTime . HasValue )
{
TimeSpan ts = b . arrivalDateTime . Value . Subtract ( b . departureDateTime . Value ) ;
var timeDiff = ts . TotalHours ;
showDto . ETD = model . departureDateTime . Value ;
}
else
{
throw Oops . Bah ( $"查询船期错误,预计离港日期查询为空" ) ;
}
info . days = ( int ) Math . Ceiling ( timeDiff / 24.0 ) ;
//ETA
if ( model . arrivalDateTime . HasValue )
{
showDto . ETA = model . arrivalDateTime . Value ;
}
else
{
throw Oops . Bah ( $"查询船期错误,预计到港日期查询为空" ) ;
}
if ( b . facilities ! = null )
//计算预计天数
if ( showDto . ETD . HasValue & & showDto . ETD . HasValue )
{
info . orignCityName = b . facilities . collectionOrigin ? . cityName ;
info . orignCarrierSiteGeoID = b . facilities . collectionOrigin ? . carrierSiteGeoID ;
info . orignLocationName = b . facilities . collectionOrigin ? . locationName ;
info . orignCountryCode = b . facilities . collectionOrigin ? . countryCode ;
info . orignLocationType = b . facilities . collectionOrigin ? . locationType ;
info . orignUNLocationCode = b . facilities . collectionOrigin ? . UNLocationCode ;
info . orignUNRegionCode = b . facilities . collectionOrigin ? . UNRegionCode ;
TimeSpan ts = showDto . ETA . Value . Subtract ( showDto . ETD . Value ) ;
var timeDiff = ts . TotalHours ;
info . deliveryCityName = b . facilities . deliveryDestination ? . cityName ;
info . deliveryCarrierSiteGeoID = b . facilities . deliveryDestination ? . carrierSiteGeoID ;
info . deliveryLocationName = b . facilities . deliveryDestination ? . locationName ;
info . deliveryCountryCode = b . facilities . deliveryDestination ? . countryCode ;
info . deliveryLocationType = b . facilities . deliveryDestination ? . locationType ;
info . deliveryUNLocationCode = b . facilities . deliveryDestination ? . UNLocationCode ;
info . deliveryUNRegionCode = b . facilities . deliveryDestination ? . UNRegionCode ;
showDto . days = ( int ) Math . Ceiling ( timeDiff / 24.0 ) ;
}
info . vesselIMONumber = b . firstDepartureVessel ? . vesselIMONumber ;
info . carrierVesselCode = b . firstDepartureVessel ? . carrierVesselCode ;
info . vesselName = b . firstDepartureVessel ? . vesselName ;
if ( model . transportLegs . Count > 1 )
showDto . isTransfer = true ;
//Legs
if ( model . facilities ! = null )
{
showDto . orignCountryCode = model . facilities . collectionOrigin . countryCode ;
showDto . deliveryCountryCode = model . facilities . deliveryDestination . countryCode ;
var legs = new List < MSKAPISPOTScheduleRateResultShowLegsDto > ( ) ;
for ( int i = 0 ; i < model . transportLegs . Count ; i + + )
{
var b = model . transportLegs [ i ] ;
if ( b . transportLegs ! = null & & b . transportLegs . Count > 0 )
MSKAPISPOTScheduleRateResultShowLegsDto leg = new MSKAPISPOTScheduleRateResultShowLegsDto
{
vesselName = b . transport . vessel . vesselName ,
VoyageNo = b . transport . carrierDepartureVoyageNumber ,
From = new MSKAPISPOTScheduleRateResultShowLegsLocationDto
{
var firstTransportLegs = b . transportLegs . FirstOrDefault ( ) ;
CityName = b . facilities . startLocation . cityName ,
CountryCode = b . facilities . startLocation . countryCode ,
SiteGeoId = b . facilities . startLocation . carrierSiteGeoID ,
LocationType = "From" ,
} ,
To = new MSKAPISPOTScheduleRateResultShowLegsLocationDto
{
CityName = b . facilities . endLocation . cityName ,
CountryCode = b . facilities . endLocation . countryCode ,
SiteGeoId = b . facilities . endLocation . carrierSiteGeoID ,
LocationType = "To" ,
}
} ;
if ( firstTransportLegs . transport ! = null )
//ETD
if ( b . departureDateTime . HasValue )
{
info . transportMode = firstTransportLegs . transport . transportMode ;
info . carrierDepartureVoyageNumber = firstTransportLegs . transport . carrierDepartureVoyageNumber ;
showDto . ETD = b . departureDateTime . Value ;
}
else
{
throw Oops . Bah ( $"查询船期错误,预计离港日期查询为空" ) ;
}
//ETA
if ( b . arrivalDateTime . HasValue )
{
showDto . ETA = b . arrivalDateTime . Value ;
}
else
{
throw Oops . Bah ( $"查询船期错误,预计到港日期查询为空" ) ;
}
info . transportLegs = b . transportLegs ;
leg . SortNo = i + 1 ;
leg . From . SiteGeoId = b . facilities . startLocation . carrierSiteGeoID ;
leg . From . CityName = b . facilities . startLocation . cityName ;
leg . From . CountryCode = b . facilities . startLocation . countryCode ;
leg . From . UnLocCode = b . facilities . startLocation . UNLocationCode ;
list . Add ( info ) ;
} ) ;
} ) ;
leg . To . SiteGeoId = b . facilities . endLocation . carrierSiteGeoID ;
leg . To . CityName = b . facilities . endLocation . cityName ;
leg . To . CountryCode = b . facilities . endLocation . countryCode ;
leg . To . UnLocCode = b . facilities . endLocation . UNLocationCode ;
if ( i = = 0 & & i = = model . transportLegs . Count - 1 )
{
leg . From . CityGeoId = model . originGeoId ;
leg . From . CountryName = model . originCountryName ;
leg . From . RegionName = model . originRegionName ;
leg . To . CityGeoId = model . destinationGeoId ;
leg . To . CountryName = model . destinationCountryName ;
leg . To . RegionName = model . destinationRegionName ;
}
else
{
if ( i = = 0 )
{
leg . From . CityGeoId = model . originGeoId ;
leg . From . CountryName = model . originCountryName ;
leg . From . RegionName = model . originRegionName ;
leg . From . UnLocCode = model . originUnLocCode ;
}
catch ( Exception ex )
else if ( i = = model . transportLegs . Count - 1 )
{
_logger . LogError ( $"检索海运船期详情异常, req={JSON.Serialize(model)} 原因:{ex.Message}" ) ;
leg . To . CityGeoId = model . destinationGeoId ;
leg . To . CountryName = model . destinationCountryName ;
leg . To . RegionName = model . destinationRegionName ;
leg . To . UnLocCode = model . destinationUnLocCode ;
}
}
throw Oops . Bah ( $"检索海运船期详情失败,{ex.Message}" ) ;
legs . Add ( leg ) ;
}
return list ;
showDto . Legs = legs . OrderBy ( t = > t . ETD ) . Select ( ( t , idx ) = > {
t . SortNo = idx + 1 ;
return t ;
} ) . ToList ( ) ;
}
return showDto ;
}
# endregion
#region 缓存船期数据
/// <summary>
/// 缓存船期数据
/// </summary>
/// <param name="model">船期查询结果明细</param>
/// <param name="busiType">船期类型 MSKSPOT-马士基即期</param>
/// <returns>返回主键ID</returns>
private async Task CacheShipSailingSchedule ( MSKAPISearchTransportSchedules model , string busiType = "MSKCON" )
{
/ *
1 、 按 照 船 期 明 细 缓 存 , 并 把 ID 作 为 缓 存 的 KEY
2 、 对 数 据 进 行 JSON 串 行 化 的 文 本 提 取 MD5
3 、 写 入 缓 存 , 并 返 回 ID
* /
var newModel = model . Adapt < MSKAPISearchTransportSchedules > ( ) ;
//newModel.priceID = null;
var json = Newtonsoft . Json . JsonConvert . SerializeObject ( newModel ) ;
model . PId = YitIdHelper . NextId ( ) ;
string md5 = json . ToMd5 ( ) ;
model . MD5 = md5 ;
var shareKey = model . PId . ToString ( ) ;
DateTime nowDate = DateTime . Now ;
DateTime expireDateTime = DateTime . Now . AddHours ( 4 ) ;
var expireTimeSpan = expireDateTime . Subtract ( nowDate ) . Duration ( ) ;
if ( ! _cache . Exists ( $"{shareKey}_{busiType}" ) )
{
await _cache . SetTimeoutAsync ( $"{shareKey}_{busiType}" , Newtonsoft . Json . JsonConvert . SerializeObject ( model ) , expireTimeSpan ) ;
}
}
# endregion
private MSKAPISearchTransportSchedules GetCacheShipSailingSchedule ( long pid , string busiType = "MSKCON" )
{
if ( _cache . Exists ( $"{pid}_{busiType}" ) )
{
return _cache . Get < MSKAPISearchTransportSchedules > ( $"{pid}_{busiType}" ) ;
}
return null ;
}
#region 发送马士基订舱请求
/// <summary>
/// 发送马士基订舱请求
@ -338,6 +531,37 @@ namespace Myshipping.Application.Service.BookingOrder
//这里是校验必填项
ValidateMSKAPIData ( model ) ;
BookingDeliveryRecordShipSchedule shipScheduleRecord = null ;
MSKAPISearchTransportSchedules selectedShipSchedule = null ;
if ( model . PId = = 0 )
throw Oops . Oh ( "船期信息不能为空,请重新检索船期" ) ;
if ( model . PId > 0 )
{
if ( model . id . HasValue & & model . id . Value > 0 )
{
var recordId = model . id . Value ;
shipScheduleRecord = await _bookingDeliveryRecordShipScheduleRep . AsQueryable ( )
. FirstAsync ( a = > a . RECORD_ID = = recordId & & a . SHIP_RATE_PID ! = null & &
a . SHIP_RATE_PID . Value = = model . PId & & a . IsDeleted = = false ) ;
}
if ( shipScheduleRecord = = null )
{
selectedShipSchedule = GetCacheShipSailingSchedule ( model . PId ) ;
}
else
{
selectedShipSchedule = JSON . Deserialize < MSKAPISearchTransportSchedules > ( shipScheduleRecord . SHIP_JSON ) ;
}
if ( selectedShipSchedule = = null )
throw Oops . Oh ( "船期数据校验失败,请重新查询船期信息" ) ;
}
DateTime nowDate = DateTime . Now ;
var recordInfo = model . Adapt < BookingDeliveryRecord > ( ) ;
@ -400,15 +624,13 @@ namespace Myshipping.Application.Service.BookingOrder
{
placeOfReceipt = new MSKAPIBookingRouteDetailsBase
{
UNLocationCode = model . userPlaceOfReceiptUnLocCode
//: model.placeOfReceiptUnLocCode,
//cityName = model.placeOfReceiptCityName,
UNLocationCode = model . userPlaceOfReceiptUnLocCode ,
maerskCityGeoId = selectedShipSchedule . originGeoId ,
} ,
placeOfDelivery = new MSKAPIBookingRouteDetailsBase
{
UNLocationCode = model . userPlaceOfDeliveryUnLocCode
//: model.placeOfDeliveryUnLocCode,
//cityName = model.placeOfDeliveryCityName,
UNLocationCode = model . userPlaceOfDeliveryUnLocCode ,
maerskCityGeoId = selectedShipSchedule . destinationGeoId ,
} ,
selectedRoute = new MSKAPIBookingRoute
{
@ -445,11 +667,140 @@ namespace Myshipping.Application.Service.BookingOrder
}
} ;
//ETD
//if (!string.IsNullOrWhiteSpace(selectedShipSchedule.facilities.)
//{
// DateTime currDate = DateTime.MinValue;
// if (DateTime.TryParse($"{selectedShipSchedule.scheduleDetails.FirstOrDefault().fromLocation.date} {selectedShipSchedule.scheduleDetails.FirstOrDefault().fromLocation.time}", out currDate))
// {
// bookingDto.bookingBody.transport.earliestDepartureDate = currDate.ToString("yyyy-MM-ddTHH:mm:ss");
// }
// else
// {
// throw Oops.Bah($"查询船期错误, priceID={model.priceID} pid={model.PId} 预计离港日期departureDate={selectedShipSchedule.scheduleDetails.FirstOrDefault().fromLocation.date} {selectedShipSchedule.scheduleDetails.FirstOrDefault().fromLocation.time} 格式解析错误");
// }
//}
//if(!model.isSendNoSchedule)
//{
// bookingDto.bookingBody.transport.routeDetails.selectedRoute.routeScheduleId = model.carrierProductId;
//}
for ( int i = 0 ; i < selectedShipSchedule . transportLegs . Count ; i + + )
{
var detail = selectedShipSchedule . transportLegs [ i ] ;
var currDto = new MSKAPIBookingSchedules ( ) ;
//ETD
if ( detail . departureDateTime . HasValue )
{
currDto . originDepartureDateTimeLocal = detail . departureDateTime . Value . ToString ( "yyyy-MM-ddTHH:mm:ss" ) ;
}
else
{
throw Oops . Bah ( $"查询船期错误, pid={model.PId} 预计离港日期departureDate 格式解析错误" ) ;
}
//ETA
if ( detail . arrivalDateTime . HasValue )
{
currDto . destinationArrivalDateTimeLocal = detail . arrivalDateTime . Value . ToString ( "yyyy-MM-ddTHH:mm:ss" ) ;
}
else
{
throw Oops . Bah ( $"查询船期错误, pid={model.PId} 预计到港日期arrivalDateTime 格式解析错误" ) ;
}
currDto . transportMode = new MSKAPIBookingTransportMode
{
vessel = new MSKAPIBookingTransportModeVessel
{
name = detail . transport . vessel . vesselName ,
maerskVesselCode = detail . transport . vessel . carrierVesselCode ,
vesselIMONumber = detail . transport . vessel . vesselIMONumber
} ,
exportVoyageNumber = detail . transport . carrierDepartureVoyageNumber ,
} ;
currDto . serviceCode = detail . transport . carrierServiceCode ;
currDto . transportModeCode = detail . transport . transportMode ;
//首个
if ( i = = 0 )
{
currDto . startLocation = new MSKAPIBookingRouteDetailsBase
{
cityName = detail . facilities . startLocation . cityName ,
ISOcountryCode = detail . facilities . startLocation . countryCode ,
UNLocationCode = detail . facilities . startLocation . UNLocationCode ,
maerskCityGeoId = selectedShipSchedule . originGeoId ,
} ;
if ( i = = selectedShipSchedule . transportLegs . Count - 1 )
{
currDto . endLocation = new MSKAPIBookingRouteDetailsBase
{
cityName = detail . facilities . endLocation . cityName ,
ISOcountryCode = detail . facilities . endLocation . countryCode ,
UNLocationCode = detail . facilities . endLocation . UNLocationCode ,
maerskCityGeoId = selectedShipSchedule . destinationGeoId ,
} ;
}
else
{
currDto . endLocation = new MSKAPIBookingRouteDetailsBase
{
cityName = detail . facilities . endLocation . cityName ,
ISOcountryCode = detail . facilities . endLocation . countryCode ,
UNLocationCode = detail . facilities . endLocation . UNLocationCode ,
maerskSiteGeoId = detail . facilities . endLocation . carrierSiteGeoID ,
} ;
}
}
else if ( i = = selectedShipSchedule . transportLegs . Count - 1 )
{
currDto . startLocation = new MSKAPIBookingRouteDetailsBase
{
cityName = detail . facilities . startLocation . cityName ,
ISOcountryCode = detail . facilities . startLocation . countryCode ,
UNLocationCode = detail . facilities . startLocation . UNLocationCode ,
maerskSiteGeoId = detail . facilities . startLocation . carrierSiteGeoID ,
} ;
currDto . endLocation = new MSKAPIBookingRouteDetailsBase
{
cityName = detail . facilities . endLocation . cityName ,
ISOcountryCode = detail . facilities . endLocation . countryCode ,
UNLocationCode = detail . facilities . endLocation . UNLocationCode ,
maerskCityGeoId = selectedShipSchedule . destinationGeoId ,
} ;
}
else
{
currDto . startLocation = new MSKAPIBookingRouteDetailsBase
{
cityName = detail . facilities . startLocation . cityName ,
ISOcountryCode = detail . facilities . startLocation . countryCode ,
UNLocationCode = detail . facilities . startLocation . UNLocationCode ,
maerskSiteGeoId = detail . facilities . startLocation . carrierSiteGeoID ,
} ;
currDto . endLocation = new MSKAPIBookingRouteDetailsBase
{
cityName = detail . facilities . endLocation . cityName ,
ISOcountryCode = detail . facilities . endLocation . countryCode ,
UNLocationCode = detail . facilities . endLocation . UNLocationCode ,
maerskSiteGeoId = detail . facilities . endLocation . carrierSiteGeoID ,
} ;
}
bookingDto . bookingBody . transport . routeDetails . selectedRoute . bookingSchedules . Add ( currDto ) ;
}
bookingDto . bookingBody . cargo = new MSKAPIBookingCargo
{
commodityCode = model . commodityCode ,
@ -1156,6 +1507,25 @@ namespace Myshipping.Application.Service.BookingOrder
} ) . ToList ( ) ;
}
MSKAPISearchTransportSchedules selectedShipSchedule = null ;
if ( model . PId > 0 )
{
var shipScheduleRecord = await _bookingDeliveryRecordShipScheduleRep . AsQueryable ( )
. FirstAsync ( a = > a . SHIP_RATE_PID ! = null & & a . SHIP_RATE_PID . Value = = model . PId ) ;
if ( shipScheduleRecord ! = null )
{
selectedShipSchedule = JSON . Deserialize < MSKAPISearchTransportSchedules > ( shipScheduleRecord . SHIP_JSON ) ;
if ( selectedShipSchedule ! = null )
{
model . selectedShipScheduleShow = GetShipScheduleShow ( selectedShipSchedule ) ;
}
}
}
return model ;
}
# endregion
@ -1188,6 +1558,42 @@ namespace Myshipping.Application.Service.BookingOrder
_logger . LogInformation ( $"获取请求马士基API订舱报文, JSON={JSON.Serialize(model)}" ) ;
BookingDeliveryRecordShipSchedule shipScheduleRecord = null ;
MSKAPISearchTransportSchedules selectedShipSchedule = null ;
if ( model . PId > 0 )
{
if ( model . id . HasValue & & model . id . Value > 0 )
{
var recordId = model . id . Value ;
shipScheduleRecord = await _bookingDeliveryRecordShipScheduleRep . AsQueryable ( )
. FirstAsync ( a = > a . RECORD_ID = = recordId & & a . SHIP_RATE_PID ! = null & &
a . SHIP_RATE_PID . Value = = model . PId & & a . IsDeleted = = false ) ;
}
if ( shipScheduleRecord = = null )
{
selectedShipSchedule = GetCacheShipSailingSchedule ( model . PId ) ;
}
else
{
selectedShipSchedule = JSON . Deserialize < MSKAPISearchTransportSchedules > ( shipScheduleRecord . SHIP_JSON ) ;
}
if ( selectedShipSchedule = = null )
throw Oops . Oh ( "船期数据校验失败,请重新查询船期信息" ) ;
model . placeOfReceiptCountryName = selectedShipSchedule . originCountryName ;
model . placeOfReceiptRegionName = selectedShipSchedule . originRegionName ;
model . carrierCollectionOriginGeoID = selectedShipSchedule . originGeoId ;
model . placeOfDeliveryCountryName = selectedShipSchedule . destinationCountryName ;
model . placeOfDeliveryRegionName = selectedShipSchedule . destinationRegionName ;
model . carrierDeliveryDestinationGeoID = selectedShipSchedule . destinationGeoId ;
}
if ( model . ctns ! = null & & model . ctns . Count > 0 )
{
ctnStat = string . Join ( "," , model . ctns . GroupBy ( a = > a . ctnName )
@ -1218,6 +1624,8 @@ namespace Myshipping.Application.Service.BookingOrder
entity . UpdatedUserId = UserManager . UserId ;
entity . UpdatedUserName = UserManager . Name ;
entity . CTN_STAT = ctnStat ;
entity . BOOKING_CHANNEL_TYPE = "CON_API" ;
entity . BOOKING_CHANNEL_TYPE_NAME = "合约API" ;
await _bookingDeliveryRecordRep . AsUpdateable ( entity ) . IgnoreColumns ( x = > new
{
@ -1309,6 +1717,27 @@ namespace Myshipping.Application.Service.BookingOrder
}
}
if ( shipScheduleRecord = = null )
{
if ( model . PId > 0 & & selectedShipSchedule ! = null )
{
shipScheduleRecord = new BookingDeliveryRecordShipSchedule
{
Id = YitIdHelper . NextId ( ) ,
RECORD_ID = model . id . Value ,
SHIP_RATE_PID = selectedShipSchedule . PId ,
SHIP_RATE_MD5 = selectedShipSchedule . MD5 ,
SHIP_JSON = Newtonsoft . Json . JsonConvert . SerializeObject ( selectedShipSchedule ) ,
CreatedTime = nowDate ,
UpdatedTime = nowDate ,
CreatedUserId = UserManager . UserId ,
CreatedUserName = UserManager . Name
} ;
await _bookingDeliveryRecordShipScheduleRep . InsertAsync ( shipScheduleRecord ) ;
}
}
return model . id . Value ;
}
else
@ -1322,6 +1751,8 @@ namespace Myshipping.Application.Service.BookingOrder
entity . STATUS = "TEMP" ;
entity . STATUS_NAME = "暂存" ;
entity . CTN_STAT = ctnStat ;
entity . BOOKING_CHANNEL_TYPE = "CON_API" ;
entity . BOOKING_CHANNEL_TYPE_NAME = "合约API" ;
await _bookingDeliveryRecordRep . InsertAsync ( entity ) ;
@ -1348,6 +1779,66 @@ namespace Myshipping.Application.Service.BookingOrder
} ) ;
}
if ( shipScheduleRecord = = null )
{
if ( model . PId > 0 & & selectedShipSchedule ! = null )
{
shipScheduleRecord = new BookingDeliveryRecordShipSchedule
{
Id = YitIdHelper . NextId ( ) ,
RECORD_ID = entity . Id ,
SHIP_RATE_PID = selectedShipSchedule . PId ,
SHIP_RATE_MD5 = selectedShipSchedule . MD5 ,
SHIP_JSON = Newtonsoft . Json . JsonConvert . SerializeObject ( selectedShipSchedule ) ,
CreatedTime = nowDate ,
UpdatedTime = nowDate ,
CreatedUserId = UserManager . UserId ,
CreatedUserName = UserManager . Name
} ;
await _bookingDeliveryRecordShipScheduleRep . InsertAsync ( shipScheduleRecord ) ;
}
}
else
{
//只有船期发生变化时才重新写入新的船期记录
if ( model . PId ! = shipScheduleRecord . SHIP_RATE_PID . Value )
{
_logger . LogInformation ( $"MSK CON id={model.id} 换了船期 原记录:{selectedShipSchedule.PId} 新记录:{model.PId} 作废原船期,插入新船期" ) ;
shipScheduleRecord . IsDeleted = true ;
shipScheduleRecord . UpdatedTime = nowDate ;
shipScheduleRecord . UpdatedUserId = UserManager . UserId ;
shipScheduleRecord . UpdatedUserName = UserManager . Name ;
await _bookingDeliveryRecordShipScheduleRep . AsUpdateable ( shipScheduleRecord ) . UpdateColumns ( x = > new {
x . IsDeleted ,
x . UpdatedUserId ,
x . UpdatedUserName ,
x . UpdatedTime
} ) . ExecuteCommandAsync ( ) ;
shipScheduleRecord = new BookingDeliveryRecordShipSchedule
{
Id = YitIdHelper . NextId ( ) ,
RECORD_ID = model . id . Value ,
SHIP_RATE_PID = selectedShipSchedule . PId ,
SHIP_RATE_MD5 = selectedShipSchedule . MD5 ,
SHIP_JSON = Newtonsoft . Json . JsonConvert . SerializeObject ( selectedShipSchedule ) ,
CreatedTime = nowDate ,
UpdatedTime = nowDate ,
CreatedUserId = UserManager . UserId ,
CreatedUserName = UserManager . Name
} ;
await _bookingDeliveryRecordShipScheduleRep . InsertAsync ( shipScheduleRecord ) ;
}
else
{
_logger . LogInformation ( $"MSK CON id={model.id} 船期没变化 model.PId={model.PId} shipScheduleRecord.SHIP_RATE_PID={shipScheduleRecord.SHIP_RATE_PID.Value}" ) ;
}
}
return entity . Id ;
}
}
@ -1419,6 +1910,8 @@ namespace Myshipping.Application.Service.BookingOrder
failNum + + ;
}
Thread . Sleep ( 1000 ) ;
} ) ;
msgList . Add ( $"共计{totalNum} 条 成功{succNum}条 失败:{failNum}" ) ;
@ -1732,5 +2225,43 @@ namespace Myshipping.Application.Service.BookingOrder
return "校验成功" ;
}
# endregion
#region 获取初始化页面默认值
/// <summary>
/// 获取初始化页面默认值
/// </summary>
/// <returns>返回详情</returns>
[HttpGet("/BookingMSKAPI/GetInitInfo")]
public async Task < MSKSPOTBookingInitDto > GetInitInfo ( )
{
MSKSPOTBookingInitDto dto = null ;
var webAccountConfig = await _webAccountConfig . GetAccountConfigByTenantId ( "MSKApi" , UserManager . UserId , UserManager . TENANT_ID ) ;
if ( webAccountConfig = = null )
throw Oops . Oh ( "未配置公司账户维护-MSK即期, 请联系管理员" ) ;
if ( string . IsNullOrWhiteSpace ( webAccountConfig . RegistPartyCode )
| | string . IsNullOrWhiteSpace ( webAccountConfig . RegistPartyName ) | | string . IsNullOrWhiteSpace ( webAccountConfig . RegistContractName )
| | string . IsNullOrWhiteSpace ( webAccountConfig . RegistContractEmail ) )
{
throw Oops . Oh ( "账户维护-MSK即期,未配置完整注册信息(备案代码、备案全称、联系人、邮箱必填),请联系管理员" ) ;
}
dto = new MSKSPOTBookingInitDto
{
bookedByMaerskPartyCode = webAccountConfig . RegistPartyCode ,
bookedByCompanyName = webAccountConfig . RegistPartyName ,
priceOwnerMaerskPartyCode = webAccountConfig . RegistPartyCode ,
priceOwnerCompanyName = webAccountConfig . RegistPartyName ,
bookedByCompanyContactName = webAccountConfig . RegistContractName ,
bookedByCompanyContactEmail = webAccountConfig . RegistContractEmail ,
priceOwnerContactName = webAccountConfig . RegistContractName ,
priceOwnerContactEmail = webAccountConfig . RegistContractEmail ,
} ;
return dto ;
}
# endregion
}
}