From b35f765c90554a69c0e108805324616c6d08c6fa Mon Sep 17 00:00:00 2001 From: hao <86whm@163.com> Date: Tue, 9 Jan 2024 15:49:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entity/BookingSlot/BookingSlotStock.cs | 14 +- .../Event/BookingSlotStockSubscriber.cs | 43 +++-- .../Service/BookingSlot/BookingSlotService.cs | 74 ++++++-- .../Dto/BookingSlotStockPageInput.cs | 174 ++++++++++++++++++ Myshipping.Web.Core/Startup.cs | 2 + 5 files changed, 270 insertions(+), 37 deletions(-) create mode 100644 Myshipping.Application/Service/BookingSlot/Dto/BookingSlotStockPageInput.cs diff --git a/Myshipping.Application/Entity/BookingSlot/BookingSlotStock.cs b/Myshipping.Application/Entity/BookingSlot/BookingSlotStock.cs index eee45bce..2054b26d 100644 --- a/Myshipping.Application/Entity/BookingSlot/BookingSlotStock.cs +++ b/Myshipping.Application/Entity/BookingSlot/BookingSlotStock.cs @@ -5,7 +5,7 @@ using Myshipping.Core.Entity; /* * @author : whm - * @date : 2024-1-2 + * @date : 2024-1-9 * @desc : 舱位库存表,用来增减 */ namespace Myshipping.Application @@ -113,23 +113,17 @@ namespace Myshipping.Application public string REMAIN_CTN_STAT{ get; set; } /// - /// 总票数 + /// 总舱位数 /// [SugarColumn(ColumnName = "TOTAL_ORDERS")] public int TOTAL_ORDERS{ get; set; } /// - /// 使用票数 + /// 使用舱位数 /// [SugarColumn(ColumnName = "USE_NUM")] public int USE_NUM{ get; set; } - /// - /// 剩余票数 - /// - [SugarColumn(ColumnName = "REMAIN_NUM")] - public int REMAIN_NUM{ get; set; } - /// /// 总箱数 /// @@ -147,7 +141,7 @@ namespace Myshipping.Application /// [SugarColumn(ColumnName = "REMAIN_CTNS_NUM")] public int REMAIN_CTNS_NUM{ get; set; } - + /// /// 租户名称 /// diff --git a/Myshipping.Application/Event/BookingSlotStockSubscriber.cs b/Myshipping.Application/Event/BookingSlotStockSubscriber.cs index 1073d9ec..b3e62fa2 100644 --- a/Myshipping.Application/Event/BookingSlotStockSubscriber.cs +++ b/Myshipping.Application/Event/BookingSlotStockSubscriber.cs @@ -20,6 +20,7 @@ using System.Linq; using System.Net.Http; using System.Text; using System.Threading.Tasks; +using Yitter.IdGenerator; namespace Myshipping.Application.Event { @@ -31,17 +32,24 @@ namespace Myshipping.Application.Event private readonly SqlSugarRepository _repBase; private readonly SqlSugarRepository _repCtn; private readonly SqlSugarRepository _repStock; + private readonly SqlSugarRepository _repAlloc; + private readonly SqlSugarRepository _repAllocCtn; private readonly ILogger _logger; public BookingSlotStockSubscriber(SqlSugarRepository repBase, SqlSugarRepository repCtn, SqlSugarRepository repStock, + SqlSugarRepository repAlloc, + SqlSugarRepository repAllocCtn, + ILogger logger) { _repBase = repBase; _repCtn = repCtn; _repStock = repStock; + _repAlloc = repAlloc; + _repAllocCtn = repAllocCtn; _logger = logger; } @@ -60,6 +68,7 @@ namespace Myshipping.Application.Event && x.CONTRACT_NO == paraObj.CONTRACT_NO && x.BOOKING_SLOT_TYPE == paraObj.BOOKING_SLOT_TYPE && x.CARRIERID == paraObj.CARRIERID) + .OrderByDescending(x => x.UpdatedTime) .ToListAsync(); var stockObj = await _repStock.AsQueryable() @@ -73,28 +82,32 @@ namespace Myshipping.Application.Event if (stockObj == null) { stockObj = new BookingSlotStock(); - stockObj.VESSEL= baseList[0].VESSEL; - stockObj.VOYNO= baseList[0].VOYNO; - stockObj.CONTRACT_NO= baseList[0].CONTRACT_NO; - stockObj.BOOKING_SLOT_TYPE= baseList[0].BOOKING_SLOT_TYPE; - stockObj.BOOKING_SLOT_TYPE_NAME = baseList[0].BOOKING_SLOT_TYPE_NAME; - stockObj.BOOKING_PARTY = baseList[0].BOOKING_PARTY; - stockObj.CARRIERID = baseList[0].CARRIERID; - stockObj.CARRIER = baseList[0].CARRIER; - stockObj.ETD = baseList[0].ETD; - stockObj.ETA = baseList[0].ETA; - stockObj.LANECODE = baseList[0].LANECODE; - stockObj.LANENAME = baseList[0].LANENAME; - stockObj.WEEK_AT= baseList[0].WEEK_AT; - stockObj.TenantId = baseList[0].TenantId; + stockObj.Id = YitIdHelper.NextId(); await _repStock.InsertAsync(stockObj); } - stockObj.TOTAL_ORDERS = baseList.Count; + 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.TOTAL_CTNS = _repCtn.Where(x => lstBaseId.Contains(x.SLOT_ID)).Count(); //总箱数 + + var lstAllocIdList = await _repAlloc.Where(x => lstBaseId.Contains(x.BOOKING_SLOT_ID)).Select(x => x.Id).ToListAsync(); + stockObj.USE_NUM = lstAllocIdList.Count; //使用舱位数 + + stockObj.USE_CTNS_NUM = _repAllocCtn.Where(x => lstAllocIdList.Contains(x.SLOT_ALLOC_ID)).Count(); //使用箱数 + + await _repStock.UpdateAsync(stockObj); } } + /// + /// 刷新库存统计对象 + /// public class BookingSlotStockUpdateModel { diff --git a/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs b/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs index 5cf63825..497b8e6a 100644 --- a/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs +++ b/Myshipping.Application/Service/BookingSlot/BookingSlotService.cs @@ -25,6 +25,8 @@ using Myshipping.Application.ConfigOption; using Myshipping.Core.Service; using Myshipping.Application.Service.BookingSlot.Dto; using NPOI.SS.Formula.Functions; +using Furion.EventBus; +using Myshipping.Application.Event; namespace Myshipping.Application { @@ -40,17 +42,22 @@ namespace Myshipping.Application private readonly ILogger _logger; private readonly ISysCacheService _cache; + private readonly IEventPublisher _publisher; + public BookingSlotService(SqlSugarRepository repBase, SqlSugarRepository repCtn, SqlSugarRepository repStock, ILogger logger, - ISysCacheService cache) + ISysCacheService cache, + IEventPublisher publisher) { _repBase = repBase; _repCtn = repCtn; _repStock = repStock; _logger = logger; _cache = cache; + + _publisher = publisher; } #region 舱位 @@ -123,6 +130,16 @@ namespace Myshipping.Application } } + //更新库存 + await _publisher.PublishAsync(new ChannelEventSource("BookingSlotStock:Update", new BookingSlotStockUpdateModel + { + BOOKING_SLOT_TYPE = model.BOOKING_SLOT_TYPE, + CARRIERID = model.CARRIERID, + CONTRACT_NO = model.CONTRACT_NO, + VESSEL = model.VESSEL, + VOYNO = model.VOYNO + })); + return await Detail(model.Id); } @@ -145,6 +162,16 @@ namespace Myshipping.Application item.IsDeleted = true; } await _repCtn.UpdateAsync(ctns); + + //更新库存 + await _publisher.PublishAsync(new ChannelEventSource("BookingSlotStock:Update", new BookingSlotStockUpdateModel + { + BOOKING_SLOT_TYPE = entity.BOOKING_SLOT_TYPE, + CARRIERID = entity.CARRIERID, + CONTRACT_NO = entity.CONTRACT_NO, + VESSEL = entity.VESSEL, + VOYNO = entity.VOYNO + })); } /// @@ -165,17 +192,40 @@ namespace Myshipping.Application #endregion #region 库存 - ///// - ///// 库存查询 - ///// - ///// - ///// - //[HttpGet("/BookingSlot/pageStock")] - //public async Task PageStock([FromQuery] BookingSlotBasePageInput input) - //{ - // var query = await _repStock.AsQueryable() - // .ToListAsync(); - //} + /// + /// 库存查询 + /// + /// + /// + [HttpPost("/BookingSlot/pageStock")] + public async Task PageStock(BookingSlotStockPageInput input) + { + var entities = await _repStock.AsQueryable() + .WhereIF(!string.IsNullOrEmpty(input.VESSEL), u => u.VESSEL.Contains(input.VESSEL)) + .WhereIF(!string.IsNullOrEmpty(input.VOYNO), u => u.VOYNO.Contains(input.VOYNO)) + .WhereIF(!string.IsNullOrEmpty(input.CARRIER), u => u.CARRIER.Contains(input.CARRIER)) + .WhereIF(!string.IsNullOrEmpty(input.CTN_STAT), u => u.CTN_STAT.Contains(input.CTN_STAT)) + .WhereIF(input.ETD_START.HasValue, u => u.ETD >= input.ETD_START.Value) + .WhereIF(input.ETD_END.HasValue, u => u.ETD < input.ETD_END.Value.AddDays(1)) + .WhereIF(input.ETA_START.HasValue, u => u.ETA >= input.ETA_START.Value) + .WhereIF(input.ETA_END.HasValue, u => u.ETA < input.ETA_END.Value.AddDays(1)) + .ToPagedListAsync(input.PageNo, input.PageSize); + + var result = entities.Adapt>(); + + return result.XnPagedResult(); + } + + /// + /// 刷新库存统计 + /// + /// + [HttpPost("/BookingSlot/refreshStock")] + public async Task RefreshStock(BookingSlotStockUpdateModel input) + { + //更新库存 + await _publisher.PublishAsync(new ChannelEventSource("BookingSlotStock:Update", input)); + } #endregion } } diff --git a/Myshipping.Application/Service/BookingSlot/Dto/BookingSlotStockPageInput.cs b/Myshipping.Application/Service/BookingSlot/Dto/BookingSlotStockPageInput.cs new file mode 100644 index 00000000..1bc6eb2b --- /dev/null +++ b/Myshipping.Application/Service/BookingSlot/Dto/BookingSlotStockPageInput.cs @@ -0,0 +1,174 @@ +using Myshipping.Core; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Myshipping.Application.Service.BookingSlot.Dto +{ + /// + /// 查询条件 + /// + public class BookingSlotStockPageInput : PageInputBase + { + /// + /// 船名 + /// + public string VESSEL { get; set; } + + /// + /// 航次号 + /// + public string VOYNO { get; set; } + + /// + /// 预计开船日期起始 + /// + public DateTime? ETD_START { get; set; } + + /// + /// 预计开船日期截至 + /// + public DateTime? ETD_END { get; set; } + + /// + /// 预计到港日期起始 + /// + public DateTime? ETA_START { get; set; } + + /// + /// 预计到港日期截至 + /// + public DateTime? ETA_END { get; set; } + + /// + /// 船公司 + /// + public string CARRIER { get; set; } + + /// + /// 箱型箱量 + /// + public string CTN_STAT { get; set; } + + } + + /// + /// dto基类 + /// + public class BookingSlotStockDto + { + /// + /// 船名 + /// + public string VESSEL { get; set; } + + /// + /// 航次号 + /// + public string VOYNO { get; set; } + + /// + /// 合约号 + /// + public string CONTRACT_NO { get; set; } + + /// + /// 订舱方式 CONTRACT_ORDER-合约订舱;SPOT_ORDER-SPOT订舱 + /// + public string BOOKING_SLOT_TYPE { get; set; } + + /// + /// 订舱方式名称 CONTRACT_ORDER-合约订舱;SPOT_ORDER-SPOT订舱 + /// + public string BOOKING_SLOT_TYPE_NAME { get; set; } + + /// + /// 订舱抬头 + /// + public string BOOKING_PARTY { get; set; } + + /// + /// 船公司代号 + /// + public string CARRIERID { get; set; } + + /// + /// 船公司 + /// + public string CARRIER { get; set; } + + /// + /// 预计开船日期 + /// + public DateTime? ETD { get; set; } + + /// + /// 预计到港日期 + /// + public DateTime? ETA { get; set; } + + /// + /// 航线代码(船公司) + /// + public string LANECODE { get; set; } + + /// + /// 航线名称(船公司) + /// + public string LANENAME { get; set; } + + /// + /// 所在周数 + /// + public string WEEK_AT { get; set; } + + /// + /// 箱型箱量 + /// + public string CTN_STAT { get; set; } + + /// + /// 使用箱型箱量 + /// + public string USE_CTN_STAT { get; set; } + + /// + /// 剩余箱型箱量 + /// + public string REMAIN_CTN_STAT { get; set; } + + /// + /// 总舱位数 + /// + public int TOTAL_ORDERS { get; set; } + + /// + /// 使用舱位数 + /// + public int USE_NUM { get; set; } + + /// + /// 总箱数 + /// + public int TOTAL_CTNS { get; set; } + + /// + /// 使用箱数 + /// + public int USE_CTNS_NUM { get; set; } + + /// + /// 剩余箱数 + /// + public int REMAIN_CTNS_NUM { get; set; } + } + + + public class BookingSlotStockListOutput : BookingSlotStockDto + { + } +} diff --git a/Myshipping.Web.Core/Startup.cs b/Myshipping.Web.Core/Startup.cs index 27b4d599..b6759eca 100644 --- a/Myshipping.Web.Core/Startup.cs +++ b/Myshipping.Web.Core/Startup.cs @@ -121,6 +121,8 @@ public class Startup : AppStartup builder.AddSubscriber(); //运踪 builder.AddSubscriber(); + //更新库存 + builder.AddSubscriber(); }); }