using iWareCC.Common.Helper; using iWareCommon.Common.Globle; using iWareCommon.Utils; using iWareModel; using iWareModel.EnumType.XiGangPublicCommon; 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 { /// /// 空托盘转运任务 /// public static class EmptySalverTransferTask { /// /// 空托盘转运任务 /// public static void Handler() { while (true) { Thread.Sleep(2000);//休眠2秒,将休眠写到前面,是为了下面的continue方法执行后不显示错误信息的提示!!!【EditBy shaocx,2022-05-24】 SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound = string.Empty; bool isHasFinishedCurrentHanlder = false;//是否已经处理完了空托盘转运任务 try { if (SystemValue.isAllowRuning_DataProcess_RobotBuffer_IssueOutboundTask && SystemValue.isStartedModel) { //此处判断 1009 1010 1011的状态 bool isEmptyPlace_1011 = false, isEmptyPlace_1010 = false, isEmptyPlace_1009 = false; V_AllStore store = null; using (DbModel context = new DbModel()) { //1、先看1011站点,光电是否有货,并且系统有库存,如果 光电有货+系统有库存, EDevice rgvLocation = EDevice.空托缓存1011; var stationCode = Convert.ToInt32(rgvLocation).ToString(); bool isGD_HasCatogryForRgvStattion = MyExtendHelper.IsGD_HasCatogryForRgvStattion(stationCode); bool isSys_HasCatogryForRgvStattion = MyExtendHelper.IsSys_HasCatogryForRgvStattion(context, stationCode, ref store); bool isExistOtherTaskDoing = PartTaskHandler.IsExistOtherTaskDoing(stationCode); if (isSys_HasCatogryForRgvStattion || isGD_HasCatogryForRgvStattion) { isEmptyPlace_1011 = false; } else { isEmptyPlace_1011 = true; } if (isSys_HasCatogryForRgvStattion && isGD_HasCatogryForRgvStattion && !isExistOtherTaskDoing) { var isAllowDoHandlerFor1011 = false; #region 判断是否允许发任务给1011 var isGD_HasCatogryForRgvStattion_1014 = MyExtendHelper.IsGD_HasCatogryForRgvStattion(((int)EDevice.拆盘机入口1014).ToString()); if (!isGD_HasCatogryForRgvStattion_1014) {//1014无货 isAllowDoHandlerFor1011 = true; } else {//1014有货 //判断1009是否有货 var isGD_HasCatogryForRgvStattion_1009 = MyExtendHelper.IsGD_HasCatogryForRgvStattionFor2(((int)EDevice.空托缓存1009).ToString()); if (isGD_HasCatogryForRgvStattion_1009) {//1009有货,就要下发1011的任务了,不能堵着人家1009的任务啊 isAllowDoHandlerFor1011 = true; } else { if (FormCC.RGV_1011_HasCategory_COUNT < SysGloble.MAX_RGV_1011_HasCategory_COUNT) { SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += "错误:1011处不允许创建任务,1011有货时间:" + FormCC.RGV_1011_HasCategory_COUNT + ",还未大于设定的最大超时时间:" + SysGloble.MAX_RGV_1011_HasCategory_COUNT + SysGloble.SPLIT_STR; } else { isAllowDoHandlerFor1011 = true; } } } #endregion if (isAllowDoHandlerFor1011 == true) { var fr = MyExtendHelper.DoHandler(context, store, rgvLocation); if (fr.result == false) { SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += "错误:1011处新建任务失败:" + fr.resMsg + SysGloble.SPLIT_STR; } else { SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += "成功创建1011任务" + SysGloble.SPLIT_STR; continue; } isHasFinishedCurrentHanlder = true; } else {//不允许下发1011的任务 } } //2、先看1010站点,光电是否有货,并且系统有库存,如果 光电有货+系统有库存, //还要判断1011是否有货 rgvLocation = EDevice.空托缓存1010; stationCode = Convert.ToInt32(rgvLocation).ToString(); isGD_HasCatogryForRgvStattion = MyExtendHelper.IsGD_HasCatogryForRgvStattion(stationCode); isSys_HasCatogryForRgvStattion = false;//1010的不关心库存,因为他不是目的点 // isSys_HasCatogryForRgvStattion = IsSys_HasCatogryForRgvStattion(context, stationCode, ref store); if (isSys_HasCatogryForRgvStattion || isGD_HasCatogryForRgvStattion) { isEmptyPlace_1010 = false; } else { isEmptyPlace_1010 = true; } //isExistOtherTaskDoing = PartTaskHandler.IsExistOtherTaskDoing(context, stationCode); //if (isSys_HasCatogryForRgvStattion && isGD_HasCatogryForRgvStattion && !isExistOtherTaskDoing // && isEmptyPlace_1011 == true) //{ // var fr = DoHandler(context, store, rgvLocation); // if (fr.result == false) // { // SystemWarningMsg._lbl_Alert_EmptySalverTransfer = "错误:1010处新建任务失败:" + fr.resMsg; // } //} //3、先看1009站点,光电是否有货,并且系统有库存,如果 光电有货+系统有库存, //还要判断1010是否有货 rgvLocation = EDevice.空托缓存1009; stationCode = Convert.ToInt32(rgvLocation).ToString(); isGD_HasCatogryForRgvStattion = MyExtendHelper.IsGD_HasCatogryForRgvStattionFor2(stationCode); isSys_HasCatogryForRgvStattion = MyExtendHelper.IsSys_HasCatogryForRgvStattion(context, stationCode, ref store); if (isSys_HasCatogryForRgvStattion || isGD_HasCatogryForRgvStattion) { isEmptyPlace_1009 = false; } else { isEmptyPlace_1009 = true; } isExistOtherTaskDoing = PartTaskHandler.IsExistOtherTaskDoing(stationCode); if (!isSys_HasCatogryForRgvStattion && isGD_HasCatogryForRgvStattion && !isExistOtherTaskDoing //注意:1009要判断没有库存才可以。 //1010必须是空闲无货 && isEmptyPlace_1010 == true //1011必须是空闲无货 && isEmptyPlace_1011 == true //是否已经处理完了空托盘转运任务为false && isHasFinishedCurrentHanlder == false ) { #region 增加光电信号点的检测 //增加光电信号点的检测 【Editby shaocx,2022-05-01】 var salverStackCount = MyExtendHelper.GetSalverStackCountForBackToStore(); if (salverStackCount == 0) { //报错 SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += ("[检测]根据1009站点的光电获取返回立体库的托盘数为0") + SysGloble.SPLIT_STR; continue; } //休眠5秒 Thread.Sleep(5000); var salverStackCount2 = MyExtendHelper.GetSalverStackCountForBackToStore(); if (salverStackCount2 == 0) { //报错 SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += ("[检测]根据1009站点的光电获取返回立体库的托盘数为0") + SysGloble.SPLIT_STR; continue; } if (salverStackCount != salverStackCount2) { //报错 SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += ("根据1009站点的光电,相差5秒获取返回立体库的托盘数不一致,第一次是" + salverStackCount + ",第二次是" + salverStackCount2) + SysGloble.SPLIT_STR; continue; } #endregion var fr = MyExtendHelper.DoHandler(context, null, rgvLocation); if (fr.result == false) { SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += "错误:1009处新建任务失败:" + fr.resMsg + SysGloble.SPLIT_STR; } else { SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += "成功创建1009任务" + SysGloble.SPLIT_STR; continue; } isHasFinishedCurrentHanlder = true; } //3、判断1014是否需要去放空托,从立体库送过来的 【EditBy shaocx,2022-04-14】 rgvLocation = EDevice.拆盘机入口1014; stationCode = Convert.ToInt32(rgvLocation).ToString(); //增加验证,1009上两个光电有货,或 1010上其中一个光电有货,或 1011上一个光电有货,就先暂停不要下发去1014的任务,目的是为了优先让托盘回收的去1014位置,提高节拍 [EditBy shaocx,2022-05-01] var errMsg = ""; if (!MyExtendHelper.IsAllowSendTaskTo1014ByTPHS(ref errMsg)) { SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += errMsg + SysGloble.SPLIT_STR; continue; } var isAllowSendTaskToPlace1014 = MyExtendHelper.IsAllowSendTaskToPlace1014(context, stationCode, ref store); if (isAllowSendTaskToPlace1014 && isHasFinishedCurrentHanlder == false) { //再校验一次 isExistOtherTaskDoing = PartTaskHandler.IsExistOtherTaskDoing(stationCode); if (!isExistOtherTaskDoing) { if (!MyExtendHelper.IsAllowSendTaskTo1014ByTPHS(ref errMsg)) {//再次校验 【EditBy shaocx,2022-05-18】 SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += errMsg + SysGloble.SPLIT_STR; continue; } //判断1011位置是否有库存,并且是未锁定状态,如果是,就不要创建从立体库到1014的任务了【EditBy shaocx,2022-05-18】 var query1011 = ((int)EDevice.空托缓存1011).ToString(); var store1011 = context.V_AllStore.Where(x => x.RgvStationCode == query1011).FirstOrDefault(); if (store1011 != null && store1011.StationId > 0) //if (store1011 != null && store1011.StationIsLock == false && store1011.StationIsHasTaskDoing == false) { SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += "1011位置有系统库存存在,因此不需要创建从立体库到1014的任务。。" + SysGloble.SPLIT_STR; continue; } var fr = MyExtendHelper.DoHandler(context, null, rgvLocation); if (fr.result == false) { SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += "错误:拆盘机入口1014处新建从立体库叫托盘任务失败:" + fr.resMsg + SysGloble.SPLIT_STR; } else { SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += "成功创建拆盘机入口1014处新建从立体库叫托盘任务" + SysGloble.SPLIT_STR; continue; } } } } } } catch (Exception ex) { SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += "分解线程出现异常:" + ex.Message + SysGloble.SPLIT_STR; Log4NetHelper.WriteErrorLog(LogType.DataProcess_RobotBuffer_IssueOutboundTask, "HandlerIssuingTask出现异常:" + ex.Message, ex); } } } } }