|
|
|
|
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 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
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 运踪
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class BookingSlotStockSubscriber : IEventSubscriber
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<BookingSlotStockSubscriber> _logger;
|
|
|
|
|
|
|
|
|
|
public BookingSlotStockSubscriber(
|
|
|
|
|
ILogger<BookingSlotStockSubscriber> logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//更新库存
|
|
|
|
|
[EventSubscribe("BookingSlotStock:Update")]
|
|
|
|
|
public async Task BookingSlotStock(EventHandlerExecutingContext context)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation($"收到更新库存订阅请求:{context.Source.Payload}");
|
|
|
|
|
|
|
|
|
|
var _repBase = App.GetService<SqlSugarRepository<BookingSlotBase>>();
|
|
|
|
|
var _repCtn = App.GetService<SqlSugarRepository<BookingSlotCtn>>();
|
|
|
|
|
var _repStock = App.GetService<SqlSugarRepository<BookingSlotStock>>();
|
|
|
|
|
var _repAlloc = App.GetService<SqlSugarRepository<BookingSlotAllocation>>();
|
|
|
|
|
var _repAllocCtn = App.GetService<SqlSugarRepository<BookingSlotAllocationCtn>>();
|
|
|
|
|
|
|
|
|
|
var paraObj = context.Source.Payload as BookingSlotStockUpdateModel;
|
|
|
|
|
|
|
|
|
|
var baseList = await _repBase.AsQueryable().Filter(null, true)
|
|
|
|
|
.Where(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)
|
|
|
|
|
.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);
|
|
|
|
|
if (stockObj == null)
|
|
|
|
|
{
|
|
|
|
|
stockObj = new BookingSlotStock();
|
|
|
|
|
stockObj.Id = YitIdHelper.NextId();
|
|
|
|
|
await _repStock.InsertAsync(stockObj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/// <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>
|
|
|
|
|
/// 船公司代号
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string CARRIERID { get; set; }
|
|
|
|
|
}
|
|
|
|
|
}
|