|
|
|
@ -14,6 +14,7 @@ using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
|
|
|
|
|
|
|
|
|
|
namespace Aucma.Core.Palletiz.Business
|
|
|
|
|
{
|
|
|
|
@ -35,7 +36,8 @@ namespace Aucma.Core.Palletiz.Business
|
|
|
|
|
|
|
|
|
|
#region 变量定义
|
|
|
|
|
public readonly List<ScannerModel> allScanners = Appsettings.app<ScannerModel>("ScannerServer").ToList();
|
|
|
|
|
public readonly string storeCode = Appsettings.app("StoreInfo", "PalletizStoreCode");//分垛库code
|
|
|
|
|
public readonly string storeCodeA = Appsettings.app("StoreInfo", "PalletizStoreCodeA");//分垛库A
|
|
|
|
|
public readonly string storeCodeB = Appsettings.app("StoreInfo", "PalletizStoreCodeB");//分垛库B
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 接口引用
|
|
|
|
@ -76,66 +78,59 @@ namespace Aucma.Core.Palletiz.Business
|
|
|
|
|
List<int> spaceNumList = new List<int>();
|
|
|
|
|
// 入库记录
|
|
|
|
|
RecordInStore recordInstore = new RecordInStore();
|
|
|
|
|
recordInstore.StoreCode = storeCode;
|
|
|
|
|
|
|
|
|
|
//1.根据成品码找货道
|
|
|
|
|
List<BaseSpaceInfo> spaceList = getSpaceBySNCode(SNCode,recordInstore);
|
|
|
|
|
// 根据货道信息判断下发plc信号
|
|
|
|
|
if (spaceList == null)
|
|
|
|
|
if (spaceList == null || spaceList.Count==0)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error("未找到匹配货道,请手动入库!");
|
|
|
|
|
// 刷新页面提示信息
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (spaceList.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
spaceNumList.Add(int.Parse(spaceList[0].SpaceCode.Substring(5, 3)));
|
|
|
|
|
spaceNumList.Add(0);
|
|
|
|
|
plcResult = sendAndAnswerPlc(scannerIp, spaceList[0].RotationRange, spaceNumList);
|
|
|
|
|
spaceList[0].LastSpace = spaceList[0].SpaceCode;
|
|
|
|
|
recordInstore.SpaceCode = spaceList[0].SpaceCode;
|
|
|
|
|
// 过滤货道,找到最终需要下发的货道
|
|
|
|
|
BaseSpaceInfo finalSpace = FilterSpace(spaceList);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// 暂时只考虑两个货道入一种型号
|
|
|
|
|
else if (spaceList.Count >= 2)
|
|
|
|
|
{
|
|
|
|
|
// 大产品占两道
|
|
|
|
|
if (spaceList[0].IsTwoSpace == 1)
|
|
|
|
|
if (finalSpace.IsTwoSpace == 1)
|
|
|
|
|
{
|
|
|
|
|
spaceNumList.Add(int.Parse(spaceList[0].SpaceCode.Substring(5, 3)));
|
|
|
|
|
spaceNumList.Add(int.Parse(spaceList[1].SpaceCode.Substring(5, 3)));
|
|
|
|
|
spaceNumList.Add(int.Parse(finalSpace.SpaceCode.Substring(5, 3)));
|
|
|
|
|
spaceNumList.Add(int.Parse(getOtherSpace(finalSpace, spaceList).SpaceCode.Substring(5, 3)));
|
|
|
|
|
plcResult = sendAndAnswerPlc(scannerIp, spaceList[0].RotationRange, spaceNumList);
|
|
|
|
|
recordInstore.SpaceCode = spaceList[0].SpaceCode;
|
|
|
|
|
recordInstore.SpaceCode = finalSpace.SpaceCode;
|
|
|
|
|
recordInstore.StoreCode = finalSpace.StoreCode;
|
|
|
|
|
// 更新货道信息,大产品last存objId大的,如货道7,8存8
|
|
|
|
|
BaseSpaceInfo otherSpace = getOtherSpace(finalSpace, spaceList);
|
|
|
|
|
if (otherSpace != null)
|
|
|
|
|
{
|
|
|
|
|
updateSapceList(otherSpace.ObjId,spaceList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// last不等于自己,可以先入自己,否则入另一条货道
|
|
|
|
|
if (!spaceList[0].LastSpace.Equals(spaceList[0].SpaceCode))
|
|
|
|
|
if (isOddNumber(finalSpace))
|
|
|
|
|
{
|
|
|
|
|
spaceNumList.Add(int.Parse(spaceList[0].SpaceCode.Substring(5, 3)));
|
|
|
|
|
spaceNumList.Add(int.Parse(finalSpace.SpaceCode.Substring(5, 3)));
|
|
|
|
|
spaceNumList.Add(0);
|
|
|
|
|
plcResult = sendAndAnswerPlc(scannerIp, spaceList[0].RotationRange, spaceNumList);
|
|
|
|
|
spaceList[0].LastSpace = spaceList[0].SpaceCode;
|
|
|
|
|
recordInstore.SpaceCode = spaceList[0].SpaceCode;
|
|
|
|
|
plcResult = sendAndAnswerPlc(scannerIp, finalSpace.RotationRange, spaceNumList);
|
|
|
|
|
updateSapceList(finalSpace.ObjId, spaceList);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
spaceNumList.Add(0);
|
|
|
|
|
spaceNumList.Add(int.Parse(spaceList[1].SpaceCode.Substring(5, 3)));
|
|
|
|
|
sendAndAnswerPlc(scannerIp, spaceList[0].RotationRange, spaceNumList);
|
|
|
|
|
spaceList[0].LastSpace = spaceList[1].SpaceCode;
|
|
|
|
|
recordInstore.SpaceCode = spaceList[1].SpaceCode;
|
|
|
|
|
}
|
|
|
|
|
spaceNumList.Add(int.Parse(finalSpace.SpaceCode.Substring(5, 3)));
|
|
|
|
|
plcResult = sendAndAnswerPlc(scannerIp, finalSpace.RotationRange, spaceNumList);
|
|
|
|
|
updateSapceList(finalSpace.ObjId, spaceList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (plcResult==true)
|
|
|
|
|
{
|
|
|
|
|
// 更新货道信息,入库记录,刷新界面
|
|
|
|
|
_baseSpaceInfoServices.UpdateAsync(spaceList);
|
|
|
|
|
|
|
|
|
|
// 更新入库记录,刷新界面
|
|
|
|
|
#region 添加入库记录
|
|
|
|
|
recordInstore.SpaceCode = finalSpace.SpaceCode;
|
|
|
|
|
recordInstore.StoreCode = finalSpace.StoreCode;
|
|
|
|
|
recordInstore.InStoreAmount = 1;
|
|
|
|
|
recordInstore.InStoreTime = DateTime.Now;
|
|
|
|
|
recordInstore.CreatedTime = DateTime.Now;
|
|
|
|
@ -169,12 +164,13 @@ namespace Aucma.Core.Palletiz.Business
|
|
|
|
|
CodeBindingRecord bindingRecord = _codeBindingServices.Query(c => c.ProductCode.Equals(SNCode)).FirstOrDefault();
|
|
|
|
|
if (bindingRecord == null) return null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
recordInstore.BarCodeCode = bindingRecord.BoxCode;
|
|
|
|
|
recordInstore.MaterialCode = bindingRecord.BoxCode;
|
|
|
|
|
recordInstore.MaterialType = bindingRecord.BoxCode.Substring(7, 10);
|
|
|
|
|
recordInstore.MaterialName = bindingRecord.BoxName;
|
|
|
|
|
|
|
|
|
|
return _baseSpaceInfoServices.Query(s => s.MaterialType.Equals(bindingRecord.BoxCode.Substring(7, 10)) &&s.StoreCode.Equals(storeCode));
|
|
|
|
|
return _baseSpaceInfoServices.Query(s => s.MaterialType.Equals(bindingRecord.BoxCode.Substring(7, 10)) && (s.StoreCode.Equals(storeCodeA) || s.StoreCode.Equals(storeCodeB)) ).OrderBy(x=>x.ObjId).ToList();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
@ -183,11 +179,29 @@ namespace Aucma.Core.Palletiz.Business
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private BaseSpaceInfo FilterSpace(List<BaseSpaceInfo> spaceInfos)
|
|
|
|
|
{
|
|
|
|
|
if (spaceInfos.Count == 1 || string.IsNullOrEmpty(spaceInfos[0].LastSpace))
|
|
|
|
|
{
|
|
|
|
|
return spaceInfos[0];
|
|
|
|
|
}
|
|
|
|
|
List<BaseSpaceInfo> spaceList = spaceInfos.Where(s=>s.ObjId> int.Parse(spaceInfos[0].LastSpace)).ToList();
|
|
|
|
|
if(spaceList==null|| spaceList.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return spaceInfos[0];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return spaceList[0];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 大产品占据两条货道,根据一条货道找到另一条货道
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="spaceInfo"></param>
|
|
|
|
|
private string getOtherSpace(BaseSpaceInfo spaceInfo)
|
|
|
|
|
private BaseSpaceInfo getOtherSpace(BaseSpaceInfo spaceInfo,List<BaseSpaceInfo> spaceList)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// 找到当前货道匹配的另一条货道
|
|
|
|
|
int num = int.Parse(spaceInfo.SpaceCode.Substring(5, 3));
|
|
|
|
@ -200,9 +214,55 @@ namespace Aucma.Core.Palletiz.Business
|
|
|
|
|
{
|
|
|
|
|
otherSpaceCode = spaceInfo.SpaceCode.Substring(0, 5) + (num + 1).ToString("D3");
|
|
|
|
|
}
|
|
|
|
|
return otherSpaceCode;
|
|
|
|
|
spaceList = spaceList.Where(s => s.SpaceCode.Equals(otherSpaceCode)).ToList();
|
|
|
|
|
if (spaceList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
return spaceList[0];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error(ex.Message.ToString());
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 判断货道编号是否为奇数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="space"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private bool isOddNumber(BaseSpaceInfo space)
|
|
|
|
|
{
|
|
|
|
|
int num = int.Parse(space.SpaceCode.Substring(5, 3));
|
|
|
|
|
if(num % 2 == 0)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 将该物料的所有货道列表的last修改为上次入库货道objId
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="objId"></param>
|
|
|
|
|
/// <param name="spaceList"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private bool updateSapceList(int objId,List<BaseSpaceInfo> spaceList)
|
|
|
|
|
{
|
|
|
|
|
foreach(BaseSpaceInfo space in spaceList)
|
|
|
|
|
{
|
|
|
|
|
space.LastSpace = objId.ToString();
|
|
|
|
|
}
|
|
|
|
|
return _baseSpaceInfoServices.UpdateAsync(spaceList).Result;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region plc信号下发
|
|
|
|
|