Ejemplo n.º 1
0
 /// <summary>
 /// 创建点到点任务
 /// </summary>
 public string CreatPointToPointTask(string BeginLandCode, string EndLandCode)
 {
     try
     {
         string           dispatchNo = Guid.NewGuid().ToString();
         DispatchTaskInfo TaskInfo   = new DispatchTaskInfo();
         TaskInfo.dispatchNo = dispatchNo;
         TaskInfo.taskType   = 0;
         TaskInfo.TaskState  = 0;
         TaskInfo.CallLand   = "Test";
         TaskInfo.stationNo  = 0;
         DispatchTaskDetail taskFirstDetail = new DispatchTaskDetail();
         taskFirstDetail.dispatchNo    = dispatchNo;
         taskFirstDetail.DetailID      = 1;
         taskFirstDetail.LandCode      = BeginLandCode;
         taskFirstDetail.State         = 0;
         taskFirstDetail.IsAllowExcute = 1;
         TaskInfo.TaskDetail.Add(taskFirstDetail);
         DispatchTaskDetail taskSecondDetail = new DispatchTaskDetail();
         taskSecondDetail.dispatchNo    = dispatchNo;
         taskSecondDetail.DetailID      = 2;
         taskSecondDetail.LandCode      = EndLandCode;
         taskSecondDetail.State         = 0;
         taskSecondDetail.IsAllowExcute = 1;
         TaskInfo.TaskDetail.Add(taskSecondDetail);
         OperateReturnInfo opr = AGVSimulationDAccess.SaveTask(TaskInfo);
         if (opr.ReturnCode == OperateCodeEnum.Success)
         {
             return("操作成功");
         }
         else
         {
             return("操作失败:" + opr.ReturnInfo.ToString());
         }
     }
     catch (Exception ex)
     { throw ex; }
 }
Ejemplo n.º 2
0
 public static DispatchTaskDetail GetTaskDetail(string No, int id)
 {
     try
     {
         IDbOperator dbOperator = CreateDbOperator.DbOperatorInstance(ConnectConfigTool.DBase);
         Hashtable   dic        = new Hashtable();
         dic["dispatchNo"]   = No;
         dic["TaskDetailID"] = id;
         DataTable          dtDetail = dbOperator.LoadDatas("GetTaskDetail", dic);
         DispatchTaskDetail detail   = null;
         if (dtDetail != null && dtDetail.Rows.Count > 0)
         {
             detail = ConnectConfigTool.TableToEntity <DispatchTaskDetail>(dtDetail)[0];
             return(detail);
         }
         else
         {
             return(null);
         }
     }
     catch (Exception ex)
     { throw ex; }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 分派任务
        /// </summary>
        private async void assignTask()
        {
            try
            {
                lock (HandleTaskobje)
                {
                    timerFreshTask.Enabled = false;
                    foreach (CarMonitor car in MoniCars.Where(p => (!string.IsNullOrEmpty(p.ExcuteTaksNo)) && p.TaskDetailID >= 0))
                    {
                        //将当前的任务明细更新完成
                        if (!string.IsNullOrEmpty(car.ExcuteTaksNo) && car.TaskDetailID != -1)
                        {
                            //HandTaskDetail(car.CurrSite.ToString(), car.ExcuteTaksNo, car.TaskDetailID);
                            if (car.Sate == 0 && car.CurrSite.ToString() == car.ArmLand)
                            {
                                #region 更新储位状态
                                UnLockStorage(car, Stores);
                                #endregion
                                AGVSimulationDAccess.HandTaskDetail(car.AgvID, car.CurrSite.ToString(), car.ExcuteTaksNo, car.TaskDetailID);
                                AGVSimulationDAccess.HandTaskzb(car.ExcuteTaksNo);
                                DispatchTaskInfo CarTaskInfo = AGVSimulationDAccess.CheckTaskIsFinish(car.ExcuteTaksNo);
                                if (CarTaskInfo == null)
                                {
                                    car.ExcuteTaksNo = "";
                                }
                            }
                        }
                    }


                    Hashtable hs = new Hashtable();
                    //查找当前有效任务
                    IList <DispatchTaskInfo> tasks = AGVSimulationDAccess.LoadDispatchTask("0,1");
                    if (tasks != null && tasks.Count > 0)
                    {
                        foreach (DispatchTaskInfo task in tasks)
                        {
                            if (task.TaskDetail.Count <= 0)
                            {
                                continue;
                            }
                            //查找合适的AGV来领取任务
                            CarMonitor NoTaskCar = null;
                            //如果任务为待处理的,就找空闲的车来执行
                            //如果任务是正在执行中的,则找对应的空闲agv来继续执行
                            //查找任务到具体任务明细
                            DispatchTaskDetail TaskDetail = (from a in task.TaskDetail
                                                             where (a.State == 0 || a.State == 1)
                                                             orderby a.DetailID ascending
                                                             select a).FirstOrDefault();
                            if (task.TaskState == 0)
                            {
                                if (TaskDetail != null)
                                {
                                    if (task.ExeAgvID != 0)
                                    {
                                        NoTaskCar = (from a in MoniCars
                                                     where task.ExeAgvID == a.AgvID && !string.IsNullOrEmpty(a.CurrSite.ToString()) && (a.Sate == 0 || a.IsBack) && a.ExcuteTaksNo == "" && /*a.TaskDetailID == -1*/
                                                     getDistant(a.CurrSite.ToString(), TaskDetail.LandCode) >= 0
                                                     orderby getDistant(a.CurrSite.ToString(), TaskDetail.LandCode) ascending
                                                     select a).FirstOrDefault();
                                    }
                                    else
                                    {
                                        NoTaskCar = (from a in MoniCars
                                                     where !string.IsNullOrEmpty(a.CurrSite.ToString()) && (a.Sate == 0 || a.IsBack) && a.ExcuteTaksNo == "" && /*a.TaskDetailID == -1*/
                                                     getDistant(a.CurrSite.ToString(), TaskDetail.LandCode) >= 0
                                                     orderby getDistant(a.CurrSite.ToString(), TaskDetail.LandCode) ascending
                                                     select a).FirstOrDefault();
                                    }
                                }
                            }
                            else if (task.TaskState == 1)
                            {
                                NoTaskCar = MoniCars.FirstOrDefault(p => p.AgvID == task.ExeAgvID && ((p.Sate == 0 || p.Sate == 2 || p.IsBack)));
                            }
                            //找到对应的agv
                            if (NoTaskCar != null && NoTaskCar.CurrSite > 0)
                            {
                                if (NoTaskCar.IsBack)
                                {
                                    NoTaskCar.IsBack = !NoTaskCar.IsBack;
                                }
                            }
                            else
                            {
                                continue;
                            }
                            //如果任务明细全部完成,那么需要将主任务状态更新并且让对应的agv回待命点
                            LandmarkInfo BeginLand, EndLand = null;
                            if (TaskDetail == null)
                            {
                            }
                            else
                            {
                                //判断一下当前小时是否就在任务地标上
                                if (NoTaskCar.CurrSite.ToString() == TaskDetail.LandCode && (TaskDetail.State == 0 || TaskDetail.State == 1))
                                {
                                    NoTaskCar.OperType     = TaskDetail.OperType;
                                    NoTaskCar.PutType      = TaskDetail.PutType;
                                    NoTaskCar.ArmLand      = TaskDetail.LandCode;
                                    NoTaskCar.ExcuteTaksNo = TaskDetail.dispatchNo;
                                    NoTaskCar.TaskDetailID = TaskDetail.DetailID;
                                    AGVSimulationDAccess.HandTaskDetail(NoTaskCar.AgvID, TaskDetail.LandCode, TaskDetail.dispatchNo, TaskDetail.DetailID);
                                    UnLockStorage(NoTaskCar, Stores);
                                    //NoTaskCar.TaskDetailID = -1;
                                    continue;
                                }

                                //判断小车当前的任务明细是否允许需要等待放行命令
                                DispatchTaskDetail PreTaskDetail = (from a in task.TaskDetail
                                                                    where a.LandCode == NoTaskCar.CurrSite.ToString()
                                                                    orderby a.DetailID ascending
                                                                    select a).FirstOrDefault();
                                //如果不允许执行则跳过
                                if (PreTaskDetail != null && PreTaskDetail.IsAllowExcute == 0)
                                {
                                    continue;
                                }
                                //记录当前小车的任务信息
                                //更新任务为执行状态
                                AGVSimulationDAccess.TaskHandle(task.dispatchNo, NoTaskCar.AgvID, 1, TaskDetail.LandCode, TaskDetail.DetailID);
                                NoTaskCar.ExcuteTaksNo = task.dispatchNo;
                                NoTaskCar.TaskDetailID = TaskDetail.DetailID;
                                NoTaskCar.ArmLand      = TaskDetail.LandCode;
                                NoTaskCar.PutType      = TaskDetail.PutType;
                                NoTaskCar.OperType     = TaskDetail.OperType;
                                BeginLand = AllLands.FirstOrDefault(p => p.LandmarkCode == NoTaskCar.CurrSite.ToString());
                                EndLand   = AllLands.FirstOrDefault(p => p.LandmarkCode == TaskDetail.LandCode);
                                if (BeginLand != null && EndLand != null)
                                {
                                    NoTaskCar.CurrRoute = DataToObject.CreateDeepCopy <List <LandmarkInfo> >(CountRoute.GetRoute(BeginLand, EndLand));
                                    string CountRouteResult = string.Join(",", NoTaskCar.CurrRoute.Select(p => p.LandmarkCode));
                                    LogHelper.WriteLog(CountRouteResult);
                                    if (NoTaskCar.CurrRoute.Count <= 0)
                                    {
                                        continue;
                                    }
                                    if (!Traffic.BeforStartTrafficForStop(NoTaskCar))
                                    {
                                        Traffic.GetTrafficResour(NoTaskCar);
                                        //if (Route_Ini != null)
                                        //{ Route_Ini(NoTaskCar.CurrRoute); }
                                        NoTaskCar.StepChange += DoCar_StepChange;
                                        NoTaskCar.Start();
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        List <CarMonitor> NoReleaseCars = MoniCars.Where(p => p.Sate != 1 && p.Sate != 2 && !string.IsNullOrEmpty(p.ExcuteTaksNo)).ToList();
                        foreach (CarMonitor item in NoReleaseCars)
                        {
                            item.ExcuteTaksNo = "";
                        }
                    }
                    List <CarMonitor> NoBackCars = MoniCars.Where(p => p.Sate != 1 && p.Sate != 2 && string.IsNullOrEmpty(p.ExcuteTaksNo) && p.CurrSite.ToString() != p.StandbyLandMark).ToList();
                    foreach (CarMonitor car in NoBackCars)
                    {
                        if (string.IsNullOrEmpty(car.StandbyLandMark))
                        {
                            continue;
                        }
                        LandmarkInfo BeginLand = AllLands.FirstOrDefault(p => p.LandmarkCode == car.CurrSite.ToString());
                        LandmarkInfo EndLand   = AllLands.FirstOrDefault(p => p.LandmarkCode == car.StandbyLandMark);
                        //以车的当前地标为开始地标,待命点为结束地标规划回待命点路线
                        if (BeginLand == null || EndLand == null)
                        {
                            continue;
                        }
                        else
                        {
                            //规划路线
                            car.CurrRoute = DataToObject.CreateDeepCopy <List <LandmarkInfo> >(CountRoute.GetRoute(BeginLand, EndLand));
                            if (car.CurrRoute.Count <= 0)
                            {
                                continue;
                            }
                            if (!Traffic.BeforStartTrafficForStop(car))
                            {
                                Traffic.GetTrafficResour(car);
                                //if (Route_Ini != null)
                                //{ Route_Ini(car.CurrRoute); }
                                car.StepChange += DoCar_StepChange;
                                car.Start();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            { throw ex; }
            finally
            { timerFreshTask.Enabled = true; }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 创建任务
        /// </summary>
        public string CreatTask(int CallBoxID, int BtnID)
        {
            try
            {
                CallBoxInfo BoxInfo = AGVSimulationDAccess.LoadAllCallBoxByID(CallBoxID);
                if (BoxInfo == null)
                {
                    return("未配置按钮盒档案信息");
                }
                IList <CallBoxDetail> BoxDetails = AGVSimulationDAccess.LoadCallBoxDetails(CallBoxID);
                if (BoxDetails == null || (BoxDetails != null && BoxDetails.Count <= 0))
                {
                    return("未配置按钮盒明细档案信息");
                }


                CallBoxDetail CurrBoxDetail = BoxDetails.FirstOrDefault(p => p.CallBoxID == CallBoxID && p.ButtonID == BtnID);
                if (CurrBoxDetail == null)
                {
                    return("当前按钮没有配置信息");
                }
                if (CurrBoxDetail.OperaType == 0)
                {
                    IList <TaskConfigDetail> TaskConfigDetails = AGVClientDAccess.load_TaskDetail(CurrBoxDetail.TaskConditonCode);
                    if (TaskConfigDetails == null && (TaskConfigDetails != null && TaskConfigDetails.Count <= 0))
                    {
                        return("当前按钮未配置任务信息");
                    }
                    //开始创建任务
                    StorageInfo CallStore = Stores.FirstOrDefault(q => q.ID == CurrBoxDetail.LocationID);
                    if (CallStore == null)
                    {
                        return("未设置当前按钮的监控储位!");
                    }
                    //CallStore.StorageState = CurrBoxDetail.LocationState;

                    ///后面再处理
                    if (AGVSimulationDAccess.ChekAllowCreatTask(CallBoxID, CallStore.LankMarkCode, 0) > 0)
                    {
                        return("存在未完成任务,请稍后再试!");
                    }
                    string           dispatchNo = Guid.NewGuid().ToString();
                    DispatchTaskInfo TaskInfo   = new DispatchTaskInfo();
                    TaskInfo.dispatchNo = dispatchNo;
                    TaskInfo.taskType   = 0;
                    TaskInfo.TaskState  = 0;
                    TaskInfo.CallLand   = CallStore.LankMarkCode;
                    TaskInfo.stationNo  = CallBoxID;
                    //创建任务明细
                    int DetailID      = 1;
                    int PreStoreState = -1;
                    foreach (TaskConfigDetail item in TaskConfigDetails)
                    {
                        DispatchTaskDetail taskDetail = new DispatchTaskDetail();
                        taskDetail.dispatchNo = dispatchNo;
                        taskDetail.DetailID   = DetailID;
                        //寻找目标地表
                        StorageInfo ArmStore = null;
                        if (item.ArmOwnArea == -1)
                        {
                            ArmStore = CallStore;
                        }
                        else
                        {
                            ArmStore = Stores.FirstOrDefault(p => p.OwnArea == item.ArmOwnArea && p.StorageState == item.StorageState && p.MaterielType == item.MaterialType);
                        }
                        if (ArmStore == null)
                        {
                            return("任务条件不满足!");
                        }
                        taskDetail.LandCode      = ArmStore.LankMarkCode;
                        taskDetail.OperType      = item.Action;
                        taskDetail.PutType       = PreStoreState == -1 ? 0 : (PreStoreState == 1 ? 0 : 1);
                        taskDetail.IsAllowExcute = item.IsWaitPass;
                        taskDetail.State         = 0;
                        TaskInfo.TaskDetail.Add(taskDetail);
                        DetailID     += 1;
                        PreStoreState = ArmStore.StorageState;
                    }
                    OperateReturnInfo opr = AGVSimulationDAccess.SaveTask(TaskInfo);
                    if (opr.ReturnCode == OperateCodeEnum.Success)
                    {
                        foreach (TaskConfigDetail item in TaskConfigDetails)
                        {
                            StorageInfo ArmStore = Stores.FirstOrDefault(p => p.OwnArea == item.ArmOwnArea && p.StorageState == item.StorageState && p.MaterielType == item.MaterialType);
                            if (ArmStore != null)
                            {
                                ArmStore.LockState = 2;
                            }
                        }
                    }
                    else
                    {
                        return(opr.ReturnInfo.ToString());
                    }
                }
                else if (CurrBoxDetail.OperaType == 1)
                {
                    CurrBoxDetail = BoxDetails.FirstOrDefault(p => p.CallBoxID == CallBoxID && p.ButtonID == BtnID);
                    if (CurrBoxDetail == null)
                    {
                        return("当前按钮没有配置信息");
                    }
                    IList <TaskConfigDetail> TaskConfigDetails = AGVClientDAccess.load_TaskDetail(CurrBoxDetail.TaskConditonCode);
                    if (TaskConfigDetails == null && (TaskConfigDetails != null && TaskConfigDetails.Count <= 0))
                    {
                        return("当前按钮未配置任务信息");
                    }
                    //开始创建任务
                    StorageInfo CallStore = Stores.FirstOrDefault(q => q.ID == CurrBoxDetail.LocationID);
                    if (CallStore == null)
                    {
                        return("未设置当前按钮的监控储位!");
                    }
                    CallStore.StorageState = CurrBoxDetail.LocationState;
                    AGVSimulationDAccess.UpdateStore(CallStore.ID, CallStore.StorageState);
                }
                else if (CurrBoxDetail.OperaType == 2)//放行
                {
                    StorageInfo CheckStore = Stores.FirstOrDefault(p => p.ID == CurrBoxDetail.LocationID);
                    if (CheckStore == null)
                    {
                        return("监控放行储位不存在!");
                    }
                    CarMonitor ReleaseCar = MoniCars.FirstOrDefault(p => p.CurrSite.ToString() == CheckStore.LankMarkCode);
                    if (ReleaseCar == null)
                    {
                        return("当前没有放行车辆!");
                    }
                    OperateReturnInfo opr = AGVSimulationDAccess.ReleaseCar(ReleaseCar.ExcuteTaksNo, ReleaseCar.ArmLand);
                    if (opr.ReturnCode != OperateCodeEnum.Success)
                    {
                        return(opr.ReturnInfo.ToString());
                    }
                }
                else//取消任务
                {
                }
                return("操作成功!");
            }
            catch (Exception ex)
            {
                return("发送异常!" + ex.Message);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 处理呼叫盒呼叫
        /// </summary>
        /// <param name="CallBoxID">呼叫盒ID</param>
        /// <param name="BtnID">按钮ID</param>
        /// <returns></returns>
        private bool HandleCallBoxCall(CallBoxInfo CallBox, CallBoxDetail CurrBoxDetail, int BtnID)
        {
            try
            {
                #region 处理呼叫逻辑
                //加载是否启用储位状态
                string IsUserStoreState = CoreData.SysParameter["IsUserStoreState"].ToString();
                if (string.IsNullOrEmpty(IsUserStoreState))
                {
                    IsUserStoreState = "否";
                }
                int CallBoxID = CallBox.CallBoxID;
                IList <TaskConfigDetail> TaskConfigDetails = AGVClientDAccess.load_TaskDetail(CurrBoxDetail.TaskConditonCode);
                if (TaskConfigDetails == null && (TaskConfigDetails != null && TaskConfigDetails.Count <= 0))
                {
                    LogHelper.WriteCallBoxLog("未配置按钮盒" + CallBox.CallBoxID.ToString() + "任务信息");
                    return(false);
                }

                //开始根据任务配置信息创建任务
                StorageInfo CallStore = CoreData.StorageList.FirstOrDefault(q => q.ID == CurrBoxDetail.LocationID);
                if (CallStore == null)
                {
                    LogHelper.WriteCallBoxLog("未配置按钮盒" + CallBox.CallBoxID.ToString() + "对应的监控储位");
                    return(false);
                }
                //验证当前按钮盒下是否存在未完成的任务
                if (AGVSimulationDAccess.ChekAllowCreatTask(CallBoxID, CallStore.LankMarkCode, BtnID) > 0)
                {
                    LogHelper.WriteCallBoxLog("按钮盒" + CallBox.CallBoxID.ToString() + "对应呼叫存在未完成任务,请稍后再试!");
                    return(false);
                }

                //组装任务信息
                string           dispatchNo = Guid.NewGuid().ToString();
                DispatchTaskInfo TaskInfo   = new DispatchTaskInfo();
                TaskInfo.dispatchNo = dispatchNo;
                TaskInfo.TaskState  = 0;
                TaskInfo.CallLand   = CallStore.LankMarkCode;
                TaskInfo.stationNo  = CallBoxID;
                TaskInfo.CallID     = BtnID;
                TaskInfo.taskType   = 0;

                //创建任务明细
                int DetailID   = 1;
                int PrePutType = -1;
                foreach (TaskConfigDetail item in TaskConfigDetails)
                {
                    //通过任务任务配置明细寻找目标地标
                    StorageInfo ArmStore = null;
                    LogHelper.WriteCallBoxLog("呼叫储位为:" + item.ArmOwnArea.ToString());
                    if (item.ArmOwnArea == -1)
                    {
                        ArmStore = CallStore;
                        LogHelper.WriteCallBoxLog("呼叫储位地标为:" + CallStore.LankMarkCode);
                    }
                    else
                    {
                        if (IsUserStoreState == "否")
                        {
                            ArmStore = CoreData.StorageList.FirstOrDefault(p => p.OwnArea == item.ArmOwnArea && p.StorageState == item.StorageState && p.MaterielType == item.MaterialType);
                        }
                        else
                        {
                            ArmStore = CoreData.StorageList.FirstOrDefault(p => p.OwnArea == item.ArmOwnArea && p.StorageState == item.StorageState && p.MaterielType == item.MaterialType && p.LockState == 0);
                        }
                    }
                    if (ArmStore == null)
                    {
                        LogHelper.WriteCallBoxLog("按钮盒" + CallBox.CallBoxID.ToString() + "对应呼叫,目的储位不存在[原因:不存在或被占用]");
                        return(false);
                    }

                    //再通过配置任务号来处理必经地标
                    IList <TaskConfigMustPass> ConfigMustPasses = AGVServerDAccess.LoadTaskMustPass(item.TaskConditonCode, item.DetailID);
                    if (ConfigMustPasses != null && ConfigMustPasses.Count > 0)
                    {
                        ////如果配置的必经地标则需要产生任务经过必经地标
                        foreach (TaskConfigMustPass MustPassItem in ConfigMustPasses)
                        {
                            foreach (IOActionInfo Action in MustPassItem.MustPassIOAction)
                            {
                                IOActionInfo CurrIOActionInfo = AGVServerDAccess.LoadAllIOAction(Action.ActionID);
                                if (CurrIOActionInfo == null)
                                {
                                    LogHelper.WriteCallBoxLog("按钮盒" + CallBox.CallBoxID.ToString() + "对应呼叫,必经地标中的IO动作" + Action.ActionID.ToString() + "档案信息不存在");
                                    continue;
                                }
                                DispatchTaskDetail newTaskDetail = new DispatchTaskDetail();
                                newTaskDetail.dispatchNo         = dispatchNo;
                                newTaskDetail.DetailID           = DetailID;
                                newTaskDetail.LandCode           = MustPassItem.MustPassLandCode;
                                newTaskDetail.IsAllowExcute      = Action.IsPass;
                                newTaskDetail.IsSensorStop       = 0;
                                newTaskDetail.OperType           = -1;
                                newTaskDetail.IsWait             = Action.IsWait;
                                newTaskDetail.WaitTime           = Action.WaitTime;
                                newTaskDetail.TaskConditonCode   = MustPassItem.TaskConditonCode;
                                newTaskDetail.TaskConfigDetailID = item.DetailID;
                                TaskInfo.TaskDetail.Add(newTaskDetail);
                            }
                        }



                        //foreach (TaskConfigMustPass MustPassItem in ConfigMustPasses)
                        //{
                        //    //根据配置的IO动作ID加载对应的IO动作明细信息
                        //    IOActionInfo CurrIOActionInfo = AGVServerDAccess.LoadAllIOAction(MustPassItem.Action);
                        //    if (CurrIOActionInfo == null)
                        //    {
                        //        LogHelper.WriteCallBoxLog("按钮盒" + CallBox.CallBoxID.ToString() + "对应呼叫,必经地标中的IO动作" + MustPassItem.Action.ToString() + "档案信息不存在");
                        //        continue;
                        //    }
                        //    //找到必经地标中的IO动作后组装任务体
                        //    DispatchTaskDetail dispathDetail_MustPas = new DispatchTaskDetail();
                        //    dispathDetail_MustPas.dispatchNo = dispatchNo;
                        //    dispathDetail_MustPas.DetailID = DetailID;
                        //    dispathDetail_MustPas.LandCode = MustPassItem.MustPassLandCode;
                        //    dispathDetail_MustPas.OperType = -1;
                        //    dispathDetail_MustPas.IsAllowExcute = CurrIOActionInfo.IsWait;
                        //    dispathDetail_MustPas.PutType = -1;
                        //    dispathDetail_MustPas.IOActionID = CurrIOActionInfo.ActionID;
                        //    TaskInfo.TaskDetail.Add(dispathDetail_MustPas);
                        //    DetailID += 1;
                        //}//结束循环处理必经地标配置
                    }

                    //如果没有必经地标或者添加完必经地标后需要继续添加后续的任务配置明细
                    DispatchTaskDetail dispathDetail_TaskConfig = new DispatchTaskDetail();
                    dispathDetail_TaskConfig.dispatchNo    = dispatchNo;
                    dispathDetail_TaskConfig.DetailID      = DetailID;
                    dispathDetail_TaskConfig.LandCode      = ArmStore.LankMarkCode;
                    dispathDetail_TaskConfig.OperType      = item.Action;
                    dispathDetail_TaskConfig.IsAllowExcute = item.IsWaitPass;
                    dispathDetail_TaskConfig.PassType      = item.PassType;
                    if (PrePutType == -1)
                    {
                        dispathDetail_TaskConfig.PutType = ArmStore.StorageState;
                    }
                    else
                    {
                        dispathDetail_TaskConfig.PutType = PrePutType;
                    }
                    dispathDetail_TaskConfig.IsSensorStop = item.IsSensorStop;
                    TaskInfo.TaskDetail.Add(dispathDetail_TaskConfig);
                    PrePutType = ArmStore.StorageState;
                    DetailID  += 1;
                }//结束循环处理任务配置

                //循环组装完任务信息后保存到数据库
                if (TaskInfo != null && TaskInfo.TaskDetail.Count > 0)
                {
                    AGVServerDAccess.CreatTaskInfo(TaskInfo, IsUserStoreState == "是" ? true : false);
                }
                return(true);

                #endregion
            }
            catch (Exception ex)
            {
                LogHelper.WriteCallBoxLog("处理呼叫器呼叫异常:" + ex.Message);
                return(false);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 处理呼叫器呼叫任务
        /// </summary>
        /// <param name="CallBox"></param>
        /// <param name="CurrBoxDetail"></param>
        /// <param name="BtnID"></param>
        /// <returns></returns>
        private bool HandleCallBoxCall(CallBoxInfo CallBox, CallBoxDetail CurrBoxDetail, int BtnID)
        {
            try
            {
                lock (lockstorage)
                {
                    #region 处理呼叫逻辑
                    //加载是否启用储位状态
                    string IsUserStoreState = CoreData.SysParameter["IsUserStoreState"].ToString();
                    if (string.IsNullOrEmpty(IsUserStoreState))
                    {
                        IsUserStoreState = "否";
                    }
                    int CallBoxID = CallBox.CallBoxID;
                    IList <TaskConfigDetail> TaskConfigDetails = AGVClientDAccess.load_TaskDetail(CurrBoxDetail.TaskConditonCode);
                    if (TaskConfigDetails == null && (TaskConfigDetails != null && TaskConfigDetails.Count <= 0))
                    {
                        LogHelper.WriteCallBoxLog("未配置按钮盒" + CallBox.CallBoxID.ToString() + "任务信息");
                        return(false);
                    }
                    DataTable dtstorage = CoreData.dbOperator.LoadDatas("QueryAllStore");
                    CoreData.StorageList = DataToObject.TableToEntity <StorageInfo>(dtstorage);
                    //开始根据任务配置信息创建任务
                    StorageInfo CallStore = CoreData.StorageList.FirstOrDefault(q => q.ID == CurrBoxDetail.LocationID);
                    if (CallStore == null)
                    {
                        LogHelper.WriteCallBoxLog("未配置按钮盒" + CallBox.CallBoxID.ToString() + "对应的监控储位");
                        return(false);
                    }
                    //验证当前按钮盒下是否存在未完成的任务
                    if (AGVSimulationDAccess.ChekAllowCreatTask(CallBoxID, CallStore.LankMarkCode, CurrBoxDetail.ButtonID) > 0)
                    {
                        LogHelper.WriteCallBoxLog("按钮盒" + CallBox.CallBoxID.ToString() + "对应呼叫存在未完成任务,请稍后再试!");
                        return(false);
                    }
                    //验证当前按钮盒下是否存在未完成的任务
                    if (AGVSimulationDAccess.ChekAllowCreatTask2(CallBoxID, CallStore.LankMarkCode, CurrBoxDetail.ButtonID) > 0)
                    {
                        LogHelper.WriteCallBoxLog("按钮盒" + CallBox.CallBoxID.ToString() + "对应呼叫存在未完成任务 未回写的任务,请稍后再试!");
                        return(false);
                    }
                    AreaInfo callarea = CoreData.AllAreaList.FirstOrDefault(p => p.OwnArea == CallStore.OwnArea);
                    if (callarea != null && callarea.MaxTaskCount > 0)
                    {
                        if (AGVSimulationDAccess.ChekAllowCreatTask3(callarea.OwnArea) >= callarea.MaxTaskCount)
                        {
                            LogHelper.WriteCallBoxLog("按钮盒" + CallBox.CallBoxIP.ToString() + " 地址" + CurrBoxDetail.DBAddress + " 对应的区域任务数量达到最大,不产生任务");
                            return(false);
                        }
                    }
                    if (!string.IsNullOrEmpty(CallStore.StorageName))
                    {
                        LogHelper.WriteCallBoxLog("按钮盒" + CallBox.CallBoxIP.ToString() + " 地址" + CurrBoxDetail.DBAddress + "对应储位未启用");
                        return(false);
                    }

                    //组装任务信息
                    string           dispatchNo = Guid.NewGuid().ToString();
                    DispatchTaskInfo TaskInfo   = new DispatchTaskInfo();
                    TaskInfo.dispatchNo = dispatchNo;
                    TaskInfo.TaskState  = 0;
                    TaskInfo.CallLand   = CallStore.LankMarkCode;
                    TaskInfo.stationNo  = CallBoxID;
                    TaskInfo.CallID     = BtnID;
                    TaskInfo.taskType   = 0;
                    TaskInfo.OwerArea   = CallStore.OwnArea;
                    //创建任务明细
                    int DetailID   = 1;
                    int PrePutType = -1;
                    foreach (TaskConfigDetail item in TaskConfigDetails)
                    {
                        //通过任务任务配置明细寻找目标地标
                        StorageInfo ArmStore = null;
                        LogHelper.WriteCallBoxLog("呼叫储位为:" + item.ArmOwnArea.ToString());
                        if (item.ArmOwnArea == -1)
                        {
                            ArmStore = CallStore;
                            LogHelper.WriteCallBoxLog("呼叫储位地标为:" + CallStore.LankMarkCode);
                        }
                        else
                        {
                            if (IsUserStoreState == "否")
                            {
                                ArmStore = CoreData.StorageList.FirstOrDefault(p => p.OwnArea == item.ArmOwnArea && p.StorageState == item.StorageState && p.MaterielType == item.MaterialType);
                            }
                            else
                            {
                                ArmStore = CoreData.StorageList.FirstOrDefault(p => p.OwnArea == item.ArmOwnArea && p.StorageState == item.StorageState && p.MaterielType == item.MaterialType && p.LockState == 0);
                            }
                        }
                        if (ArmStore == null)
                        {
                            LogHelper.WriteCallBoxLog(string.Format("按钮盒{0}   地址:{1}   BtnID{2}   对应呼叫,目的储位不存在[原因:不存在或被占用]", CallBox.CallBoxID, CurrBoxDetail.DBAddress, CurrBoxDetail.ButtonID));
                            return(false);
                        }

                        #region  用
                        //再通过配置任务号来处理必经地标
                        IList <TaskConfigMustPass> ConfigMustPasses = AGVServerDAccess.LoadTaskMustPass(item.TaskConditonCode, item.DetailID);
                        if (ConfigMustPasses != null && ConfigMustPasses.Count > 0)
                        {
                            ////如果配置的必经地标则需要产生任务经过必经地标
                            foreach (TaskConfigMustPass MustPassItem in ConfigMustPasses)
                            {
                                foreach (IOActionInfo Action in MustPassItem.MustPassIOAction)
                                {
                                    IOActionInfo CurrIOActionInfo = AGVServerDAccess.LoadAllIOAction(Action.ActionID);
                                    if (CurrIOActionInfo == null)
                                    {
                                        LogHelper.WriteCallBoxLog("按钮器" + CallBox.CallBoxID.ToString() + "对应呼叫,必经地标中的IO动作" + Action.ActionID.ToString() + "档案信息不存在");
                                        continue;
                                    }
                                    DispatchTaskDetail newTaskDetail = new DispatchTaskDetail();
                                    newTaskDetail.dispatchNo         = dispatchNo;
                                    newTaskDetail.DetailID           = DetailID;
                                    newTaskDetail.LandCode           = MustPassItem.MustPassLandCode;
                                    newTaskDetail.IsAllowExcute      = Action.IsPass;
                                    newTaskDetail.IsSensorStop       = 0;
                                    newTaskDetail.OperType           = -1;
                                    newTaskDetail.IsWait             = Action.IsWait;
                                    newTaskDetail.WaitTime           = Action.WaitTime;
                                    newTaskDetail.TaskConditonCode   = MustPassItem.TaskConditonCode;
                                    newTaskDetail.TaskConfigDetailID = item.DetailID;
                                    TaskInfo.TaskDetail.Add(newTaskDetail);
                                }
                            }
                        }
                        #endregion


                        //如果没有必经地标或者添加完必经地标后需要继续添加后续的任务配置明细
                        DispatchTaskDetail dispathDetail_TaskConfig = new DispatchTaskDetail();
                        dispathDetail_TaskConfig.dispatchNo = dispatchNo;
                        dispathDetail_TaskConfig.DetailID   = DetailID;
                        dispathDetail_TaskConfig.LandCode   = ArmStore.LankMarkCode;
                        dispathDetail_TaskConfig.StorageID  = ArmStore.ID;
                        if (!string.IsNullOrEmpty(ArmStore.Remark))
                        {
                            TaskInfo.GoodsInfo = ArmStore.Remark;
                        }
                        dispathDetail_TaskConfig.OperType       = item.Action;
                        dispathDetail_TaskConfig.IsAllowExcute  = item.IsWaitPass;
                        dispathDetail_TaskConfig.PassType       = item.PassType;
                        dispathDetail_TaskConfig.IsNeedCallBack = item.IsNeedCallBack;
                        dispathDetail_TaskConfig.IsCallGoods    = item.IsCallGoods;

                        if (PrePutType == -1)
                        {
                            dispathDetail_TaskConfig.PutType = ArmStore.StorageState;
                        }
                        else
                        {
                            dispathDetail_TaskConfig.PutType = PrePutType;
                        }
                        dispathDetail_TaskConfig.IsSensorStop = item.IsSensorStop;
                        TaskInfo.TaskDetail.Add(dispathDetail_TaskConfig);
                        PrePutType = ArmStore.StorageState;
                        DetailID  += 1;
                    }//结束循环处理任务配置

                    //循环组装完任务信息后保存到数据库
                    if (TaskInfo != null && TaskInfo.TaskDetail.Count > 0)
                    {
                        AGVServerDAccess.CreatTaskInfo(TaskInfo, IsUserStoreState == "是" ? true : false);
                    }
                    return(true);

                    #endregion
                }
            }
            catch (Exception ex)
            {
                DelegateState.InvokeDispatchStateEvent(ex.Message);
                return(false);
            }
        }