LineOneToManyJob.cs 11.6 KB
using Common;
using DeviceLibrary.manager;

namespace DeviceLibrary.bean.job
{
    /// <summary>
    /// 一线体到多线体
    /// </summary>
    public class LineOneToManyJob : Job
    {
        /// <summary>
        ///线体到多线体任务
        /// </summary>
        public LineOneToManyJob(JobParam jobParam) : base(jobParam)
        {
        }
        public LineOneToManyJob() : base()
        {

        }
        lift.LiftStatus liftStatus;
        public override Job Run(AgvInfo agv)
        {
            if (JobRunStep.IsStep(RunStep.NONE))
            {
                JobRunStep.ToNextStep(RunStep.SD_Line_OneToMany_01_ToPickUpPosition);
                runInfo = $"任务开始,去{JobParam.SrcNode.AliceName}的取料点";
                //任务状态变更
                MissionManager.SetMissionState(JobParam.GetMissionInfo().missionId, service.model.MissionState.接料, out string msg);
                AllocateTask(agv, $"{JobParam.SrcNode.Name}_{SettingString.PutShelfOn}");
                JobRunStep.Msg = runInfo;
            }
            else if (JobRunStep.IsStep(RunStep.SD_Line_OneToMany_01_ToPickUpPosition))
            {
                if (agv.TaskRunState.CheckTaskFinished(agv.Name))
                {
                    JobRunStep.ToNextStep(RunStep.SD_Line_OneToMany_02_PutShelfOn);
                    runInfo = $"到达{JobParam.SrcNode.AliceName}的取料点,准备拾取料车";
                    JobRunStep.Msg = runInfo;
                    AllocateTask(agv, $"{SettingString.PutShelfOn}");
                    //上报运输状态
                    manager.UploadManager.UploadTransportStatus(new service.model.TransportStatus(agv.CurJob.JobParam.GetMissionInfo().missionId,
                    service.model.TransportStatus.TypeStr.status, agv.Name, agv.Place.Name, service.model.TransportStatus.ModeStr.auto,
                    $"到达{ JobParam.SrcNode.Name }"));
                }
            }
            else if (JobRunStep.IsStep(RunStep.SD_Line_OneToMany_02_PutShelfOn))
            {
                if (agv.TaskRunState.CheckTaskFinished(agv.Name))
                {
                    JobRunStep.ToNextStep(RunStep.SD_Line_OneToMany_03_ToLine);
                    //上报运输状态
                    manager.UploadManager.UploadTransportStatus(new service.model.TransportStatus(agv.CurJob.JobParam.GetMissionInfo().missionId,
                    service.model.TransportStatus.TypeStr.status, agv.Name, agv.Place.Name, service.model.TransportStatus.ModeStr.auto,
                    $"取车"));
                    runInfo = $"在{JobParam.SrcNode.AliceName}拾取料车完成,去{JobParam.CurTargetNode.AliceName}的放料点";
                    //任务状态变更
                    MissionManager.SetMissionState(JobParam.GetMissionInfo().missionId, service.model.MissionState.送料, out string msg);
                    AllocateTask(agv, $"{JobParam.CurTargetNode.Name}_{SettingString.TakeShelfOff}");
                    JobRunStep.Msg = runInfo;
                }
            }
            else if (JobRunStep.IsStep(RunStep.SD_Line_OneToMany_03_ToLine))
            {
                if (agv.TaskRunState.CheckTaskFinished(agv.Name))
                {
                    //确认按钮生效
                    JobParam.CurTargetNode.ExtendEquip.AllowConfirm();

                    JobRunStep.ToNextStep(RunStep.SD_Line_OneToMany_04_UpdateLocation);
                    runInfo = $"到达{JobParam.CurTargetNode.AliceName}的放料点,上报运输状态";
                    JobRunStep.Msg = runInfo;
                    //上报运输状态
                    manager.UploadManager.UploadTransportStatus(new service.model.TransportStatus(agv.CurJob.JobParam.GetMissionInfo().missionId,
                        service.model.TransportStatus.TypeStr.status, agv.Name, agv.Place.Name, service.model.TransportStatus.ModeStr.auto,
                        $"到达{ JobParam.CurTargetNode.Name }"));
                }
            }
            else if (JobRunStep.IsStep(RunStep.SD_Line_OneToMany_04_UpdateLocation))
            {
                if(NeedConfirm())
                {
                    JobRunStep.ToNextStep(RunStep.SD_Line_OneToMany_05_WaitConfirm);
                    runInfo = $"等待{JobParam.CurTargetNode.AliceName}的人员确认";
                    JobRunStep.Msg = runInfo;
                }
                else
                {
                    JobRunStep.ToNextStep(RunStep.SD_Line_OneToMany_06_CheckNextLine);
                    runInfo = $"{JobParam.CurTargetNode.AliceName}无需人员确认";
                    JobRunStep.Msg = runInfo;
                    //manager.UploadManager.UploadTransportStatus(new service.model.TransportStatus(agv.CurJob.JobParam.GetMissionInfo().missionId,
                    //service.model.TransportStatus.TypeStr.status, agv.Name, agv.Place.Name, service.model.TransportStatus.ModeStr.agvButton,
                    //$"卸货{ JobParam.CurTargetNode.Name }"));
                }
            }
            else if (JobRunStep.IsStep(RunStep.SD_Line_OneToMany_05_WaitConfirm))
            {
                if (OpManager.WaitConfirm.Line(JobParam.CurTargetNode))
                {
                    JobRunStep.ToNextStep(RunStep.SD_Line_OneToMany_06_CheckNextLine);
                    runInfo = $"{JobParam.CurTargetNode.AliceName}的人员确认完成,检查是否有下一线体";
                    JobRunStep.Msg = runInfo;
                    manager.UploadManager.UploadTransportStatus(new service.model.TransportStatus(agv.CurJob.JobParam.GetMissionInfo().missionId,
                    service.model.TransportStatus.TypeStr.status, agv.Name, agv.Place.Name, service.model.TransportStatus.ModeStr.agvButton,
                    $"卸货{ JobParam.CurTargetNode.Name }"));
                    //关闭按钮确认
                    JobParam.CurTargetNode.ExtendEquip.Reset();
                }
                else if (JobRunStep.IsTimeOut(WaitTimeOut, out double timeoutval))
                {
                    //报警,$"等待{JobParam.CurTargetNode.AliceName}的人员确认超时{timeoutval}分"
                    manager.UploadManager.UploadTransportStatus(new service.model.TransportStatus(agv.CurJob.JobParam.GetMissionInfo().missionId,
                   service.model.TransportStatus.TypeStr.error, agv.Name, agv.Place.Name, service.model.TransportStatus.ModeStr.agvButton,
                    $"等待{ JobParam.CurTargetNode.Name }确认超时{timeoutval}分"));
                }
            }
            else if (JobRunStep.IsStep(RunStep.SD_Line_OneToMany_06_CheckNextLine))
            {
                if (JobParam.TargetNodes != null && JobParam.TargetNodes.Count > 0)
                {
                    JobRunStep.ToNextStep(RunStep.SD_Line_OneToMany_03_ToLine);
                    JobParam.CurTargetNode = JobParam.TargetNodes[0];
                    JobParam.TargetNodes.RemoveAt(0);
                    System.Threading.Thread.Sleep(1000);
                    runInfo = $"去下一线体{JobParam.CurTargetNode.AliceName}的放料点";
                    JobRunStep.Msg = runInfo;
                    AllocateTask(agv, $"{JobParam.CurTargetNode.Name}_{SettingString.TakeShelfOff}");
                }
                else
                {
                    if (JobParam.GetMissionInfo() != null && JobParam.GetMissionInfo().needBack)
                    {
                        JobRunStep.ToNextStep(RunStep.SD_Line_OneToMany_07_BackToPickUpPosition);
                        runInfo = $"{JobParam.CurTargetNode.AliceName}是最后一个线体,分发结束,需要返回{JobParam.SrcNode.Name}的放料点";
                        //任务状态变更
                        MissionManager.SetMissionState(JobParam.GetMissionInfo().missionId, service.model.MissionState.返回起始地, out string msg);
                        AllocateTask(agv, $"{JobParam.SrcNode.Name}_{SettingString.TakeShelfOff}");
                        JobRunStep.Msg = runInfo;
                    }
                    else if (JobParam.GetMissionInfo() != null && !JobParam.GetMissionInfo().needBack)
                    {
                        JobRunStep.ToNextStep(RunStep.SD_Line_OnToMany_08_TakeShelfOff);
                        runInfo = $"{JobParam.CurTargetNode.AliceName}是最后一个线体,分发结束,无需返回,直接卸下";
                        JobRunStep.Msg = runInfo;
                        AllocateTask(agv, $"{SettingString.TakeShelfOff}");
                    }
                    else
                    {
                        LogUtil.error(JobParam.GetMissionInfo().ToString());
                    }
                }
            }
            else if (JobRunStep.IsStep(RunStep.SD_Line_OneToMany_07_BackToPickUpPosition))
            {
                if (agv.TaskRunState.CheckTaskFinished(agv.Name))
                {
                    JobRunStep.ToNextStep(RunStep.SD_Line_OnToMany_08_TakeShelfOff);
                    //上报运输状态
                    manager.UploadManager.UploadTransportStatus(new service.model.TransportStatus(agv.CurJob.JobParam.GetMissionInfo().missionId,
                        service.model.TransportStatus.TypeStr.status, agv.Name, agv.Place.Name, service.model.TransportStatus.ModeStr.auto,
                        $"到达{ JobParam.SrcNode.Name }"));
                    runInfo = $"到达{JobParam.SrcNode.AliceName}的放料点,准备卸下料车";
                    JobRunStep.Msg = runInfo;
                    AllocateTask(agv, SettingString.TakeShelfOff);
                }
            }
            else if (JobRunStep.IsStep(RunStep.SD_Line_OnToMany_08_TakeShelfOff))
            {
                if (agv.TaskRunState.CheckTaskFinished(agv.Name))
                {
                    JobRunStep.ToNextStep(RunStep.END);
                    if (JobParam.GetMissionInfo() != null && JobParam.GetMissionInfo().needBack)
                    {
                        //上报运输状态
                        manager.UploadManager.UploadTransportStatus(new service.model.TransportStatus(agv.CurJob.JobParam.GetMissionInfo().missionId,
                         service.model.TransportStatus.TypeStr.status, agv.Name, agv.Place.Name, service.model.TransportStatus.ModeStr.auto,
                        $"还车"));
                    }
                    else if (JobParam.GetMissionInfo() != null && !JobParam.GetMissionInfo().needBack)
                    {
                        //上报运输状态
                        manager.UploadManager.UploadTransportStatus(new service.model.TransportStatus(agv.CurJob.JobParam.GetMissionInfo().missionId,
                        service.model.TransportStatus.TypeStr.status, agv.Name, agv.Place.Name, service.model.TransportStatus.ModeStr.auto,
                        $"卸车"));
                    }

                    runInfo = $"料车在{JobParam.SrcNode.AliceName}放下完成,任务结束";
                    //任务状态变更
                    MissionManager.SetMissionState(JobParam.GetMissionInfo().missionId, service.model.MissionState.完成, out string msg);
                    JobRunStep.Msg = runInfo;
                }
            }
            else if (JobRunStep.IsStep(RunStep.END))
            {
                JobRunStep.EndJob();
                return null;
            }
            agv.SetJobContext(new bean.agv.JobContext()
            {
                MissionId = JobParam.GetMissionInfo().missionId,
                AgvTask = agv.TaskRunState.Task,
                JobFullName = this.ToString(),
                JobStep = JobRunStep.PreStep(),
                Name = agv.Name,
                JobParam = JobParam
            });
            return this;
        }
    }
}