using IWareCC.CacheInfo;
|
using IWareCC.CacheInfo.Container;
|
using IWareCC.ORM;
|
using IWareCC.Properties;
|
using IWareCC.SRM.Entity;
|
using IWareCommon.Enum.Common;
|
using IWareCommon.Enum.Conveyor;
|
using IWareCommon.Help;
|
using IWareCommon.Util;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace IWareCC.SRM.Handle.DoStackerTaskAuto
|
{
|
public class 选择一个未执行的堆垛机的任务 : IHandler
|
{
|
/// <summary>
|
/// 该节点的下一个节点
|
/// </summary>
|
private IHandler nextHandler = null;
|
public IHandler NextHandler
|
{
|
set { nextHandler = value; }
|
}
|
|
private SrmEntity Stacker;
|
|
/// <summary>
|
/// 任务容器
|
/// </summary>
|
private PartTaskContainer DecompositionTaskContainer;
|
|
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
/// <param name="resultContainer">结果容器</param>
|
/// <param name="decompositionTaskContainer">WIP任务容器</param>
|
public 选择一个未执行的堆垛机的任务(PartTaskContainer decompositionTaskContainer)
|
{
|
|
this.DecompositionTaskContainer = decompositionTaskContainer;
|
}
|
|
|
public void Handle()
|
{
|
|
using (var dbModel = new DbModel())
|
{
|
try
|
{
|
string msg;
|
var task = dbModel.PartTasks.OrderBy(x => x.priority).ThenBy(x => x.updatetime).FirstOrDefault(x => x.eqtype == (int)EPartTaskType.堆垛机任务 && x.isreleased == (int)EYesOrNo.否 && x.isfinished == (int)EYesOrNo.否);
|
|
if (task == null)
|
{
|
// LogTextHelper.WriteLine(Resources.LogDir + @"/自动执行堆垛机任务流程/", "选择一个未执行的堆垛机的任务:{0}", "未找到相应的堆垛机任务");
|
return;
|
}
|
int tdevid = (int)((EDeviceId)task.eqid);
|
var srm = CacheEntity.Srms.FirstOrDefault(x => x.DeviceId == tdevid);
|
Stacker = srm;
|
task.updatetime = DateTime.Now;
|
dbModel.SaveChanges();
|
|
if (!Stacker.CanSendTask(Stacker.RSrmNo, out msg))
|
{
|
LogTextHelper.WriteLine(Resources.LogDir + @"/自动执行堆垛机任务流程/" + Stacker.SrmName, "选择一个未执行的堆垛机的任务:堆垛机{0}不能执行任务--{1}", Stacker.SrmName, msg);
|
if (task.filereason != msg)
|
{
|
task.filereason = msg;
|
dbModel.SaveChanges();
|
}
|
return;
|
}
|
|
#region 判定出库口是否有货
|
string name = "";
|
if (task.maintasktype == (int)EMainTaskType.组盘出库 || task.maintasktype == (int)EMainTaskType.空托出库)
|
{
|
if (task.storageno == (int)EStorageno.大盘库)
|
{
|
|
name = "Line" + "1032";
|
}
|
else
|
{
|
|
name = "Line" + "1030";
|
}
|
}
|
if (task.maintasktype == (int)EMainTaskType.常规出库)
|
{
|
if (task.storageno == (int)EStorageno.大盘库)
|
{
|
|
name = "Line" + "1013";
|
}
|
else
|
{
|
|
name = "Line" + "1015";
|
}
|
}
|
if (!string.IsNullOrEmpty(name))
|
{
|
var conveyor = CacheEntity.Conveyors.FirstOrDefault(x => x.ConveyorName == name);
|
|
if (conveyor == null)
|
{
|
LogTextHelper.WriteLine(Resources.LogDir + @"/自动执行堆垛机任务流程/" + conveyor.ConveyorName, "选择一个未执行的堆垛机的任务:{0}", "PLC通信中断");
|
msg = "PLC通信中断";
|
if (task.filereason != msg)
|
{
|
task.filereason = msg;
|
dbModel.SaveChanges();
|
}
|
return;
|
}
|
|
if (conveyor.RState != (int)EConveyorState.空闲)
|
{
|
LogTextHelper.WriteLine(Resources.LogDir + @"/自动执行堆垛机任务流程/" + conveyor.ConveyorName, "选择一个未执行的堆垛机的任务:{0}", "输送线状态不为空闲");
|
msg = "输送线状态不为空闲";
|
if (task.filereason != msg)
|
{
|
task.filereason = msg;
|
dbModel.SaveChanges();
|
}
|
return;
|
}
|
|
if (!( conveyor.RPh1 == 2 && conveyor.RPh2 == 2 && conveyor.RPh3 == 2))
|
{
|
LogTextHelper.WriteLine(Resources.LogDir + @"/自动执行堆垛机任务流程/" + conveyor.ConveyorName, "选择一个未执行的堆垛机的任务:{0}", "出库口光电检测有货");
|
msg = "出库口光电检测有货";
|
if (task.filereason != msg)
|
{
|
task.filereason = msg;
|
dbModel.SaveChanges();
|
}
|
return;
|
}
|
|
}
|
#endregion
|
var otherdotask = dbModel.PartTasks.OrderBy(x => x.priority).ThenBy(x => x.updatetime).FirstOrDefault(x => x.eqtype == (int)EPartTaskType.堆垛机任务 && x.isreleased == (int)EYesOrNo.是 && x.isfinished == (int)EYesOrNo.否 && x.eqid == Stacker.DeviceId);
|
if (otherdotask != null)
|
{
|
LogTextHelper.WriteLine(Resources.LogDir + @"/自动执行堆垛机任务流程/" + Stacker.SrmName, "选择一个未执行的堆垛机的任务:{0}", "请先确认当前堆垛机任务是否完成");
|
return;
|
}
|
|
DecompositionTaskContainer.DecompositionTask = task;
|
|
LogTextHelper.WriteLine(Resources.LogDir + @"/自动执行堆垛机任务流程/" + Stacker.SrmName, "选择一个未执行的堆垛机的任务:{0}", DecompositionTaskContainer.DecompositionTask.id);
|
|
if (nextHandler != null)
|
{
|
nextHandler.Handle();
|
}
|
|
}
|
catch (Exception ex)
|
{
|
LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "Handle", ex.Message);
|
}
|
}
|
|
|
}
|
}
|
}
|