|
|
@ -17,6 +17,7 @@ using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.ComponentModel;
|
|
|
|
using System.ComponentModel;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -52,7 +53,8 @@ namespace Myshipping.Application
|
|
|
|
ILogger<BookingSlotService> logger,
|
|
|
|
ILogger<BookingSlotService> logger,
|
|
|
|
ISysCacheService cache,
|
|
|
|
ISysCacheService cache,
|
|
|
|
IEventPublisher publisher,
|
|
|
|
IEventPublisher publisher,
|
|
|
|
SqlSugarRepository<BookingSlotAllocation> repAllocation)
|
|
|
|
SqlSugarRepository<BookingSlotAllocation> repAllocation,
|
|
|
|
|
|
|
|
SqlSugarRepository<BookingSlotAllocationCtn> repAllocationCtn)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_repBase = repBase;
|
|
|
|
_repBase = repBase;
|
|
|
|
_repCtn = repCtn;
|
|
|
|
_repCtn = repCtn;
|
|
|
@ -60,6 +62,7 @@ namespace Myshipping.Application
|
|
|
|
_repBookingLog = repBookingLog;
|
|
|
|
_repBookingLog = repBookingLog;
|
|
|
|
_repBookingLogDetail = repBookingLogDetail;
|
|
|
|
_repBookingLogDetail = repBookingLogDetail;
|
|
|
|
_repAllocation = repAllocation;
|
|
|
|
_repAllocation = repAllocation;
|
|
|
|
|
|
|
|
_repAllocationCtn = repAllocationCtn;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_logger = logger;
|
|
|
|
_logger = logger;
|
|
|
@ -530,7 +533,7 @@ namespace Myshipping.Application
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="slots">待引入的舱位列表</param>
|
|
|
|
/// <param name="slots">待引入的舱位列表</param>
|
|
|
|
/// <param name="bookingOrderId">待关联的订舱记录</param>
|
|
|
|
/// <param name="bookingOrderId">待关联的订舱记录</param>
|
|
|
|
/// <returns>(指定订舱记录是否已经引入过舱位数据,现有舱位及箱子是否满足需求,提示信息)</returns>
|
|
|
|
/// <returns>isExists:指定订舱记录是否已经引入过舱位数据,isEnough:现有舱位及箱子是否满足需求,message:提示信息</returns>
|
|
|
|
[NonAction]
|
|
|
|
[NonAction]
|
|
|
|
public async Task<(bool isExists, bool isEnough, string message)> CheckImportSlots(List<BookingSlotBaseWithCtnDto> slots, long bookingOrderId)
|
|
|
|
public async Task<(bool isExists, bool isEnough, string message)> CheckImportSlots(List<BookingSlotBaseWithCtnDto> slots, long bookingOrderId)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -573,6 +576,7 @@ namespace Myshipping.Application
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (false, true, $"可以引入");
|
|
|
|
return (false, true, $"可以引入");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static object ImportLockObj = new object();
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 为指定订舱记录引入舱位信息
|
|
|
|
/// 为指定订舱记录引入舱位信息
|
|
|
@ -580,63 +584,71 @@ namespace Myshipping.Application
|
|
|
|
/// <param name="slots">待引入的舱位列表</param>
|
|
|
|
/// <param name="slots">待引入的舱位列表</param>
|
|
|
|
/// <param name="bookingOrderId">待关联的订舱记录</param>
|
|
|
|
/// <param name="bookingOrderId">待关联的订舱记录</param>
|
|
|
|
/// <param name="isCheck">是否进行剩余量检查</param>
|
|
|
|
/// <param name="isCheck">是否进行剩余量检查</param>
|
|
|
|
/// <returns>(是否成功,提示消息)</returns>
|
|
|
|
/// <returns>isSuccess:检查(余量及已引用检查)是否成功通过,message:提示信息</returns>
|
|
|
|
[NonAction]
|
|
|
|
[NonAction]
|
|
|
|
public async Task<(bool isSuccess, string message)> ImportSlots(List<BookingSlotBaseWithCtnDto> slots, long bookingOrderId, bool isCheck)
|
|
|
|
public async Task<(bool isSuccess, string message)> ImportSlots(List<BookingSlotBaseWithCtnDto> slots, long bookingOrderId, bool isCheck)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
slots ??= new List<BookingSlotBaseWithCtnDto>();
|
|
|
|
slots ??= new List<BookingSlotBaseWithCtnDto>();
|
|
|
|
|
|
|
|
|
|
|
|
if (isCheck)
|
|
|
|
Monitor.Enter(ImportLockObj);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
(bool isExists, bool isEnough, string message) checkResult = await CheckImportSlots(slots, bookingOrderId);
|
|
|
|
if (isCheck)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
(bool isExists, bool isEnough, string message) checkResult = await CheckImportSlots(slots, bookingOrderId);
|
|
|
|
|
|
|
|
|
|
|
|
if (checkResult.isExists || !checkResult.isEnough)
|
|
|
|
if (checkResult.isExists || !checkResult.isEnough)
|
|
|
|
return (false, checkResult.message);
|
|
|
|
return (false, checkResult.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var slotIdList = slots.Select(s => s.Id).ToList();
|
|
|
|
var slotIdList = slots.Select(s => s.Id).ToList();
|
|
|
|
List<BookingSlotBase> latestSlotList = await _repBase.AsQueryable().Where(b => slotIdList.Contains(b.Id)).ToListAsync();
|
|
|
|
List<BookingSlotBase> latestSlotList = await _repBase.AsQueryable().Where(b => slotIdList.Contains(b.Id)).ToListAsync();
|
|
|
|
foreach (var inSlotItem in slots)
|
|
|
|
foreach (var inSlotItem in slots)
|
|
|
|
{
|
|
|
|
|
|
|
|
var latestSlot = latestSlotList.First(b => b.Id == inSlotItem.Id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var config = new TypeAdapterConfig();
|
|
|
|
|
|
|
|
config.ForType<BookingSlotBase, BookingSlotAllocation>()
|
|
|
|
|
|
|
|
.Ignore(dest => dest.CreatedTime)
|
|
|
|
|
|
|
|
.Ignore(dest => dest.UpdatedTime)
|
|
|
|
|
|
|
|
.Ignore(dest => dest.CreatedUserId)
|
|
|
|
|
|
|
|
.Ignore(dest => dest.UpdatedUserId)
|
|
|
|
|
|
|
|
.Ignore(dest => dest.CreatedUserName)
|
|
|
|
|
|
|
|
.Ignore(dest => dest.UpdatedUserName)
|
|
|
|
|
|
|
|
.Ignore(dest => dest.TenantId)
|
|
|
|
|
|
|
|
.Ignore(dest => dest.TenantName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var newSlotAllocation = latestSlot.Adapt<BookingSlotAllocation>(config);
|
|
|
|
|
|
|
|
newSlotAllocation.Id = 0;
|
|
|
|
|
|
|
|
newSlotAllocation.BOOKING_SLOT_ID = latestSlot.Id;
|
|
|
|
|
|
|
|
newSlotAllocation.BOOKING_ID = bookingOrderId;
|
|
|
|
|
|
|
|
newSlotAllocation.ALLO_BILL_NO = latestSlot.SLOT_BOOKING_NO;
|
|
|
|
|
|
|
|
newSlotAllocation.FINAL_BILL_NO = latestSlot.SLOT_BOOKING_NO;
|
|
|
|
|
|
|
|
await _repAllocation.InsertAsync(newSlotAllocation);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var insertCtnList = inSlotItem.CtnList.Select(c => new BookingSlotAllocationCtn()
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
SLOT_ALLOC_ID = newSlotAllocation.Id,
|
|
|
|
var latestSlot = latestSlotList.First(b => b.Id == inSlotItem.Id);
|
|
|
|
CTNCODE = c.CTNCODE,
|
|
|
|
|
|
|
|
CTNALL = c.CTNALL,
|
|
|
|
var config = new TypeAdapterConfig();
|
|
|
|
CTNNUM = c.CTNNUM
|
|
|
|
config.ForType<BookingSlotBase, BookingSlotAllocation>()
|
|
|
|
});
|
|
|
|
.Ignore(dest => dest.CreatedTime)
|
|
|
|
await _repAllocationCtn.InsertAsync(insertCtnList);
|
|
|
|
.Ignore(dest => dest.UpdatedTime)
|
|
|
|
|
|
|
|
.Ignore(dest => dest.CreatedUserId)
|
|
|
|
|
|
|
|
.Ignore(dest => dest.UpdatedUserId)
|
|
|
|
|
|
|
|
.Ignore(dest => dest.CreatedUserName)
|
|
|
|
|
|
|
|
.Ignore(dest => dest.UpdatedUserName)
|
|
|
|
|
|
|
|
.Ignore(dest => dest.TenantId)
|
|
|
|
|
|
|
|
.Ignore(dest => dest.TenantName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var newSlotAllocation = latestSlot.Adapt<BookingSlotAllocation>(config);
|
|
|
|
|
|
|
|
newSlotAllocation.Id = 0;
|
|
|
|
|
|
|
|
newSlotAllocation.BOOKING_SLOT_ID = latestSlot.Id;
|
|
|
|
|
|
|
|
newSlotAllocation.BOOKING_ID = bookingOrderId;
|
|
|
|
|
|
|
|
newSlotAllocation.ALLO_BILL_NO = latestSlot.SLOT_BOOKING_NO;
|
|
|
|
|
|
|
|
newSlotAllocation.FINAL_BILL_NO = latestSlot.SLOT_BOOKING_NO;
|
|
|
|
|
|
|
|
await _repAllocation.InsertAsync(newSlotAllocation);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var insertCtnList = inSlotItem.CtnList.Select(c => new BookingSlotAllocationCtn()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
SLOT_ALLOC_ID = newSlotAllocation.Id,
|
|
|
|
|
|
|
|
CTNCODE = c.CTNCODE,
|
|
|
|
|
|
|
|
CTNALL = c.CTNALL,
|
|
|
|
|
|
|
|
CTNNUM = c.CTNNUM
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
await _repAllocationCtn.InsertAsync(insertCtnList);
|
|
|
|
|
|
|
|
|
|
|
|
// 更新库存
|
|
|
|
// 更新库存
|
|
|
|
await _publisher.PublishAsync(new ChannelEventSource("BookingSlotStock:Update", new Event.BookingSlotStockUpdateModel
|
|
|
|
await _publisher.PublishAsync(new ChannelEventSource("BookingSlotStock:Update", new Event.BookingSlotStockUpdateModel
|
|
|
|
{
|
|
|
|
{
|
|
|
|
BOOKING_SLOT_TYPE = latestSlot.BOOKING_SLOT_TYPE,
|
|
|
|
BOOKING_SLOT_TYPE = latestSlot.BOOKING_SLOT_TYPE,
|
|
|
|
CARRIERID = latestSlot.CARRIERID,
|
|
|
|
CARRIERID = latestSlot.CARRIERID,
|
|
|
|
CONTRACT_NO = latestSlot.CONTRACT_NO,
|
|
|
|
CONTRACT_NO = latestSlot.CONTRACT_NO,
|
|
|
|
VESSEL = latestSlot.VESSEL,
|
|
|
|
VESSEL = latestSlot.VESSEL,
|
|
|
|
VOYNO = latestSlot.VOYNO
|
|
|
|
VOYNO = latestSlot.VOYNO
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
finally
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Monitor.Exit(ImportLockObj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (true, "引入成功");
|
|
|
|
return (true, "引入成功");
|
|
|
|