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.DEV.EnumType;
|
using iWareDataCore.ORM;
|
using iWareDataCore.TASK.Dao;
|
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.FinishStackerTask.Chain
|
{
|
public class 将完成结果更新至数据库 : IHandler
|
{
|
/// <summary>
|
/// 该节点的下一个节点
|
/// </summary>
|
private IHandler nextHandler = null;
|
public IHandler NextHandler
|
{
|
set { nextHandler = value; }
|
}
|
|
private StackerEntity Stacker;
|
|
/// <summary>
|
/// 任务容器
|
/// </summary>
|
private PartTaskContainer DecompositionTaskContainer;
|
|
|
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 parttasklst=dbModel.TASKPartTasks.Where(x => x.isfinished == (int)EYesOrNo.否 && x.islots == 1).ToList();
|
if (parttasklst != null && parttasklst.Count>0)
|
{
|
if (parttasklst.Count == 1 && parttasklst[0].id == task.Id)//如果批次入的只剩下当前的任务则退出批次模式
|
{
|
CacheEntity.IsLots = false;
|
}
|
else
|
{
|
CacheEntity.IsLots = true;
|
}
|
}
|
|
task.IsFinished = (int)EYesOrNo.是;
|
task.Status = (int)EPartTaskStatus.已完成;
|
task.UpdateTime = DateTime.Now;
|
task.IsCurrent = (int)EYesOrNo.否;
|
///如果当前任务的排数在
|
if (task.IsLots==0&& !CacheEntity.IsLots)//不是批次
|
{
|
if (((task.ToPosx == 2 || task.ToPosx == 6) && task.ToPosy <= 7) || task.MainTaskType == (int)EMainTaskType.出库任务)
|
{
|
BASEPlace toplace = new BASEPlace();
|
BASEPlace sorplace = new BASEPlace();
|
int soueplaceid = task.ToPlaceId;
|
sorplace = dbModel.BASEPlaces.FirstOrDefault(x => x.id == soueplaceid);
|
if (task.ToPosx == 2)//2154
|
{
|
toplace = dbModel.BASEPlaces.FirstOrDefault(x => x.code == "21004");
|
}
|
else if (task.ToPosx == 6) //61512
|
{
|
|
toplace = dbModel.BASEPlaces.FirstOrDefault(x => x.code == "61012");
|
}
|
else
|
{
|
toplace = dbModel.BASEPlaces.FirstOrDefault(x => x.code == "21004");
|
|
sorplace = dbModel.BASEPlaces.FirstOrDefault(x => x.code == "20104");
|
}
|
string stackerName = Enum.GetName(typeof(EEquipmentCnName), EEquipmentCnName.stacker1);
|
var PartTask = new PartTaskEntity
|
{
|
Type = (int)EPartTaskType.堆垛机任务,
|
MainTaskId = -1,
|
MainTaskType = 4,//代表仅升高货叉,不实际放货的任务
|
TaskNo = DateTime.Now.ToFileTimeUtc().ToString(),
|
SysCode = "1",
|
ExecutionSequence = 1,
|
SourcePlace = sorplace.code,
|
SourcePlaceId = sorplace.id,
|
SourcePosx = sorplace.row,
|
SourcePosy = sorplace.layer,
|
SourcePosz = sorplace.col,
|
ToPlace = toplace.code,
|
ToPlaceId = toplace.id,
|
ToPosx = (int)toplace.row,
|
ToPosy = (int)toplace.layer,
|
ToPosz = (int)toplace.col,
|
Status = (int)EPartTaskStatus.未开始,
|
CreateTime = DateTime.Now,
|
UpdateTime = DateTime.Now,
|
EquipId = 1,
|
EquipName = stackerName,
|
TaskProcessStatus = (int)ESrmState.未知,
|
VoidLabel = (int)EYesOrNo.否,
|
Priority = 200,
|
IsMoveTask = (int)EYesOrNo.否,
|
ProcessCardNumber = "",
|
PackageNo = "",
|
MaterialCode ="",
|
Quantity = 1,
|
IsHandled=1
|
};
|
dbModel.TASKPartTasks.Add(PartTask.ToOrm());
|
}
|
}
|
if (task.MainTaskType!=4)
|
{
|
|
var fromPlace = dbModel.BASEPlaces.FirstOrDefault(y => y.id == task.SourcePlaceId);
|
|
if (fromPlace != null)
|
{
|
fromPlace.isexecute = (int)EYesOrNo.否;
|
fromPlace.islock = (int)EYesOrNo.否;
|
fromPlace.status = (int)EPlaceStatus.空库位;
|
}
|
|
var toPlace = dbModel.BASEPlaces.FirstOrDefault(y => y.id == task.ToPlaceId);
|
|
if (toPlace != null)
|
{
|
toPlace.isexecute = (int)EYesOrNo.否;
|
toPlace.islock = (int)EYesOrNo.否;
|
toPlace.status = (int)EPlaceStatus.有货;
|
}
|
|
var placeMaterialViews = dbModel.BASEPlaceMaterialViews.FirstOrDefault(y => y.placeid == task.SourcePlaceId && y.materialcode == task.MaterialCode);
|
|
if (placeMaterialViews != null)
|
{
|
var placeMaterial = dbModel.BASEPlaceMaterials.FirstOrDefault(x => x.placeid == placeMaterialViews.placeid && x.materialid == placeMaterialViews.materialid);
|
placeMaterial.placeid = task.ToPlaceId;
|
placeMaterial.updatetime = DateTime.Now;
|
}
|
}
|
|
PartTaskDao.GetInstance().Update(task, dbModel);
|
|
LogTextHelper.WriteLine(Resources.LogDir + @"/完成堆垛机任务/" + Stacker.Equipment.EquipName, "将完成结果更新至数据库:{0}", "保存成功");
|
|
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);
|
}
|
}
|
}
|
}
|
}
|