You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
BookingHeChuan/Myshipping.Application/Event/BookingSlotStockSubscriber.cs

127 lines
4.3 KiB
C#

11 months ago
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;
namespace Myshipping.Application.Event
{
/// <summary>
/// 运踪
/// </summary>
public class BookingSlotStockSubscriber : IEventSubscriber
{
private readonly SqlSugarRepository<BookingSlotBase> _repBase;
private readonly SqlSugarRepository<BookingSlotCtn> _repCtn;
private readonly SqlSugarRepository<BookingSlotStock> _repStock;
private readonly ILogger<BookingSlotStockSubscriber> _logger;
public BookingSlotStockSubscriber(SqlSugarRepository<BookingSlotBase> repBase,
SqlSugarRepository<BookingSlotCtn> repCtn,
SqlSugarRepository<BookingSlotStock> repStock,
ILogger<BookingSlotStockSubscriber> logger)
{
_repBase = repBase;
_repCtn = repCtn;
_repStock = repStock;
_logger = logger;
}
//更新库存
[EventSubscribe("BookingSlotStock:Update")]
public async Task BookingSlotStock(EventHandlerExecutingContext context)
{
_logger.LogInformation($"收到更新库存订阅请求:{context.Source.Payload}");
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)
.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.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;
await _repStock.InsertAsync(stockObj);
}
stockObj.TOTAL_ORDERS = baseList.Count;
}
}
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; }
}
}