DoubleLineNodeFor4D.cs 5.1 KB
using BLL;
using log4net.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AGVControl
{
    /// <summary>
    /// 
    /// </summary>
    public class DoubleLineNodeFor4D : ClientNode
    {
        public DoubleLineNodeFor4D(string name, string ip, string aliceName, string lineName, string pos_name, string pos_guid, bool isUse, int emptyCnt) : base(name, ip, aliceName, lineName, pos_name, pos_guid, isUse, emptyCnt)
        {

        }

        /// <summary>
        /// 双层线任务
        /// </summary>
        /// <param name="currentAgv"></param>
        /// <returns></returns>
        public override Job GetNewJob(Agv_Info currentAgv)
        {
            if (SettingString.C4_AGV_IPs.Contains(currentAgv.IP))
                return null;
            if (!Common.CheckCanExecuteMission(currentAgv))
                return null;
            if (!Common.CheckAGVStatusNone(currentAgv))
                return null;
            //执行空料架任务的小车数量
            int emptyJobCnt = 0;
            foreach (Agv_Info agv in Common.agvInfo)
            {
                if (SettingString.C4_AGV_IPs.Contains(agv.IP))
                    continue;
                if (agv.CurJob is GoEmptyShelfLineJob || agv.CurJob is EmptyShelfBackJob)
                {
                    emptyJobCnt++;
                }
            }
            if ((SettingString.AGVCNT / 2 - emptyJobCnt).Equals(1))//保留1辆小车出满料架
            {
                return null;
            }
            //出工单料的目的地是否有空料架
            if (Common.FindEmptyShelfBeforeSendFullShelf(out string nodeName))
            {
                if (nodeName.StartsWith("E") && !SettingString.C4_AGV_IPs.Contains(currentAgv.IP))
                {
                    ClientNode clientNode = Common.nodeInfo.Find(s => s.Name.Equals(nodeName));
                    int cnt = 0;
                    foreach (Agv_Info agv in Common.agvInfo)
                    {
                        if (SettingString.C4_AGV_IPs.Contains(agv.IP))
                            continue;
                        if (agv.CurJob is GoEmptyShelfLineJob)
                        {
                            if (((GoEmptyShelfLineJob)agv.CurJob).EmptyShelfPlace.Equals(nodeName))
                                cnt++;
                        }
                    }
                    if (cnt < clientNode.EmptyShelfCnt)
                    {
                        return new GoEmptyShelfLineJob(currentAgv.Place, nodeName);
                    }
                }

            }
            //回收空料架
            if (Common.FindEmptyShelfNode(currentAgv, out string emptyNodeName))
            {
                if (!SettingString.C4_AGV_IPs.Contains(currentAgv.IP))
                {
                    int i = Common.agvInfo.FindIndex(s => s.CurJob is GoEmptyShelfLineJob && ((GoEmptyShelfLineJob)s.CurJob).EmptyShelfPlace.Equals(emptyNodeName));
                    if (i > -1)
                        return null;

                    //foreach (Agv_Info agv in Common.agvInfo)
                    //{
                    //    if (SettingString.C4_AGV_IPs.Contains(agv.IP))
                    //        continue;
                    //    if (agv.CurJob is GoEmptyShelfLineJob && ((GoEmptyShelfLineJob)agv.CurJob).EmptyShelfPlace.Equals(emptyNodeName))
                    //    {
                    //        return null;
                    //    }
                    //}
                    return new GoEmptyShelfLineJob(currentAgv.Place, emptyNodeName);
                }
            }

            //出满料
            if (Common.FindFullShelfTask(currentAgv))
            {
                if (!SettingString.C4_AGV_IPs.Contains(currentAgv.IP))
                {
                    int i = Common.agvInfo.FindIndex(s => s.CurJob is GoFullShelfStationJob && !s.IP.Equals(currentAgv.IP));
                    if (i > -1)
                    {
                        return null;
                    }

                    ClientNode node = Common.nodeInfo.Find(s => s.Name.Equals(SettingString.A6)
                        && (s.StateEquals(eNodeStatus.NeedLeave) || s.StateEquals(eNodeStatus.NeedEnterLeave)) && !s.RFID.Equals("00"));
                    if (node != null && node.Name.Equals(SettingString.A6))
                    {
                        if (AGVManager.FindFullShelfTarget(node.RFID, out AGVManager.BoxDestInfo boxDestInfo))
                        {
                            if (boxDestInfo != null)
                            {
                                i = Common.agvInfo.FindIndex(s => s.CurJob is SendFullShelfToLineJob && !s.IP.Equals(currentAgv.IP) 
                                && ((SendFullShelfToLineJob)s.CurJob).FullShelfPlace.Equals(boxDestInfo.location));
                                if (i > -1)
                                    return null;
                            }
                        }
                    }

                    return new GoFullShelfStationJob(currentAgv.Place);
                }
            }

            return null;
        }
    }
}