转库单原材料到中储仓转库、中储仓退回原材料转库
This commit is contained in:
@@ -429,11 +429,16 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
|
||||
{
|
||||
WmsCarryH? carry = db_Scantimer.Queryable<WmsCarryH>().Single(it => it.carry_code == coderesult);
|
||||
LoggerBGWCarrySupplement.LogInformation($"【ScanInStock】 八工位 {key} 查找{coderesult}绑定的托盘: {JsonConvert.SerializeObject(carry)}");
|
||||
//if (carry.location_id != "30773146852470")
|
||||
//{
|
||||
// LoggerBGWCarrySupplement.LogInformation($"【ScanInStock】 八工位 {key} 查找{coderesult}绑定的托盘{carry.carry_code}起始库位既不是空也不是拆盘机,此时不能生成入库任务(防止重复生成任务)");
|
||||
// continue;
|
||||
//}
|
||||
if (carry != null)
|
||||
{
|
||||
if (db_Scantimer.Queryable<WmsDistaskH>().Where(p => p.carry_id == carry.id && p.status != WmsWareHouseConst.TASK_BILL_STATUS_COMPLE_ID && p.status != WmsWareHouseConst.TASK_BILL_STATUS_CANCEL_ID).Any())
|
||||
{
|
||||
LoggerBGWCarrySupplement.LogInformation($"【ScanInStock】 八工位 {key} 托盘 {carry.carry_code} 找到了执行任务状态(status)既不是26126860808229(已完成)或26126863175461(已取消)的历史任务,此时不能执行入库");
|
||||
LoggerBGWCarrySupplement.LogInformation($"【ScanInStock】 八工位 {key} 托盘 {carry.carry_code} 找到了执行任务状态(status)既不是26126860808229(已完成)也不是26126863175461(已取消)的历史任务,此时不能执行入库");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
namespace Tnb.WarehouseMgr.Entities.Dto
|
||||
{
|
||||
/// <summary>
|
||||
/// 库房业务更新输入参数
|
||||
/// </summary>
|
||||
public class MaterialTransferDistributeSCWToYCLInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 组织ID
|
||||
/// </summary>
|
||||
public string org_id { get; set; }
|
||||
/// <summary>
|
||||
/// 创建用户
|
||||
/// </summary>
|
||||
public string create_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 来源单据id(转库单主表)
|
||||
/// </summary>
|
||||
public string? source_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 载具条码
|
||||
/// </summary>
|
||||
public string? carry_code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数量
|
||||
/// </summary>
|
||||
public decimal qty { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -13,5 +13,7 @@ namespace Tnb.WarehouseMgr.Interfaces
|
||||
Task<dynamic> CarryBind(VisualDevModelDataCrInput input);
|
||||
|
||||
Task<Result> CarryBind(CarryBindInput input, ISqlSugarClient dbConn = null);
|
||||
|
||||
Task CarryMaterialBind(CarryMaterialBindInput input, ISqlSugarClient dbConn = null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,14 +580,85 @@ 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;
|
||||
// 剩余分配数
|
||||
{
|
||||
decimal? needOut = input.needOut;
|
||||
int endlocation_index = 0;
|
||||
BasLocation endlocation_ssx = null;
|
||||
|
||||
for (int i = 0; i < itemsDESC.Count; i++)
|
||||
{
|
||||
WmsCarryH wmsCarryH = itemsDESC[i].wmsCarryH;
|
||||
WmsCarryCode wmsCarryCode = itemsDESC[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 < 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 (needOut > 0)
|
||||
{
|
||||
throw new AppFriendlyException($"物料{input.material_code}没有足够的库存!,缺失数量为{needOut}", 500);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
decimal? needOut = input.needOut;
|
||||
int endlocation_index = 0;
|
||||
BasLocation endlocation_ssx = null;
|
||||
|
||||
@@ -595,7 +667,7 @@ namespace Tnb.WarehouseMgr
|
||||
WmsCarryH wmsCarryH = itemsASC[i].wmsCarryH;
|
||||
WmsCarryCode wmsCarryCode = itemsASC[i].wmsCarryCode;
|
||||
|
||||
if (input.needOut <= 0)
|
||||
if (needOut <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -611,14 +683,14 @@ namespace Tnb.WarehouseMgr
|
||||
for (int j = i + 1; j < itemsASC.Count; j++)
|
||||
{
|
||||
WmsCarryCode _wmsCarryCode = itemsASC[j].wmsCarryCode;
|
||||
if (_wmsCarryCode.codeqty == input.needOut)
|
||||
if (_wmsCarryCode.codeqty == needOut)
|
||||
{
|
||||
input.needOut -= _wmsCarryCode.codeqty;
|
||||
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));
|
||||
carrysASC.Add(new Tuple<WmsCarryH, decimal, BasLocation>(_wmsCarryH, _wmsCarryCode.codeqty, endlocation_ssx));
|
||||
|
||||
isFind = true;
|
||||
break;
|
||||
@@ -629,21 +701,30 @@ namespace Tnb.WarehouseMgr
|
||||
break;
|
||||
|
||||
// 目前只支持一个料箱只有一个物料
|
||||
input.needOut -= wmsCarryCode.codeqty;
|
||||
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));
|
||||
carrysASC.Add(new Tuple<WmsCarryH, decimal, BasLocation>(wmsCarryH, wmsCarryCode.codeqty, endlocation_ssx));
|
||||
}
|
||||
#endregion
|
||||
|
||||
if (input.needOut > 0)
|
||||
if (needOut > 0)
|
||||
{
|
||||
throw new AppFriendlyException($"物料{input.material_code}没有足够的库存!,缺失数量为{input.needOut}", 500);
|
||||
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>
|
||||
|
||||
@@ -152,11 +152,14 @@ namespace Tnb.WarehouseMgr
|
||||
return result;
|
||||
}
|
||||
[HttpPost]
|
||||
public async Task CarryMaterialBind(CarryMaterialBindInput input)
|
||||
public async Task CarryMaterialBind(CarryMaterialBindInput input, ISqlSugarClient dbConn = null)
|
||||
{
|
||||
var db = _db;
|
||||
if (dbConn != null)
|
||||
db = dbConn;
|
||||
try
|
||||
{
|
||||
WmsCarryH? carry = await _db.Queryable<WmsCarryH>().SingleAsync(it => it.carry_code == input.carrycode);
|
||||
WmsCarryH? carry = await db.Queryable<WmsCarryH>().SingleAsync(it => it.carry_code == input.carrycode);
|
||||
List<WmsCarryCode> WmsCarryCodes = new List<WmsCarryCode>();
|
||||
foreach (var detail in input.details)
|
||||
{
|
||||
@@ -170,7 +173,7 @@ namespace Tnb.WarehouseMgr
|
||||
}
|
||||
int rows = 0;
|
||||
if (WmsCarryCodes.Count > 0)
|
||||
rows = await _db.Insertable(WmsCarryCodes).ExecuteCommandAsync();
|
||||
rows = await db.Insertable(WmsCarryCodes).ExecuteCommandAsync();
|
||||
if (rows == 0)
|
||||
{
|
||||
throw new Exception($"物料列表为空,不能提交绑定,可能的原因;1.需要检查扫码设置(新PDA) 2.未扫到有效的二维码 详细信息:接收到{input.details.Count}个条码 但是成功绑定的条码数量为0个!");
|
||||
|
||||
@@ -372,7 +372,6 @@ namespace Tnb.WarehouseMgr
|
||||
|
||||
foreach (var wmsCarryH in items)
|
||||
{
|
||||
WmsCarryCode wmsCarryCode = await _db.Queryable<WmsCarryCode>().Where(r => r.carry_id == wmsCarryH.id).FirstAsync();
|
||||
BasLocation startLocation = await _db.Queryable<BasLocation>().Where(r => r.id == wmsCarryH.location_id).FirstAsync();
|
||||
|
||||
BasLocation endLocation = null;
|
||||
@@ -523,6 +522,23 @@ namespace Tnb.WarehouseMgr
|
||||
throw new AppFriendlyException($@"生成预任务失败", 500);
|
||||
}
|
||||
|
||||
CarryMaterialBindInput carryMaterialBindInput = new CarryMaterialBindInput();
|
||||
carryMaterialBindInput.carrycode = wmsCarryHs[index].carry_code;
|
||||
carryMaterialBindInput.create_id = input.create_id;
|
||||
|
||||
List<CarryMaterialDetail> carryMaterialDetails = new List<CarryMaterialDetail>();
|
||||
CarryMaterialDetail carryMaterialDetail = new CarryMaterialDetail();
|
||||
carryMaterialDetail.material_id = wmsMaterialTransferD.material_id;
|
||||
carryMaterialDetail.material_code = wmsMaterialTransferD.material_code;
|
||||
carryMaterialDetail.codeqty = wmsCarryH.qty.ToString();
|
||||
carryMaterialDetail.code_batch = wmsMaterialTransferD.code_batch;
|
||||
carryMaterialDetail.barcode = wmsCarryHs[index].carry_code;
|
||||
carryMaterialDetail.unit_id = wmsMaterialTransferD.unit_id;
|
||||
carryMaterialDetails.Add(carryMaterialDetail);
|
||||
carryMaterialBindInput.details = carryMaterialDetails;
|
||||
await _wmsCarryBindService.CarryMaterialBind(carryMaterialBindInput, _db);
|
||||
await _db.Updateable<WmsCarryH>().SetColumns(r => r.carry_status == "1").Where(r => r.id == wmsCarryHs[index].id).ExecuteCommandAsync();
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
@@ -534,8 +550,8 @@ namespace Tnb.WarehouseMgr
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
Logger.LogError("【Distribute】" + ex.Message);
|
||||
Logger.LogError("【Distribute】" + ex.StackTrace);
|
||||
Logger.LogError("【DistributeYCLToZCC】" + ex.Message);
|
||||
Logger.LogError("【DistributeYCLToZCC】" + ex.StackTrace);
|
||||
return await ToApiResult(HttpStatusCode.InternalServerError, ex.Message);
|
||||
}
|
||||
finally
|
||||
@@ -580,7 +596,7 @@ namespace Tnb.WarehouseMgr
|
||||
WmsMaterialTransferD wmsMaterialTransferD = await _db.Queryable<WmsMaterialTransferD>().FirstAsync(it => it.id == input.source_id);
|
||||
WmsMaterialTransfer wmsMaterialTransfer = await _db.Queryable<WmsMaterialTransfer>().FirstAsync(it => it.id == wmsMaterialTransferD.bill_id);
|
||||
|
||||
if (wmsMaterialTransferD.yxfqty == wmsMaterialTransferD.qty)
|
||||
if (wmsMaterialTransferD.yxfqty >= wmsMaterialTransferD.qty)
|
||||
{
|
||||
throw new AppFriendlyException("已下发数量已达到转库数量", 500);
|
||||
}
|
||||
@@ -651,7 +667,6 @@ namespace Tnb.WarehouseMgr
|
||||
|
||||
foreach (var wmsCarryH in items)
|
||||
{
|
||||
WmsCarryCode wmsCarryCode = await _db.Queryable<WmsCarryCode>().Where(r => r.carry_id == wmsCarryH.id).FirstAsync();
|
||||
BasLocation startLocation = await _db.Queryable<BasLocation>().Where(r => r.id == wmsCarryH.location_id).FirstAsync();
|
||||
|
||||
CommonCreatePretaskInput commonCreatePretaskInput = new CommonCreatePretaskInput();
|
||||
@@ -787,7 +802,7 @@ namespace Tnb.WarehouseMgr
|
||||
WmsMaterialTransferD wmsMaterialTransferD = await _db.Queryable<WmsMaterialTransferD>().FirstAsync(it => it.id == input.source_id);
|
||||
WmsMaterialTransfer wmsMaterialTransfer = await _db.Queryable<WmsMaterialTransfer>().FirstAsync(it => it.id == wmsMaterialTransferD.bill_id);
|
||||
|
||||
if (wmsMaterialTransferD.yxfqty == wmsMaterialTransferD.qty)
|
||||
if (wmsMaterialTransferD.yxfqty >= wmsMaterialTransferD.qty)
|
||||
{
|
||||
throw new AppFriendlyException("已下发数量已达到转库数量", 500);
|
||||
}
|
||||
@@ -841,13 +856,12 @@ namespace Tnb.WarehouseMgr
|
||||
int index = 0;
|
||||
foreach (var wmsCarryH in items)
|
||||
{
|
||||
WmsCarryCode wmsCarryCode = await _db.Queryable<WmsCarryCode>().Where(r => r.carry_id == wmsCarryH.id).FirstAsync();
|
||||
BasLocation startLocation = await _db.Queryable<BasLocation>().Where(r => r.id == wmsCarryH.location_id).FirstAsync();
|
||||
|
||||
CommonCreatePretaskInput commonCreatePretaskInput = new CommonCreatePretaskInput();
|
||||
commonCreatePretaskInput.startlocation_id = startLocation.id;
|
||||
commonCreatePretaskInput.endlocation_id = endlocations[index].id;
|
||||
commonCreatePretaskInput.task_type = WmsWareHouseConst.WMS_PRETASK_TRANSFER_TYPE_ID;
|
||||
commonCreatePretaskInput.task_type = WmsWareHouseConst.WMS_PRETASK_INSTOCK_TYPE_ID;
|
||||
commonCreatePretaskInput.biz_type = WmsWareHouseConst.BIZTYPE_WMSMATERIALTRANSFER_ID;
|
||||
// 转库单id
|
||||
commonCreatePretaskInput.source_id = input.source_id;
|
||||
@@ -896,16 +910,23 @@ namespace Tnb.WarehouseMgr
|
||||
try
|
||||
{
|
||||
List<WmsCarryCode> wmsCarryCodes = await _db.Queryable<WmsCarryCode>().Where(r => r.carry_id == input.carryIds[0]).ToListAsync();
|
||||
if (wmsCarryCodes.Count == 0)
|
||||
{
|
||||
Logger.LogWarning($"【WmsMaterialTransferService ModifyAsync】载具{input.carryIds[0]}没有绑定物料条码");
|
||||
return;
|
||||
}
|
||||
//if (wmsCarryCodes.Count == 0)
|
||||
//{
|
||||
// Logger.LogWarning($"【WmsMaterialTransferService ModifyAsync】载具{input.carryIds[0]}没有绑定物料条码");
|
||||
// return;
|
||||
//}
|
||||
await _db.Ado.BeginTranAsync();
|
||||
|
||||
WmsMaterialTransferD wmsMaterialTransferd = await _db.Queryable<WmsMaterialTransferD>().Where(r => r.id == input.source_id).SingleAsync();
|
||||
WmsMaterialTransfer wmsMaterialTransfer = await _db.Queryable<WmsMaterialTransfer>().SingleAsync(x => x.id == wmsMaterialTransferd.bill_id);
|
||||
|
||||
bool isOk = false;
|
||||
// 入库回写入库数量字段
|
||||
if (input.wmsDistaskH.task_type == WmsWareHouseConst.WMS_PRETASK_INSTOCK_TYPE_ID)
|
||||
|
||||
#region 更新已转数量
|
||||
// 8线到中储仓入库或三工位退回原材料操作时回写数量
|
||||
if ((wmsMaterialTransfer.warehouse_outstock == WmsWareHouseConst.WAREHOUSE_YCL_ID && wmsMaterialTransfer.warehouse_instock == WmsWareHouseConst.WAREHOUSE_ZC_ID)
|
||||
|| (wmsMaterialTransfer.warehouse_outstock == WmsWareHouseConst.WAREHOUSE_ZC_ID && wmsMaterialTransfer.warehouse_instock == WmsWareHouseConst.WAREHOUSE_YCL_ID)
|
||||
&& input.wmsDistaskH.task_type == WmsWareHouseConst.WMS_PRETASK_INSTOCK_TYPE_ID)
|
||||
{
|
||||
// 更新已转数量(入库)
|
||||
isOk = await _db.Updateable<WmsMaterialTransferD>().SetColumns(it => new WmsMaterialTransferD { yzqty_rk = it.yzqty_rk + wmsCarryCodes.Sum(r => r.codeqty) })
|
||||
@@ -913,21 +934,55 @@ namespace Tnb.WarehouseMgr
|
||||
}
|
||||
else
|
||||
{
|
||||
// 中储仓到8线后自动解绑物料
|
||||
if ((wmsMaterialTransfer.warehouse_outstock == WmsWareHouseConst.WAREHOUSE_ZC_ID && wmsMaterialTransfer.warehouse_instock == WmsWareHouseConst.WAREHOUSE_YCL_ID)
|
||||
&& input.wmsDistaskH.task_type == WmsWareHouseConst.WMS_PRETASK_TRANSFER_TYPE_ID)
|
||||
{
|
||||
CarryCodeUnbindInput carryCodeUnbindInput = new();
|
||||
carryCodeUnbindInput.carry_id = input.wmsDistaskH.carry_id;
|
||||
var resCarryUnbind = await _wmsCarryUnbindService.CarryCodeUnbind(carryCodeUnbindInput, _db);
|
||||
if (resCarryUnbind.code != JNPF.Common.Enums.HttpStatusCode.OK)
|
||||
{
|
||||
throw new AppFriendlyException($"载具{input.wmsDistaskH.carry_code}解绑条码", 500);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新已转数量
|
||||
isOk = await _db.Updateable<WmsMaterialTransferD>().SetColumns(it => new WmsMaterialTransferD { yzqty = it.yzqty + wmsCarryCodes.Sum(r => r.codeqty) })
|
||||
.Where(it => it.id == input.source_id).ExecuteCommandHasChangeAsync();
|
||||
}
|
||||
#endregion
|
||||
|
||||
// 如果所有明细已完成 更新主表状态为完成
|
||||
WmsMaterialTransferD wmsMaterialTransferd = await _db.Queryable<WmsMaterialTransferD>().Where(r => r.id == input.source_id).SingleAsync();
|
||||
List<WmsMaterialTransferD> wmsMaterialTransferDs = _db.Queryable<WmsMaterialTransferD>()
|
||||
.Where(a => a.bill_id == wmsMaterialTransferd.bill_id && a.yzqty < a.qty).ToList();
|
||||
#region 如果所有明细已完成 更新主表状态为完成
|
||||
bool isOk2 = true;
|
||||
// 原材料到中储仓入库操作时回写状态
|
||||
if ((wmsMaterialTransfer.warehouse_outstock == WmsWareHouseConst.WAREHOUSE_YCL_ID && wmsMaterialTransfer.warehouse_instock == WmsWareHouseConst.WAREHOUSE_ZC_ID)
|
||||
|| (wmsMaterialTransfer.warehouse_outstock == WmsWareHouseConst.WAREHOUSE_ZC_ID && wmsMaterialTransfer.warehouse_instock == WmsWareHouseConst.WAREHOUSE_YCL_ID))
|
||||
{
|
||||
if (input.wmsDistaskH.task_type == WmsWareHouseConst.WMS_PRETASK_INSTOCK_TYPE_ID)
|
||||
{
|
||||
List<WmsMaterialTransferD> wmsMaterialTransferDs = _db.Queryable<WmsMaterialTransferD>()
|
||||
.Where(a => a.bill_id == wmsMaterialTransferd.bill_id && a.yxfqty_rk < a.yzqty_rk).ToList();
|
||||
if (wmsMaterialTransferDs.Count == 0)
|
||||
{
|
||||
isOk2 = await _db.Updateable<WmsMaterialTransfer>().SetColumns(it => new WmsMaterialTransfer { status = WmsWareHouseConst.BILLSTATUS_COMPLETE_ID })
|
||||
.Where(it => it.id == wmsMaterialTransferd.bill_id).ExecuteCommandHasChangeAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
List<WmsMaterialTransferD> wmsMaterialTransferDs = _db.Queryable<WmsMaterialTransferD>()
|
||||
.Where(a => a.bill_id == wmsMaterialTransferd.bill_id && a.yzqty < a.qty).ToList();
|
||||
if (wmsMaterialTransferDs.Count == 0)
|
||||
{
|
||||
isOk2 = await _db.Updateable<WmsMaterialTransfer>().SetColumns(it => new WmsMaterialTransfer { status = WmsWareHouseConst.BILLSTATUS_COMPLETE_ID })
|
||||
.Where(it => it.id == wmsMaterialTransferd.bill_id).ExecuteCommandHasChangeAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
// require_code是任务单
|
||||
//string mo_task_code = input.require_code;
|
||||
@@ -955,7 +1010,6 @@ namespace Tnb.WarehouseMgr
|
||||
{
|
||||
Logger.LogInformation("【WmsMaterialTransferService ModifyAsync】同步其它出库单到erp...");
|
||||
|
||||
WmsMaterialTransfer wmsMaterialTransfer = await _db.Queryable<WmsMaterialTransfer>().SingleAsync(x => x.id == wmsMaterialTransferd.bill_id);
|
||||
List<WmsMaterialTransferD> dList = await _db.Queryable<WmsMaterialTransferD>().Where(x => x.bill_id == wmsMaterialTransferd.bill_id).OrderBy(x => x.id).ToListAsync();
|
||||
DictionaryDataEntity unitData = await _db.Queryable<DictionaryTypeEntity>()
|
||||
.LeftJoin<DictionaryDataEntity>((x, y) => x.Id == y.DictionaryTypeId)
|
||||
@@ -1325,7 +1379,145 @@ namespace Tnb.WarehouseMgr
|
||||
return await ToApiResult(HttpStatusCode.OK, "成功");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 三工位入库到原材料仓
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="AppFriendlyException"></exception>
|
||||
[HttpPost, NonUnify, AllowAnonymous]
|
||||
public async Task<Entities.Dto.Outputs.Result> DistributeSCWToYCL(MaterialTransferDistributeSCWToYCLInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(input.source_id))
|
||||
{
|
||||
throw new AppFriendlyException("来源单据id不可为空", 500);
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(input.carry_code))
|
||||
{
|
||||
throw new AppFriendlyException("载具不可为空", 500);
|
||||
}
|
||||
|
||||
if (input.qty <= 0)
|
||||
{
|
||||
throw new AppFriendlyException("数量必须大于0", 500);
|
||||
}
|
||||
|
||||
WmsMaterialTransferD wmsMaterialTransferD = await _db.Queryable<WmsMaterialTransferD>().FirstAsync(it => it.id == input.source_id);
|
||||
if (wmsMaterialTransferD == null)
|
||||
{
|
||||
Logger.LogWarning($"不存在id为{input.source_id}的转库单明细!");
|
||||
throw new AppFriendlyException($"不存在id为{input.source_id}的转库单明细!", 500);
|
||||
}
|
||||
|
||||
if (wmsMaterialTransferD.yxfqty_rk >= wmsMaterialTransferD.yzqty)
|
||||
{
|
||||
throw new AppFriendlyException("已下发数量已达到中储仓的转出数量", 500);
|
||||
}
|
||||
|
||||
WmsCarryH wmsCarryH = await _db.Queryable<WmsCarryH>().FirstAsync(it => it.carry_code == input.carry_code);
|
||||
if (wmsCarryH == null)
|
||||
{
|
||||
Logger.LogWarning($"不存在编码为{input.carry_code}的载具!");
|
||||
throw new AppFriendlyException($"不存在编码为{input.carry_code}的载具!", 500);
|
||||
}
|
||||
if (wmsCarryH.carry_status != "0")
|
||||
{
|
||||
Logger.LogWarning($"载具{input.carry_code}状态为占用!");
|
||||
throw new AppFriendlyException($"载具{input.carry_code}状态为占用!", 500);
|
||||
}
|
||||
if (wmsCarryH.is_lock == 1)
|
||||
{
|
||||
Logger.LogWarning($"载具{input.carry_code}已锁定!");
|
||||
throw new AppFriendlyException($"载具{input.carry_code}已锁定!", 500);
|
||||
}
|
||||
if (string.IsNullOrEmpty(wmsCarryH.location_id))
|
||||
{
|
||||
Logger.LogWarning($"载具{input.carry_code}的库位为空!");
|
||||
throw new AppFriendlyException($"载具{input.carry_code}的库位为空!", 500);
|
||||
}
|
||||
if (!_wareHouseService.GetFloor1WXSGWOutstockLocation().Contains(wmsCarryH.location_id))
|
||||
{
|
||||
Logger.LogWarning($"载具{input.carry_code}当前所在库位不是三工位!");
|
||||
throw new AppFriendlyException($"载具{input.carry_code}当前所在库位不是三工位!", 500);
|
||||
}
|
||||
|
||||
await s_taskExecuteSemaphore.WaitAsync();
|
||||
await _db.Ado.BeginTranAsync();
|
||||
|
||||
|
||||
InStockStrategyQuery inStockStrategyInput = new()
|
||||
{
|
||||
warehouse_id = WmsWareHouseConst.WAREHOUSE_YCL_ID,
|
||||
Size = 1
|
||||
};
|
||||
List<BasLocation> endlocations = await _wareHouseService.InStockStrategy(inStockStrategyInput);
|
||||
|
||||
if (endlocations.Count < 1)
|
||||
{
|
||||
throw new AppFriendlyException($@"没有可以入库的库位", 500);
|
||||
}
|
||||
|
||||
BasLocation startLocation = await _db.Queryable<BasLocation>().Where(r => r.id == wmsCarryH.location_id).FirstAsync();
|
||||
|
||||
CommonCreatePretaskInput commonCreatePretaskInput = new CommonCreatePretaskInput();
|
||||
commonCreatePretaskInput.startlocation_id = startLocation.id;
|
||||
commonCreatePretaskInput.endlocation_id = endlocations[0].id;
|
||||
commonCreatePretaskInput.task_type = WmsWareHouseConst.WMS_PRETASK_INSTOCK_TYPE_ID;
|
||||
commonCreatePretaskInput.biz_type = WmsWareHouseConst.BIZTYPE_WMSMATERIALTRANSFER_ID;
|
||||
// 转库单id
|
||||
commonCreatePretaskInput.source_id = input.source_id;
|
||||
commonCreatePretaskInput.carry_id = wmsCarryH.id;
|
||||
commonCreatePretaskInput.carry_code = wmsCarryH.carry_code;
|
||||
commonCreatePretaskInput.isExcuteMission = false;
|
||||
|
||||
Entities.Dto.Outputs.Result res = await _wareHouseService.CommonCreatePretask(commonCreatePretaskInput);
|
||||
|
||||
if (res.code != HttpStatusCode.OK)
|
||||
{
|
||||
Logger.LogInformation($@"生成预任务失败");
|
||||
throw new AppFriendlyException($@"生成预任务失败", 500);
|
||||
}
|
||||
|
||||
CarryMaterialBindInput carryMaterialBindInput = new CarryMaterialBindInput();
|
||||
carryMaterialBindInput.carrycode = wmsCarryH.carry_code;
|
||||
carryMaterialBindInput.create_id = input.create_id;
|
||||
|
||||
List<CarryMaterialDetail> carryMaterialDetails = new List<CarryMaterialDetail>();
|
||||
CarryMaterialDetail carryMaterialDetail = new CarryMaterialDetail();
|
||||
carryMaterialDetail.material_id = wmsMaterialTransferD.material_id;
|
||||
carryMaterialDetail.material_code = wmsMaterialTransferD.material_code;
|
||||
carryMaterialDetail.codeqty = input.qty.ToString();
|
||||
carryMaterialDetail.code_batch = wmsMaterialTransferD.code_batch;
|
||||
carryMaterialDetail.barcode = wmsCarryH.carry_code;
|
||||
carryMaterialDetail.unit_id = wmsMaterialTransferD.unit_id;
|
||||
carryMaterialDetails.Add(carryMaterialDetail);
|
||||
carryMaterialBindInput.details = carryMaterialDetails;
|
||||
await _wmsCarryBindService.CarryMaterialBind(carryMaterialBindInput, _db);
|
||||
await _db.Updateable<WmsCarryH>().SetColumns(r => r.carry_status == "1").Where(r => r.id == wmsCarryH.id).ExecuteCommandAsync();
|
||||
|
||||
// 更新子表已下发数量
|
||||
await _db.Updateable<WmsMaterialTransferD>().SetColumns(r => r.yxfqty_rk == r.yxfqty_rk + input.qty).Where(r => r.id == input.source_id).ExecuteCommandAsync();
|
||||
|
||||
await _db.Ado.CommitTranAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
Logger.LogError("【DistributeSCWToYCL】" + ex.Message);
|
||||
Logger.LogError("【DistributeSCWToYCL】" + ex.StackTrace);
|
||||
return await ToApiResult(HttpStatusCode.InternalServerError, ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_ = s_taskExecuteSemaphore.Release();
|
||||
InvokeGenPretaskExcute();
|
||||
}
|
||||
|
||||
return await ToApiResult(HttpStatusCode.OK, "成功");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从暂存仓呼叫料架到产线
|
||||
|
||||
@@ -253,7 +253,6 @@ namespace Tnb.WarehouseMgr
|
||||
commonCreatePretaskInput2.task_type = WmsWareHouseConst.WMS_PRETASK_INSTOCK_TYPE_ID;
|
||||
commonCreatePretaskInput2.biz_type = WmsWareHouseConst.BIZTYPE_WMSPRDINSTOCK_ID;
|
||||
commonCreatePretaskInput2.require_id = wmsPrdInstockD.id;
|
||||
commonCreatePretaskInput2.isChangeCarryLoc2StartLoc = false;
|
||||
|
||||
Entities.Dto.Outputs.Result res2 = await _wareHouseService.CommonCreatePretask(commonCreatePretaskInput2, db);
|
||||
if (res2.code != HttpStatusCode.OK)
|
||||
|
||||
Reference in New Issue
Block a user