diff --git a/Myshipping.Application/Entity/BookingOrder.cs b/Myshipping.Application/Entity/BookingOrder.cs index 5d28a31f..06f4a68f 100644 --- a/Myshipping.Application/Entity/BookingOrder.cs +++ b/Myshipping.Application/Entity/BookingOrder.cs @@ -1052,5 +1052,10 @@ namespace Myshipping.Application.Entity /// 运输条款代码 /// public string SERVICECODE { get; set; } + + /// + /// 是否为舱位拆票后生成的订舱 + /// + public bool? IsSplit { get; set; } } } \ No newline at end of file diff --git a/Myshipping.Application/Service/BookingOrder/Dto/BookingOrderDto.cs b/Myshipping.Application/Service/BookingOrder/Dto/BookingOrderDto.cs index 1c74b850..20a4b2bc 100644 --- a/Myshipping.Application/Service/BookingOrder/Dto/BookingOrderDto.cs +++ b/Myshipping.Application/Service/BookingOrder/Dto/BookingOrderDto.cs @@ -9,7 +9,7 @@ namespace Myshipping.Application /// /// 订舱主表输出参数 /// - public class BookingOrderDto + public class BookingOrderDto { /// /// 主键 @@ -718,7 +718,7 @@ namespace Myshipping.Application public string SourceName { get; set; } - + #region 船舶日期相关 @@ -857,6 +857,11 @@ namespace Myshipping.Application /// 扩展状态 /// public BookingExtendState ExtendState { get; set; } + + /// + /// 是否为舱位拆票后生成的订舱 + /// + public bool? IsSplit { get; set; } } /// diff --git a/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs b/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs index 98d9d2cc..9151578d 100644 --- a/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs +++ b/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs @@ -1232,9 +1232,9 @@ namespace Myshipping.Application [HttpGet("/BookingSlot/getAvailableCtnsBySlot")] public async Task> GetAvailableCtnsBySlot(long slotId) { - if (await _repBase.IsExistsAsync(x => x.Id == slotId) == false) + if (await _repBase.IsExistsAsync(x => x.Id == slotId && x.IS_CANCELLATION == false) == false) { - throw Oops.Oh($"获取舱位失败,舱位不存在或已作废,请刷新页面后重试"); + throw Oops.Oh($"获取舱位失败,舱位不存在或已作废"); } // 1. 【舱位基础表】与【箱子表】做关联,并根据【舱位主键】、【箱型】做分组,统计出【总的箱量】,作为queryable1 @@ -1424,7 +1424,9 @@ namespace Myshipping.Application await _repAllocationCtn.InsertAsync(insertCtnList); // 为订舱保存附件信息 - var lastestBcFile = await _bookingfile.Where(x => x.TypeCode == "bc" || x.TypeCode == "bc_notice").OrderByDescending(x => x.Id).FirstAsync(); + var lastestBcFile = await _bookingfile.Where(x => (x.TypeCode == "bc" || x.TypeCode == "bc_notice") && x.BookingId == latestSlot.Id) + .OrderByDescending(x => x.Id) + .FirstAsync(); if (lastestBcFile != null) { var file = lastestBcFile.Adapt(); @@ -1532,7 +1534,7 @@ namespace Myshipping.Application } //var sql = select.OrderByDescending(u => u.CreatedTime).ToSqlString(); - var entities = await select.OrderByDescending(u => u.CreatedTime) + var entities = await select.OrderByDescending(u => u.Id) .ToPagedListAsync(input.PageNo, input.PageSize); var result = entities.Adapt>(); @@ -1880,19 +1882,19 @@ namespace Myshipping.Application throw Oops.Oh($"舱位信息不存在或已作废"); // 判断是否已存在引用关系 - if (_repAllocation.IsExists(a => a.BOOKING_SLOT_ID == slotInfo.Id - && a.BOOKING_ID > 0 && a.IsDeleted == false)) - { - throw Oops.Oh($"舱位已有对应的订舱订单,不能重复执行"); - } + //if (_repAllocation.IsExists(a => a.BOOKING_SLOT_ID == slotInfo.Id + // && a.BOOKING_ID > 0 && a.IsDeleted == false)) + //{ + // throw Oops.Oh($"舱位已有对应的订舱订单,不能重复执行"); + //} - var ctnList = _repCtn.AsQueryable().Where(a => a.SLOT_ID == slotInfo.Id && a.IsDeleted == false) - .ToList(); + //var ctnList = _repCtn.AsQueryable().Where(a => a.SLOT_ID == slotInfo.Id && a.IsDeleted == false) + // .ToList(); var fileList = await _bookingfile.AsQueryable().Filter(null, true) .Where(u => u.BookingId == slotInfo.Id && u.Moudle == "BookingSlot").ToListAsync(); - var bookingOrderId = await GenerateBookingOrder(slotInfo, ctnList, fileList, model); + var bookingOrderId = await GenerateBookingOrder(slotInfo, fileList, model); result.succ = true; result.msg = "成功"; @@ -1907,13 +1909,12 @@ namespace Myshipping.Application /// 生成订舱 /// /// 舱位详情 - /// 舱位集装箱列表 /// 舱位附件列表 /// 订舱请求详情 /// 返回订舱ID - private async Task GenerateBookingOrder(BookingSlotBase bookingSlotBase, List bookingSlotCtnList, - List bookingSlotFileList, - BookingGenerateDto generateModel) + private async Task GenerateBookingOrder(BookingSlotBase bookingSlotBase, + List bookingSlotFileList, + BookingGenerateDto generateModel) { long id = 0; @@ -1930,13 +1931,16 @@ namespace Myshipping.Application || t.EnName.Equals(bookingSlotBase.CARRIERID, StringComparison.OrdinalIgnoreCase) || t.CnName.Equals(bookingSlotBase.CARRIERID, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); + var custNo = bookingSlotBase.SLOT_BOOKING_NO.Trim(); + SaveBookingOrderInput bkModel = new SaveBookingOrderInput { CUSTOMERID = generateModel.CustomerId, CUSTOMERNAME = generateModel.CustomerName, CARRIERID = carrierInfo.Code?.Trim(), CARRIER = carrierInfo.CnName?.Trim(), - MBLNO = bookingSlotBase.SLOT_BOOKING_NO.Trim(), + CUSTNO = custNo, + //MBLNO = bookingSlotBase.SLOT_BOOKING_NO.Trim(), CONTRACTNO = !string.IsNullOrWhiteSpace(bookingSlotBase.CONTRACT_NO) ? bookingSlotBase.CONTRACT_NO : "", VESSEL = bookingSlotBase.VESSEL.ToUpper().Trim(), VOYNO = bookingSlotBase.VOYNO.ToUpper().Trim(), @@ -1963,11 +1967,33 @@ namespace Myshipping.Application ctnInputs = new List() }; + // 判断是否为拆票的舱位,如果为拆票,提单号需要加上ABCD... + var selectNum = generateModel.CtnList.Sum(x => x.CTNNUM); + var allNum = await _repCtn.AsQueryable().Where(x => x.SLOT_ID == generateModel.SlotId).SumAsync(x => x.CTNNUM); + bkModel.IsSplit = selectNum != allNum; + if (bkModel.IsSplit == true) + { + var sql = _repBookingOrder.AsQueryable().Where(" MBLNO like @mblno+'_' ", new { mblno = custNo }).ToSqlString(); + var currentOrder = await _repBookingOrder.AsQueryable().Where(" MBLNO like @mblno+'_' ", new { mblno = custNo }) + .OrderByDescending(x => x.Id) + .FirstAsync(); + if (currentOrder == null) + { + bkModel.MBLNO = custNo + "A"; + } + else + { + var lastLetter = currentOrder.MBLNO.Substring(currentOrder.MBLNO.Length - 1, 1)[0]; + var newMblno = custNo + LetterIndexUtil.GetNextLetter(lastLetter); + bkModel.MBLNO = newMblno; + } + } + var ctnCodeList = _cache.GetAllCodeCtn().GetAwaiter().GetResult().ToList(); - if (bookingSlotCtnList.Count > 0) + if (generateModel.CtnList != null && generateModel.CtnList.Count > 0) { - bookingSlotCtnList.ForEach(t => + generateModel.CtnList.ForEach(t => { var ctnCode = ctnCodeList.FirstOrDefault(a => !string.IsNullOrWhiteSpace(a.Name) && a.Name.Equals(t.CTNALL, StringComparison.OrdinalIgnoreCase)); @@ -1983,6 +2009,16 @@ namespace Myshipping.Application }); } + // 验证舱位是否可用 + var slotInfo = bookingSlotBase.Adapt(); + slotInfo.CtnList = generateModel.CtnList; + var importSlots = new List() { slotInfo }; + var checkResult = await CheckImportSlots(importSlots, 0); + if (!checkResult.isEnough) + { + throw Oops.Oh(checkResult.message); + } + var bookingOrderService = _namedBookingOrderServiceProvider.GetService(nameof(BookingOrderService)); var bkRlt = await bookingOrderService.Save(bkModel); @@ -1992,19 +2028,8 @@ namespace Myshipping.Application if (id > 0) { - List slots = new List(); - - //检索舱位信息 - var slotInfo = Detail(bookingSlotBase.Id).GetAwaiter().GetResult(); - - BookingSlotBaseWithCtnDto baseInfo = slotInfo.Adapt(); - baseInfo.Id = bookingSlotBase.Id; - baseInfo.CtnList = slotInfo.CtnList.Adapt>(); - - slots.Add(baseInfo); - - //对应订舱和舱位关系 - var allocRlt = await ImportSlots(slots, id, false); + ////对应订舱和舱位关系 + var allocRlt = await ImportSlots(importSlots, id, false, generateModel); //这里如果指定了委托单位的邮件联系人,则推送订舱联系人 if (generateModel.CustomerContactList != null && generateModel.CustomerContactList.Count > 0) @@ -2135,6 +2160,7 @@ namespace Myshipping.Application catch (Exception ex) { _logger.LogError($"MBLNO:{bookingSlotBase.SLOT_BOOKING_NO} 生成订舱订单异常,原因:{ex.Message}"); + throw; } diff --git a/Myshipping.Application/Service/BookingSlot/Dto/BookingGenerateDto.cs b/Myshipping.Application/Service/BookingSlot/Dto/BookingGenerateDto.cs index 6dd3f4f1..02e12ef8 100644 --- a/Myshipping.Application/Service/BookingSlot/Dto/BookingGenerateDto.cs +++ b/Myshipping.Application/Service/BookingSlot/Dto/BookingGenerateDto.cs @@ -1,4 +1,5 @@ -using System; +using Myshipping.Application.Service.BookingSlot.Dto; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -126,5 +127,10 @@ namespace Myshipping.Application /// 卖价 /// public decimal? SELLING_PRICE { get; set; } + + /// + /// 舱位箱信息 + /// + public List CtnList { get; set; } } } diff --git a/Myshipping.Core/Myshipping.Core.xml b/Myshipping.Core/Myshipping.Core.xml index 66cf7389..3c491d6a 100644 --- a/Myshipping.Core/Myshipping.Core.xml +++ b/Myshipping.Core/Myshipping.Core.xml @@ -19836,6 +19836,11 @@ 长TAB键的识别替换空格 + + + 根据当前字母获取它在26个英文字母中的下一个字母 + + 获取服务器信息 diff --git a/Myshipping.Core/Util/LetterIndexUtil.cs b/Myshipping.Core/Util/LetterIndexUtil.cs new file mode 100644 index 00000000..65642e32 --- /dev/null +++ b/Myshipping.Core/Util/LetterIndexUtil.cs @@ -0,0 +1,13 @@ +namespace Myshipping.Core; +public static class LetterIndexUtil +{ + /// + /// 根据当前字母获取它在26个英文字母中的下一个字母 + /// + public static char GetNextLetter(char currentLetter) + { + if (currentLetter == 'z') return 'a'; + if (currentLetter == 'Z') return 'A'; + return (char)(currentLetter + 1); + } +} \ No newline at end of file