using Pms.DataLibrary.Order;
using ProjectManagementSystem.Common.Config;
using ProjectManagementSystem.Common.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjectManagementSystem.TaskEvent
{
    public class ProcessPlcClear : ICustomProcess
    {
        private List<string> m_currentPosList = new List<string>();
        public void CustomProcess(List<TaskData> dataList)
        {
            m_currentPosList.Clear();
            for (int i = 0; i < dataList.Count; i++)
            {
                var data = dataList[i];

                string[] posArray = data.StepList?
                    .OrderBy(d => d.StepID)?
                    .Select(d => d.WareHouseID)?
                    .Distinct()?
                    .ToArray();

                if (posArray != null)
                {
                    for (int idx = 0; idx < posArray.Length; idx++)
                    {
                        m_currentPosList.Add(posArray[idx]);
                    }
                }
            }

            var RouteConfigList = ExcelConfig.Instance.RouteConfigList;
            for (int i = 0; i < RouteConfigList.Count; i++)
            {
                var routeConfig = ExcelConfig.Instance.RouteConfigList[i];

                //工位没有任务了，需要清零信号
                routeConfig.PlcIsNeedClear = (!string.IsNullOrEmpty(routeConfig.PlcIpAddr) || routeConfig.IOTransID > 0)&& !m_currentPosList.Contains(routeConfig.LocationCode);
            }
        }
    }
}
