diff --git a/Myshipping.Application/Service/BookingOrder/BookingMSKAPIService.cs b/Myshipping.Application/Service/BookingOrder/BookingMSKAPIService.cs index 3c8b7b0a..a6b1a9f9 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingMSKAPIService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingMSKAPIService.cs @@ -39,6 +39,8 @@ namespace Myshipping.Application.Service.BookingOrder { private readonly SqlSugarRepository _bookingDeliveryRecordRep; private readonly SqlSugarRepository _bookingDeliveryRecordCtnRep; + private readonly SqlSugarRepository _bookingDeliveryRecordShipScheduleRep; + private readonly ISysCacheService _cache; private readonly IDjyWebsiteAccountConfigService _webAccountConfig; private readonly ILogger _logger; @@ -52,7 +54,7 @@ namespace Myshipping.Application.Service.BookingOrder public BookingMSKAPIService(ILogger logger, ISysCacheService cache, IDjyWebsiteAccountConfigService webAccountConfig, SqlSugarRepository bookingDeliveryRecordRep, ISysDataUserMenu sysDataUserMenuService, - SqlSugarRepository bookingDeliveryRecordCtnRep) + SqlSugarRepository bookingDeliveryRecordCtnRep, SqlSugarRepository 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($"{pid}_{busiType}"); + return _cache.Get($"{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(shipScheduleRecord.SHIP_JSON); + } + + if (selectedShipSchedule == null) + throw Oops.Oh("船期数据校验失败,请重新查询船期信息"); + } + DateTime nowDate = DateTime.Now; var recordInfo = model.Adapt(); @@ -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(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; } } diff --git a/Myshipping.Application/Service/BookingOrder/Dto/MSKBookingDto.cs b/Myshipping.Application/Service/BookingOrder/Dto/MSKBookingDto.cs index 25ccd7ec..73463198 100644 --- a/Myshipping.Application/Service/BookingOrder/Dto/MSKBookingDto.cs +++ b/Myshipping.Application/Service/BookingOrder/Dto/MSKBookingDto.cs @@ -27,6 +27,16 @@ namespace Myshipping.Application /// public long bookingId { get; set; } + /// + /// 主键ID + /// + public long PId { get; set; } + + /// + /// 船期MD5 + /// + public string MD5 { get; set; } + /// /// 合同唯一id /// @@ -360,6 +370,16 @@ namespace Myshipping.Application /// 箱型箱量列表 /// public List ctns { get; set; } + + /// + /// 收货地定位ID + /// + public string carrierCollectionOriginGeoID { get; set; } + + /// + /// 交货地定位ID + /// + public string carrierDeliveryDestinationGeoID { get; set; } } public class MSKBookingCtnInfo