调整舱位库存计算方法

optimize
zhangxiaofeng 10 months ago
parent 5b56f607d2
commit 2693c7a902

@ -12,6 +12,7 @@ using Myshipping.Core;
using Myshipping.Core.Entity;
using Myshipping.Core.Service;
using Newtonsoft.Json.Linq;
using NPOI.OpenXmlFormats.Wordprocessing;
using SqlSugar;
using System;
using System.Collections.Generic;
@ -60,6 +61,10 @@ namespace Myshipping.Application.Event
&& x.CARRIERID == paraObj.CARRIERID)
.OrderByDescending(x => x.UpdatedTime)
.ToListAsync();
if (!baseList.Any())
{
return;
}
var stockObj = await _repStock.AsQueryable()
.Filter(null, true)
@ -80,33 +85,74 @@ namespace Myshipping.Application.Event
baseList[0].Adapt(stockObj);
stockObj.Id = bkId;
stockObj.TOTAL_ORDERS = baseList.Count; //总舱位数
// 总舱位数
stockObj.TOTAL_ORDERS = baseList.Count;
var lstBaseId = baseList.Select(x => x.Id).ToList();
stockObj.TOTAL_CTNS = _repCtn.AsQueryable()
.Filter(null, true)
.Where(x => !x.IsDeleted && lstBaseId.Contains(x.SLOT_ID))
.Sum(x => x.CTNNUM); //总箱数
// 总的箱型箱量
var ctnAllList = await _repCtn.AsQueryable().Filter(null, true)
.Where(x => !x.IsDeleted && lstBaseId.Contains(x.SLOT_ID))
.GroupBy(x => x.CTNALL)
.Select(x => new
{
x.CTNALL,
CTNNUM = SqlFunc.AggregateSum(x.CTNNUM)
}).ToListAsync();
stockObj.CTN_STAT = string.Join(' ', ctnAllList.Select(c => c.CTNALL + "*" + c.CTNNUM));
// 总箱数
stockObj.TOTAL_CTNS = ctnAllList.Sum(x => x.CTNNUM);
var lstAllocKeyList = await _repAlloc.AsQueryable()
.Filter(null, true)
.Where(x => !x.IsDeleted && lstBaseId.Contains(x.BOOKING_SLOT_ID))
.Select(x => new { x.Id, x.BOOKING_SLOT_ID })
.ToListAsync();
stockObj.USE_NUM = lstAllocKeyList.DistinctBy(x => x.BOOKING_SLOT_ID).Count(); //使用舱位数
// 已使用舱位数
stockObj.USE_NUM = lstAllocKeyList.DistinctBy(x => x.BOOKING_SLOT_ID).Count();
var lstAllocIdList = lstAllocKeyList.Select(x => x.Id).ToList();
stockObj.USE_CTNS_NUM = _repAllocCtn.AsQueryable()
.Filter(null, true)
.Where(x => !x.IsDeleted && lstAllocIdList.Contains(x.SLOT_ALLOC_ID))
.Sum(x => x.CTNNUM); //使用箱数
// 已使用的箱型箱量
var userCtnList = await _repAllocCtn.AsQueryable()
.Filter(null, true)
.Where(x => !x.IsDeleted && lstAllocIdList.Contains(x.SLOT_ALLOC_ID))
.GroupBy(x => x.CTNALL)
.Select(x => new
{
x.CTNALL,
CTNNUM = SqlFunc.AggregateSum(x.CTNNUM)
}).ToListAsync();
stockObj.USE_CTN_STAT = string.Join(' ', userCtnList.Select(c => c.CTNALL + "*" + c.CTNNUM));
// 已使用的箱数
stockObj.USE_CTNS_NUM = userCtnList.Sum(x => x.CTNNUM);
// 剩余的箱型箱量
Dictionary<string, int> remainCtnList = new(ctnAllList.Count);
foreach (var item in ctnAllList)
{
var useItem = userCtnList.FirstOrDefault(x => x.CTNALL == item.CTNALL);
if (useItem == null)
{
remainCtnList.Add(item.CTNALL, item.CTNNUM);
}
else
{
int remainCtnNum = item.CTNNUM - useItem.CTNNUM;
if (remainCtnNum > 0)
{
remainCtnList.Add(item.CTNALL, remainCtnNum);
}
}
}
stockObj.REMAIN_CTN_STAT = string.Join(' ', remainCtnList.Select(x => x.Key + "*" + x.Value));
stockObj.REMAIN_CTNS_NUM = stockObj.TOTAL_CTNS - stockObj.USE_CTNS_NUM; //剩余箱数
// 剩余箱数
stockObj.REMAIN_CTNS_NUM = stockObj.TOTAL_CTNS - stockObj.USE_CTNS_NUM;
await _repStock.UpdateAsync(stockObj);
}
}

@ -47,7 +47,7 @@ namespace Myshipping.Application
/// 分页查询往来单位固定费用列表
/// </summary>
[HttpGet("/FeeCustTemplate/Page")]
public async Task<dynamic> Page(FeeCustTemplatePageInput input)
public async Task<dynamic> Page([FromQuery] FeeCustTemplatePageInput input)
{
var entities = await _repCustTemplete.AsQueryable()
.ToPagedListAsync(input.PageNo, input.PageSize);

Loading…
Cancel
Save