using iWareCc.Conveyor.Entity;
|
using iWareCc.Conveyor.EnumType;
|
using iWareCc.DecomposeTask.Entity;
|
using iWareCcTest.Properties;
|
using iWareCommon.Common.Entity;
|
using iWareCommon.Common.EnumType;
|
using iWareCommon.Utils;
|
using iWareDataCore.BASE.EnumType;
|
using iWareDataCore.ORM;
|
using iWareDataCore.TASK.Entity;
|
using iWareDataCore.TASK.EnumType;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace iWareCc.CreateMainTask.chain
|
{
|
public class 根据扫码生成入库主任务: IHandler
|
{
|
/// <summary>
|
/// 该节点的下一个节点
|
/// </summary>
|
private IHandler nextHandler = null;
|
public IHandler NextHandler
|
{
|
set { nextHandler = value; }
|
}
|
|
private ConveyorEntity Conveyor;
|
|
private MainTaskContainer MainTaskContainer;
|
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
/// <param name="resultContainer">结果容器</param>
|
/// <param name="decompositionTaskContainer">WIP任务容器</param>
|
public 根据扫码生成入库主任务(ConveyorEntity c, MainTaskContainer mainTaskContainer)
|
{
|
this.Conveyor = c;
|
this.MainTaskContainer = mainTaskContainer;
|
}
|
|
|
public void Handle()
|
{
|
|
using (var dbModel = new DbModelCore())
|
{
|
try
|
{
|
var alarm = Conveyor.Gates.Find(x => x.Place.PlaceTypeName == "alarm");
|
var sc = Conveyor.Gates.Find(x => x.Place.PlaceTypeName == "sc");
|
if (sc != null && !string.IsNullOrEmpty(sc.RCheckMaterialCode) && !string.IsNullOrWhiteSpace(sc.RCheckMaterialCode) && !sc.RCheckMaterialCode.Contains("ERROR"))
|
{
|
var material = dbModel.BASEMaterialViews.FirstOrDefault(x => x.code == sc.RCheckMaterialCode.Trim());
|
//判断物料是否入库,如果入库直接发送入库任务,不入库生成退库记录
|
if (material != null)
|
{
|
var placematerial = dbModel.BASEPlaceMaterialViews.FirstOrDefault(x => x.materialcode == sc.RCheckMaterialCode.Trim());
|
if (placematerial != null)
|
{
|
|
// alarm.SendGateAlarmTask((int)ESendCode.已在立库中不能入库);
|
LogTextHelper.WriteLine(Resources.LogDir + @"/自动生成入库主任务流程", "物料号:{0}", sc.RCheckMaterialCode + "已在立库中");
|
sc.RCheckMaterialCode = "";
|
return;
|
}
|
var tasknew = dbModel.TASKPartTasks.FirstOrDefault(x => x.type == (int)EPartTaskType.输送机任务 && x.isreleased == (int)EYesOrNo.否 && x.isfinished == (int)EYesOrNo.否 && x.materialcode == material.code && x.maintasktype == (int)EMainTaskType.入库任务);
|
if (tasknew != null)
|
{
|
// LogTextHelper.WriteLine(Resources.LogDir + @"/自动生成主任务流程", "物料号:{0}", sc.RCheckMaterialCode + "已在要执行的任务序列中");
|
return;
|
}
|
var emptyPlace = dbModel.BASEEmptyPlaceViews.Where(x => x.isexecute == (int)EYesOrNo.否 && x.islock == (int)EYesOrNo.否 && x.typeid == 4 && x.status == (int)EPlaceStatus.空库位).OrderBy(x => new { x.layer, x.col }).FirstOrDefault();
|
if (emptyPlace == null)
|
{
|
alarm.SendGateAlarmTask((int)ESendCode.入库库位不足);
|
LogTextHelper.WriteLine(Resources.LogDir + @"/自动生成入库主任务流程", "寻找空库位:{0}", "空库位不足");
|
return;
|
}
|
|
var task = dbModel.TASKMainTasks.FirstOrDefault(x => x.materialcode == sc.RCheckMaterialCode.Trim() && x.tasktype == (int)EMainTaskType.入库任务);
|
if (task != null)
|
{
|
//alarm.SendGateAlarmTask((int)ESendCode.已存在该任务);
|
LogTextHelper.WriteLine(Resources.LogDir + @"/自动生成入库主任务流程", "物料号:{0}", "该任务已存在");
|
return;
|
}
|
int materialid = material.id;
|
var inoutlistdetail = dbModel.BASEInOutListDetails.FirstOrDefault(x => x.materialid == materialid && x.isfinish != 1);
|
if (inoutlistdetail == null)
|
{
|
alarm.SendGateAlarmTask((int)ESendCode.物料不在入库清单中);
|
LogTextHelper.WriteLine(Resources.LogDir + @"/自动生成入库主任务流程", "物料号:{0}", "不在入库清单中");
|
sc.RCheckMaterialCode = "";
|
return;
|
}
|
TASKMainTask matask = new TASKMainTask()
|
{
|
taskno = DateTime.Now.ToFileTime().ToString(),
|
tasktype = (int)EMainTaskType.入库任务,
|
materialcode = sc.RCheckMaterialCode,
|
syscode = "1",
|
sendtime = DateTime.Now,
|
sourceplace = "100101",
|
toplace = emptyPlace.code,
|
packageno = "",
|
processcardnumber = "",
|
quantity = 1,
|
status = 0,
|
decompositiontime = DateTime.Now,
|
wipstatus = 0,
|
decompositiontimes = 0,
|
islots = 0,
|
priority = 0,
|
|
};
|
MainTaskContainer.MainTask = new MainTaskEntity(matask);
|
}
|
else
|
{
|
alarm.SendGateAlarmTask((int)ESendCode.物料不存在);
|
LogTextHelper.WriteLine(Resources.LogDir + @"/自动生成入库主任务流程", "物料号:{0}", sc.RCheckMaterialCode + "不存在此物料");
|
sc.RCheckMaterialCode = "";
|
return;
|
}
|
|
if (nextHandler != null)
|
{
|
nextHandler.Handle();
|
}
|
}
|
else
|
{
|
LogTextHelper.WriteLine(Resources.LogDir + @"/自动生成入库主任务流程", "未检测到有扫码信息");
|
return;
|
}
|
|
}
|
catch (Exception ex)
|
{
|
LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "Handle", ex.Message);
|
}
|
}
|
|
|
}
|
}
|
}
|