|
|
|
@ -17,6 +17,7 @@ using Myshipping.Core.Service;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Myshipping.Application.Helper;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
|
|
|
|
namespace Myshipping.Application.Service.BookingOrder
|
|
|
|
|
{
|
|
|
|
@ -280,6 +281,7 @@ namespace Myshipping.Application.Service.BookingOrder
|
|
|
|
|
userSecret = App.Configuration["MSKAPIDjyUserSecret"],
|
|
|
|
|
operatingEnvironment = App.Configuration["MSKAPIOPEnvironment"],
|
|
|
|
|
mskAppKey = webAccountConfig.Account,
|
|
|
|
|
mskAppSecret = webAccountConfig.Password,
|
|
|
|
|
bookingBody = new MSKAPIBookingBodyDto()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -288,6 +290,7 @@ namespace Myshipping.Application.Service.BookingOrder
|
|
|
|
|
priceReference = model.priceReference,
|
|
|
|
|
productCode = model.productCode,
|
|
|
|
|
sender = model.sender,
|
|
|
|
|
bookingOfficeUNLocationCode = "CNTAO"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bookingDto.bookingBody.mandatoryParties = new MSKAPIBookingMandatoryParties
|
|
|
|
@ -311,7 +314,7 @@ namespace Myshipping.Application.Service.BookingOrder
|
|
|
|
|
bookingDto.bookingBody.transport = new MSKAPIBookingTransport
|
|
|
|
|
{
|
|
|
|
|
carrierCode = model.carrierCode,
|
|
|
|
|
earliestDepartureDate = model.earliestDepartureDate,
|
|
|
|
|
earliestDepartureDate = model.earliestDepartureDate.Value.ToString("yyyy-MM-ddTHH:mm:ss"),
|
|
|
|
|
exportServiceMode = model.exportServiceMode,
|
|
|
|
|
importServiceMode = model.importServiceMode,
|
|
|
|
|
routeDetails = new MSKAPIBookingRouteDetails
|
|
|
|
@ -328,30 +331,32 @@ namespace Myshipping.Application.Service.BookingOrder
|
|
|
|
|
},
|
|
|
|
|
selectedRoute = new MSKAPIBookingRoute
|
|
|
|
|
{
|
|
|
|
|
bookingSchedules = new MSKAPIBookingSchedules
|
|
|
|
|
{
|
|
|
|
|
originDepartureDateTimeLocal = model.originDepartureDateTimeLocal.Value.ToString("yyyy-MM-dd"),
|
|
|
|
|
destinationArrivalDateTimeLocal = model.destinationArrivalDateTimeLocal.Value.ToString("yyyy-MM-dd"),
|
|
|
|
|
transportMode = new MSKAPIBookingTransportMode
|
|
|
|
|
bookingSchedules = new List<MSKAPIBookingSchedules> {
|
|
|
|
|
new MSKAPIBookingSchedules
|
|
|
|
|
{
|
|
|
|
|
vessel = new MSKAPIBookingTransportModeVessel
|
|
|
|
|
originDepartureDateTimeLocal = model.originDepartureDateTimeLocal.Value.ToString("yyyy-MM-ddTHH:mm:ss"),
|
|
|
|
|
destinationArrivalDateTimeLocal = model.destinationArrivalDateTimeLocal.Value.ToString("yyyy-MM-ddTHH:mm:ss"),
|
|
|
|
|
transportMode = new MSKAPIBookingTransportMode
|
|
|
|
|
{
|
|
|
|
|
name = model.vesselName,
|
|
|
|
|
maerskVesselCode = model.carrierVesselCode,
|
|
|
|
|
vessel = new MSKAPIBookingTransportModeVessel
|
|
|
|
|
{
|
|
|
|
|
name = model.vesselName,
|
|
|
|
|
maerskVesselCode = model.carrierVesselCode,
|
|
|
|
|
},
|
|
|
|
|
exportVoyageNumber = model.exportVoyageNumber,
|
|
|
|
|
},
|
|
|
|
|
exportVoyageNumber = model.exportVoyageNumber,
|
|
|
|
|
},
|
|
|
|
|
startLocation = new MSKAPIBookingRouteDetailsBase
|
|
|
|
|
{
|
|
|
|
|
cityName = model.placeOfReceiptCityName,
|
|
|
|
|
UNLocationCode = model.placeOfReceiptUnLocCode
|
|
|
|
|
},
|
|
|
|
|
endLocation = new MSKAPIBookingRouteDetailsBase
|
|
|
|
|
{
|
|
|
|
|
cityName = model.placeOfDeliveryCityName,
|
|
|
|
|
UNLocationCode = model.placeOfDeliveryUnLocCode
|
|
|
|
|
},
|
|
|
|
|
transportModeCode = model.transportMode
|
|
|
|
|
startLocation = new MSKAPIBookingRouteDetailsBase
|
|
|
|
|
{
|
|
|
|
|
cityName = model.placeOfReceiptCityName,
|
|
|
|
|
UNLocationCode = model.placeOfReceiptUnLocCode
|
|
|
|
|
},
|
|
|
|
|
endLocation = new MSKAPIBookingRouteDetailsBase
|
|
|
|
|
{
|
|
|
|
|
cityName = model.placeOfDeliveryCityName,
|
|
|
|
|
UNLocationCode = model.placeOfDeliveryUnLocCode
|
|
|
|
|
},
|
|
|
|
|
transportModeCode = model.transportMode
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
@ -412,13 +417,14 @@ namespace Myshipping.Application.Service.BookingOrder
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var id = await Save(model);
|
|
|
|
|
var id = await InnerSave(model, isSendApi: true);
|
|
|
|
|
|
|
|
|
|
MSKAPIBookingResultDto resultInfo = null;
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"开始请求MSK API订舱,JSON={JSON.Serialize(bookingDto)}");
|
|
|
|
|
|
|
|
|
|
var rlt = await sendUrl.SetBody(bookingDto)
|
|
|
|
|
var jsonBody = Newtonsoft.Json.JsonConvert.SerializeObject(bookingDto);
|
|
|
|
|
var rlt = await sendUrl.SetBody(jsonBody)
|
|
|
|
|
.PostAsStringAsync();
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"开始请求MSK API订舱,返回结果 JSON={JSON.Serialize(rlt)}");
|
|
|
|
@ -437,14 +443,21 @@ namespace Myshipping.Application.Service.BookingOrder
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MSKAPIBookingResultDataDto resultData = null;
|
|
|
|
|
|
|
|
|
|
if(resultInfo.code == 200)
|
|
|
|
|
{
|
|
|
|
|
resultData = JSON.Deserialize<MSKAPIBookingResultDataDto>(JSON.Serialize(resultInfo.data));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var entity = _bookingDeliveryRecordRep
|
|
|
|
|
.FirstOrDefault(a => a.Id == recordInfo.Id);
|
|
|
|
|
|
|
|
|
|
if (resultInfo != null && resultInfo.code == 200
|
|
|
|
|
&& resultInfo.data != null)
|
|
|
|
|
&& resultData != null)
|
|
|
|
|
{
|
|
|
|
|
entity.REQUEST_ACKNOWLEDGEMENT_ID = resultInfo.data.requestAcknowledgementId;
|
|
|
|
|
entity.BOOKING_REFERENCE = resultInfo.data.bookingReference;
|
|
|
|
|
entity.REQUEST_ACKNOWLEDGEMENT_ID = resultData.requestAcknowledgementId;
|
|
|
|
|
entity.BOOKING_REFERENCE = resultData.bookingReference;
|
|
|
|
|
entity.STATUS = "SUCC";
|
|
|
|
|
|
|
|
|
|
await _bookingDeliveryRecordRep.AsUpdateable(entity).UpdateColumns(x => new
|
|
|
|
@ -464,6 +477,9 @@ namespace Myshipping.Application.Service.BookingOrder
|
|
|
|
|
x.STATUS,
|
|
|
|
|
x.NOTES
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
throw Oops.Bah(resultInfo.msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
@ -500,6 +516,7 @@ namespace Myshipping.Application.Service.BookingOrder
|
|
|
|
|
12、如果选择了冷冻处理,至少要填个温度
|
|
|
|
|
13、箱型、箱量、重量必填
|
|
|
|
|
14、总重=箱量*单箱重量
|
|
|
|
|
15、预计离港日期必填
|
|
|
|
|
*/
|
|
|
|
|
if (string.IsNullOrWhiteSpace(model.priceReference))
|
|
|
|
|
throw Oops.Bah($"订舱合同惟一ID必填");
|
|
|
|
@ -585,6 +602,9 @@ namespace Myshipping.Application.Service.BookingOrder
|
|
|
|
|
if (string.IsNullOrWhiteSpace(model.cargoType))
|
|
|
|
|
throw Oops.Bah($"货物标志必填");
|
|
|
|
|
|
|
|
|
|
if(!model.earliestDepartureDate.HasValue)
|
|
|
|
|
throw Oops.Bah($"预计离港日期必填");
|
|
|
|
|
|
|
|
|
|
if (model.isReefer)
|
|
|
|
|
{
|
|
|
|
|
if (!model.temperature.HasValue)
|
|
|
|
@ -960,9 +980,9 @@ namespace Myshipping.Application.Service.BookingOrder
|
|
|
|
|
/// <param name="id">马士基API订舱ID</param>
|
|
|
|
|
/// <returns>返回详情</returns>
|
|
|
|
|
[HttpGet("/BookingMSKAPI/GetInfo")]
|
|
|
|
|
public async Task<BookingDeliveryRecordDto> GetInfo(long id)
|
|
|
|
|
public async Task<MSKBookingDto> GetInfo(long id)
|
|
|
|
|
{
|
|
|
|
|
BookingDeliveryRecordDto model = null;
|
|
|
|
|
MSKBookingDto model = null;
|
|
|
|
|
|
|
|
|
|
var entity = await _bookingDeliveryRecordRep.AsQueryable()
|
|
|
|
|
.FirstAsync(a => a.Id == id);
|
|
|
|
@ -970,14 +990,15 @@ namespace Myshipping.Application.Service.BookingOrder
|
|
|
|
|
if(entity == null)
|
|
|
|
|
throw Oops.Oh($"获取马士基API订舱详情失败,不存在或已作废");
|
|
|
|
|
|
|
|
|
|
model = entity.Adapt<BookingDeliveryRecordDto>();
|
|
|
|
|
model = entity.Adapt<MSKBookingDto>();
|
|
|
|
|
|
|
|
|
|
var ctnList = _bookingDeliveryRecordCtnRep.AsQueryable()
|
|
|
|
|
.Where(a => a.RECORD_ID == id && a.IsDeleted == false).ToList();
|
|
|
|
|
|
|
|
|
|
if (ctnList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
model.ctns = ctnList.Select(a => new BookingDeliveryRecordCtnDto {
|
|
|
|
|
model.ctns = ctnList.Select(a => new MSKBookingCtnInfo
|
|
|
|
|
{
|
|
|
|
|
id = a.Id,
|
|
|
|
|
ctnCode = a.CTN_CODE,
|
|
|
|
|
carrierCtnCode = a.CARRIER_CTN_CODE,
|
|
|
|
@ -1000,6 +1021,18 @@ namespace Myshipping.Application.Service.BookingOrder
|
|
|
|
|
/// <returns>返回ID</returns>
|
|
|
|
|
[HttpPost("/BookingMSKAPI/Save")]
|
|
|
|
|
public async Task<long> Save([FromBody] MSKBookingDto model)
|
|
|
|
|
{
|
|
|
|
|
return await InnerSave(model);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存内部方法
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model">API订舱详情</param>
|
|
|
|
|
/// <param name="isSendApi">是否发送API,true-发送需要校验状态;false-不校验状态</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private async Task<long> InnerSave(MSKBookingDto model,bool isSendApi = false)
|
|
|
|
|
{
|
|
|
|
|
DateTime nowDate = DateTime.Now;
|
|
|
|
|
|
|
|
|
@ -1013,10 +1046,20 @@ namespace Myshipping.Application.Service.BookingOrder
|
|
|
|
|
.Select(a => $"{a.Key}*{a.ToList().Sum(b => b.ctnNum.HasValue ? b.ctnNum.Value : 0)}").ToArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (model.id.HasValue && model.id.Value > 0)
|
|
|
|
|
{
|
|
|
|
|
var oldInfo = _bookingDeliveryRecordRep.AsQueryable()
|
|
|
|
|
.First(a=>a.Id == model.id);
|
|
|
|
|
|
|
|
|
|
if (oldInfo == null)
|
|
|
|
|
throw Oops.Oh("订舱数据不存在或已作废");
|
|
|
|
|
|
|
|
|
|
if (isSendApi)
|
|
|
|
|
{
|
|
|
|
|
if(oldInfo.STATUS == "SUCC")
|
|
|
|
|
throw Oops.Oh("订舱数据已发送成功,不能重复发送");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BookingDeliveryRecord entity = model.Adapt<BookingDeliveryRecord>();
|
|
|
|
|
|
|
|
|
|
entity.Id = model.id.Value;
|
|
|
|
@ -1060,7 +1103,7 @@ namespace Myshipping.Application.Service.BookingOrder
|
|
|
|
|
ctnEntity.UpdatedUserId = UserManager.UserId;
|
|
|
|
|
ctnEntity.UpdatedUserName = UserManager.Name;
|
|
|
|
|
|
|
|
|
|
_bookingDeliveryRecordCtnRep.AsUpdateable(ctnEntity).IgnoreColumns(x => new {
|
|
|
|
|
_bookingDeliveryRecordCtnRep.AsUpdateable(ctnEntity).IgnoreColumns(x => new {
|
|
|
|
|
x.CreatedUserId,
|
|
|
|
|
x.CreatedUserName,
|
|
|
|
|
x.CreatedTime,
|
|
|
|
@ -1083,10 +1126,10 @@ namespace Myshipping.Application.Service.BookingOrder
|
|
|
|
|
|
|
|
|
|
_bookingDeliveryRecordCtnRep.Insert(ctnEntity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if(ctnEntityList.Count > 0)
|
|
|
|
|
if (ctnEntityList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
ctnEntityList.ForEach(async ctn => {
|
|
|
|
|
ctn.IsDeleted = true;
|
|
|
|
@ -1140,7 +1183,6 @@ namespace Myshipping.Application.Service.BookingOrder
|
|
|
|
|
return entity.Id;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 删除
|
|
|
|
|
/// <summary>
|
|
|
|
|