修改MSK SPOT 单票获取详情增加船期详情

master
jianghaiqing 5 months ago
parent bfa29f0476
commit c335f974dd

@ -325,165 +325,179 @@ namespace Myshipping.Application.Service.BookingOrder
list = resultInfo.data.Select(a =>
{
MSKAPISPOTScheduleRateResultShowDto showDto = new MSKAPISPOTScheduleRateResultShowDto
{
priceID = a.priceID,
PId = a.PId,
MD5 = a.MD5,
totalAmount = a.totalAmount.HasValue ? (decimal)a.totalAmount.Value : 0,
TotalCurrency = a.totalCurrency,
orignCarrierCityGeoID = a.originGeoId,
orignUNLocationCode = a.originUnLocCode,
orignCityName = a.originCityName,
originRegionName = a.originRegionName,
originCountryName = a.originCountryName,
deliveryCarrierCityGeoID = a.destinationGeoId,
deliveryUNLocationCode = a.destinationUnLocCode,
deliveryCityName = a.destinationCityName,
deliveryRegionName = a.destinationRegionName,
deliveryCountryName = a.destinationCountryName,
vesselName = a.vesselName,
carrierDepartureVoyageNumber = a.voyageNumber,
Legs = new List<MSKAPISPOTScheduleRateResultShowLegsDto>()
};
if (a.totalAmount.HasValue)
showDto.totalAmountShow = string.Format("{0:N}", a.totalAmount.Value);
//ETD
if (!string.IsNullOrWhiteSpace(a.departureDate))
{
DateTime currDate = DateTime.MinValue;
return GetShipScheduleShow(a);
}).ToList();
}
else
{
throw Oops.Bah($"检索海运船期详情失败,{resultInfo.msg}");
}
}
catch (Exception ex)
{
_logger.LogError($"检索海运船期详情异常req={JSON.Serialize(query)} 原因:{ex.Message}");
if (DateTime.TryParse(a.departureDate, out currDate))
{
showDto.ETD = currDate;
}
else
{
throw Oops.Bah($"查询船期错误priceID={a.priceID} pid={a.PId} 预计离港日期departureDate={a.departureDate} 格式解析错误");
}
}
throw Oops.Bah($"检索海运船期详情失败,{ex.Message}");
}
//ETA
if (!string.IsNullOrWhiteSpace(a.arrivalDate))
{
DateTime currDate = DateTime.MinValue;
return list;
}
#endregion
if (DateTime.TryParse(a.arrivalDate, out currDate))
{
showDto.ETA = currDate;
}
else
{
throw Oops.Bah($"查询船期错误priceID={a.priceID} pid={a.PId} 预计到达日期 arrivalDate={a.arrivalDate} 格式解析错误");
}
}
#region 组织返回船期数据
/// <summary>
/// 组织返回船期数据
/// </summary>
/// <param name="model">查询的船期详情</param>
/// <returns>返回显示的船期数据</returns>
private MSKAPISPOTScheduleRateResultShowDto GetShipScheduleShow(MSKAPISPOTSearchScheduleRateResultDataDto model)
{
MSKAPISPOTScheduleRateResultShowDto showDto = new MSKAPISPOTScheduleRateResultShowDto
{
priceID = model.priceID,
PId = model.PId,
MD5 = model.MD5,
totalAmount = model.totalAmount.HasValue ? (decimal)model.totalAmount.Value : 0,
TotalCurrency = model.totalCurrency,
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.vesselName,
carrierDepartureVoyageNumber = model.voyageNumber,
Legs = new List<MSKAPISPOTScheduleRateResultShowLegsDto>()
};
//计算预计天数
if (showDto.ETD.HasValue && showDto.ETA.HasValue)
{
TimeSpan ts = showDto.ETA.Value.Subtract(showDto.ETD.Value);
var timeDiff = ts.TotalHours;
if (model.totalAmount.HasValue)
showDto.totalAmountShow = string.Format("{0:N}", model.totalAmount.Value);
showDto.days = (int)Math.Ceiling(timeDiff / 24.0);
}
//ETD
if (!string.IsNullOrWhiteSpace(model.departureDate))
{
DateTime currDate = DateTime.MinValue;
if (a.isTransfer.Equals("true", StringComparison.OrdinalIgnoreCase))
showDto.isTransfer = true;
if (DateTime.TryParse(model.departureDate, out currDate))
{
showDto.ETD = currDate;
}
else
{
throw Oops.Bah($"查询船期错误priceID={model.priceID} pid={model.PId} 预计离港日期departureDate={model.departureDate} 格式解析错误");
}
}
//Legs
if (a.scheduleDetails != null && a.scheduleDetails.Count > 0)
{
var legs = a.scheduleDetails.Select(b =>
{
MSKAPISPOTScheduleRateResultShowLegsDto leg = new MSKAPISPOTScheduleRateResultShowLegsDto
{
vesselName = b.transport.vessel.longName,
VoyageNo = b.transport.voyageNumber,
From = new MSKAPISPOTScheduleRateResultShowLegsLocationDto {
CityGeoId = b.fromLocation.cityGeoId,
CityName = b.fromLocation.cityName,
CountryCode = b.fromLocation.countryCode,
CountryName = b.fromLocation.countryName,
rkstCode = b.fromLocation.rkstCode,
SiteGeoId = b.fromLocation.siteGeoId,
LocationType = "From",
RegionName = b.fromLocation.regionName,
SiteName = b.fromLocation.siteName,
UnLocCode = b.fromLocation.unLocCode,
},
To = new MSKAPISPOTScheduleRateResultShowLegsLocationDto {
CityGeoId = b.toLocation.cityGeoId,
CityName = b.toLocation.cityName,
CountryCode = b.toLocation.countryCode,
CountryName = b.toLocation.countryName,
rkstCode = b.toLocation.rkstCode,
SiteGeoId = b.toLocation.siteGeoId,
LocationType = "To",
RegionName = b.toLocation.regionName,
SiteName = b.toLocation.siteName,
UnLocCode = b.toLocation.unLocCode,
}
};
//ETD
if (!string.IsNullOrWhiteSpace(b.fromLocation.date))
{
DateTime currDate = DateTime.MinValue;
if (DateTime.TryParse($"{b.fromLocation.date} {b.fromLocation.time}", out currDate))
{
leg.ETD = currDate;
}
else
{
throw Oops.Bah($"查询船期错误,航程明细 priceID={a.priceID} pid={a.PId} 预计离港日期fromLocation.date={b.fromLocation.date} {b.fromLocation.time} 格式解析错误");
}
}
//ETA
if (!string.IsNullOrWhiteSpace(b.toLocation.date))
{
DateTime currDate = DateTime.MinValue;
if (DateTime.TryParse(a.arrivalDate, out currDate))
{
leg.ETA = currDate;
}
else
{
throw Oops.Bah($"查询船期错误,航程明细 priceID={a.priceID} pid={a.PId} 预计到达日期 toLocation.date={b.toLocation.date} {b.toLocation.time} 格式解析错误");
}
}
return leg;
}).ToList();
showDto.Legs = legs.OrderBy(t=>t.ETD).Select((t,idx)=> {
t.SortNo = idx + 1;
return t;
}).ToList();
}
//ETA
if (!string.IsNullOrWhiteSpace(model.arrivalDate))
{
DateTime currDate = DateTime.MinValue;
return showDto;
}).ToList();
if (DateTime.TryParse(model.arrivalDate, out currDate))
{
showDto.ETA = currDate;
}
else
{
throw Oops.Bah($"检索海运船期详情失败,{resultInfo.msg}");
throw Oops.Bah($"查询船期错误priceID={model.priceID} pid={model.PId} 预计到达日期 arrivalDate={model.arrivalDate} 格式解析错误");
}
}
catch (Exception ex)
//计算预计天数
if (showDto.ETD.HasValue && showDto.ETD.HasValue)
{
_logger.LogError($"检索海运船期详情异常req={JSON.Serialize(query)} 原因:{ex.Message}");
TimeSpan ts = showDto.ETD.Value.Subtract(showDto.ETA.Value);
var timeDiff = ts.TotalHours;
throw Oops.Bah($"检索海运船期详情失败,{ex.Message}");
showDto.days = (int)Math.Ceiling(timeDiff / 24.0);
}
return list;
if (model.isTransfer.Equals("true", StringComparison.OrdinalIgnoreCase))
showDto.isTransfer = true;
//Legs
if (model.scheduleDetails != null && model.scheduleDetails.Count > 0)
{
var legs = model.scheduleDetails.Select(b =>
{
MSKAPISPOTScheduleRateResultShowLegsDto leg = new MSKAPISPOTScheduleRateResultShowLegsDto
{
vesselName = b.transport.vessel.longName,
VoyageNo = b.transport.voyageNumber,
From = new MSKAPISPOTScheduleRateResultShowLegsLocationDto
{
CityGeoId = b.fromLocation.cityGeoId,
CityName = b.fromLocation.cityName,
CountryCode = b.fromLocation.countryCode,
CountryName = b.fromLocation.countryName,
rkstCode = b.fromLocation.rkstCode,
SiteGeoId = b.fromLocation.siteGeoId,
LocationType = "From",
RegionName = b.fromLocation.regionName,
SiteName = b.fromLocation.siteName,
UnLocCode = b.fromLocation.unLocCode,
},
To = new MSKAPISPOTScheduleRateResultShowLegsLocationDto
{
CityGeoId = b.toLocation.cityGeoId,
CityName = b.toLocation.cityName,
CountryCode = b.toLocation.countryCode,
CountryName = b.toLocation.countryName,
rkstCode = b.toLocation.rkstCode,
SiteGeoId = b.toLocation.siteGeoId,
LocationType = "To",
RegionName = b.toLocation.regionName,
SiteName = b.toLocation.siteName,
UnLocCode = b.toLocation.unLocCode,
}
};
//ETD
if (!string.IsNullOrWhiteSpace(b.fromLocation.date))
{
DateTime currDate = DateTime.MinValue;
if (DateTime.TryParse($"{b.fromLocation.date} {b.fromLocation.time}", out currDate))
{
leg.ETD = currDate;
}
else
{
throw Oops.Bah($"查询船期错误,航程明细 priceID={model.priceID} pid={model.PId} 预计离港日期fromLocation.date={b.fromLocation.date} {b.fromLocation.time} 格式解析错误");
}
}
//ETA
if (!string.IsNullOrWhiteSpace(b.toLocation.date))
{
DateTime currDate = DateTime.MinValue;
if (DateTime.TryParse(model.arrivalDate, out currDate))
{
leg.ETA = currDate;
}
else
{
throw Oops.Bah($"查询船期错误,航程明细 priceID={model.priceID} pid={model.PId} 预计到达日期 toLocation.date={b.toLocation.date} {b.toLocation.time} 格式解析错误");
}
}
return leg;
}).ToList();
showDto.Legs = legs.OrderBy(t => t.ETD).Select((t, idx) => {
t.SortNo = idx + 1;
return t;
}).ToList();
}
return showDto;
}
#endregion
@ -1226,6 +1240,12 @@ namespace Myshipping.Application.Service.BookingOrder
if (shipScheduleRecord != null)
{
selectedShipSchedule = JSON.Deserialize<MSKAPISPOTSearchScheduleRateResultDataDto>(shipScheduleRecord.SHIP_JSON);
if (selectedShipSchedule != null)
{
model.selectedShipScheduleShow = GetShipScheduleShow(selectedShipSchedule);
}
}
}

@ -410,5 +410,10 @@ namespace Myshipping.Application
/// 交货地定位ID
/// </summary>
public string placeOfDeliveryGeoId { get; set; }
/// <summary>
/// 选择的船期详情
/// </summary>
public MSKAPISPOTScheduleRateResultShowDto selectedShipScheduleShow { get; set; }
}
}

Loading…
Cancel
Save