From 08134abfc7bd47d927cd06ca2c4b71f9a4f5f028 Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Mon, 4 Mar 2024 14:37:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A9=AC=E5=A3=AB=E5=9F=BA?= =?UTF-8?q?=E8=AE=A2=E8=88=B1API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BookingOrder/BookingOrderService.cs | 81 +++++++++++++++++++ .../MSKAPISearchPoint2PointScheduleDto.cs | 2 +- ...SKAPISearchPoint2PointScheduleResultDto.cs | 2 +- .../Service/BookingOrder/Dto/MSKBookingDto.cs | 8 ++ .../Dto/QueryShipSailingScheduleDto.cs | 5 ++ 5 files changed, 96 insertions(+), 2 deletions(-) diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index beaa2fd7..26cc2469 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -11881,11 +11881,92 @@ namespace Myshipping.Application */ try { + if(string.IsNullOrWhiteSpace(model.collectionOriginCityName)) + throw Oops.Oh($"始发地不能为空"); + if (string.IsNullOrWhiteSpace(model.deliveryDestinationCityName)) + throw Oops.Oh($"目的地不能为空"); + + if (string.IsNullOrWhiteSpace(model.vesselOperatorCarrierCode)) + throw Oops.Oh($"服务船公司不能为空"); + + if (string.IsNullOrWhiteSpace(model.startDate)) + throw Oops.Oh($"预计离港日期不能为空"); + + DateTime etd = DateTime.MinValue; + + if(!DateTime.TryParse(model.startDate,out etd)) + throw Oops.Oh($"预计离港日期格式错误"); + + string queryUrl = string.Empty; + + if (model.carrierId.Equals("MSK", StringComparison.OrdinalIgnoreCase)) + { + queryUrl = _cache.GetAllDictData().GetAwaiter().GetResult() + .FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == CONST_MSK_API_Poing2P_SECD_URL)?.Value; + } + else + { + throw Oops.Oh($"当前船公司 {model.carrierId} 未配置相应的请求接口"); + } + + if (string.IsNullOrWhiteSpace(queryUrl)) + throw Oops.Oh("未配置查询船期请求接口地址,请联系管理员"); + + var webAccountConfig = _webAccountConfig + .GetAccountConfig("MSKApi", UserManager.UserId).GetAwaiter().GetResult(); + + if (webAccountConfig == null) + throw Oops.Oh("未配置个人账户,请先配置个人账户 类型-MSKApi"); + + MSKAPISearchPoint2PointScheduleDto queryInfo = new MSKAPISearchPoint2PointScheduleDto + { + userKey = App.Configuration["MSKAPIDjyUserKey"], + userSecret = App.Configuration["MSKAPIDjyUserSecret"], + operatingEnvironment = App.Configuration["MSKAPIOPEnvironment"], + mskAppKey = webAccountConfig.Account, + collectionOriginCityName = model.collectionOriginCityName, + collectionOriginCountryCode = model.collectionOriginCountryCode, + deliveryDestinationCityName = model.deliveryDestinationCityName, + deliveryDestinationCountryCode = model.deliveryDestinationCountryCode, + cargoType = model.cargoType, + exportServiceMode = model.exportServiceMode, + importServiceMode = model.importServiceMode, + vesselOperatorCarrierCode = model.vesselOperatorCarrierCode, + startDate = etd.ToString("yyyy-MM-dd"), + startDateType = "D", + }; + + MSKAPISearchPoint2PointScheduleResultDto resultInfo = null; + + var rlt = await queryUrl.SetBody(queryInfo) + .PostAsStringAsync(); + + if (!string.IsNullOrWhiteSpace(rlt)) + { + try + { + resultInfo = JSON.Deserialize(rlt); + } + catch (Exception ex) + { + _logger.LogInformation($"请求MSK API查询船期异常,原因:{ex.Message}"); + + throw Oops.Bah($"请求MSK API查询船期异常,原因:{ex.Message}"); + } + } + + if (resultInfo != null && resultInfo.code == 200 + && resultInfo.data != null && resultInfo.data.Count > 0) + { + list = resultInfo.data.Adapt>(); + } } catch (Exception ex) { + _logger.LogError($"检索海运船期详情异常,req={JSON.Serialize(model)} 原因:{ex.Message}"); + throw Oops.Bah($"检索海运船期详情失败,{ex.Message}"); } return list; diff --git a/Myshipping.Application/Service/BookingOrder/Dto/MSKAPI/MSKAPISearchPoint2PointScheduleDto.cs b/Myshipping.Application/Service/BookingOrder/Dto/MSKAPI/MSKAPISearchPoint2PointScheduleDto.cs index 649ef298..b7ef0854 100644 --- a/Myshipping.Application/Service/BookingOrder/Dto/MSKAPI/MSKAPISearchPoint2PointScheduleDto.cs +++ b/Myshipping.Application/Service/BookingOrder/Dto/MSKAPI/MSKAPISearchPoint2PointScheduleDto.cs @@ -109,7 +109,7 @@ namespace Myshipping.Application /// /// 箱体积 /// - public int stuffingVolume { get; set; } + public Nullable stuffingVolume { get; set; } /// /// 体积单位(MTQ, FTQ) diff --git a/Myshipping.Application/Service/BookingOrder/Dto/MSKAPI/MSKAPISearchPoint2PointScheduleResultDto.cs b/Myshipping.Application/Service/BookingOrder/Dto/MSKAPI/MSKAPISearchPoint2PointScheduleResultDto.cs index aebef052..05d5b8df 100644 --- a/Myshipping.Application/Service/BookingOrder/Dto/MSKAPI/MSKAPISearchPoint2PointScheduleResultDto.cs +++ b/Myshipping.Application/Service/BookingOrder/Dto/MSKAPI/MSKAPISearchPoint2PointScheduleResultDto.cs @@ -24,7 +24,7 @@ namespace Myshipping.Application /// /// 回执代码 /// - public MSKAPISearchPoint2PointScheduleResultDataDto data { get; set; } + public List data { get; set; } } public class MSKAPISearchPoint2PointScheduleResultDataDto diff --git a/Myshipping.Application/Service/BookingOrder/Dto/MSKBookingDto.cs b/Myshipping.Application/Service/BookingOrder/Dto/MSKBookingDto.cs index 4630e2a6..cb05a233 100644 --- a/Myshipping.Application/Service/BookingOrder/Dto/MSKBookingDto.cs +++ b/Myshipping.Application/Service/BookingOrder/Dto/MSKBookingDto.cs @@ -187,6 +187,14 @@ namespace Myshipping.Application /// public string commodityCodeType { get; set; } + /// + /// 箱型箱量列表 + /// + public List ctns { get; set; } + } + + public class MSKBookingCtnInfo + { /// /// 箱型 /// diff --git a/Myshipping.Application/Service/BookingOrder/Dto/QueryShipSailingScheduleDto.cs b/Myshipping.Application/Service/BookingOrder/Dto/QueryShipSailingScheduleDto.cs index c8436203..c5ad3cb9 100644 --- a/Myshipping.Application/Service/BookingOrder/Dto/QueryShipSailingScheduleDto.cs +++ b/Myshipping.Application/Service/BookingOrder/Dto/QueryShipSailingScheduleDto.cs @@ -11,6 +11,11 @@ namespace Myshipping.Application /// public class QueryShipSailingScheduleDto { + /// + /// 船公司代码 + /// + public string carrierId { get; set; } + /// /// 起始地的GEO ID ///