|
|
|
@ -29,6 +29,8 @@ using Furion.EventBus;
|
|
|
|
|
using Myshipping.Application.Event;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Furion.DatabaseAccessor;
|
|
|
|
|
using static ICSharpCode.SharpZipLib.Zip.ExtendedUnixData;
|
|
|
|
|
using Myshipping.Application.Service.BookingOrder.Dto;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Myshipping.Application
|
|
|
|
@ -42,6 +44,10 @@ namespace Myshipping.Application
|
|
|
|
|
private readonly SqlSugarRepository<BookingSlotBase> _repBase;
|
|
|
|
|
private readonly SqlSugarRepository<BookingSlotCtn> _repCtn;
|
|
|
|
|
private readonly SqlSugarRepository<BookingSlotStock> _repStock;
|
|
|
|
|
|
|
|
|
|
private readonly SqlSugarRepository<BookingLog> _repBookingLog;
|
|
|
|
|
private readonly SqlSugarRepository<BookingLogDetail> _repBookingLogDetail;
|
|
|
|
|
|
|
|
|
|
private readonly ILogger<BookingSlotService> _logger;
|
|
|
|
|
private readonly ISysCacheService _cache;
|
|
|
|
|
|
|
|
|
@ -50,6 +56,8 @@ namespace Myshipping.Application
|
|
|
|
|
public BookingSlotService(SqlSugarRepository<BookingSlotBase> repBase,
|
|
|
|
|
SqlSugarRepository<BookingSlotCtn> repCtn,
|
|
|
|
|
SqlSugarRepository<BookingSlotStock> repStock,
|
|
|
|
|
SqlSugarRepository<BookingLog> repBookingLog,
|
|
|
|
|
SqlSugarRepository<BookingLogDetail> repBookingLogDetail,
|
|
|
|
|
ILogger<BookingSlotService> logger,
|
|
|
|
|
ISysCacheService cache,
|
|
|
|
|
IEventPublisher publisher)
|
|
|
|
@ -57,6 +65,10 @@ namespace Myshipping.Application
|
|
|
|
|
_repBase = repBase;
|
|
|
|
|
_repCtn = repCtn;
|
|
|
|
|
_repStock = repStock;
|
|
|
|
|
_repBookingLog = repBookingLog;
|
|
|
|
|
_repBookingLogDetail = repBookingLogDetail;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_cache = cache;
|
|
|
|
|
|
|
|
|
@ -102,7 +114,7 @@ namespace Myshipping.Application
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/BookingSlot/save")]
|
|
|
|
|
public async Task<BookingSlotBaseSaveDto> Save(BookingSlotBaseSaveDto input)
|
|
|
|
|
public async Task<BookingSlotBaseSaveOutput> Save(BookingSlotBaseSaveInput input)
|
|
|
|
|
{
|
|
|
|
|
BookingSlotBase model = null;
|
|
|
|
|
if (input.Id > 0) //修改
|
|
|
|
@ -114,6 +126,7 @@ namespace Myshipping.Application
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model = _repBase.FirstOrDefault(x => x.Id == input.Id);
|
|
|
|
|
var oldObj = model.Adapt<BookingSlotBaseSaveInput>();
|
|
|
|
|
|
|
|
|
|
input.Adapt(model);
|
|
|
|
|
|
|
|
|
@ -126,6 +139,8 @@ namespace Myshipping.Application
|
|
|
|
|
newCtn.SLOT_ID = model.Id;
|
|
|
|
|
await _repCtn.InsertAsync(newCtn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await InsLog("Update", model.Id, typeof(BookingSlotBaseSaveInput), oldObj, input, "CtnList");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
@ -143,6 +158,8 @@ namespace Myshipping.Application
|
|
|
|
|
newCtn.SLOT_ID = model.Id;
|
|
|
|
|
await _repCtn.InsertAsync(newCtn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await InsLog("Add", model.Id, "新增舱位");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//更新库存
|
|
|
|
@ -178,6 +195,8 @@ namespace Myshipping.Application
|
|
|
|
|
}
|
|
|
|
|
await _repCtn.UpdateAsync(ctns);
|
|
|
|
|
|
|
|
|
|
await InsLog("Del", entity.Id, "取消舱位");
|
|
|
|
|
|
|
|
|
|
//更新库存
|
|
|
|
|
await _publisher.PublishAsync(new ChannelEventSource("BookingSlotStock:Update", new BookingSlotStockUpdateModel
|
|
|
|
|
{
|
|
|
|
@ -195,13 +214,30 @@ namespace Myshipping.Application
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("/BookingSlot/detail")]
|
|
|
|
|
public async Task<BookingSlotBaseSaveDto> Detail(long id)
|
|
|
|
|
public async Task<BookingSlotBaseSaveOutput> Detail(long id)
|
|
|
|
|
{
|
|
|
|
|
var slotBase = await _repBase.FirstOrDefaultAsync(u => u.Id == id);
|
|
|
|
|
var ctns = await _repCtn.Where(x => x.SLOT_ID == id).ToListAsync();
|
|
|
|
|
|
|
|
|
|
var rtn = slotBase.Adapt<BookingSlotBaseSaveDto>();
|
|
|
|
|
var rtn = slotBase.Adapt<BookingSlotBaseSaveOutput>();
|
|
|
|
|
rtn.CtnList = ctns.Adapt<List<BookingSlotCtnSaveInput>>();
|
|
|
|
|
|
|
|
|
|
List<BookingLogDto> list = new List<BookingLogDto>();
|
|
|
|
|
var main = await _repBookingLog.AsQueryable().Where(u => u.BookingId == slotBase.Id).ToListAsync();
|
|
|
|
|
var mailidlist = main.Select(x => x.Id).ToList();
|
|
|
|
|
list = main.Adapt<List<BookingLogDto>>();
|
|
|
|
|
if (list != null)
|
|
|
|
|
{
|
|
|
|
|
var bookinglogdetail = await _repBookingLogDetail.AsQueryable().Where(x => mailidlist.Contains(x.PId)).ToListAsync();
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
|
|
|
|
var details = bookinglogdetail.Where(x => x.PId == item.Id).ToList();
|
|
|
|
|
item.details = details;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rtn.LogList = list;
|
|
|
|
|
|
|
|
|
|
return rtn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -234,6 +270,8 @@ namespace Myshipping.Application
|
|
|
|
|
newCtn.SLOT_ID = model.Id;
|
|
|
|
|
await _repCtn.InsertAsync(newCtn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await InsLog("Add", model.Id, "新增舱位");
|
|
|
|
|
}
|
|
|
|
|
else if (dto.OpType == "update")
|
|
|
|
|
{
|
|
|
|
@ -243,6 +281,7 @@ namespace Myshipping.Application
|
|
|
|
|
throw Oops.Bah($"未找到订舱编号为 {dto.DataObj.SLOT_BOOKING_NO} 的数据");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var oldObj = model.Adapt<BookingSlotBaseApiSaveDto>();
|
|
|
|
|
|
|
|
|
|
dto.DataObj.Adapt(model);
|
|
|
|
|
await _repBase.UpdateAsync(model);
|
|
|
|
@ -253,6 +292,8 @@ namespace Myshipping.Application
|
|
|
|
|
newCtn.SLOT_ID = model.Id;
|
|
|
|
|
await _repCtn.InsertAsync(newCtn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await InsLog("Update", model.Id, typeof(BookingSlotBaseApiSaveDto), oldObj, dto.DataObj, "CtnList");
|
|
|
|
|
}
|
|
|
|
|
else if (dto.OpType == "del")
|
|
|
|
|
{
|
|
|
|
@ -271,6 +312,8 @@ namespace Myshipping.Application
|
|
|
|
|
ctn.IsDeleted = true;
|
|
|
|
|
await _repCtn.UpdateAsync(ctn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await InsLog("Del", model.Id, "取消舱位");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//更新库存
|
|
|
|
@ -290,6 +333,118 @@ namespace Myshipping.Application
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 插入日志(仅显示一条文本信息)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="type"></param>
|
|
|
|
|
/// <param name="slotId"></param>
|
|
|
|
|
/// <param name="status"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[NonAction]
|
|
|
|
|
private async Task InsLog(string type, long slotId, string status)
|
|
|
|
|
{
|
|
|
|
|
var bid = await _repBookingLog.InsertReturnSnowflakeIdAsync(new BookingLog
|
|
|
|
|
{
|
|
|
|
|
Type = type,
|
|
|
|
|
BookingId = slotId,
|
|
|
|
|
TenantId = Convert.ToInt64(UserManager.TENANT_ID),
|
|
|
|
|
CreatedTime = DateTime.Now,
|
|
|
|
|
CreatedUserId = UserManager.UserId,
|
|
|
|
|
CreatedUserName = UserManager.Name,
|
|
|
|
|
Module = "Slot"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(status))
|
|
|
|
|
{
|
|
|
|
|
await _repBookingLogDetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
|
|
|
|
|
{
|
|
|
|
|
PId = bid,
|
|
|
|
|
Field = "",
|
|
|
|
|
OldValue = "",
|
|
|
|
|
NewValue = status,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 插入日志(比对修改内容)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="type"></param>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <param name="objType"></param>
|
|
|
|
|
/// <param name="objOld"></param>
|
|
|
|
|
/// <param name="objNew"></param>
|
|
|
|
|
/// <param name="excepProp"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[NonAction]
|
|
|
|
|
private async Task InsLog(string type, long id, Type objType, object objOld, object objNew, params string[] excepProp)
|
|
|
|
|
{
|
|
|
|
|
var bid = await _repBookingLog.InsertReturnSnowflakeIdAsync(new BookingLog
|
|
|
|
|
{
|
|
|
|
|
Type = type,
|
|
|
|
|
BookingId = id,
|
|
|
|
|
TenantId = Convert.ToInt64(UserManager.TENANT_ID),
|
|
|
|
|
CreatedTime = DateTime.Now,
|
|
|
|
|
CreatedUserId = UserManager.UserId,
|
|
|
|
|
CreatedUserName = UserManager.Name,
|
|
|
|
|
Module = "Slot"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(objType))
|
|
|
|
|
{
|
|
|
|
|
if (excepProp.Contains(descriptor.Name))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var compResult = false;
|
|
|
|
|
var oldValue = descriptor.GetValue(objOld);
|
|
|
|
|
var newValue = descriptor.GetValue(objNew);
|
|
|
|
|
if (oldValue != null && newValue != null)
|
|
|
|
|
{
|
|
|
|
|
if (descriptor.PropertyType == typeof(string))
|
|
|
|
|
{
|
|
|
|
|
compResult = oldValue.ToString() == newValue.ToString();
|
|
|
|
|
}
|
|
|
|
|
else if (descriptor.PropertyType == typeof(DateTime) || descriptor.PropertyType == typeof(DateTime?))
|
|
|
|
|
{
|
|
|
|
|
compResult = Convert.ToDateTime(oldValue) == Convert.ToDateTime(newValue);
|
|
|
|
|
}
|
|
|
|
|
else if (descriptor.PropertyType == typeof(decimal) || descriptor.PropertyType == typeof(float) || descriptor.PropertyType == typeof(double)
|
|
|
|
|
|| descriptor.PropertyType == typeof(decimal?) || descriptor.PropertyType == typeof(float?) || descriptor.PropertyType == typeof(double?))
|
|
|
|
|
{
|
|
|
|
|
compResult = Convert.ToDecimal(oldValue) == Convert.ToDecimal(newValue);
|
|
|
|
|
}
|
|
|
|
|
else if (descriptor.PropertyType == typeof(int) || descriptor.PropertyType == typeof(long)
|
|
|
|
|
|| descriptor.PropertyType == typeof(int?) || descriptor.PropertyType == typeof(long?))
|
|
|
|
|
{
|
|
|
|
|
compResult = Convert.ToInt64(oldValue) == Convert.ToInt64(newValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
compResult = oldValue == newValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!compResult)
|
|
|
|
|
{
|
|
|
|
|
var fieldName = descriptor.Name;
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(descriptor.Description))
|
|
|
|
|
{
|
|
|
|
|
fieldName = descriptor.Description;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await _repBookingLogDetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
|
|
|
|
|
{
|
|
|
|
|
PId = bid,
|
|
|
|
|
Field = fieldName,
|
|
|
|
|
OldValue = $"{oldValue}",
|
|
|
|
|
NewValue = $"{newValue}",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 库存
|
|
|
|
@ -327,6 +482,96 @@ namespace Myshipping.Application
|
|
|
|
|
//更新库存
|
|
|
|
|
await _publisher.PublishAsync(new ChannelEventSource("BookingSlotStock:Update", input));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询可用的舱位及箱子
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet("/BookingSlot/getAvailableSlots")]
|
|
|
|
|
public async Task<List<BookingSlotAvailableDto>> GetAvailableSlots([FromQuery] BookingSlotBaseDto input)
|
|
|
|
|
{
|
|
|
|
|
string[] ctnCodeList = null;
|
|
|
|
|
if (!string.IsNullOrEmpty(input.CTN_STAT))
|
|
|
|
|
{
|
|
|
|
|
ctnCodeList = input.CTN_STAT.Split(',');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 1. 【舱位基础表】与【箱子表】做关联,并根据【舱位主键】、【箱型】做分组,统计出【总的箱量】,作为queryable1
|
|
|
|
|
var queryable1 = _repBase.Context.Queryable<BookingSlotBase, BookingSlotCtn>((bas, ctn) => bas.Id == ctn.SLOT_ID)
|
|
|
|
|
.WhereIF(!string.IsNullOrEmpty(input.PORTLOAD), bas => bas.PORTLOAD.Contains(input.PORTLOAD))
|
|
|
|
|
.WhereIF(!string.IsNullOrEmpty(input.PORTDISCHARGE), bas => bas.PORTLOAD.Contains(input.PORTLOAD))
|
|
|
|
|
.WhereIF(!string.IsNullOrEmpty(input.VESSEL), bas => bas.VESSEL.Contains(input.VESSEL))
|
|
|
|
|
.WhereIF(!string.IsNullOrEmpty(input.VOYNO), bas => bas.VOYNO.Contains(input.VOYNO))
|
|
|
|
|
.WhereIF(!string.IsNullOrEmpty(input.CARRIAGE_TYPE), bas => bas.CARRIAGE_TYPE == input.CARRIAGE_TYPE)
|
|
|
|
|
.WhereIF(!string.IsNullOrEmpty(input.BOOKING_SLOT_TYPE), bas => bas.BOOKING_SLOT_TYPE == input.BOOKING_SLOT_TYPE)
|
|
|
|
|
.WhereIF(ctnCodeList != null, (bas, ctn) => ctnCodeList.Contains(ctn.CTNCODE))
|
|
|
|
|
.GroupBy((bas, ctn) => new
|
|
|
|
|
{
|
|
|
|
|
bas.Id,
|
|
|
|
|
ctn.CTNCODE
|
|
|
|
|
})
|
|
|
|
|
.Select((bas, ctn) => new
|
|
|
|
|
{
|
|
|
|
|
id = bas.Id,
|
|
|
|
|
ctnCode = ctn.CTNCODE,
|
|
|
|
|
numAll = SqlFunc.AggregateSum(ctn.CTNNUM)
|
|
|
|
|
})
|
|
|
|
|
.MergeTable();
|
|
|
|
|
|
|
|
|
|
// 2. 【已引入舱位表】与【已使用的箱子表】做关联,并根据【舱位主键】、【箱型】做分组,统计出【已使用的箱量】,作为queryable2
|
|
|
|
|
var queryable2 = _repBase.Context.Queryable<BookingSlotAllocation, BookingSlotAllocationCtn>((alc, ctn) => alc.Id == ctn.SLOT_ALLOC_ID)
|
|
|
|
|
.GroupBy((alc, ctn) => new
|
|
|
|
|
{
|
|
|
|
|
alc.BOOKING_SLOT_ID,
|
|
|
|
|
ctn.CTNCODE
|
|
|
|
|
})
|
|
|
|
|
.Select((alc, ctn) => new
|
|
|
|
|
{
|
|
|
|
|
id = alc.BOOKING_SLOT_ID,
|
|
|
|
|
ctnCode = ctn.CTNCODE,
|
|
|
|
|
numUse = SqlFunc.AggregateSum(ctn.CTNNUM)
|
|
|
|
|
})
|
|
|
|
|
.MergeTable();
|
|
|
|
|
|
|
|
|
|
// 3. 将queryable1 左连接 queryable2,使用【总的箱量】减去【已使用的箱量】,得到【剩余的箱量】,添加【剩余的箱量】> 0 的条件,作为queryable3
|
|
|
|
|
var queryable3 = queryable1.LeftJoin(queryable2, (q1, q2) => q1.id == q2.id && q1.ctnCode == q2.ctnCode)
|
|
|
|
|
.Select((q1, q2) => new
|
|
|
|
|
{
|
|
|
|
|
q1.id,
|
|
|
|
|
q1.ctnCode,
|
|
|
|
|
numResidue = SqlFunc.IsNull(q1.numAll - q2.numUse, q1.numAll)
|
|
|
|
|
})
|
|
|
|
|
.MergeTable()
|
|
|
|
|
.Where(r => r.numResidue > 0);
|
|
|
|
|
|
|
|
|
|
// 4. 执行ToList(),得到可用的【舱位主键】、【箱型】、【箱量】列表
|
|
|
|
|
var canUselist = await queryable3.ToListAsync();
|
|
|
|
|
|
|
|
|
|
// 查询舱位列表
|
|
|
|
|
var baseIdList = canUselist.Select(c => c.id);
|
|
|
|
|
List<BookingSlotBase> baseList = await _repBase.AsQueryable()
|
|
|
|
|
.Where(u => baseIdList.Contains(u.Id))
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
List<Core.Entity.CodeCtn> ctnCodeCache = await _cache.GetAllCodeCtn();
|
|
|
|
|
|
|
|
|
|
// 构建结果
|
|
|
|
|
List<BookingSlotAvailableDto> result = baseList.Adapt<List<BookingSlotAvailableDto>>();
|
|
|
|
|
foreach (var item in result)
|
|
|
|
|
{
|
|
|
|
|
var ctnList = canUselist.Where(c => c.id == item.Id).ToList();
|
|
|
|
|
if (ctnList?.Any() == true)
|
|
|
|
|
{
|
|
|
|
|
item.CtnList = ctnList.Select(c => new BookingSlotCtnDto()
|
|
|
|
|
{
|
|
|
|
|
CTNCODE = c.ctnCode,
|
|
|
|
|
CTNNUM = c.numResidue,
|
|
|
|
|
CTNALL = ctnCodeCache.FirstOrDefault(e => e.Code == c.ctnCode)?.Name ?? throw new Exception($"舱位信息中存在未收录的箱型:{c.ctnCode},需要在箱型字典中补充"),
|
|
|
|
|
}).ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|