using iWareCc.Cache.Entity;
|
using iWareCc.DecomposeTask.Entity;
|
using iWareCc.Properties;
|
using iWareCc.Srm.Entity;
|
using iWareCommon.Common.Entity;
|
using iWareCommon.Common.EnumType;
|
using iWareCommon.Utils;
|
using iWareDataCore.BASE.EnumType;
|
using iWareDataCore.ORM;
|
using iWareDataCore.TASK.EnumType;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace iWareCc.DoStackerTaskAuto.Chain
|
{
|
public class 发送堆垛机任务 : IHandler
|
{
|
/// <summary>
|
/// 该节点的下一个节点
|
/// </summary>
|
private IHandler nextHandler = null;
|
public IHandler NextHandler
|
{
|
set { nextHandler = value; }
|
}
|
|
|
/// <summary>
|
/// 任务容器
|
/// </summary>
|
private PartTaskContainer DecompositionTaskContainer;
|
|
/// <summary>
|
/// 需要执行任务的堆垛机
|
/// </summary>
|
private StackerEntity Stacker;
|
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
/// <param name="resultContainer">结果容器</param>
|
/// <param name="decompositionTaskContainer">WIP任务容器</param>
|
public 发送堆垛机任务(StackerEntity stacker, PartTaskContainer decompositionTaskContainer)
|
{
|
this.Stacker = stacker;
|
this.DecompositionTaskContainer = decompositionTaskContainer;
|
}
|
|
public void Handle()
|
{
|
using (var dbModel = new DbModelCore())
|
{
|
try
|
{
|
var task = DecompositionTaskContainer.PartTask;
|
|
var dTask = dbModel.TASKPartTasks.FirstOrDefault(x => x.id == task.Id);
|
if (dTask.maintasktype != 4)//不是仅移动任务的任务需要判断物料库位,其余不用
|
{
|
var placeMaterial = dbModel.BASEPlaceMaterialViews.FirstOrDefault(x => x.materialcode == dTask.materialcode && x.placeid == dTask.sourceplaceid);
|
|
if (placeMaterial == null)
|
{
|
LogTextHelper.WriteLine(Resources.LogDir + @"/自动执行堆垛机任务流程/" + Stacker.Equipment.EquipName, "发送堆垛机任务:{0},{1}", task.Id, "未找到指定的物料的库位信息");
|
return;
|
}
|
placeMaterial.updatetime = DateTime.Now;
|
}
|
var toPlace = dbModel.BASEPlaces.FirstOrDefault(x => x.id == dTask.toplaceid);
|
|
if (toPlace == null)
|
{
|
LogTextHelper.WriteLine(Resources.LogDir + @"/自动执行堆垛机任务流程/" + Stacker.Equipment.EquipName, "发送堆垛机任务:{0},{1}", task.Id, "未找到指定的目标库位");
|
return;
|
}
|
|
int SourcePosx = task.SourcePosx;
|
int SourcePosy = task.SourcePosy;
|
int SourcePosz = task.SourcePosz;
|
|
if (task.SourcePlace == "100105")//入库口
|
{
|
SourcePosx = 801;
|
SourcePosy = 0;
|
SourcePosz = 0;
|
}
|
else
|
{
|
if (SourcePosz % 2 == 0)
|
{
|
SourcePosz = 1;
|
}
|
else
|
{
|
SourcePosz = 2;
|
}
|
}
|
|
int ToPosx = task.ToPosx;
|
int ToPosy = task.ToPosy;
|
int ToPosz = task.ToPosz;
|
if (task.ToPlace == "100201")
|
{
|
ToPosx = 901;
|
ToPosy = 0;
|
ToPosz = 0;
|
}
|
else
|
{
|
if (ToPosz % 2 == 0)
|
{
|
ToPosz = 1;
|
}
|
else
|
{
|
ToPosz = 2;
|
}
|
}
|
int lots = task.IsLots;
|
if (CacheEntity.IsLots && task.MainTaskType == (int)EMainTaskType.入库任务)//如果设置批次入库按钮也是可以执行的
|
{
|
lots = 1;
|
}
|
|
string stackerCnName = Enum.GetName(typeof(iWareDataCore.DEV.EnumType.EEquipmentCnName), iWareDataCore.DEV.EnumType.EEquipmentCnName.stacker1);
|
var flag = Stacker.SendTask(task.Id, Stacker.Equipment.EquipName == stackerCnName ? 1 : 2, SourcePosx, SourcePosy, SourcePosz, ToPosx, ToPosy, ToPosz, task.MainTaskType, lots);//x列,y层,z排
|
|
if (flag)
|
{
|
dTask.isreleased = (int)EYesOrNo.是;
|
dTask.status = (int)EPartTaskStatus.执行中;
|
dTask.iscurrent = (int)EYesOrNo.是;
|
dTask.updatetime = DateTime.Now;
|
if (task.MainTaskType != 4)
|
{
|
toPlace.isexecute = (int)EYesOrNo.是;
|
toPlace.islock = (int)EYesOrNo.是;
|
toPlace.status = (int)EPlaceStatus.执行中;
|
}
|
|
dbModel.SaveChanges();
|
LogTextHelper.WriteLine(Resources.LogDir + @"/自动执行堆垛机任务流程/" + Stacker.Equipment.EquipName, "发送堆垛机机任务:{0},{1},{2}", task.Id, flag, lots);
|
}
|
else
|
{
|
LogTextHelper.WriteLine(Resources.LogDir + @"/自动执行堆垛机任务流程/" + Stacker.Equipment.EquipName, "发送堆垛机机任务:{0},{1},{2}", task.Id, flag, lots);
|
return;
|
}
|
|
|
if (nextHandler != null)
|
{
|
nextHandler.Handle();
|
}
|
}
|
catch (Exception ex)
|
{
|
LogTextHelper.WriteLine(Resources.LogDir + @"/自动执行堆垛机任务流程/" + Stacker.Equipment.EquipName, "发送堆垛机机任务:{0}", ex.Message);
|
LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "Handle", ex.Message);
|
}
|
}
|
}
|
}
|
}
|