AutoChargeTask.cs 2.5 KB
using CtuDeviceLib;
using Mushiny;
using OnlineStore.Common;

namespace DeviceLibrary.CtuService
{
    /// <summary>
    /// 自动充电任务
    /// </summary>
    public class AutoChargeTask : CtuTaskBase
    {
        public AutoChargeTask(CTU ctu) : base(ctu)
        {
            Name = "自动充电";
        }



        CtuTaskBase GetChargeTask()
        {
            var chargeStation = PosInfos.GetAllPosInfos().Find(posInfo =>
            {
                if (posInfo.Name.StartsWith("ChargeStation"))
                {
                    var thisStationUsedCtu = CTUManager.GetEnabledCTUs().Find(otherCtu => otherCtu.CtuTask != null && otherCtu.CtuTask is ChargeTask && otherCtu.CtuTask.DstName.Equals(posInfo.Name));
                    if (thisStationUsedCtu == null)
                    {
                        return true;
                    }
                }
                return false;
            });

            if (chargeStation != null)
            {
                return new ChargeTask(ctu, chargeStation.Name);
            }
            else
            {
                MoveInfo.Info($"CTU [{ctu.Name}] 到达强制充电值,但未找到可用充电位");
            }
            return null;
        }

        public override void Excute()
        {
            if (ctu.AllBasketIsEmpty())
            {
                var chargeTask = GetChargeTask();
                if (chargeTask != null)
                {
                    ctu.CtuTask = chargeTask;
                    return;
                }
            }

            switch (MoveInfo.MoveStep)
            {
                case RunStep.Wait:
                    MoveInfo.Info($"自动充电任务取出背篓料箱任务处理中");
                    CtuTaskBase putBoxTask = null;

                    putBoxTask = OutTaskHelper.GetPutBoxTask(ctu);
                    if (putBoxTask == null)
                    {
                        putBoxTask = OutTaskHelper.GetPutBoxToLineTask(ctu);
                        if (putBoxTask != null)
                        {
                            ctu.CtuTask = putBoxTask;
                            return;
                        }
                    }

                    if (putBoxTask != null)
                    {
                        ctu.CtuTask = putBoxTask;
                        return;
                    }

                    break;
                case RunStep.CtuTask_ProcessFinished:

                    break;



            }

        }

    }
}