diff --git a/Myshipping.Application/Service/BookingOrder/BookingMSKAPIService.cs b/Myshipping.Application/Service/BookingOrder/BookingMSKAPIService.cs index 8c8188ee..88e28237 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingMSKAPIService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingMSKAPIService.cs @@ -261,6 +261,9 @@ namespace Myshipping.Application.Service.BookingOrder if (webAccountConfig == null) throw Oops.Oh("未配置个人账户,请先配置个人账户 类型-MSKApi"); + //这里是校验必填项 + ValidateMSKAPIData(model); + DateTime nowDate = DateTime.Now; var recordInfo = model.Adapt(); @@ -464,6 +467,141 @@ namespace Myshipping.Application.Service.BookingOrder } #endregion + #region 校验马士基API订舱必填项 + /// + /// 校验马士基API订舱必填项 + /// + /// + private void ValidateMSKAPIData(MSKBookingDto model) + { + /* + 马士基API订舱内容校验 + 1、合约号必填 + 2、请求类别必填 + 3、服务船公司必填 + 4、订舱公司名称、代码、联系人、邮箱必填 + 5、持约方公司名称、代码、联系、邮箱必填 + 6、始发地城市名称、UNLOC、国家代码、服务模式 + 7、目的地城市名称、UNLOC、国家代码、服务模式 + 8、船名、航次、ETD、ETA + 9、商品名称、代码必填 + 10、总重必填 + 11、货物标志必填 + 12、如果选择了冷冻处理,至少要填个温度 + 13、箱型、箱量、重量必填 + 14、总重=箱量*单箱重量 + */ + if (string.IsNullOrWhiteSpace(model.priceReference)) + throw Oops.Bah($"订舱合同惟一ID必填"); + + if(!Regex.IsMatch(model.priceReference,"[a-zA-Z0-9_/,-]{1,50}")) + throw Oops.Bah($"订舱合同惟一ID格式错误 [a-zA-Z0-9_/,-]{{1,50}}"); + + if (string.IsNullOrWhiteSpace(model.sender)) + throw Oops.Bah($"请求类别必填"); + + if (string.IsNullOrWhiteSpace(model.carrierCode)) + throw Oops.Bah($"服务船公司必填"); + + if (string.IsNullOrWhiteSpace(model.bookedByCompanyName)) + throw Oops.Bah($"订舱公司名称必填"); + + if (string.IsNullOrWhiteSpace(model.bookedByMaerskPartyCode)) + throw Oops.Bah($"订舱方ID必填"); + + if (string.IsNullOrWhiteSpace(model.bookedByCompanyContactName)) + throw Oops.Bah($"订舱方公司联系人必填"); + + if (string.IsNullOrWhiteSpace(model.bookedByCompanyContactEmail)) + throw Oops.Bah($"订舱方公司邮箱必填"); + + if (string.IsNullOrWhiteSpace(model.priceOwnerContactName)) + throw Oops.Bah($"持约方公司名称必填"); + + if (string.IsNullOrWhiteSpace(model.priceOwnerMaerskPartyCode)) + throw Oops.Bah($"持约方ID必填"); + + if (string.IsNullOrWhiteSpace(model.priceOwnerContactName)) + throw Oops.Bah($"持约方公司联系人必填"); + + if (string.IsNullOrWhiteSpace(model.priceOwnerContactEmail)) + throw Oops.Bah($"持约方公司邮箱必填"); + + if (string.IsNullOrWhiteSpace(model.placeOfReceiptCityName)) + throw Oops.Bah($"始发地城市名称必填"); + + if (string.IsNullOrWhiteSpace(model.placeOfReceiptUnLocCode)) + throw Oops.Bah($"始发地UN CODE必填"); + + if (string.IsNullOrWhiteSpace(model.placeOfReceiptCountryCode)) + throw Oops.Bah($"始发地国家代码必填"); + + if (string.IsNullOrWhiteSpace(model.exportServiceMode)) + throw Oops.Bah($"始发地服务模式必填"); + + if (string.IsNullOrWhiteSpace(model.placeOfDeliveryCityName)) + throw Oops.Bah($"目的地城市名称必填"); + + if (string.IsNullOrWhiteSpace(model.placeOfDeliveryUnLocCode)) + throw Oops.Bah($"目的地UN CODE必填"); + + if (string.IsNullOrWhiteSpace(model.placeOfDeliveryCountryCode)) + throw Oops.Bah($"目的地国家代码必填"); + + if (string.IsNullOrWhiteSpace(model.importServiceMode)) + throw Oops.Bah($"目的地服务模式必填"); + + if (string.IsNullOrWhiteSpace(model.vesselName)) + throw Oops.Bah($"船名必填,请确认正确选择了船期"); + + if (string.IsNullOrWhiteSpace(model.exportVoyageNumber)) + throw Oops.Bah($"航次号必填,请确认正确选择了船期"); + + if (!model.originDepartureDateTimeLocal.HasValue) + throw Oops.Bah($"ETD必填,请确认正确选择了船期"); + + if (!model.destinationArrivalDateTimeLocal.HasValue) + throw Oops.Bah($"ETA必填,请确认正确选择了船期"); + + if (string.IsNullOrWhiteSpace(model.commodityCode)) + throw Oops.Bah($"商品代码必填,请确认正确选择了商品"); + + if (string.IsNullOrWhiteSpace(model.commodityName)) + throw Oops.Bah($"商品名称必填,请确认正确选择了商品"); + + if (!model.totalCargoWeight.HasValue || model.totalCargoWeight.Value < 1) + throw Oops.Bah($"总重必填"); + + if (string.IsNullOrWhiteSpace(model.cargoType)) + throw Oops.Bah($"货物标志必填"); + + if (model.isReefer) + { + if (!model.temperature.HasValue) + throw Oops.Bah($"选择了冷冻处理,温度必填"); + } + + if (model.ctns.Count == 0) + throw Oops.Bah($"箱型箱量信息必填"); + + if (model.ctns.Any(a => string.IsNullOrWhiteSpace(a.ctnCode))) + throw Oops.Bah($"箱型不能为空"); + + if (model.ctns.Any(a => !a.ctnNum.HasValue || a.ctnNum.Value < 1)) + throw Oops.Bah($"箱量不能为空,并且不能小于1"); + + if (model.ctns.Any(a => !a.ctnSufferWeight.HasValue || a.ctnSufferWeight.Value < 1)) + throw Oops.Bah($"箱内重量不能为空,并且不能小于1"); + + + if (model.totalCargoWeight.Value != model.ctns.Sum(b => b.ctnNum.Value * b.ctnSufferWeight.Value)) + { + throw Oops.Bah($"箱内重量合计不等于总重,请修改"); + } + + } + #endregion + #region 检索商品名称 /// /// 检索商品名称 @@ -855,6 +993,14 @@ namespace Myshipping.Application.Service.BookingOrder { DateTime nowDate = DateTime.Now; + string ctnStat = string.Empty; + + if (model.ctns != null && model.ctns.Count > 0) + { + ctnStat = string.Join(",", model.ctns.GroupBy(a => a.ctnCode) + .Select(a => $"{a.Key}*{a.ToList().Sum(b => b.ctnNum.HasValue ? b.ctnNum.Value : 0)}").ToArray()); + } + if (model.id.HasValue && model.id.Value > 0) { BookingDeliveryRecord entity = model.Adapt(); @@ -862,6 +1008,7 @@ namespace Myshipping.Application.Service.BookingOrder entity.UpdatedTime = nowDate; entity.UpdatedUserId = UserManager.UserId; entity.UpdatedUserName = UserManager.Name; + entity.CTN_STAT = ctnStat; await _bookingDeliveryRecordRep.AsUpdateable(entity).IgnoreColumns(x => new { @@ -952,6 +1099,7 @@ namespace Myshipping.Application.Service.BookingOrder entity.CreatedUserId = UserManager.UserId; entity.CreatedUserName = UserManager.Name; entity.STATUS = "TEMP"; + entity.CTN_STAT = ctnStat; await _bookingDeliveryRecordRep.InsertAsync(entity); @@ -977,5 +1125,32 @@ namespace Myshipping.Application.Service.BookingOrder } } #endregion + + #region 删除 + /// + /// 删除 + /// + /// 请求订舱ID + /// + public async Task Delete(long id) + { + var info = _bookingDeliveryRecordRep.AsQueryable().First(a => a.Id == id); + + if(info == null) + throw Oops.Bah($"删除失败,业务信息不存在或已作废"); + + info.IsDeleted = true; + info.UpdatedTime = DateTime.Now; + info.UpdatedUserId = UserManager.UserId; + info.UpdatedUserName = UserManager.Name; + + await _bookingDeliveryRecordRep.AsUpdateable(info).UpdateColumns(x => new { + x.IsDeleted, + x.UpdatedTime, + x.UpdatedUserId, + x.UpdatedUserName + }).ExecuteCommandAsync(); + } + #endregion } } diff --git a/Myshipping.Application/Service/BookingOrder/IBookingMSKAPIService.cs b/Myshipping.Application/Service/BookingOrder/IBookingMSKAPIService.cs index 27a2958e..7aa9d591 100644 --- a/Myshipping.Application/Service/BookingOrder/IBookingMSKAPIService.cs +++ b/Myshipping.Application/Service/BookingOrder/IBookingMSKAPIService.cs @@ -58,5 +58,12 @@ namespace Myshipping.Application /// 请求订舱详情 /// 返回ID Task Save(MSKBookingDto model); + + /// + /// 删除 + /// + /// 请求订舱ID + /// + Task Delete(long id); } }