From 27c33b21e3321ae65f17065144408a2957e5cce5 Mon Sep 17 00:00:00 2001 From: zhangxiaofeng <1939543722@qq.com> Date: Sat, 11 May 2024 10:54:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=93=E5=AD=98=E8=AE=A1=E7=AE=97=EF=BC=9A?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Event/BookingSlotStockSubscriber.cs | 99 +++++++++---------- .../Service/BookingSlot/BookingSlotService.cs | 1 + .../Dto/BookingSlotStockPageInput.cs | 4 + 3 files changed, 51 insertions(+), 53 deletions(-) diff --git a/Myshipping.Application/Event/BookingSlotStockSubscriber.cs b/Myshipping.Application/Event/BookingSlotStockSubscriber.cs index ba70cf76..56d64f0f 100644 --- a/Myshipping.Application/Event/BookingSlotStockSubscriber.cs +++ b/Myshipping.Application/Event/BookingSlotStockSubscriber.cs @@ -1,27 +1,12 @@ using Furion; using Furion.EventBus; -using Furion.FriendlyException; -using Furion.RemoteRequest.Extensions; using Mapster; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Myshipping.Application.ConfigOption; -using Myshipping.Application.Entity; -using Myshipping.Application.Service.BookingOrder.Dto; using Myshipping.Core; -using Myshipping.Core.Entity; -using Myshipping.Core.Service; -using Newtonsoft.Json.Linq; -using NPOI.OpenXmlFormats.Wordprocessing; using SqlSugar; -using System; using System.Collections.Generic; -using System.IO; using System.Linq; -using System.Net.Http; -using System.Text; using System.Threading.Tasks; -using Yitter.IdGenerator; namespace Myshipping.Application.Event { @@ -53,56 +38,58 @@ namespace Myshipping.Application.Event var paraObj = context.Source.Payload as BookingSlotStockUpdateModel; var baseList = await _repBase.AsQueryable().Filter(null, true) - .Where(x => !x.IsDeleted - && !x.IS_CANCELLATION - && x.VESSEL == paraObj.VESSEL - && x.VOYNO == paraObj.VOYNO - && x.CONTRACT_NO == paraObj.CONTRACT_NO - && x.BOOKING_SLOT_TYPE == paraObj.BOOKING_SLOT_TYPE - && x.CARRIERID == paraObj.CARRIERID - && x.PLACEDELIVERY == paraObj.PLACEDELIVERY - && x.PLACERECEIPT == paraObj.PLACERECEIPT) - .OrderByDescending(x => x.UpdatedTime) - .ToListAsync(); - - var stockObj = await _repStock.AsQueryable() - .Filter(null, true) - .FirstAsync(x => !x.IsDeleted - && x.VESSEL == paraObj.VESSEL - && x.VOYNO == paraObj.VOYNO - && x.CONTRACT_NO == paraObj.CONTRACT_NO - && x.BOOKING_SLOT_TYPE == paraObj.BOOKING_SLOT_TYPE - && x.CARRIERID == paraObj.CARRIERID - && x.PLACEDELIVERY == paraObj.PLACEDELIVERY - && x.PLACERECEIPT == paraObj.PLACERECEIPT); + .Where(x => !x.IsDeleted + && x.TenantId == paraObj.TenantId + && x.VESSEL == paraObj.VESSEL + && x.VOYNO == paraObj.VOYNO + && x.CONTRACT_NO == paraObj.CONTRACT_NO + && x.BOOKING_SLOT_TYPE == paraObj.BOOKING_SLOT_TYPE + && x.CARRIERID == paraObj.CARRIERID + && x.PLACEDELIVERY == paraObj.PLACEDELIVERY + && x.PLACERECEIPT == paraObj.PLACERECEIPT) + .OrderByDescending(x => x.UpdatedTime) + .ToListAsync(); + + var stockObj = await _repStock.AsQueryable().Filter(null, true) + .FirstAsync(x => !x.IsDeleted + && x.TenantId == paraObj.TenantId + && x.VESSEL == paraObj.VESSEL + && x.VOYNO == paraObj.VOYNO + && x.CONTRACT_NO == paraObj.CONTRACT_NO + && x.BOOKING_SLOT_TYPE == paraObj.BOOKING_SLOT_TYPE + && x.CARRIERID == paraObj.CARRIERID + && x.PLACEDELIVERY == paraObj.PLACEDELIVERY + && x.PLACERECEIPT == paraObj.PLACERECEIPT); if (!baseList.Any()) { - // 从库存表删除这7项维度的库存数据 - + if (stockObj != null) + { + // 从库存表删除这7项维度的库存数据 + await _repStock.DeleteAsync(x => x.Id == stockObj.Id); + } return; } - - + var isInsert = false; if (stockObj == null) { - stockObj = new BookingSlotStock(); - stockObj.Id = YitIdHelper.NextId(); - await _repStock.InsertAsync(stockObj); + isInsert = true; + stockObj = baseList[0].Adapt(stockObj); + stockObj.Id = 0; } - var bkId = stockObj.Id; - baseList[0].Adapt(stockObj); - stockObj.Id = bkId; - // 总舱位数 stockObj.TOTAL_ORDERS = baseList.Count; - var lstBaseId = baseList.Select(x => x.Id).ToList(); + // 取消舱位数 + stockObj.CANCEL_NUM = baseList.Count(x => x.IS_CANCELLATION); + + // 舱位主键列表 + var slotBaseIdList = baseList.Select(x => x.Id).ToList(); // 总的箱型箱量 var ctnAllList = await _repCtn.AsQueryable().Filter(null, true) - .Where(x => !x.IsDeleted && lstBaseId.Contains(x.SLOT_ID)) + .Where(x => !x.IsDeleted && slotBaseIdList.Contains(x.SLOT_ID)) .GroupBy(x => x.CTNALL) .Select(x => new { @@ -117,7 +104,7 @@ namespace Myshipping.Application.Event // 订舱引用表主键与订舱主表主键 var lstAllocKeyList = await _repAlloc.AsQueryable() .Filter(null, true) - .Where(x => !x.IsDeleted && lstBaseId.Contains(x.BOOKING_SLOT_ID)) + .Where(x => !x.IsDeleted && slotBaseIdList.Contains(x.BOOKING_SLOT_ID)) .Select(x => new { x.Id, x.BOOKING_SLOT_ID }) .ToListAsync(); @@ -183,8 +170,14 @@ namespace Myshipping.Application.Event stockObj.REMAIN_CTNS_NUM = stockObj.TOTAL_CTNS - stockObj.USE_CTNS_NUM; } - - await _repStock.UpdateAsync(stockObj); + if (isInsert) + { + await _repStock.InsertAsync(stockObj); + } + else + { + await _repStock.UpdateAsync(stockObj); + } } } diff --git a/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs b/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs index 69b064a1..ad3abba1 100644 --- a/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs +++ b/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs @@ -819,6 +819,7 @@ namespace Myshipping.Application [HttpPost("/BookingSlot/refreshStock")] public async Task RefreshStock(BookingSlotStockUpdateModel input) { + input.TenantId = UserManager.TENANT_ID; //更新库存 await _publisher.PublishAsync(new ChannelEventSource("BookingSlotStock:Update", input)); } diff --git a/Myshipping.Application/Service/BookingSlot/Dto/BookingSlotStockPageInput.cs b/Myshipping.Application/Service/BookingSlot/Dto/BookingSlotStockPageInput.cs index 1220c927..69afd1e7 100644 --- a/Myshipping.Application/Service/BookingSlot/Dto/BookingSlotStockPageInput.cs +++ b/Myshipping.Application/Service/BookingSlot/Dto/BookingSlotStockPageInput.cs @@ -150,6 +150,10 @@ namespace Myshipping.Application.Service.BookingSlot.Dto /// 使用舱位数 /// public int USE_NUM { get; set; } + /// + /// 取消舱位数 + /// + public int CANCEL_NUM { get; set; } /// /// 总箱数