180 lines
8.7 KiB
C#
180 lines
8.7 KiB
C#
using WcsMain.Business.Convey.HistoryDataHandler.HisGetData.I;
|
||
using WcsMain.Common;
|
||
using WcsMain.DataBase.Dao;
|
||
using WcsMain.DataBase.TableEntity;
|
||
using WcsMain.DataService;
|
||
using WcsMain.Enum.Convey;
|
||
using WcsMain.EquipOperation.Convey;
|
||
using WcsMain.EquipOperation.Entity;
|
||
using WcsMain.ExtendMethod;
|
||
|
||
namespace WcsMain.Business.Convey.HistoryDataHandler.HisGetData;
|
||
|
||
/// <summary>
|
||
/// 出库分流扫码器 C1
|
||
/// </summary>
|
||
/// <remarks>
|
||
/// 有异常的或者只有 6789站台拣选的去往二层
|
||
/// </remarks>
|
||
public class StackerOutC1(ConveyOperation conveyOperation, DataBaseData dataBaseData, AppConveyTaskDao conveyTaskDao) : IBaseGetData
|
||
{
|
||
/// <summary>
|
||
/// 读码失败
|
||
/// </summary>
|
||
/// <param name="disPlayName"></param>
|
||
/// <param name="msg"></param>
|
||
/// <param name="area"></param>
|
||
/// <param name="routerMethodData"></param>
|
||
public void ReadFail(string? disPlayName, string msg, string? area, AppRouterMethod routerMethodData)
|
||
{
|
||
int plcId = dataBaseData.GetNewPlcTaskId() ?? StaticData.StaticInt.ErrPlcId;
|
||
ConveyPLCTask plcTask = new(plcId, (short)ConveyRouterEnum.Move);
|
||
string errText = conveyOperation.WriteTask(area, plcTask);
|
||
if (string.IsNullOrEmpty(errText))
|
||
{
|
||
ConsoleLog.Warning($"出库分流:{area} 读码失败,写入PLC成功,{plcTask}");
|
||
return;
|
||
}
|
||
ConsoleLog.Warning($"【警告】出库分流:{area} 读码失败,写入PLC失败,{plcTask},信息:{errText}");
|
||
return;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 读码成功
|
||
/// </summary>
|
||
/// <param name="disPlayName"></param>
|
||
/// <param name="msg"></param>
|
||
/// <param name="area"></param>
|
||
/// <param name="routerMethodData"></param>
|
||
public void ReadSuccess(string? disPlayName, string msg, string? area, AppRouterMethod routerMethodData)
|
||
{
|
||
int plcId = dataBaseData.GetNewPlcTaskId() ?? StaticData.StaticInt.ErrPlcId; // 获取一个 plcId
|
||
/* 判断条码有没有拣选任务 */
|
||
List<AppConveyTask>? conveyTasks = conveyTaskDao.Query(new AppConveyTask { VehicleNo = msg, TaskStatus = (int)ConveyTaskStatusEnum.create });
|
||
if(conveyTasks == default)
|
||
{
|
||
ConsoleLog.Warning($"【警告】出库分流:{area} 箱码:{msg} 查询任务失败,和服务器连接中断");
|
||
ConveyPLCTask plcTask = new(plcId, (short)ConveyRouterEnum.Go); // 连接中断去往拣选站台
|
||
string errText = conveyOperation.WriteTask(area, plcTask);
|
||
if (string.IsNullOrEmpty(errText))
|
||
{
|
||
ConsoleLog.Success($"出库分流:{area} 箱码:{msg},写入PLC成功,{plcTask}");
|
||
return;
|
||
}
|
||
ConsoleLog.Warning($"【警告】出库分流:{area} 箱码:{msg},写入PLC失败,{plcTask},信息:{errText}");
|
||
return;
|
||
}
|
||
if(conveyTasks.Count < 1)
|
||
{
|
||
ConsoleLog.Warning($"【警告】出库分流:{area} 箱码:{msg} 无拣选任务");
|
||
ConveyPLCTask plcTask = new(plcId, (short)ConveyRouterEnum.Move);
|
||
string errText = conveyOperation.WriteTask(area, plcTask);
|
||
if (string.IsNullOrEmpty(errText))
|
||
{
|
||
ConsoleLog.Success($"出库分流:{area} 箱码:{msg},写入PLC成功,{plcTask}");
|
||
return;
|
||
}
|
||
ConsoleLog.Warning($"【警告】出库分流:{area} 箱码:{msg},写入PLC失败,{plcTask},信息:{errText}");
|
||
return;
|
||
}
|
||
|
||
(bool isHavePick1, bool isHavePick2) = (false, false); // 默认都不含有任务
|
||
// 检验是否存在 pick1 区域的任务
|
||
List<AppConveyStand> pick1Stand = CommonData.AppConveyStands.FindAll(f => f.StandType == (int)ConveyStandTypeEnum.pick && f.Area == "pick1");
|
||
List<string?> pick1Stands = pick1Stand.Select(f => f.StandId).ToList();
|
||
foreach (var conveyTask in conveyTasks)
|
||
{
|
||
if (pick1Stands.Contains(conveyTask.Location))
|
||
{
|
||
isHavePick1 = true;
|
||
break;
|
||
}
|
||
}
|
||
// 校验是否含有 pick2区域的任务
|
||
List<AppConveyStand> pick2Stand = CommonData.AppConveyStands.FindAll(f => f.StandType == (int)ConveyStandTypeEnum.pick && f.Area == "pick2");
|
||
List<string?> pick2Stands = pick2Stand.Select(f => f.StandId).ToList();
|
||
foreach (var conveyTask in conveyTasks)
|
||
{
|
||
if (pick2Stands.Contains(conveyTask.Location))
|
||
{
|
||
isHavePick2 = true;
|
||
break;
|
||
}
|
||
}
|
||
if (isHavePick1 && !isHavePick2) // 存在该区域任务 1~5 站台(pick1 区域),不存在 pick2 区域任务
|
||
{
|
||
ConsoleLog.Info($"出库分流:{area} 箱码:{msg} 存在 1~5 站台任务");
|
||
ConveyPLCTask plcTask = new(plcId, (short)ConveyRouterEnum.Go);
|
||
string errText = conveyOperation.WriteTask(area, plcTask);
|
||
if (string.IsNullOrEmpty(errText))
|
||
{
|
||
ConsoleLog.Success($"出库分流:{area} 箱码:{msg},写入PLC成功,{plcTask}");
|
||
return;
|
||
}
|
||
ConsoleLog.Warning($"【警告】出库分流:{area} 箱码:{msg},写入PLC失败,{plcTask},信息:{errText}");
|
||
return;
|
||
}
|
||
else if (!isHavePick1 && isHavePick2) // 不存在该区域pick1任务,存在 pick2 区域任务
|
||
{
|
||
ConsoleLog.Info($"出库分流:{area} 箱码:{msg} 不存在 1~5 站台任务");
|
||
ConveyPLCTask plcTask = new(plcId, (short)ConveyRouterEnum.Move);
|
||
string errText = conveyOperation.WriteTask(area, plcTask);
|
||
if (string.IsNullOrEmpty(errText))
|
||
{
|
||
ConsoleLog.Success($"出库分流:{area} 箱码:{msg},写入PLC成功,{plcTask}");
|
||
return;
|
||
}
|
||
ConsoleLog.Warning($"【警告】出库分流:{area} 箱码:{msg},写入PLC失败,{plcTask},信息:{errText}");
|
||
return;
|
||
}
|
||
else // 两个地区都存在任务
|
||
{
|
||
// 比对两个区的箱子数量
|
||
var readResult_1 = CommonTool.Siemens.ReadInt16WithName($"数量1");
|
||
var readResult_2 = CommonTool.Siemens.ReadInt16WithName($"数量2");
|
||
ConsoleLog.Info($"前区箱子数量{readResult_1.Value},后区箱子数量{readResult_2.Value}");
|
||
if (readResult_1.Value >= readResult_2.Value)//前区数量多去后区
|
||
{
|
||
ConsoleLog.Info($"出库分流:{area} 箱码:{msg} 存在 1~5 站台任务且存在 6~9 区域任务");
|
||
ConveyPLCTask plcTask = new(plcId, (short)ConveyRouterEnum.Move);
|
||
string errText = conveyOperation.WriteTask(area, plcTask);
|
||
if (string.IsNullOrEmpty(errText))
|
||
{
|
||
ConsoleLog.Success($"出库分流:{area} 箱码:{msg},写入PLC成功,{plcTask}");
|
||
return;
|
||
}
|
||
ConsoleLog.Warning($"【警告】出库分流:{area} 箱码:{msg},写入PLC失败,{plcTask},信息:{errText}");
|
||
return ;
|
||
}
|
||
else//后区数量多去前区
|
||
{
|
||
ConsoleLog.Info($"出库分流:{area} 箱码:{msg} 存在 1~5 站台任务且存在 6~9 区域任务");
|
||
ConveyPLCTask plcTask = new(plcId, (short)ConveyRouterEnum.Go);
|
||
string errText = conveyOperation.WriteTask(area, plcTask);
|
||
if (string.IsNullOrEmpty(errText))
|
||
{
|
||
ConsoleLog.Success($"出库分流:{area} 箱码:{msg},写入PLC成功,{plcTask}");
|
||
return;
|
||
}
|
||
ConsoleLog.Warning($"【警告】出库分流:{area} 箱码:{msg},写入PLC失败,{plcTask},信息:{errText}");
|
||
return;
|
||
}
|
||
|
||
|
||
//ConsoleLog.Info($"出库分流:{area} 箱码:{msg} 存在 1~5 站台任务且存在 6~9 区域任务");
|
||
//Random random = new();
|
||
//var id = random.Next(0, 100);
|
||
//ConveyPLCTask plcTask = new(plcId, id < Convert.ToInt32(CommonData.AppConfig.Pick2Lv) ? (short)ConveyRouterEnum.Move : (short)ConveyRouterEnum.Go);
|
||
//string errText = conveyOperation.WriteTask(area, plcTask);
|
||
//if (string.IsNullOrEmpty(errText))
|
||
//{
|
||
// ConsoleLog.Success($"出库分流:{area} 箱码:{msg},写入PLC成功,{plcTask}");
|
||
// return;
|
||
//}
|
||
//ConsoleLog.Warning($"【警告】出库分流:{area} 箱码:{msg},写入PLC失败,{plcTask},信息:{errText}");
|
||
//return;
|
||
|
||
}
|
||
}
|
||
}
|