using logtxtWrite;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using wcftest.EnumDefine;
|
using wcftest.orm;
|
|
namespace wcftest.BussinessExtension.Handle
|
{
|
/// <summary>
|
/// 寻找空库位的帮助类
|
/// </summary>
|
public class FindEmptyLocationHandler
|
{
|
/// <summary>
|
/// 获取预留库位数
|
/// </summary>
|
/// <param name="areaCode"></param>
|
/// <param name="position"></param>
|
/// <param name="containerType"></param>
|
/// <param name="restrictNumber"></param>
|
public static void GetRestrictNumber(int areaCode, Base_Position position, int containerType, ref int restrictNumber)
|
{
|
if (position == null)
|
{
|
return;
|
}
|
bool isNeedRestrictNumber = false;//是否需要预留库位给空托盘
|
//小托盘
|
//restrictNumber = restrictNumber == 1 ? 2 : 0;//需要给空托盘留3个库位的信号
|
//restrict.Add(" and (RowCode=1 or RowCode=11 )");
|
int i_rowCode = Convert.ToInt32(position.RowCode);
|
int i_columnCode = Convert.ToInt32(position.ColumnCode);
|
if (areaCode == 1)
|
{//库区1
|
if (i_rowCode == 1 || i_rowCode == 11)
|
{
|
isNeedRestrictNumber = true;
|
}
|
}
|
|
//大托盘
|
//restrictNumber = restrictNumber == 1 ? 2 : 0;//需要给空托盘留3个库位的信号
|
//restrict.Add(" and (ColumnCode<2 or ColumnCode>9) and (RowCode=1 or RowCode=13 or RowCode=14 )");
|
if (areaCode == 2 && containerType == 2)
|
{
|
if ((i_rowCode == 1 || i_rowCode == 13 || i_rowCode == 14) && (i_columnCode < 2 || i_columnCode > 9))
|
{
|
isNeedRestrictNumber = true;
|
}
|
}
|
|
//处理
|
if (isNeedRestrictNumber)
|
{
|
restrictNumber = restrictNumber == 1 ? 2 : 0;//需要给空托盘留3个库位的信号
|
}
|
}
|
|
#region 分配库位(重要!!!!!!!)
|
|
/// <summary>寻找目标库位
|
/// 寻找目标库位
|
/// </summary>
|
/// <param name="plcTaskId">PLC任务号</param>
|
/// <param name="continerType">托盘类型</param>
|
/// <param name="sysHeight">系统判断的高度</param>
|
/// <param name="checkHeight">光电检测的高度</param>
|
/// <returns></returns>
|
public static string toPlace(int plcTaskId, int continerType, int sysHeight, int checkHeight, ref string findEmptyReason, int wmsTaskId)
|
{
|
//height值说明 小托盘入口检测值是1-6,到1号堆垛机要转换成1-2,到2号堆垛机要转换成1-4,大托盘是对应的直接使用
|
string toplace = "";
|
findEmptyReason = "";
|
if (Form1.single.WaitOne())//增加线程锁防止并发
|
{
|
bool isInMoreHighPosition = false;
|
try
|
{
|
using (dbModel mod = new dbModel())
|
{
|
Purchase_Shelve shelveOrder = null;
|
Purchase_ShelveList shelveList = null;
|
|
//修复 [EditBy shaocx,2022-04-18]
|
//Task_Queue task = mod.Task_Queue.Find(taskId);
|
Task_Queue task = null;
|
if (wmsTaskId != 0)
|
{
|
task = mod.Task_Queue.Where(x => x.PlcTaskNo == plcTaskId && x.Task_Id == wmsTaskId).OrderByDescending(x => x.Task_Id).FirstOrDefault();
|
}
|
else
|
{//注意:后期稳定后,必须要求wmsTaskId大于0!!!【EditBy shaocx,2022-09-22】
|
task = mod.Task_Queue.Where(x => x.PlcTaskNo == plcTaskId).OrderByDescending(x => x.Task_Id).FirstOrDefault();
|
}
|
if (task != null)
|
{
|
int shelveid = (int)task.Bill_Id;
|
shelveList = mod.Purchase_ShelveList.Where(x => x.Shelve_Id == shelveid).FirstOrDefault();
|
shelveOrder = mod.Purchase_Shelve.Find(shelveid);
|
|
//注意:如果已经找到了该任务,就直接返回该任务的目标位置,不需要再进行查找新库位了 [EditBy shaocx,2022-09-22]
|
if ((task.TaskStatus == "未下发" || task.TaskStatus == "已下发" || task.TaskStatus == "下发中")
|
&& !string.IsNullOrEmpty(task.ToPositionName) && task.ToPositionName != "0")
|
{
|
return task.ToPositionName;
|
}
|
}
|
else
|
{//没有找到任务号,就报错 【EditBy shaocx,2022-09-22】
|
findEmptyReason = "根据PLC号" + plcTaskId + ",wms任务号:" + wmsTaskId + ",没有找到任务数据";
|
return "";
|
}
|
|
List<Base_Equipment> srmIsOk = mod.Base_Equipment.Where(x => x.DeviceType == "堆垛机").ToList();
|
int areaCode = 0;//库区,如果等于0,表示两台堆垛机都没有禁用,如果等于1,表示2号堆垛机被禁用,如果等于2,表示1号堆垛机被禁用
|
bool srmOne = true;
|
bool srmTwo = true;
|
|
#region 使用事务 [EditBy shaocx,2022-09-22]
|
using (var trans = mod.Database.BeginTransaction())
|
{
|
bool transBool = true;
|
try
|
{
|
#region 判断堆垛机是否禁用 来设置库区
|
if (srmIsOk != null)
|
{
|
#region 查询堆垛机是否可用
|
foreach (var item in srmIsOk)
|
{
|
if (item.DeviceCode == "1")
|
{
|
if (item.Enable == 0)
|
{
|
srmOne = false;
|
}
|
}
|
if (item.DeviceCode == "2")
|
{
|
if (item.Enable == 0)
|
{
|
srmTwo = false;
|
}
|
}
|
}
|
#endregion
|
if (srmOne == false && srmTwo == false)
|
{
|
findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, " 类名:Form1/函数名:toPlace 码盘上架,两台堆垛机已禁用无法分配库位,任务ID: ");
|
return "";
|
}
|
if (srmOne == false)
|
{
|
areaCode = 2;
|
}
|
if (srmTwo == false)
|
{
|
areaCode = 1;
|
}
|
}
|
else
|
{
|
findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toPlace 码盘上架,读取堆垛机设置失败,任务ID: ");
|
return "";
|
}
|
#endregion
|
|
#region 大托盘入库
|
if (continerType == 2)
|
{
|
if (areaCode == 1)
|
{
|
findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toPlace 码盘上架,堆垛机2已经禁用,不能入大托盘,任务ID:", 0, "", 0, checkHeight, "大托盘不能去一号库位");
|
return "";
|
}
|
areaCode = 2;
|
if (checkHeight > 4)
|
{//注意:这里判断的是 光电检测高度【EditBy shaocx,2022-09-17】
|
findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toPlace 码盘上架,WCS托盘参数传入错误,任务ID:", 0, "", sysHeight, checkHeight, "高度异常,光电检测高度为:" + checkHeight);
|
return "";
|
}
|
toplace = findStorage(mod, "", true, ref isInMoreHighPosition, ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
|
if (toplace == "")
|
{
|
changPlateCode();
|
Form1.lastPlateCode = "1";
|
shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
|
int saveResult = mod.SaveChanges();
|
if (saveResult < 1)
|
{
|
mod.SaveChanges();
|
}
|
findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toPlace 找不到库位,任务ID: ", 0, "", sysHeight, checkHeight, "找不到可用空库位");
|
return "";
|
}
|
findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
|
return areaCode + "-" + toplace;
|
|
}
|
#endregion
|
#region 小托盘入库
|
if (continerType == 1)
|
{
|
#region 如果有堆垛机被禁用
|
//如果堆垛机2被禁用
|
if (areaCode == 1)
|
{
|
//height = height > 3 ? 2 : 1;
|
//bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
|
sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
|
|
toplace = findStorage(mod, "", true, ref isInMoreHighPosition, ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
|
if (toplace == "")
|
{
|
changPlateCode();
|
Form1.lastPlateCode = "1";
|
shelveOrder.OnShelveStatus = "堆垛机2被禁用,1号库位没有了-光电检测高度:" + checkHeight + ",系统转换的检测高度:" + sysHeight;
|
|
int saveResult = mod.SaveChanges();
|
if (saveResult < 1)
|
{
|
mod.SaveChanges();
|
}
|
findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 找不到库位(堆垛机2被禁用,1号库位没有了),任务ID: ", 0, "", sysHeight, checkHeight, "堆垛机2被禁用,1号库位没有了");
|
return "";
|
}
|
findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
|
return areaCode + "-" + toplace;
|
}
|
//如果堆垛机1被禁用
|
if (areaCode == 2)
|
{
|
if (checkHeight >= 6)
|
{//注意:这里判断的是 光电检测高度【EditBy shaocx,2022-09-17】
|
findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 找不到库位(2号库位没有这个高度,光电检测高度为:" + checkHeight + "),任务ID: ");
|
return "";
|
}
|
//height = height > 3 ? height - 1 : height;
|
//bug修复,库区2高度重新计算 【EditBy shaocx,2022-04-16】
|
sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
|
toplace = findStorage(mod, "", true, ref isInMoreHighPosition, ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
|
if (toplace == "")
|
{
|
changPlateCode();
|
Form1.lastPlateCode = "1";
|
shelveOrder.OnShelveStatus = "堆垛机1被禁用,2号库位没有了-光电检测高度:" + checkHeight + ",系统转换的检测高度:" + sysHeight;
|
|
int saveResult = mod.SaveChanges();
|
if (saveResult < 1)
|
{
|
mod.SaveChanges();
|
}
|
findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 找不到库位(堆垛机1被禁用,2号库位没有了),任务ID: ", 0, "", sysHeight, checkHeight, "堆垛机1被禁用,2号库位没有了");
|
return "";
|
}
|
findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
|
return areaCode + "-" + toplace;
|
}
|
#endregion
|
|
//如果堆垛机没禁用
|
if (areaCode == 0)
|
{
|
|
//找到物料编号 用来分别哪个哪个巷道物料多
|
|
if (task == null)
|
{
|
findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 找不到库位(寻找小库位,查不到任务号),任务ID: ", 0, "", 0, checkHeight, "任务被删除");
|
return toplace = "";
|
}
|
if (shelveList == null)
|
{
|
findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 找不到库位(寻找小库位,查不到码盘上架明细),任务ID: ", 0, "", sysHeight, checkHeight, "出库单被删除");
|
return toplace = "";
|
}
|
string productNo = shelveList.ProductCode;
|
#region 先检查2号库有没有小托盘空位 没有直接放1号库
|
string sql = "select * from [dbo].[" + "Base_Position" + "] where AreaCode='2' " +
|
" and ColumnCode>1 and ColumnCode<10" + " and IsLocked=" + (int)IsLockedEnum.未锁定 +
|
" and IsFreeze=" + (int)IsFreezeEnum.无货 + " and Enable=" + (int)usable.可用;//isFreeze 是否有货 先拿这个字段用
|
List<Base_Position> smallPosition = mod.Database.SqlQuery<Base_Position>(sql).ToList();
|
//先检查2号库有没有小托盘空位 没有直接放1号库
|
if (smallPosition.Count == 0)
|
{
|
//height = height > 3 ? 2 : 1;
|
//bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
|
areaCode = 1;
|
sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
|
|
|
toplace = findStorage(mod, "", true, ref isInMoreHighPosition, ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
|
if (toplace == "")
|
{
|
changPlateCode();
|
Form1.lastPlateCode = "1";
|
shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
|
findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 找不到库位(1号库位没有了),任务ID: ", 0, "", sysHeight, checkHeight, "找不到可用空库位");
|
int saveResult = mod.SaveChanges();
|
if (saveResult < 1)
|
{
|
mod.SaveChanges();
|
}
|
return "";
|
}
|
findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
|
return areaCode + "-" + toplace;
|
}
|
#endregion
|
|
#region 假如高度等于6必须要去1号库位
|
if (checkHeight == 6)
|
{//注意:这里判断的是 光电检测高度【EditBy shaocx,2022-09-17】
|
areaCode = 1;
|
sysHeight = 2;//注意:这里将系统检测高度写死为2,就表示去找库区1的高库位(放到 975-1850的高度库位)
|
toplace = findStorage(mod, "", true, ref isInMoreHighPosition, ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位,注意:这里将系统检测高度写死为2,就表示去找库区1的高库位(放到 975-1850的高度库位)
|
if (toplace == "")
|
{
|
changPlateCode();
|
Form1.lastPlateCode = "1";
|
shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
|
findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 6号高度去1号巷道 找不到库位(1号库位没有了),任务ID: ", 0, "", sysHeight, checkHeight, "找不到可用空库位");
|
int saveResult = mod.SaveChanges();
|
if (saveResult < 1)
|
{
|
mod.SaveChanges();
|
}
|
return "";
|
}
|
findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
|
return areaCode + "-" + toplace;
|
}
|
#endregion
|
#region 比较巷道里的货物数量
|
|
//原先的写法,我发现了,有跟踪号的计算物料数量和没有跟踪号的计算物料数量里面的代码是一模一样的,不管shelveList.TrackingNumber是不是NULL,因此判定代码重复了,因此我整理了一下 【EditBy shaocx,2022-09-17】
|
//【存疑】这里我发现一个问题,为什么只要是查找库区1找不到库存,就放弃再次寻找库区2的库存,为什么呢? 【EditBy shaocx,2022-09-17】
|
#region 计算物料数量,新代码 【EditBy shaocx,2022-09-17】
|
|
var productOne = mod.Base_ProductPosition.Where(x => x.AreaCode == "1" && x.ProductCode == productNo).ToList();
|
var productTwo = mod.Base_ProductPosition.Where(x => x.AreaCode == "2" && x.ProductCode == productNo).ToList();
|
if (productOne.Count == 0)
|
{
|
areaCode = 1;
|
//height = height > 3 ? 2 : 1;//一排只有两种高度,高度>3就是高库位否则是低库位
|
//bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
|
sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
|
|
toplace = findStorage(mod, "", true, ref isInMoreHighPosition, ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
|
if (toplace == "")
|
{
|
changPlateCode();
|
Form1.lastPlateCode = "1";
|
shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
|
findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 一号库小库位分配失败,任务ID: ", 0, "", sysHeight, checkHeight, "找不到可用空库位");
|
int saveResult = mod.SaveChanges();
|
if (saveResult < 1)
|
{
|
mod.SaveChanges();
|
}
|
return "";
|
}
|
findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
|
return areaCode + "-" + toplace;
|
}
|
if (productTwo.Count == 0)
|
{
|
//height = height > 3 ? height - 1 : height;
|
//bug修复,库区2高度重新计算 【EditBy shaocx,2022-04-16】
|
areaCode = 2;
|
sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
|
|
toplace = findStorage(mod, "", true, ref isInMoreHighPosition, ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
|
if (toplace == "")
|
{
|
areaCode = 1;//如果2号小库位找不到就去一号库位找
|
//height = height > 3 ? 2 : 1;
|
//bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
|
sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
|
|
toplace = findStorage(mod, "", true, ref isInMoreHighPosition, ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
|
if (toplace == "")
|
{
|
|
changPlateCode();
|
Form1.lastPlateCode = "1";
|
shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
|
findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 2号库小库位分配失败,任务ID: ", 0, "", sysHeight, checkHeight, "找不到可用空库位");
|
int saveResult = mod.SaveChanges();
|
if (saveResult < 1)
|
{
|
mod.SaveChanges();
|
}
|
return "";
|
}
|
findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
|
return areaCode + "-" + toplace;
|
|
}
|
findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
|
return areaCode + "-" + toplace;
|
}
|
decimal oneQty = (decimal)productOne.Sum(x => x.ProductStorage);
|
decimal twoQty = (decimal)productTwo.Sum(x => x.ProductStorage);
|
if (oneQty > twoQty)
|
{
|
areaCode = 2;
|
//height = height > 3 ? height - 1 : height;
|
//bug修复,库区2高度重新计算 【EditBy shaocx,2022-04-16】
|
sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
|
|
toplace = findStorage(mod, "", true, ref isInMoreHighPosition, ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
|
if (toplace == "")
|
{
|
areaCode = 1;//如果2号小库位找不到就去一号库位找
|
//height = height > 3 ? 2 : 1;
|
//bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
|
sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
|
|
toplace = findStorage(mod, "", true, ref isInMoreHighPosition, ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
|
if (toplace == "")
|
{
|
changPlateCode();
|
Form1.lastPlateCode = "1";
|
shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
|
findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 小库位分配失败,任务ID: ", 0, "", sysHeight, checkHeight, "1和2排都找不到可用空库位");
|
int saveResult = mod.SaveChanges();
|
if (saveResult < 1)
|
{
|
mod.SaveChanges();
|
}
|
return "";
|
}
|
|
findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
|
return areaCode + "-" + toplace;
|
|
|
}
|
findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
|
return areaCode + "-" + toplace;
|
}
|
else
|
{
|
areaCode = 1;
|
//height = height > 3 ? 2 : 1;
|
//bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
|
sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
|
|
toplace = findStorage(mod, "", true, ref isInMoreHighPosition, ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
|
if (toplace == "")
|
{
|
changPlateCode();
|
Form1.lastPlateCode = "1";
|
shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
|
findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 小库位分配失败,任务ID: ", 0, "", sysHeight, checkHeight, "找不到可用空库位");
|
int saveResult = mod.SaveChanges();
|
if (saveResult < 1)
|
{
|
mod.SaveChanges();
|
}
|
return "";
|
}
|
findStorageReuslt(wmsTaskId, mod, isInMoreHighPosition, findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
|
return areaCode + "-" + toplace;
|
}
|
|
#endregion
|
|
#region 放弃的代码 【EditBy shaocx,2022-09-17】
|
/*
|
//有跟踪号的计算物料数量
|
if (shelveList.TrackingNumber == null)
|
{
|
#region 有跟踪号的计算物料数量
|
|
var productOne = mod.Base_ProductPosition.Where(x => x.AreaCode == "1" && x.ProductCode == productNo).ToList();
|
var productTwo = mod.Base_ProductPosition.Where(x => x.AreaCode == "2" && x.ProductCode == productNo).ToList();
|
if (productOne.Count == 0)
|
{
|
areaCode = 1;
|
//height = height > 3 ? 2 : 1;//一排只有两种高度,高度>3就是高库位否则是低库位
|
//bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
|
sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
|
|
toplace = findStorage(true,ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
|
if (toplace == "")
|
{
|
changPlateCode();
|
lastPlateCode = "1";
|
shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
|
findStorageError(findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 一号库小库位分配失败,任务ID: ", 0, "", sysHeight, checkHeight, "找不到可用空库位");
|
int saveResult = mod.SaveChanges();
|
if (saveResult < 1)
|
{
|
mod.SaveChanges();
|
}
|
return "";
|
}
|
findStorageError(findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
|
return areaCode + "-" + toplace;
|
}
|
if (productTwo.Count == 0)
|
{
|
//height = height > 3 ? height - 1 : height;
|
//bug修复,库区2高度重新计算 【EditBy shaocx,2022-04-16】
|
areaCode = 2;
|
sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
|
|
toplace = findStorage(true,ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
|
if (toplace == "")
|
{
|
areaCode = 1;//如果2号小库位找不到就去一号库位找
|
//height = height > 3 ? 2 : 1;
|
//bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
|
sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
|
|
toplace = findStorage(true,ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
|
if (toplace == "")
|
{
|
|
changPlateCode();
|
lastPlateCode = "1";
|
shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
|
findStorageError(findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 2号库小库位分配失败,任务ID: ", 0, "", sysHeight, checkHeight, "找不到可用空库位");
|
int saveResult = mod.SaveChanges();
|
if (saveResult < 1)
|
{
|
mod.SaveChanges();
|
}
|
return "";
|
}
|
findStorageError(findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
|
return areaCode + "-" + toplace;
|
|
}
|
findStorageError(findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
|
return areaCode + "-" + toplace;
|
}
|
decimal oneQty = (decimal)productOne.Sum(x => x.ProductStorage);
|
decimal twoQty = (decimal)productTwo.Sum(x => x.ProductStorage);
|
if (oneQty > twoQty)
|
{
|
areaCode = 2;
|
//height = height > 3 ? height - 1 : height;
|
//bug修复,库区2高度重新计算 【EditBy shaocx,2022-04-16】
|
sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
|
|
toplace = findStorage(true,ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
|
if (toplace == "")
|
{
|
areaCode = 1;//如果2号小库位找不到就去一号库位找
|
//height = height > 3 ? 2 : 1;
|
//bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
|
sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
|
|
toplace = findStorage(true,ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
|
if (toplace == "")
|
{
|
changPlateCode();
|
lastPlateCode = "1";
|
shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
|
findStorageError(findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 小库位分配失败,任务ID: ", 0, "", sysHeight, checkHeight, "1和2排都找不到可用空库位");
|
int saveResult = mod.SaveChanges();
|
if (saveResult < 1)
|
{
|
mod.SaveChanges();
|
}
|
return "";
|
}
|
|
findStorageError(findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
|
return areaCode + "-" + toplace;
|
|
|
}
|
findStorageError(findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
|
return areaCode + "-" + toplace;
|
}
|
else
|
{
|
areaCode = 1;
|
//height = height > 3 ? 2 : 1;
|
//bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
|
sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
|
|
toplace = findStorage(true,ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
|
if (toplace == "")
|
{
|
changPlateCode();
|
lastPlateCode = "1";
|
shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
|
findStorageError(findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 小库位分配失败,任务ID: ", 0, "", sysHeight, checkHeight, "找不到可用空库位");
|
int saveResult = mod.SaveChanges();
|
if (saveResult < 1)
|
{
|
mod.SaveChanges();
|
}
|
return "";
|
}
|
findStorageError(findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
|
return areaCode + "-" + toplace;
|
}
|
|
#endregion
|
}
|
//没有跟踪号的计算物料数量
|
else
|
{
|
#region 没有跟踪号的计算物料数量
|
|
string tranckingNumber = shelveList.TrackingNumber;
|
|
var productOne = mod.Base_ProductPosition.Where(x => x.AreaCode == "1" && x.ProductCode == productNo).ToList();//.Sum(x => x.ProductStorage);
|
var productTwo = mod.Base_ProductPosition.Where(x => x.AreaCode == "2" && x.ProductCode == productNo).ToList();// Sum(x => x.ProductStorage);
|
|
if (productOne.Count == 0)
|
{
|
areaCode = 1;
|
//height = height > 3 ? 2 : 1;
|
//bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
|
sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
|
|
toplace = findStorage(true,ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
|
if (toplace == "")
|
{
|
changPlateCode();
|
lastPlateCode = "1";
|
shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
|
findStorageError(findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 小库位分配失败,任务ID: ", 0, "", sysHeight, checkHeight, "找不到可用空库位");
|
int saveResult = mod.SaveChanges();
|
if (saveResult < 1)
|
{
|
mod.SaveChanges();
|
}
|
return "";
|
}
|
findStorageError(findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
|
return areaCode + "-" + toplace;
|
}
|
if (productTwo.Count == 0)
|
{
|
areaCode = 2;
|
//height = height > 3 ? height - 1 : height;
|
//bug修复,库区2高度重新计算 【EditBy shaocx,2022-04-16】
|
sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
|
|
toplace = findStorage(true,ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
|
if (toplace == "")
|
{
|
areaCode = 1;//如果2排找不到就去一排找
|
//height = height > 3 ? 2 : 1;
|
//bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
|
sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
|
|
toplace = findStorage(true,ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
|
if (toplace == "")
|
{
|
changPlateCode();
|
lastPlateCode = "1";
|
shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
|
findStorageError(findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 小库位分配失败,任务ID: ", 0, "", sysHeight, checkHeight, "找不到可用空库位");
|
int saveResult = mod.SaveChanges();
|
if (saveResult < 1)
|
{
|
mod.SaveChanges();
|
}
|
return "";
|
}
|
findStorageError(findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
|
return areaCode + "-" + toplace;
|
}
|
findStorageError(findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
|
return areaCode + "-" + toplace;
|
}
|
decimal oneQty = (decimal)productOne.Sum(x => x.ProductStorage);
|
decimal twoQty = (decimal)productTwo.Sum(x => x.ProductStorage);
|
if (oneQty > twoQty)
|
{
|
areaCode = 2;
|
//height = height > 3 ? height - 1 : height;
|
//bug修复,库区2高度重新计算 【EditBy shaocx,2022-04-16】
|
sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
|
|
toplace = findStorage(true,ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
|
if (toplace == "")
|
{
|
areaCode = 1;//如果2排找不到就去一排找
|
//height = height > 3 ? 2 : 1;
|
//bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
|
sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
|
|
toplace = findStorage(true,ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
|
if (toplace == "")
|
{
|
changPlateCode();
|
lastPlateCode = "1";
|
shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
|
findStorageError(findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 小库位分配失败,任务ID: ", 0, "", sysHeight, checkHeight, "1和2排找不到可用空库位");
|
int saveResult = mod.SaveChanges();
|
if (saveResult < 1)
|
{
|
mod.SaveChanges();
|
}
|
return "";
|
}
|
findStorageError(findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
|
return areaCode + "-" + toplace;
|
}
|
findStorageError(findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
|
return areaCode + "-" + toplace;
|
}
|
else
|
{
|
areaCode = 1;
|
//height = height > 3 ? 2 : 1;
|
//bug修复,库区1出现高货物进入低库位的情况 【EditBy shaocx,2022-03-03】
|
sysHeight = ExtendHelper.ConvertHeightByArea(areaCode, checkHeight);
|
|
toplace = findStorage(true,ref findEmptyReason, areaCode, continerType, sysHeight);//分配库位
|
if (toplace == "")
|
{
|
changPlateCode();
|
lastPlateCode = "1";
|
shelveOrder.OnShelveStatus = ExtendHelper.GetOnShelveStatusFailMsg(checkHeight, sysHeight, findEmptyReason);
|
findStorageError(findEmptyReason, plcTaskId, "类名:Form1/函数名:toplace 小库位分配失败,任务ID: ", 0, "", sysHeight, checkHeight, "找不到可用空库位");
|
int saveResult = mod.SaveChanges();
|
if (saveResult < 1)
|
{
|
mod.SaveChanges();
|
}
|
return "";
|
}
|
findStorageError(findEmptyReason, plcTaskId, "找到库位", areaCode, toplace, sysHeight, checkHeight);
|
return areaCode + "-" + toplace;
|
}
|
|
#endregion
|
}
|
//*/
|
#endregion
|
|
#endregion
|
}
|
}
|
#endregion
|
}
|
catch (Exception)
|
{
|
transBool = false;
|
throw;
|
}
|
finally
|
{
|
if (transBool)
|
{
|
trans.Commit();
|
}
|
else
|
{
|
trans.Rollback();
|
}
|
}
|
}
|
#endregion
|
|
|
}
|
}
|
catch (Exception ex)
|
{
|
toplace = "";
|
logtxt.txtWrite("类名:Form1/函数名:toPlace 找目标库位产生异常" + ex.Message + "出错行号" + (string)ex.StackTrace, 2);
|
}
|
finally { Form1.single.ReleaseMutex(); }//一轮结束
|
}
|
if (toplace == "")
|
{
|
Form1.lastPlateCode = "1";
|
}
|
|
return toplace;
|
|
}
|
/// <summary>
|
/// 找库位处理结果
|
/// </summary>
|
/// <param name="isInMoreHighPosition">是否入的是匹配自己高度的更高库位,这些库位需要移库的</param>
|
/// <param name="findEmptyReason">原因</param>
|
/// <param name="plcTaskId">PLC任务号</param>
|
/// <param name="info"></param>
|
/// <param name="areaCode"></param>
|
/// <param name="toplace"></param>
|
/// <param name="height">系统判断的高度</param>
|
/// <param name="checkHeight">光电检测的高度</param>
|
/// <param name="msg"></param>
|
private static void findStorageReuslt(int wmsTaskId, dbModel mod, bool isInMoreHighPosition, string findEmptyReason, int plcTaskId, string info, int areaCode = 0, string toplace = "", int height = 0, int checkHeight = 0, string msg = "")
|
{
|
try
|
{
|
Form1.lastPlateCode = "0";
|
//修复 [EditBy shaocx,2022-04-18]
|
//查找对应任务
|
//Task_Queue changeTaksStatus = mod.Task_Queue.Find(taskId);
|
Task_Queue curTask = null;
|
if (wmsTaskId != 0)
|
{
|
curTask = mod.Task_Queue.Where(x => x.PlcTaskNo == plcTaskId && x.Task_Id == wmsTaskId).OrderByDescending(x => x.Task_Id).FirstOrDefault();
|
}
|
else
|
{//注意:后期稳定后,必须要求wmsTaskId大于0!!!【EditBy shaocx,2022-09-22】
|
curTask = mod.Task_Queue.Where(x => x.PlcTaskNo == plcTaskId).OrderByDescending(x => x.Task_Id).FirstOrDefault();
|
}
|
|
if (curTask != null)
|
{
|
if (areaCode == 0)//没传库区值就是异常
|
{
|
if (height > 0)//传高度值就是找不到库位
|
{
|
curTask.TaskStatus = msg + "-" + "光电检测高度:" + checkHeight + ",系统校验高度:" + height + "," + findEmptyReason;
|
}
|
else //没传高度值 可能是任务被删除或入库单被删除
|
{
|
curTask.TaskStatus = msg;
|
}
|
logtxt.txtWrite("类名:Form1/函数名:findStorageError ,不能找库位" + info, 2);
|
}
|
else
|
{
|
curTask.LogicHeight = height;//逻辑高度(系统判断的高度)【EditBy shaocx,2022-08-25】
|
curTask.PhysicsHeight = checkHeight;//物理高度(光电检测的高度)【EditBy shaocx,2022-08-25】
|
curTask.ToPositionName = toplace;//高度检测获取后,并且找到了库存后,才写入任务表的ToPositionName值 【EditBy shaocx,2022-08-25】
|
curTask.DoCount = areaCode;
|
//我注释了该代码,因为 常规入库任务,在创建任务时状态是“下发中”,经过线程common_autoSendTask下发给WCS成功后,就改为 状态“已下发”
|
//因此这个地方就没有必要重复改此状态了,避嫌 【EditBy shaocx,2022-09-10】
|
//curTask.TaskStatus = "已下发";
|
curTask.IsInMoreHighPosition = isInMoreHighPosition == true ? 1 : 0;// 【EditBy shaocx,2022-09-19】
|
}
|
mod.SaveChanges();
|
}
|
}
|
catch (Exception ex)
|
{
|
logtxt.txtWrite("类名:Form1/函数名:finishConfirm 查询任务完成产生异常" + ex.Message + "出错行号" + (string)ex.StackTrace, 2);
|
}
|
}
|
|
|
/// <summary> 分配库位
|
/// 分配库位
|
/// </summary>
|
/// <param name="filter_shelveCode">按照排数过滤</param>
|
/// <param name="isNeedSaveChangeWhenFind">当发现空库位时,是否需要更新数据(目前仅供闲时移库使用,闲时移库传递false,其他情况传递true)</param>
|
/// <param name="areaCode">库区号</param>
|
/// <param name="containerType">托盘类型</param>
|
/// <param name="containerHeight">托盘总高(系统检测高度)</param>
|
/// <param name="restrictNumber">预留库位数</param>
|
/// <returns>返回格式:格式: 01-03-01</returns>
|
public static string findStorage(dbModel mod, string filter_shelveCode, bool isNeedSaveChangeWhenFind, ref bool isInMoreHighPosition, ref string findEmptyReason, int areaCode, int containerType, int containerHeight, int restrictNumber = 1)
|
{
|
string errMsg = "";
|
string position = "";
|
if (Form1.single.WaitOne())//增加线程锁防止并发
|
{
|
try
|
{//满托回库 入库 移库
|
|
List<string> restrict = new List<string>();//筛选条件
|
|
|
#region 库位范围和排序
|
if (areaCode == 1)
|
{
|
#region 一号机都是小托盘
|
switch (containerHeight)
|
{
|
case 1:
|
//一号机975以下
|
//【存疑】这里为什么没有优先原则,而是只能放到大于1或小于11的地方?按道理不应该全部库位都能放吗?[EditBy shaocx,2022-09-17]
|
restrict.Add(" and RowCode>1 and RowCode<11 ");
|
//增加以下代码,没有低库位就去高库位找 【EditBy shaocx,2022-09-19】
|
restrict.Add(" and (RowCode=1 or RowCode=11 )");
|
break;
|
case 2://放到 975-1850的高度库位
|
//注释以下代码,统一用方法GetRestrictNumber判断 【EditBy shaocx,2022-09-19】
|
//restrictNumber = restrictNumber == 1 ? 2 : 0;//需要给空托盘留3个库位的信号
|
restrict.Add(" and (RowCode=1 or RowCode=11 )");
|
break;
|
}
|
#endregion
|
}
|
else
|
{
|
#region 二号机小托盘
|
if (areaCode == 2 && containerType == 1)
|
{
|
//疑问:明明有14层高,但是放小托盘的地方只放到 11层,为什么!【EditBy shaocx,2022-10-19】
|
//回答:上面 你说的不对,二号机放小托盘的最高高度是11,不是14!!!!【EditBy shaocx,2022-10-20】
|
switch (containerHeight)
|
{//二号堆垛机 小托盘 750以下都是2-10层 750-1150 是3
|
case 1:
|
case 2://同650一样条件
|
case 3://750-1150高度优先放3,5,7,9,10 其次是1和11而且只能在这其中
|
//二号机小托盘650以下 优先放 2 ,4,6,8
|
//下面的restrict集合是分配执行的,保证了优先原则 [EditBy shaocx,2022-09-17]
|
restrict.Add(" and ColumnCode>1 and ColumnCode<10 and (RowCode>=1 AND RowCode<=11 ) ");
|
break;
|
case 4://1150-1350只能放1和11层
|
errMsg = findEmptyReason = "大堆垛机区域,放小托盘,逻辑高度" + containerHeight + ",等于4,该区域没有符合该货物的货位,查找的是库区:" + areaCode;
|
position = "";
|
break;
|
}
|
|
}
|
#endregion
|
|
#region 二号机大托盘
|
else
|
{
|
switch (containerHeight)
|
{//二号堆垛机 大托盘
|
case 1:
|
//二号机大托盘600以下
|
//下面的restrict集合是分配执行的,保证了优先原则 [EditBy shaocx,2022-09-17]
|
//ColumnCode是当前列,RowCode是当前层
|
//【存疑】为什么要ColumnCode<2 or ColumnCode>9? 列要小于2或者大于9?? [EditBy shaocx,2022-09-17]
|
//回答上面:因为 从2到9排 放的都是小托盘,其他排放的都是大托盘 【EditBy shaocx,2022-09-19】
|
restrict.Add(" and ( ( (ColumnCode=1 and (RowCode>=3 and RowCode<=12) ) OR ( ColumnCode>=10 and ColumnCode<=21 and (RowCode>=3 and RowCode<=11)) ) ) ");
|
restrict.Add(" and (ColumnCode>=10 and ColumnCode<=21) and (RowCode=12 )");
|
restrict.Add(" and (ColumnCode<2 or ColumnCode>9) and ( RowCode=2 )");
|
restrict.Add(" and (ColumnCode<2 or ColumnCode>9) and (RowCode=1 or RowCode=13 or RowCode=14 )");
|
break;
|
case 2://同600-750
|
restrict.Add(" and (ColumnCode>=10 and ColumnCode<=21) and (RowCode=12 )");
|
restrict.Add(" and (ColumnCode<2 or ColumnCode>9) and ( RowCode=2 )");
|
restrict.Add(" and (ColumnCode<2 or ColumnCode>9) and (RowCode=1 or RowCode=13 or RowCode=14 )");
|
break;
|
case 3://750-1150高度,放2层
|
restrict.Add(" and (ColumnCode<2 or ColumnCode>9) and ( RowCode=2 )");
|
restrict.Add(" and (ColumnCode<2 or ColumnCode>9) and (RowCode=1 or RowCode=13 or RowCode=14 )");
|
break;
|
case 4://1150-1350
|
restrict.Add(" and (ColumnCode<2 or ColumnCode>9) and (RowCode=1 or RowCode=13 or RowCode=14 )");
|
break;
|
|
}
|
}
|
#endregion
|
|
}
|
#endregion
|
|
int index = 0;
|
//[注意]这里分批次执行,就决定了优先放哪层的逻辑
|
foreach (var item in restrict)
|
{
|
index++;
|
|
if (isNeedSaveChangeWhenFind == false && index >= 2)
|
{//说明是闲时移库寻找库存,那么如果是寻找不是最合适库存,则终止寻找。注意:这里的闲时移库类型包括(高库位寻找合适库位+库存平衡) 【EditBy shaocx,2022-09-26】
|
errMsg = findEmptyReason = "闲时移库寻找库存,那么如果是寻找不是最合适库存,则终止寻找,查找的是库区:" + areaCode;
|
position = "";
|
break;
|
}
|
|
//入库优化策略 先判断哪排空库位多 再判断两头哪边空库位多(两头往中间放),
|
Base_Position storage = null;//最终寻找到的目标库位对象
|
//一号库位 都是小托盘
|
if (areaCode == 1)
|
{
|
findStorageForAreaCode1(filter_shelveCode, mod, areaCode, item, ref restrictNumber, ref storage, containerType);
|
}
|
else
|
{
|
findStorageForAreaCode2(filter_shelveCode, mod, areaCode, item, ref restrictNumber, ref storage, containerType);
|
}
|
|
if (storage != null)
|
{
|
if (restrictNumber == 3)
|
{
|
errMsg = "预留库位数等于" + restrictNumber + ",设置寻找的库位为空,即使找到了空库位" + storage.PositionName;
|
findEmptyReason = "空库存不足预留库位数" + restrictNumber + ",查找的是库区:" + areaCode;
|
position = "";
|
break;
|
}
|
#region MyRegion
|
|
int pid = storage.Position_Id;
|
//mod.SaveChanges();
|
Base_Position storage1 = mod.Base_Position.Find(pid);
|
|
//mod.Base_Position.AddOrUpdate(storage);
|
string[] positions = storage1.PositionName.Split('-');
|
position = positions[1] + "-" + positions[2] + "-" + positions[3];//格式: 01-03-01
|
|
if (isNeedSaveChangeWhenFind)
|
{//需要更新数据
|
storage1.IsLocked = 1;//找到空库位时,库位锁定!
|
storage1.Remark = "正常入库-找到空库位时,库位锁定!";
|
//storage1.IsFreeze = 1;
|
storage1.IsFreeze = (int)IsFreezeEnum.有货;
|
|
int dd = mod.SaveChanges();
|
if (dd < 1)
|
{//保存数据失败
|
logtxt.txtWrite("类名:Form1/函数名:findStorage/ 库区=" + areaCode.ToString() + "托盘类型=" + containerType.ToString() + "托盘高度=" + containerHeight.ToString() + "保存数据库失败", 2);
|
findEmptyReason = errMsg = "保存数据库失败";
|
position = "";
|
}
|
else
|
{//找到库位,并保存数据成功
|
if (index != 1)
|
{
|
isInMoreHighPosition = true;//表示不是按照最佳匹配高度找到的库位 【EditBy shaocx,2022-09-19】
|
}
|
}
|
}
|
else
|
{//不需要更新数据
|
if (index != 1)
|
{
|
isInMoreHighPosition = true;//表示不是按照最佳匹配高度找到的库位 【EditBy shaocx,2022-09-19】
|
}
|
}
|
#endregion
|
|
break;
|
}
|
else
|
{
|
errMsg = "未找到空闲库位";
|
position = "";
|
|
}
|
|
}
|
}
|
catch (Exception ex)
|
{
|
logtxt.txtWrite("类名:Form1/函数名:findStorage/产生异常 库区=" + areaCode.ToString() + "托盘类型=" + containerType.ToString() + "托盘高度=" + containerHeight.ToString() + "-出错信息" + ex.Message + "-出错行号" + (string)ex.StackTrace, 2);
|
errMsg = "出现异常:" + ex.Message;
|
findEmptyReason = "出现异常:" + ex.Message;
|
position = "";
|
throw ex;//抛出异常
|
}
|
finally { Form1.single.ReleaseMutex(); }//一轮结束
|
}
|
return position;
|
|
}
|
|
/// <summary>
|
/// 在库区1中分配库位
|
/// </summary>
|
/// <param name="mod"></param>
|
/// <param name="areaCode"></param>
|
/// <param name="item"></param>
|
/// <param name="restrictNumber"></param>
|
/// <param name="storage"></param>
|
private static void findStorageForAreaCode1(string filter_shelveCode, dbModel mod, int areaCode, string item, ref int restrictNumber, ref Base_Position storage, int containerType)
|
{
|
#region 库区1
|
//第一排搜索
|
string row1Sql = "select * from [dbo].[" + "Base_Position" + "] where AreaCode= '" + areaCode.ToString() + "'" + item + "and ShelveCode='01' and IsLocked=" + (int)IsLockedEnum.未锁定 +
|
" and IsFreeze=" + (int)IsFreezeEnum.无货 + " and Enable=" + (int)usable.可用;//isFreeze 是否有货 先拿这个字段用
|
FitlerShelveCode(filter_shelveCode, ref row1Sql);//按照排数过滤 【EditBy shaocx,2022-09-21】
|
List<Base_Position> row1Storage = mod.Database.SqlQuery<Base_Position>(row1Sql).ToList();
|
//第二排搜索
|
string row2Sql = "select * from [dbo].[" + "Base_Position" + "] where AreaCode= '" + areaCode.ToString() + "'" + item + "and ShelveCode='02' and IsLocked=" + (int)IsLockedEnum.未锁定 +
|
" and IsFreeze=" + (int)IsFreezeEnum.无货 + " and Enable=" + (int)usable.可用;//isFreeze 是否有货 先拿这个字段用
|
FitlerShelveCode(filter_shelveCode, ref row2Sql);//按照排数过滤 【EditBy shaocx,2022-09-21】
|
List<Base_Position> row2Storage = mod.Database.SqlQuery<Base_Position>(row2Sql).ToList();
|
|
//再次筛选出真正的空闲库位,将有库存的剔除掉 【EditBy shaocx,2022-03-03】
|
row1Storage = BussinessExtension.FitlterFindEmptyPlace(row1Storage, areaCode, mod);
|
row2Storage = BussinessExtension.FitlterFindEmptyPlace(row2Storage, areaCode, mod);
|
int total_storage = row1Storage.Count + row2Storage.Count;//真正的空库位的总数(一个库区的)
|
|
//找出哪排空库位多
|
List<Base_Position> rowResultSpl = row1Storage.Count > row2Storage.Count ? row1Storage : row2Storage;
|
//左右均放策略 右边要倒序
|
|
List<Base_Position> colRigthSpl = rowResultSpl.Where(x => Convert.ToInt32(x.ColumnCode) > 14).OrderBy(x => x.RowCode).ThenByDescending(x => x.ColumnCode).ToList();
|
|
List<Base_Position> colLeftSpl = rowResultSpl;
|
//移除右边库位得到左边库位
|
if (colRigthSpl.Count > 0)
|
{
|
foreach (var itemColRemove in colRigthSpl)
|
{
|
colLeftSpl.Remove(itemColRemove);
|
}
|
}
|
//判断左右两边数量
|
List<Base_Position> finallyResultSql = colRigthSpl.Count > colLeftSpl.Count ? colRigthSpl : colLeftSpl;
|
if (finallyResultSql.Count > 0)
|
{
|
storage = finallyResultSql[0];
|
}
|
|
//获取预留库位数 【EditBy shaocx,2022-09-19】
|
FindEmptyLocationHandler.GetRestrictNumber(areaCode, storage, containerType, ref restrictNumber);
|
|
if (restrictNumber == 2)
|
{//表示系统要预留至少两个空库位,用于存放空托盘
|
//if (finallyResultSql.Count < 4)
|
if (total_storage < 4) //改为用真正的空库位的总数(一个库区的)判断【EditBy shaocx,2022-03-03】
|
{
|
restrictNumber = 3;
|
}
|
|
}
|
#endregion
|
}
|
|
/// <summary>
|
/// 在库区2中分配库位
|
/// </summary>
|
/// <param name="mod"></param>
|
/// <param name="areaCode"></param>
|
/// <param name="item"></param>
|
/// <param name="restrictNumber"></param>
|
/// <param name="storage"></param>
|
private static void findStorageForAreaCode2(string filter_shelveCode, dbModel mod, int areaCode, string item, ref int restrictNumber, ref Base_Position storage, int containerType)
|
{
|
#region 库区2
|
//库区2有一小半是是小托盘,所以只做排策略,两头不做
|
//第一排搜索
|
string areaCode2row1Sql = "select * from [dbo].[" + "Base_Position" + "] where AreaCode= '" + areaCode.ToString() + "'" + item + "and ShelveCode='01' and IsLocked=" + (int)IsLockedEnum.未锁定 +
|
" and IsFreeze=" + (int)IsFreezeEnum.无货 + " and Enable=" + (int)usable.可用;//isFreeze 是否有货 先拿这个字段用
|
FitlerShelveCode(filter_shelveCode, ref areaCode2row1Sql);//按照排数过滤 【EditBy shaocx,2022-09-21】
|
List<Base_Position> row1Storage = mod.Database.SqlQuery<Base_Position>(areaCode2row1Sql).ToList();
|
//第二排搜索
|
string areaCode2row2Sql = "select * from [dbo].[" + "Base_Position" + "] where AreaCode= '" + areaCode.ToString() + "'" + item + "and ShelveCode='02' and IsLocked=" + (int)IsLockedEnum.未锁定 +
|
" and IsFreeze=" + (int)IsFreezeEnum.无货 + " and Enable=" + (int)usable.可用;//isFreeze 是否有货 先拿这个字段用
|
FitlerShelveCode(filter_shelveCode, ref areaCode2row2Sql);//按照排数过滤 【EditBy shaocx,2022-09-21】
|
List<Base_Position> row2Storage = mod.Database.SqlQuery<Base_Position>(areaCode2row2Sql).ToList();
|
|
//重新筛选那些没有库存的库位【EditBy shaocx,2022-01-27】
|
row1Storage = BussinessExtension.FitlterFindEmptyPlace(row1Storage, areaCode, mod);
|
//重新筛选那些没有库存的库位【EditBy shaocx,2022-01-27】
|
row2Storage = BussinessExtension.FitlterFindEmptyPlace(row2Storage, areaCode, mod);
|
|
int total_storage = row1Storage.Count + row2Storage.Count;//真正的空库位的总数(一个库区的)
|
|
//找出哪排空库位多
|
List<Base_Position> rowResultSpl = row1Storage.Count > row2Storage.Count ? row1Storage : row2Storage;
|
|
if (rowResultSpl.Count > 0)
|
{
|
//验证
|
List<string> toPlaceList = mod.Task_Queue.Where(x => x.TaskType == TaskTypeEnum.常规入库.ToString() && (x.TaskStatus == "未下发" || x.TaskStatus == "下发中" || x.TaskStatus == "已下发")).Select(x => x.ToPositionName).ToList();
|
var Toplace = rowResultSpl.Where(x => !toPlaceList.Contains(x.PositionName)).ToList();
|
if (Toplace.Count > 0)
|
{
|
#region 找到集合就赋值给toplace
|
if (Form1.lastPosition == Toplace[0].PositionName)//假如等于上一次找的库位,这次就给list里第二个数据
|
{
|
logtxt.txtWrite("类名:Form1/函数名:findStorage/ 上次找的库位=" + Form1.lastPosition + " 本次找的库位" + Toplace[0].PositionName, 2);
|
|
if (rowResultSpl.Count >= 2)
|
{
|
storage = Toplace[1];
|
Form1.lastPosition = Toplace[1].PositionName;
|
}
|
}
|
else
|
{
|
storage = Toplace[0];
|
Form1.lastPosition = Toplace[0].PositionName;
|
|
}
|
#endregion
|
|
}
|
}
|
|
//获取预留库位数 【EditBy shaocx,2022-09-19】
|
FindEmptyLocationHandler.GetRestrictNumber(areaCode, storage, containerType, ref restrictNumber);
|
|
if (restrictNumber == 2)
|
{
|
//if (rowResultSpl.Count < 4)
|
if (total_storage < 4) //改为用真正的空库位的总数(一个库区的)判断【EditBy shaocx,2022-03-03】
|
{
|
restrictNumber = 3;
|
}
|
}
|
#endregion
|
}
|
|
/// <summary>
|
/// 按照排数过滤
|
/// </summary>
|
/// <param name="filter_shelveCode"></param>
|
/// <param name="rowSql"></param>
|
private static void FitlerShelveCode(string filter_shelveCode, ref string rowSql)
|
{
|
if (!string.IsNullOrEmpty(filter_shelveCode))
|
{
|
rowSql += " and ShelveCode='" + filter_shelveCode + "' ";
|
}
|
}
|
|
#endregion
|
|
public static void changPlateCode()
|
{
|
Form1.lastPlateCode = "0";
|
}
|
}
|
}
|