AutoInoutInfo.cs 4.9 KB
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OnlineStore.DeviceLibrary
{
    public class AutoInoutInfo
    {
        /// <summary>
        /// 入库完成后自动出库,出库完成后自动入库
        /// </summary>
        public bool autoNext = false;
        /// <summary>
        /// 自动出入库间隔
        /// </summary>
        private int Jiange = 3;
        private int positionIndex = 0;
        public string autoMsg = "";
        private int startIndex = -1;
        #region 出入库参数
        /// <summary>
        /// 当前出入库的次数,超过配置的数量时,需要自动重置一下,再进行出入库
        /// </summary>
        internal int CurrInOutCount = 0;
        internal int CurrInOutACount = 0;
        #endregion



        public void StartAuto(int jiange, int currIndex)
        {
            autoNext = true;
            Jiange = jiange;
            positionIndex = currIndex;
            startIndex = currIndex;
        }
        public void StopAuto()
        {
            autoNext = false;
        }

        internal void InOutEndProcess(BoxBean boxBean, MoveType storeMoveType)
        {
            try
            {
                CurrInOutCount++;
                CurrInOutACount++;
                //是否自动进入出库状态
                if (!autoNext)
                {
                    return;
                }
                if (storeMoveType.Equals(MoveType.InStore))
                {
                    int newIndex = positionIndex - 1;
                    if (newIndex < 0)
                    {
                        if (startIndex >= 0 && startIndex < boxBean.PositionNumList.Count)
                        {
                            newIndex = startIndex;
                            boxBean.LogInfo("下一个索引不存在,重新开始自动出入库,索引【" + startIndex + "】");
                        }
                        else
                        {
                            autoNext = false;
                            autoMsg = "自动出入库结束!";
                            boxBean.LogInfo("下一个索引不存在,自动 出入库结束!");
                            return;
                        }
                    }
                    positionIndex = newIndex;
                    string posid = boxBean.PositionNumList[positionIndex];

                    InOutParam param = new InOutParam(MoveType.OutStore, "AutoOut", posid, 1);
                    //判断是否需要重置
                    if (CurrInOutACount >= StoreManager.Config.Box_ResetACount)
                    {
                        boxBean.LogInfo("自动进入下一个出库:posid=" + posid + ",当时已经出入库" + CurrInOutACount + "次,需要重置BOX,先把出库信息存入排队列表中");
                        boxBean.Reset(false);
                        autoMsg = "自动出库:" + posid;
                        boxBean.waitOutStoreList.Enqueue(param);
                    }
                    else
                    {
                        boxBean.LogInfo("自动进入下一个出库:posid=" + posid);
                        autoMsg = "自动出库:" + posid;
                        boxBean.StartOutStoreMove(param);
                    }
                }
                else if (storeMoveType.Equals(MoveType.OutStore))
                {
                    int newIndex = positionIndex - Jiange;
                    if (newIndex < 0)
                    {
                        if (startIndex >= 0 && startIndex < boxBean.PositionNumList.Count)
                        {
                            newIndex = startIndex;
                            boxBean.LogInfo("下一个索引不存在,重新开始自动出入库,索引【" + startIndex + "】");
                        }
                        else
                        {
                            autoNext = false;
                            autoMsg = "自动出入库结束!";
                            boxBean.LogInfo("下一个索引不存在,自动 出入库结束!");
                            return;
                        }
                    }
                    //positionIndex = newIndex;
                    string posid = boxBean.PositionNumList[newIndex];
                    InOutParam param = new InOutParam(MoveType.InStore, "AutoIn", posid);

                    boxBean.LogInfo("自动进入下一个入库:posid=" + posid);
                    autoMsg = "自动入库:" + posid;
                    boxBean.StartInStoreMove(param);
                }
            }
            catch (Exception ex)
            {
                LogUtil.error(boxBean.Name + "InOutEndProcess ERROR:" + ex.ToString());
            }
        }

        internal void ClearCount()
        {
            CurrInOutACount = 0;
            CurrInOutCount = 0;
        }
    }
}