一楼中储仓下发二楼出库策略优化,bug
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
namespace Tnb.WarehouseMgr.Entities.Dto
|
||||
{
|
||||
public class OutStockStrategyZCC2Floor2Query
|
||||
{
|
||||
/// <summary>
|
||||
/// 仓库Id
|
||||
/// </summary>
|
||||
public string warehouse_id { get; set; }
|
||||
/// <summary>
|
||||
/// 载具Id
|
||||
/// </summary>
|
||||
public string carry_id { get; set; }
|
||||
/// <summary>
|
||||
/// 载具规格Id
|
||||
/// </summary>
|
||||
public string carrystd_id { get; set; }
|
||||
/// <summary>
|
||||
/// 物料Id
|
||||
/// </summary>
|
||||
public string material_id { get; set; }
|
||||
/// <summary>
|
||||
/// 批次
|
||||
/// </summary>
|
||||
public string code_batch { get; set; }
|
||||
/// <summary>
|
||||
/// 业务类型s
|
||||
/// </summary>
|
||||
public int BllType { get; set; }
|
||||
|
||||
public int Size { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数量
|
||||
/// </summary>
|
||||
public decimal qty { get; set; }
|
||||
/// <summary>
|
||||
/// 规格型号
|
||||
/// </summary>
|
||||
public string? material_specification { get; set; }
|
||||
/// <summary>
|
||||
/// 箱号
|
||||
/// </summary>
|
||||
public string? container_no { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public decimal? needOut { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string? material_code { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ namespace Tnb.WarehouseMgr.Interfaces
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="AppFriendlyException"></exception>
|
||||
Task<List<WmsCarryH>> OutStockStrategyZCC2Floor2([FromQuery] OutStockStrategyQuery input);
|
||||
Task<List<Tuple<WmsCarryH, decimal, BasLocation>>> OutStockStrategyZCC2Floor2([FromQuery] OutStockStrategyZCC2Floor2Query input);
|
||||
|
||||
/// <summary>
|
||||
/// 出库策略-销售出库下发
|
||||
|
||||
@@ -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 60四个料箱,下发180,要取60 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
|
||||
|
||||
@@ -142,14 +142,6 @@ namespace Tnb.WarehouseMgr
|
||||
WmsCarryH? carry = await _db.Queryable<WmsCarryH>().SingleAsync(it => it.id == input.carry_id);
|
||||
if (carry != null)
|
||||
{
|
||||
int row = await _db.Deleteable<WmsCarryD>().Where(r => r.carry_id == input.carry_id).ExecuteCommandAsync();
|
||||
isOk = row > 0;
|
||||
|
||||
if (!isOk)
|
||||
{
|
||||
throw new Exception($"料架id{input.carry_id}载具解绑失败");
|
||||
}
|
||||
|
||||
|
||||
// 插入子载具绑定记录
|
||||
//VisualDevModelDataCrInput visualDevModelCrInput = new() { data = new Dictionary<string, object>() };
|
||||
@@ -167,6 +159,17 @@ namespace Tnb.WarehouseMgr
|
||||
//VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleConsts.MODULE_WMSCARRYUNBIND_ID, true);
|
||||
//await _runService.Create(templateEntity, visualDevModelCrInput);
|
||||
|
||||
|
||||
int row = await _db.Deleteable<WmsCarryD>().Where(r => r.carry_id == input.carry_id).ExecuteCommandAsync();
|
||||
//isOk = row > 0;
|
||||
|
||||
//if (!isOk)
|
||||
//{
|
||||
// throw new Exception($"料架id{input.carry_id}载具解绑失败");
|
||||
//}
|
||||
Logger.LogInformation($"【CarryUnbind】料架{carry.carry_code}已解绑,解绑条数{row}");
|
||||
|
||||
|
||||
await _db.Ado.CommitTranAsync();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -651,37 +651,27 @@ namespace Tnb.WarehouseMgr
|
||||
|
||||
foreach (WmsMaterialTransferD wmsMaterialTransferD in wmsMaterialTransferds)
|
||||
{
|
||||
//出库取起点,获取所有符合输入的载具规格的载具
|
||||
OutStockStrategyQuery OutStockStrategyInput = new()
|
||||
{
|
||||
warehouse_id = "2",
|
||||
material_id = wmsMaterialTransferD.material_id,
|
||||
code_batch = wmsMaterialTransferD.code_batch
|
||||
};
|
||||
List<WmsCarryH>? carrys = await _wareHouseService.OutStockStrategyZCC2Floor2(OutStockStrategyInput);
|
||||
|
||||
// 需要转库数量
|
||||
decimal? needOut = wmsMaterialTransferD.qty;
|
||||
|
||||
foreach (WmsCarryH wmsCarryH in carrys)
|
||||
//出库取起点,获取所有符合输入的载具规格的载具
|
||||
OutStockStrategyZCC2Floor2Query OutStockStrategyInput = new()
|
||||
{
|
||||
if (needOut <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
warehouse_id = "2",
|
||||
material_id = wmsMaterialTransferD.material_id,
|
||||
code_batch = wmsMaterialTransferD.code_batch,
|
||||
needOut = needOut,
|
||||
material_code = wmsMaterialTransferD.material_code
|
||||
|
||||
List<WmsCarryCode> wmsCarryCodes = _db.Queryable<WmsCarryCode>().Where(r => r.carry_id == wmsCarryH.id).ToList();
|
||||
};
|
||||
List<Tuple<WmsCarryH, decimal, BasLocation>>? carrys = await _wareHouseService.OutStockStrategyZCC2Floor2(OutStockStrategyInput);
|
||||
|
||||
WmsCarryCode wmsCarryCode = wmsCarryCodes.First();
|
||||
|
||||
// 目前只支持一个料箱只有一个物料
|
||||
foreach (WmsCarryCode _wmsCarryCode in wmsCarryCodes)
|
||||
{
|
||||
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();
|
||||
foreach (var item in carrys)
|
||||
{
|
||||
WmsCarryH wmsCarryH = item.Item1;
|
||||
decimal codeqty = item.Item2;
|
||||
BasLocation endlocation_ssx = item.Item3;
|
||||
|
||||
// 转库单载具子表
|
||||
WmsMaterialTransferCarry wmsMaterialTransferCarry = new WmsMaterialTransferCarry();
|
||||
@@ -695,14 +685,9 @@ namespace Tnb.WarehouseMgr
|
||||
wmsMaterialTransferCarry.startlocation_id = wmsCarryH.location_id;
|
||||
wmsMaterialTransferCarry.startlocation_code = wmsCarryH.location_code;
|
||||
wmsMaterialTransferCarry.mat_bill_id = wmsMaterialTransferD.id;
|
||||
wmsMaterialTransferCarry.qty = wmsCarryCode.codeqty;
|
||||
wmsMaterialTransferCarry.qty = codeqty;
|
||||
wmsMaterialTransferCarrys.Add(wmsMaterialTransferCarry);
|
||||
}
|
||||
|
||||
if (needOut > 0)
|
||||
{
|
||||
throw new AppFriendlyException($"物料{wmsMaterialTransferD.material_code}没有足够的库存!,缺失数量为{needOut}", 500);
|
||||
}
|
||||
}
|
||||
|
||||
await _db.Ado.BeginTranAsync();
|
||||
|
||||
Reference in New Issue
Block a user