optimize
hao 11 months ago
parent 32e5272109
commit b35f765c90

@ -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; }
/// <summary>
/// 总
/// 总舱位
/// </summary>
[SugarColumn(ColumnName = "TOTAL_ORDERS")]
public int TOTAL_ORDERS{ get; set; }
/// <summary>
/// 使用
/// 使用舱位
/// </summary>
[SugarColumn(ColumnName = "USE_NUM")]
public int USE_NUM{ get; set; }
/// <summary>
/// 剩余票数
/// </summary>
[SugarColumn(ColumnName = "REMAIN_NUM")]
public int REMAIN_NUM{ get; set; }
/// <summary>
/// 总箱数
/// </summary>
@ -147,7 +141,7 @@ namespace Myshipping.Application
/// </summary>
[SugarColumn(ColumnName = "REMAIN_CTNS_NUM")]
public int REMAIN_CTNS_NUM{ get; set; }
/// <summary>
/// 租户名称
/// </summary>

@ -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<BookingSlotBase> _repBase;
private readonly SqlSugarRepository<BookingSlotCtn> _repCtn;
private readonly SqlSugarRepository<BookingSlotStock> _repStock;
private readonly SqlSugarRepository<BookingSlotAllocation> _repAlloc;
private readonly SqlSugarRepository<BookingSlotAllocationCtn> _repAllocCtn;
private readonly ILogger<BookingSlotStockSubscriber> _logger;
public BookingSlotStockSubscriber(SqlSugarRepository<BookingSlotBase> repBase,
SqlSugarRepository<BookingSlotCtn> repCtn,
SqlSugarRepository<BookingSlotStock> repStock,
SqlSugarRepository<BookingSlotAllocation> repAlloc,
SqlSugarRepository<BookingSlotAllocationCtn> repAllocCtn,
ILogger<BookingSlotStockSubscriber> 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);
}
}
/// <summary>
/// 刷新库存统计对象
/// </summary>
public class BookingSlotStockUpdateModel
{

@ -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<BookingSlotService> _logger;
private readonly ISysCacheService _cache;
private readonly IEventPublisher _publisher;
public BookingSlotService(SqlSugarRepository<BookingSlotBase> repBase,
SqlSugarRepository<BookingSlotCtn> repCtn,
SqlSugarRepository<BookingSlotStock> repStock,
ILogger<BookingSlotService> 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
}));
}
/// <summary>
@ -165,17 +192,40 @@ namespace Myshipping.Application
#endregion
#region 库存
///// <summary>
///// 库存查询
///// </summary>
///// <param name="input"></param>
///// <returns></returns>
//[HttpGet("/BookingSlot/pageStock")]
//public async Task<dynamic> PageStock([FromQuery] BookingSlotBasePageInput input)
//{
// var query = await _repStock.AsQueryable()
// .ToListAsync();
//}
/// <summary>
/// 库存查询
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/BookingSlot/pageStock")]
public async Task<dynamic> 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<SqlSugarPagedList<BookingSlotStockListOutput>>();
return result.XnPagedResult();
}
/// <summary>
/// 刷新库存统计
/// </summary>
/// <returns></returns>
[HttpPost("/BookingSlot/refreshStock")]
public async Task RefreshStock(BookingSlotStockUpdateModel input)
{
//更新库存
await _publisher.PublishAsync(new ChannelEventSource("BookingSlotStock:Update", input));
}
#endregion
}
}

@ -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
{
/// <summary>
/// 查询条件
/// </summary>
public class BookingSlotStockPageInput : PageInputBase
{
/// <summary>
/// 船名
/// </summary>
public string VESSEL { get; set; }
/// <summary>
/// 航次号
/// </summary>
public string VOYNO { get; set; }
/// <summary>
/// 预计开船日期起始
/// </summary>
public DateTime? ETD_START { get; set; }
/// <summary>
/// 预计开船日期截至
/// </summary>
public DateTime? ETD_END { get; set; }
/// <summary>
/// 预计到港日期起始
/// </summary>
public DateTime? ETA_START { get; set; }
/// <summary>
/// 预计到港日期截至
/// </summary>
public DateTime? ETA_END { get; set; }
/// <summary>
/// 船公司
/// </summary>
public string CARRIER { get; set; }
/// <summary>
/// 箱型箱量
/// </summary>
public string CTN_STAT { get; set; }
}
/// <summary>
/// dto基类
/// </summary>
public class BookingSlotStockDto
{
/// <summary>
/// 船名
/// </summary>
public string VESSEL { get; set; }
/// <summary>
/// 航次号
/// </summary>
public string VOYNO { get; set; }
/// <summary>
/// 合约号
/// </summary>
public string CONTRACT_NO { get; set; }
/// <summary>
/// 订舱方式 CONTRACT_ORDER-合约订舱SPOT_ORDER-SPOT订舱
/// </summary>
public string BOOKING_SLOT_TYPE { get; set; }
/// <summary>
/// 订舱方式名称 CONTRACT_ORDER-合约订舱SPOT_ORDER-SPOT订舱
/// </summary>
public string BOOKING_SLOT_TYPE_NAME { get; set; }
/// <summary>
/// 订舱抬头
/// </summary>
public string BOOKING_PARTY { get; set; }
/// <summary>
/// 船公司代号
/// </summary>
public string CARRIERID { get; set; }
/// <summary>
/// 船公司
/// </summary>
public string CARRIER { get; set; }
/// <summary>
/// 预计开船日期
/// </summary>
public DateTime? ETD { get; set; }
/// <summary>
/// 预计到港日期
/// </summary>
public DateTime? ETA { get; set; }
/// <summary>
/// 航线代码(船公司)
/// </summary>
public string LANECODE { get; set; }
/// <summary>
/// 航线名称(船公司)
/// </summary>
public string LANENAME { get; set; }
/// <summary>
/// 所在周数
/// </summary>
public string WEEK_AT { get; set; }
/// <summary>
/// 箱型箱量
/// </summary>
public string CTN_STAT { get; set; }
/// <summary>
/// 使用箱型箱量
/// </summary>
public string USE_CTN_STAT { get; set; }
/// <summary>
/// 剩余箱型箱量
/// </summary>
public string REMAIN_CTN_STAT { get; set; }
/// <summary>
/// 总舱位数
/// </summary>
public int TOTAL_ORDERS { get; set; }
/// <summary>
/// 使用舱位数
/// </summary>
public int USE_NUM { get; set; }
/// <summary>
/// 总箱数
/// </summary>
public int TOTAL_CTNS { get; set; }
/// <summary>
/// 使用箱数
/// </summary>
public int USE_CTNS_NUM { get; set; }
/// <summary>
/// 剩余箱数
/// </summary>
public int REMAIN_CTNS_NUM { get; set; }
}
public class BookingSlotStockListOutput : BookingSlotStockDto
{
}
}

@ -121,6 +121,8 @@ public class Startup : AppStartup
builder.AddSubscriber<CompanyUserSyncSubscriber>();
//运踪
builder.AddSubscriber<BillTraceSubscriber>();
//更新库存
builder.AddSubscriber<BookingSlotStockSubscriber>();
});
}

Loading…
Cancel
Save