using iWareCc.Cache.Entity;
|
using iWareCc.Conveyor.Entity;
|
using iWareCc.DecomposeTask.Entity;
|
using iWareCc.Properties;
|
using iWareCommon.Common.Entity;
|
using iWareCommon.Common.EnumType;
|
using iWareCommon.Utils;
|
using iWareDataCore.BASE.EnumType;
|
using iWareDataCore.ORM;
|
using iWareDataCore.TASK.Dao;
|
using iWareDataCore.TASK.EnumType;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace iWareCc.FinishConveyorTask.Chain
|
{
|
public class 查看物料是否到输送机末端: IHandler
|
{
|
/// <summary>
|
/// 该节点的下一个节点
|
/// </summary>
|
private IHandler nextHandler = null;
|
public IHandler NextHandler
|
{
|
set { nextHandler = value; }
|
}
|
|
private ConveyorEntity Conveyor;
|
|
/// <summary>
|
/// 任务容器
|
/// </summary>
|
private PartTaskContainer DecompositionTaskContainer;
|
|
|
public 查看物料是否到输送机末端(ConveyorEntity conveyor, PartTaskContainer decompositionTaskContainer)
|
{
|
this.Conveyor = conveyor;
|
this.DecompositionTaskContainer = decompositionTaskContainer;
|
}
|
|
|
public void Handle()
|
{
|
using (var dbModel = new DbModelCore())
|
{
|
try
|
{
|
var task = DecompositionTaskContainer.PartTask;
|
var gate = Conveyor.Gates.FirstOrDefault(y => y.Place.Id == task.ToPlaceId);
|
var gatesource = Conveyor.Gates.FirstOrDefault(y => y.Place.Id == task.SourcePlaceId);
|
gatesource.TaskId = "";
|
|
if (gate.Place.PlaceTypeName!="gate12")
|
{
|
if (gate == null || !gate.ROccupied)
|
{
|
LogTextHelper.WriteLine(Resources.LogDir + @"/完成输送机任务/" + Conveyor.Equipment.EquipName, "查看托盘是否到输送机末端:{0}", "端口未到位");
|
return;
|
}
|
}
|
if (gate.RIsEmpty)
|
{
|
LogTextHelper.WriteLine(Resources.LogDir + @"/完成输送机任务/" + Conveyor.Equipment.EquipName, "查看托盘是否到输送机末端:{0}", "未检测到有钢材");
|
return;
|
}
|
task.IsFinished = (int)EYesOrNo.是;
|
task.Status = (int)EPartTaskStatus.已完成;
|
task.UpdateTime = DateTime.Now;
|
task.IsCurrent = (int)EYesOrNo.否;
|
|
LogTextHelper.WriteLine(Resources.LogDir + @"/完成输送机任务/" + Conveyor.Equipment.EquipName, "查看托盘是否到输送机末端:{0}", task.Id.ToString());
|
var placeMaterialViews = dbModel.BASEPlaceMaterialViews.FirstOrDefault(y => y.placeid == task.SourcePlaceId && y.materialcode == task.MaterialCode);
|
var sourcePlace = dbModel.BASEPlaces.FirstOrDefault(x => x.id == task.SourcePlaceId);
|
var toPlace = dbModel.BASEPlaces.FirstOrDefault(x => x.id == task.ToPlaceId);
|
sourcePlace.isexecute = (int)EYesOrNo.否;
|
sourcePlace.status = (int)EPlaceStatus.空库位;
|
sourcePlace.islock = (int)EYesOrNo.否;
|
toPlace.isexecute = (int)EYesOrNo.否;
|
toPlace.islock = (int)EYesOrNo.否;
|
toPlace.status = (int)EPlaceStatus.空库位;
|
BASEPlaceMaterial pm = new BASEPlaceMaterial();
|
if (task.MainTaskType == (int)EMainTaskType.出库任务)//出库任务
|
{
|
if (placeMaterialViews != null)
|
{
|
pm = dbModel.BASEPlaceMaterials.FirstOrDefault(x => x.placeid == placeMaterialViews.placeid && x.materialid == placeMaterialViews.materialid);
|
}
|
if (pm.id>0)
|
{
|
dbModel.BASEPlaceMaterials.Remove(pm);
|
}
|
if (gate.Place.PlaceTypeName == "gate22")//端口有货才发送退库任务
|
{
|
if (!gate.RIsEmpty && gate.ROccupied)//gate21已经发送了滚动任务并且已经到了gate22
|
{
|
if (!gate.SendGateTask()) //如果发送失败,则发送失败
|
{
|
gate.SendGateTask();
|
}
|
}
|
}
|
}
|
else//入库任务
|
{
|
if (placeMaterialViews != null)
|
{
|
pm = dbModel.BASEPlaceMaterials.FirstOrDefault(x => x.placeid == placeMaterialViews.placeid && x.materialid == placeMaterialViews.materialid);
|
pm.placeid = task.ToPlaceId;
|
pm.updatetime = DateTime.Now;
|
|
}else
|
{
|
var material = dbModel.BASEMaterialViews.FirstOrDefault(y => y.code == task.MaterialCode);
|
pm = new BASEPlaceMaterial()
|
{
|
placeid=task.ToPlaceId,
|
materialid = material.id,
|
createtime=DateTime.Now,
|
updatetime = DateTime.Now,
|
};
|
dbModel.BASEPlaceMaterials.Add(pm);
|
}
|
}
|
|
PartTaskDao.GetInstance().Update(task, dbModel);
|
LogTextHelper.WriteLine(Resources.LogDir + @"/完成输送机任务/" + Conveyor.Equipment.EquipName, "查看托盘是否到输送机末端:{0}", "任务完成");
|
|
if (nextHandler != null)
|
{
|
nextHandler.Handle();
|
}
|
}
|
catch (Exception ex)
|
{
|
LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "Handle", ex.Message);
|
}
|
}
|
}
|
}
|
}
|