转库单原材料到中储仓转库、中储仓退回原材料转库
This commit is contained in:
@@ -545,16 +545,16 @@ namespace Tnb.WarehouseMgr
|
||||
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)
|
||||
.And((a, b, c) => !string.IsNullOrEmpty(a.location_id))
|
||||
.And((a, b, c) => c.is_type == ((int)EnumLocationType.存储库位).ToString())
|
||||
.And((a, b, c) => a.out_status == "0")
|
||||
.And((a, b, c) => c.wh_id == input.warehouse_id)
|
||||
.AndIF(!string.IsNullOrEmpty(input.material_id), (a, b, c) => b.material_id == input.material_id)
|
||||
.AndIF(!string.IsNullOrEmpty(input.code_batch), (a, b, c) => b.code_batch == input.code_batch)
|
||||
.AndIF(!string.IsNullOrEmpty(input.material_specification), (a, b, c) => b.material_specification == input.material_specification)
|
||||
.AndIF(!string.IsNullOrEmpty(input.container_no), (a, b, c) => b.container_no == input.container_no)
|
||||
.AndIF(!string.IsNullOrEmpty(input.carrystd_id), (a, b, c) => a.carrystd_id == input.carrystd_id);
|
||||
.And((a, b, c) => a.is_lock == 0 && c.is_lock == 0)
|
||||
.And((a, b, c) => !string.IsNullOrEmpty(a.location_id))
|
||||
.And((a, b, c) => c.is_type == ((int)EnumLocationType.存储库位).ToString())
|
||||
.And((a, b, c) => a.out_status == "0")
|
||||
.And((a, b, c) => c.wh_id == input.warehouse_id)
|
||||
.AndIF(!string.IsNullOrEmpty(input.material_id), (a, b, c) => b.material_id == input.material_id)
|
||||
.AndIF(!string.IsNullOrEmpty(input.code_batch), (a, b, c) => b.code_batch == input.code_batch)
|
||||
.AndIF(!string.IsNullOrEmpty(input.material_specification), (a, b, c) => b.material_specification == input.material_specification)
|
||||
.AndIF(!string.IsNullOrEmpty(input.container_no), (a, b, c) => b.container_no == input.container_no)
|
||||
.AndIF(!string.IsNullOrEmpty(input.carrystd_id), (a, b, c) => a.carrystd_id == input.carrystd_id);
|
||||
Expression<Func<WmsCarryH, WmsCarryCode, BasLocation, bool>> carryStatusFilterExp = !input.material_id.IsNullOrWhiteSpace()
|
||||
? (a, b, c) => a.carry_status == ((int)EnumCarryStatus.占用).ToString()
|
||||
: (a, b, c) => a.carry_status == ((int)EnumCarryStatus.空闲).ToString();
|
||||
@@ -570,7 +570,8 @@ namespace Tnb.WarehouseMgr
|
||||
|
||||
#region 只解决少数情况(比如只有60 59 60 60四个料箱,下发180,要取60 60 60) 其它情况不考虑
|
||||
|
||||
var itemsASC = await cyDb.Queryable<WmsCarryH>().LeftJoin<WmsCarryCode>((a, b) => a.id == b.carry_id)
|
||||
List<Tuple<WmsCarryH, decimal, BasLocation>>? carrysDESC = new List<Tuple<WmsCarryH, decimal, BasLocation>>();
|
||||
var itemsDESC = 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())
|
||||
@@ -579,71 +580,151 @@ namespace Tnb.WarehouseMgr
|
||||
|
||||
.Select((a, b) => new { wmsCarryH = a, wmsCarryCode = b })
|
||||
.ToListAsync();
|
||||
//items = itemsASC.Count < itemsDESC.Count ? itemsASC : itemsDESC;
|
||||
|
||||
itemsDESC = itemsDESC.Distinct().ToList();
|
||||
|
||||
// 数量正序
|
||||
List<Tuple<WmsCarryH, decimal, BasLocation>>? carrysASC = new List<Tuple<WmsCarryH, decimal, BasLocation>>();
|
||||
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("codeqty asc,a.location_code,layers,loc_line,loc_column")
|
||||
|
||||
.Select((a, b) => new { wmsCarryH = a, wmsCarryCode = b })
|
||||
.ToListAsync();
|
||||
|
||||
itemsASC = itemsASC.Distinct().ToList();
|
||||
|
||||
List<Tuple<WmsCarryH, decimal, BasLocation>>? carrys = new List<Tuple<WmsCarryH, decimal, BasLocation>>();
|
||||
|
||||
// 6个下发一条任务链
|
||||
int move_num = 6;
|
||||
int endlocation_index = 0;
|
||||
BasLocation endlocation_ssx = null;
|
||||
|
||||
for (int i = 0; i < itemsASC.Count; i++)
|
||||
// 剩余分配数
|
||||
{
|
||||
WmsCarryH wmsCarryH = itemsASC[i].wmsCarryH;
|
||||
WmsCarryCode wmsCarryCode = itemsASC[i].wmsCarryCode;
|
||||
decimal? needOut = input.needOut;
|
||||
int endlocation_index = 0;
|
||||
BasLocation endlocation_ssx = null;
|
||||
|
||||
if (input.needOut <= 0)
|
||||
for (int i = 0; i < itemsDESC.Count; i++)
|
||||
{
|
||||
break;
|
||||
}
|
||||
WmsCarryH wmsCarryH = itemsDESC[i].wmsCarryH;
|
||||
WmsCarryCode wmsCarryCode = itemsDESC[i].wmsCarryCode;
|
||||
|
||||
// 每6个重新获取一次终点
|
||||
if (i % move_num == 0)
|
||||
{
|
||||
endlocation_ssx = await _db.Queryable<BasLocation>().Where(r => input.endlocations.Contains(r.id)).OrderBy("is_lock, task_nums, location_code").FirstAsync();
|
||||
}
|
||||
|
||||
// 查找是否有一个料箱可以正好满足剩余需求数量(目前只做这个额外判断,其它情形不考虑)
|
||||
bool isFind = false;
|
||||
for (int j = i + 1; j < itemsASC.Count; j++)
|
||||
{
|
||||
WmsCarryCode _wmsCarryCode = itemsASC[j].wmsCarryCode;
|
||||
if (_wmsCarryCode.codeqty == input.needOut)
|
||||
if (needOut <= 0)
|
||||
{
|
||||
input.needOut -= _wmsCarryCode.codeqty;
|
||||
WmsCarryH _wmsCarryH = itemsASC[j].wmsCarryH;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// 每6个重新获取一次终点
|
||||
if (i % move_num == 0)
|
||||
{
|
||||
endlocation_ssx = await _db.Queryable<BasLocation>().Where(r => input.endlocations.Contains(r.id)).OrderBy("is_lock, task_nums, location_code").FirstAsync();
|
||||
}
|
||||
|
||||
// 查找是否有一个料箱可以正好满足剩余需求数量(目前只做这个额外判断,其它情形不考虑)
|
||||
bool isFind = false;
|
||||
for (int j = i + 1; j < itemsDESC.Count; j++)
|
||||
{
|
||||
WmsCarryCode _wmsCarryCode = itemsDESC[j].wmsCarryCode;
|
||||
if (_wmsCarryCode.codeqty == needOut)
|
||||
{
|
||||
needOut -= _wmsCarryCode.codeqty;
|
||||
WmsCarryH _wmsCarryH = itemsDESC[j].wmsCarryH;
|
||||
|
||||
await _db.Updateable<BasLocation>().SetColumns(it => it.task_nums == it.task_nums + 1).Where(it => endlocation_ssx.id == it.id).ExecuteCommandAsync();
|
||||
|
||||
carrysDESC.Add(new Tuple<WmsCarryH, decimal, BasLocation>(_wmsCarryH, _wmsCarryCode.codeqty, endlocation_ssx));
|
||||
|
||||
isFind = true;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
if (isFind)
|
||||
break;
|
||||
|
||||
// 目前只支持一个料箱只有一个物料
|
||||
needOut -= wmsCarryCode.codeqty;
|
||||
|
||||
await _db.Updateable<BasLocation>().SetColumns(it => it.task_nums == it.task_nums + 1).Where(it => endlocation_ssx.id == it.id).ExecuteCommandAsync();
|
||||
|
||||
carrysDESC.Add(new Tuple<WmsCarryH, decimal, BasLocation>(wmsCarryH, wmsCarryCode.codeqty, endlocation_ssx));
|
||||
}
|
||||
if (isFind)
|
||||
break;
|
||||
|
||||
// 目前只支持一个料箱只有一个物料
|
||||
input.needOut -= wmsCarryCode.codeqty;
|
||||
|
||||
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));
|
||||
if (needOut > 0)
|
||||
{
|
||||
throw new AppFriendlyException($"物料{input.material_code}没有足够的库存!,缺失数量为{needOut}", 500);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
if (input.needOut > 0)
|
||||
{
|
||||
throw new AppFriendlyException($"物料{input.material_code}没有足够的库存!,缺失数量为{input.needOut}", 500);
|
||||
decimal? needOut = input.needOut;
|
||||
int endlocation_index = 0;
|
||||
BasLocation endlocation_ssx = null;
|
||||
|
||||
for (int i = 0; i < itemsASC.Count; i++)
|
||||
{
|
||||
WmsCarryH wmsCarryH = itemsASC[i].wmsCarryH;
|
||||
WmsCarryCode wmsCarryCode = itemsASC[i].wmsCarryCode;
|
||||
|
||||
if (needOut <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// 每6个重新获取一次终点
|
||||
if (i % move_num == 0)
|
||||
{
|
||||
endlocation_ssx = await _db.Queryable<BasLocation>().Where(r => input.endlocations.Contains(r.id)).OrderBy("is_lock, task_nums, location_code").FirstAsync();
|
||||
}
|
||||
|
||||
// 查找是否有一个料箱可以正好满足剩余需求数量(目前只做这个额外判断,其它情形不考虑)
|
||||
bool isFind = false;
|
||||
for (int j = i + 1; j < itemsASC.Count; j++)
|
||||
{
|
||||
WmsCarryCode _wmsCarryCode = itemsASC[j].wmsCarryCode;
|
||||
if (_wmsCarryCode.codeqty == needOut)
|
||||
{
|
||||
needOut -= _wmsCarryCode.codeqty;
|
||||
WmsCarryH _wmsCarryH = itemsASC[j].wmsCarryH;
|
||||
|
||||
await _db.Updateable<BasLocation>().SetColumns(it => it.task_nums == it.task_nums + 1).Where(it => endlocation_ssx.id == it.id).ExecuteCommandAsync();
|
||||
|
||||
carrysASC.Add(new Tuple<WmsCarryH, decimal, BasLocation>(_wmsCarryH, _wmsCarryCode.codeqty, endlocation_ssx));
|
||||
|
||||
isFind = true;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
if (isFind)
|
||||
break;
|
||||
|
||||
// 目前只支持一个料箱只有一个物料
|
||||
needOut -= wmsCarryCode.codeqty;
|
||||
|
||||
await _db.Updateable<BasLocation>().SetColumns(it => it.task_nums == it.task_nums + 1).Where(it => endlocation_ssx.id == it.id).ExecuteCommandAsync();
|
||||
|
||||
carrysASC.Add(new Tuple<WmsCarryH, decimal, BasLocation>(wmsCarryH, wmsCarryCode.codeqty, endlocation_ssx));
|
||||
}
|
||||
|
||||
if (needOut > 0)
|
||||
{
|
||||
throw new AppFriendlyException($"物料{input.material_code}没有足够的库存!,缺失数量为{needOut}", 500);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
List<Tuple<WmsCarryH, decimal, BasLocation>>? carrys = new List<Tuple<WmsCarryH, decimal, BasLocation>>();
|
||||
|
||||
return carrys;
|
||||
if (carrysDESC.Count == carrysASC.Count)
|
||||
{
|
||||
return carrysDESC.Sum(r => r.Item2) <= carrysASC.Sum(r => r.Item2) ? carrysDESC : carrysASC;
|
||||
}
|
||||
else
|
||||
{
|
||||
return carrysDESC.Count <= carrysASC.Count ? carrysDESC : carrysASC;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user