JobManager.cs 1.7 KB
using DeviceLib.Model.AGV;
using System.Collections.Generic;

namespace DeviceLib.BLL
{
    public class JobManager
    {

        static List<JobType> jobTypes = new List<JobType>()
        {
            new ToShelfJobType(),
            new ToStoreJobType(),
            new ChargeStandJobType() 
        };
        /// <summary>
        /// 获取运输任务
        /// </summary>
        /// <param name="robot"></param>
        /// <returns></returns>
        public static bool CheckNewJob(Robot robot)
        {
            bool rtn= jobTypes[0].CheckNewJob(robot);
            if(!rtn)
                rtn = jobTypes[1].CheckNewJob(robot);
            return rtn;
        }
        public static void GetNewJob(Robot robot)
        {
            Job job = robot.job;
            if (job == null)
                job = getJob(robot);
            robot.job = job;
        }
        public static void Execute(Robot robot)
        {
            robot?.operation?.Check_Mission_InQueue();
            if (!robot.auto) return;
            if (robot.job != null)
                robot.job = robot.job.Execute(robot);
        }
        public static void CheckResend(Robot robot)
        {
            if (!robot.auto) return;
            if (robot?.mission_state?.run_id == -1)
            {
                if (robot.job != null)
                {
                    robot.job.ReSendMission(robot);
                }
            }
        }
        static Job getJob(Robot robot)
        {
            foreach (var item in jobTypes)
            {
                Job job = item.GetNewJob(robot);
                if (job != null) return job;
            }
            return null;
        }
    }
}