一楼中储仓下发二楼出库策略优化,bug

This commit is contained in:
2024-07-01 17:45:36 +08:00
parent fd42810269
commit 8c66d5c45c
7 changed files with 160 additions and 58 deletions

View File

@@ -456,6 +456,7 @@ namespace Tnb.WarehouseMgr
.Select<WmsCarryH>()
.ToListAsync();
items = items.Distinct().ToList();
return input.Size > 0 ? items.Take(input.Size).ToList() : items;
}
@@ -466,7 +467,7 @@ namespace Tnb.WarehouseMgr
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="AppFriendlyException"></exception>
public async Task<List<WmsCarryH>> OutStockStrategyZCC2Floor2([FromQuery] OutStockStrategyQuery input)
public async Task<List<Tuple<WmsCarryH, decimal, BasLocation>>> OutStockStrategyZCC2Floor2([FromQuery] OutStockStrategyZCC2Floor2Query input)
{
Expressionable<WmsCarryH, WmsCarryCode, BasLocation> whereExprable = Expressionable.Create<WmsCarryH, WmsCarryCode, BasLocation>()
.And((a, b, c) => a.is_lock == 0 && c.is_lock == 0)
@@ -492,17 +493,72 @@ namespace Tnb.WarehouseMgr
throw new AppFriendlyException("没有可用策略", 500);
}
List<WmsCarryH> items = await cyDb.Queryable<WmsCarryH>().LeftJoin<WmsCarryCode>((a, b) => a.id == b.carry_id)
#region 60 59 60 6018060 60 60
var itemsASC = await cyDb.Queryable<WmsCarryH>().LeftJoin<WmsCarryCode>((a, b) => a.id == b.carry_id)
.LeftJoin<BasLocation>((a, b, c) => a.location_id == c.id)
.Where(whereExpr)
//.OrderByIF((a,b,c)=>SqlFunc.IsNullOrEmpty())
.OrderBy(policy.policy)
//.OrderBy(policy.policy)
.OrderBy("codeqty desc,a.location_code,layers,loc_line,loc_column")
.Select<WmsCarryH>()
.Select((a, b) => new { wmsCarryH = a, wmsCarryCode = b })
.ToListAsync();
//items = itemsASC.Count < itemsDESC.Count ? itemsASC : itemsDESC;
items = items.Distinct().ToList();
return input.Size > 0 ? items.Take(input.Size).ToList() : items;
itemsASC = itemsASC.Distinct().ToList();
List<Tuple<WmsCarryH, decimal, BasLocation>>? carrys = new List<Tuple<WmsCarryH, decimal, BasLocation>>();
for (int i = 0; i < itemsASC.Count; i++)
{
WmsCarryH wmsCarryH = itemsASC[i].wmsCarryH;
WmsCarryCode wmsCarryCode = itemsASC[i].wmsCarryCode;
if (input.needOut <= 0)
{
break;
}
// 查找是否有一个料箱可以正好满足剩余需求数量(目前只做这个额外判断,其它情形不考虑)
bool isFind = false;
for (int j = i + 1; j < itemsASC.Count; j++)
{
WmsCarryCode _wmsCarryCode = itemsASC[j].wmsCarryCode;
if (_wmsCarryCode.codeqty == input.needOut)
{
WmsCarryH _wmsCarryH = itemsASC[j].wmsCarryH;
BasLocation _endlocation_ssx = await _db.Queryable<BasLocation>().Where(r => new string[2] { "32609229889045", "32609238573589" }.Contains(r.id)).OrderBy("is_lock, task_nums, location_code").FirstAsync();
await _db.Updateable<BasLocation>().SetColumns(it => it.task_nums == it.task_nums + 1).Where(it => _endlocation_ssx.id == it.id).ExecuteCommandAsync();
carrys.Add(new Tuple<WmsCarryH, decimal, BasLocation>(_wmsCarryH, _wmsCarryCode.codeqty, _endlocation_ssx));
isFind = true;
break;
}
}
if (isFind)
break;
// 目前只支持一个料箱只有一个物料
input.needOut -= wmsCarryCode.codeqty;
BasLocation endlocation_ssx = await _db.Queryable<BasLocation>().Where(r => new string[2] { "32609229889045", "32609238573589" }.Contains(r.id)).OrderBy("is_lock, task_nums, location_code").FirstAsync();
await _db.Updateable<BasLocation>().SetColumns(it => it.task_nums == it.task_nums + 1).Where(it => endlocation_ssx.id == it.id).ExecuteCommandAsync();
carrys.Add(new Tuple<WmsCarryH, decimal, BasLocation>(wmsCarryH, wmsCarryCode.codeqty, endlocation_ssx));
}
#endregion
if (input.needOut > 0)
{
throw new AppFriendlyException($"物料{input.material_code}没有足够的库存!,缺失数量为{input.needOut}", 500);
}
return carrys;
}
/// <summary>
@@ -2982,6 +3038,8 @@ namespace Tnb.WarehouseMgr
{
Logger.LogInformation($"【CommonCreatePretask】 {ex.Message}");
Logger.LogInformation($"【CommonCreatePretask】 {ex.StackTrace}");
if (!db.Ado.Transaction.IsNull())
await db.Ado.CommitTranAsync();
return await ToApiResult(JNPF.Common.Enums.HttpStatusCode.InternalServerError, ex.Message);
}
finally