修改MSK API订舱

master
jianghaiqing 5 months ago
parent c2d5221719
commit 884004e346

@ -39,6 +39,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;
@ -52,7 +54,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;
@ -60,6 +62,7 @@ namespace Myshipping.Application.Service.BookingOrder
_bookingDeliveryRecordRep = bookingDeliveryRecordRep;
_bookingDeliveryRecordCtnRep = bookingDeliveryRecordCtnRep;
_sysDataUserMenuService = sysDataUserMenuService;
_bookingDeliveryRecordShipScheduleRep = bookingDeliveryRecordShipScheduleRep;
}
#region 检索海运船期详情
@ -456,11 +459,11 @@ namespace Myshipping.Application.Service.BookingOrder
}
#endregion
private MSKAPISearchPoint2PointScheduleResultDataDto GetCacheShipSailingSchedule(long pid, string busiType = "MSKCON")
private MSKAPISearchTransportSchedules GetCacheShipSailingSchedule(long pid, string busiType = "MSKCON")
{
if (_cache.Exists($"{pid}_{busiType}"))
{
return _cache.Get<MSKAPISearchPoint2PointScheduleResultDataDto>($"{pid}_{busiType}");
return _cache.Get<MSKAPISearchTransportSchedules>($"{pid}_{busiType}");
}
return null;
@ -527,6 +530,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>();
@ -589,15 +623,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
{
@ -634,6 +666,21 @@ 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;
@ -1377,6 +1424,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)
@ -1407,6 +1490,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
{
@ -1498,6 +1583,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
@ -1511,6 +1617,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);
@ -1537,6 +1645,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;
}
}

@ -27,6 +27,16 @@ namespace Myshipping.Application
/// </summary>
public long bookingId { get; set; }
/// <summary>
/// 主键ID
/// </summary>
public long PId { get; set; }
/// <summary>
/// 船期MD5
/// </summary>
public string MD5 { get; set; }
/// <summary>
/// 合同唯一id
/// </summary>
@ -360,6 +370,16 @@ namespace Myshipping.Application
/// 箱型箱量列表
/// </summary>
public List<MSKBookingCtnInfo> ctns { get; set; }
/// <summary>
/// 收货地定位ID
/// </summary>
public string carrierCollectionOriginGeoID { get; set; }
/// <summary>
/// 交货地定位ID
/// </summary>
public string carrierDeliveryDestinationGeoID { get; set; }
}
public class MSKBookingCtnInfo

Loading…
Cancel
Save