using iWareCC.Common.Helper;
|
using iWareCommon.Common.Globle;
|
using iWareCommon.Utils;
|
using iWareModel;
|
using iWareSql;
|
using iWareSql.DataAccess;
|
using iWareSql.DBModel;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading;
|
using System.Threading.Tasks;
|
using XiGang.Core.Model;
|
|
namespace iWareCC
|
{
|
/// <summary>
|
/// 任务分解线程-组盘入库
|
/// </summary>
|
public static class MainTaskDecompose_ZPRK
|
{
|
/// <summary>
|
/// 任务分解线程
|
/// </summary>
|
public static void HandlerMainTaskDecompose_ZPRK()
|
{
|
while (true)
|
{
|
Thread.Sleep(2000);//休眠2秒
|
try
|
{
|
SystemWarningMsg._lbl_Alert_MainTaskDecompose_ZPRK = "";
|
if (SystemValue.isAllowRuning_MainTaskDecompose_ZPRK && SystemValue.isStartedModel)
|
{
|
using (DbModel context = new DbModel())
|
{
|
#region 组盘入库的创建规则
|
//现在逻辑 【EditBy shaocx,2022-05-11】
|
var outStoreList = MyExtendHelper.GetHasCatogryStationCodeAreaList();
|
if (outStoreList == null || outStoreList.Count == 0)
|
{//四个出库口无货的情况下
|
Do组盘入库(context);
|
SystemWarningMsg._lbl_Alert_MainTaskDecompose_ZPRK = "四个出库口无货的情况下,创建组盘入库任务" + SysGloble.SPLIT_STR;
|
continue;
|
}
|
else
|
{//四个出库口有货
|
var isHasCatogry_1012 = MyExtendHelper.IsGD_HasCatogryForRgvStattion(((int)EDevice.出库口1012).ToString());
|
var isHasCatogry_1013 = MyExtendHelper.IsGD_HasCatogryForRgvStattion(((int)EDevice.出库口1013).ToString());//[EditBy shaocx,2022-05-18]
|
if (isHasCatogry_1012 && isHasCatogry_1013)
|
{
|
Do组盘入库(context);
|
SystemWarningMsg._lbl_Alert_MainTaskDecompose_ZPRK = "四个出库口有货,1012和1013都显示有货,创建组盘入库任务" + SysGloble.SPLIT_STR;
|
continue;
|
}
|
else
|
{//四个出库口有货,1012无货,增加这种情况, 但如果此时rgv要送的出库发动机还没到输送线上,就可以先执行组盘入库任务
|
var q_taskType_出库 = (int)DeviceTaskTypeEnum.出库;
|
int int_deviceId = (int)EDevice.RGV;
|
//注意:出库任务下发就不要以CreateTime了,而是按照MainTaskSequence,因为在出库任务分解的时候,会出现那种 【EditBy shaocx,2022-05-19】
|
// 二号堆垛机、二号堆垛机、三号堆垛机出库情况,如果按照CreateTime,排序会变为 二号堆垛机、三号堆垛机、二号堆垛机
|
//var _partTask = rgvOutTaskList_出库.OrderBy(x => x.CreateTime).First();
|
//var fisrtTask = context.Task_Part.Where(x => x.DeviceId == int_deviceId && x.TaskState == (int)DeviceTaskStatusEnum.未开始 && x.TaskType == q_taskType_出库).ToList().OrderBy(x => x.CreateTime).FirstOrDefault();
|
var fisrtTask = context.Task_Part.Where(x => x.DeviceId == int_deviceId && x.TaskState == (int)DeviceTaskStatusEnum.未开始 && x.TaskType == q_taskType_出库).ToList().OrderBy(x => x.MainTaskSequence).ThenBy(x => x.CreateTime).FirstOrDefault();
|
if (fisrtTask != null)
|
{
|
//验证这个起点是否有货存在
|
var isHasCatogry_RealSourcePlace = MyExtendHelper.IsGD_HasCatogryForRgvStattion(fisrtTask.RealSourcePlace);
|
if (isHasCatogry_RealSourcePlace == false)
|
{
|
Do组盘入库(context);
|
SystemWarningMsg._lbl_Alert_MainTaskDecompose_ZPRK = "四个出库口有货,但是第一个要执行的出库任务目前还没送到输送线出口,创建组盘入库任务" + SysGloble.SPLIT_STR;
|
continue;
|
}
|
else
|
{//说明这个出库任务的起点 有货存在
|
SystemWarningMsg._lbl_Alert_MainTaskDecompose_ZPRK = "四个出库口有货,但是第一个要执行的出库任务目前已经送到输送线出口,不会创建组盘入库任务" + SysGloble.SPLIT_STR;
|
continue;
|
}
|
}
|
else
|
{//说明此时没有任何出库任务,那就允许做组盘入库的任务啊 【EditBy shaocx,2022-09-02】
|
var existTaskList = context.Task_Part.Where(x => x.DeviceId == int_deviceId && (x.TaskState == (int)DeviceTaskStatusEnum.未开始 || x.TaskState == (int)DeviceTaskStatusEnum.已下发) && x.TaskType == q_taskType_出库).ToList();
|
if (existTaskList == null || existTaskList.Count == 0)
|
{
|
Do组盘入库(context);
|
SystemWarningMsg._lbl_Alert_MainTaskDecompose_ZPRK = "四个出库口有货,但是发现系统并没有出库任务,那么就创建组盘入库任务" + SysGloble.SPLIT_STR;
|
continue;
|
}
|
else
|
{
|
SystemWarningMsg._lbl_Alert_MainTaskDecompose_ZPRK = "四个出库口其中有站点光电有货,但是1012和1013其中有站点无货,并且还有未结束的出库任务,所以不允许创建组盘入库任务:" + SysGloble.SPLIT_STR;
|
}
|
}
|
//说明此时没有任何出库任务,那就允许做组盘入库的任务啊 【EditBy shaocx,2022-09-02】
|
// SystemWarningMsg._lbl_Alert_MainTaskDecompose_ZPRK = "四个出库口有货,但是1012和1013其中有站点无货,所以不允许创建组盘入库任务:" + SysGloble.SPLIT_STR;
|
}
|
}
|
|
#endregion
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
SystemWarningMsg._lbl_Alert_MainTaskDecompose_ZPRK += "分解线程出现异常:" + ex.Message + SysGloble.SPLIT_STR;
|
Log4NetHelper.WriteErrorLog(LogType.CCWCFService, "HandlerMainTaskDecompose_ZPRK出现异常:" + ex.Message, ex);
|
}
|
|
}
|
}
|
|
private static void Do组盘入库(DbModel context)
|
{
|
var queryState1 = (int)MainTaskStatusEnum.组盘入库;
|
var mainList = context.Task_Main.Where(x => x.TaskState == queryState1).OrderBy(x => x.CreateTime).ToList();//组盘入库按照创建时间升序
|
if (mainList != null && mainList.Count > 0)
|
{//每次只处理一个
|
Do_HandlerMainTaskDecomposeForIn(mainList, context);
|
}
|
else
|
{
|
SystemWarningMsg._lbl_Alert_MainTaskDecompose_ZPRK += "没有要分解的任务" + SysGloble.SPLIT_STR;
|
}
|
}
|
|
private static void Do_HandlerMainTaskDecomposeForIn(List<Task_Main> mainList, DbModel context)
|
{
|
if (mainList != null && mainList.Count > 0)
|
{//每次只处理一个
|
//var ss=mainList.Select(x=>x.)
|
var item = mainList.First();
|
|
FunRetEntity result = null;
|
result = SingleHandlerForInTask(context, item);
|
if (result.result) context.SaveChanges();
|
|
SystemWarningMsg._lbl_Alert_MainTaskDecompose_ZPRK = result.resMsg;
|
}
|
else
|
{
|
SystemWarningMsg._lbl_Alert_MainTaskDecompose_ZPRK += "没有要分解的任务" + SysGloble.SPLIT_STR;
|
}
|
}
|
|
private static FunRetEntity SingleHandlerForInTask(DbModel context, Task_Main mainTask)
|
{
|
try
|
{
|
var toPlace = StationHandler.GetPlaceByPlaceId((int)mainTask.ToPlace, context);
|
var sourcePlace = StationHandler.GetPlaceByPlaceId((int)mainTask.SourcePlace, context);
|
var salver = SalverHandler.GetSalveById(context, mainTask.SalverId);
|
//中间点
|
var midPlace = StationHandler.GetRgvPlaceBySrmPlaceForInStore(context, toPlace);
|
if (midPlace == null)
|
{
|
return FunRetEntity.Fail("没有找到RGV入库位置");
|
}
|
|
var plcTaskNo = BusinessHelper.CreatePlcTaskIdForSrmTask();
|
var createTime = DateTime.Now;
|
|
//更新组盘入库的任务序列,同时分解任务的序列也同步 【Editby shaocx,2022-04-28】
|
string taskSequenceGuid = "";
|
mainTask.TaskSequence = MainTaskHandler.GenerateTaskSequence(context, ref taskSequenceGuid);//生成任务序列号;
|
mainTask.TaskSequenceGuid = taskSequenceGuid;
|
|
//创建RGV任务
|
FunRetEntity fre = PartTaskHandler.CreatePartTask(createTime, plcTaskNo, context, EDeviceType.RGV, mainTask.CreateBy, 1, DeviceTaskTypeEnum.组盘入库, mainTask, salver, sourcePlace, midPlace, mainTask.OperationRemark);
|
if (fre.result == false)
|
{
|
return fre;
|
}
|
//创建堆垛机任务
|
fre = PartTaskHandler.CreatePartTask(createTime, plcTaskNo, context, EDeviceType.堆垛机, mainTask.CreateBy, 2, DeviceTaskTypeEnum.组盘入库, mainTask, salver, midPlace, toPlace, mainTask.OperationRemark);
|
if (fre.result == false)
|
{
|
return fre;
|
}
|
|
//更新主表的任务状态
|
var _changeTaskState = MainTaskStatusEnum.入库任务已分解;
|
mainTask.TaskState = (int)_changeTaskState;
|
mainTask.TaskStateName = _changeTaskState.ToString();
|
|
return FunRetEntity.Success("成功新建入库设备任务");
|
}
|
catch (Exception ex)
|
{
|
return FunRetEntity.Fail("新增入库设备任务异常:" + ex.Message);
|
}
|
}
|
}
|
}
|