| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 | 
							- using Aitex.Core.RT.Fsm;
 
- using Aitex.Core.RT.Log;
 
- using Aitex.Core.RT.SCCore;
 
- using Aitex.Core.Util;
 
- using PunkHPX8_RT.Dispatch;
 
- using MECF.Framework.Common.Equipment;
 
- using System;
 
- using System.Collections.Concurrent;
 
- using System.Collections.Generic;
 
- using System.Linq;
 
- using System.Text;
 
- using System.Threading.Tasks;
 
- namespace PunkHPX8_RT.Schedulers
 
- {
 
-     public class SchedulerPlatingCellTimeManager: Singleton<SchedulerPlatingCellTimeManager>
 
-     {
 
-         #region 内部变量
 
-         private ConcurrentDictionary<string, List<SchedulerTime>> _platingCellScheduleTimeDic = new ConcurrentDictionary<string, List<SchedulerTime>>();
 
-         #endregion
 
-         /// <summary>
 
-         /// 计算PlatingCell已经使用次数
 
-         /// </summary>
 
-         /// <param name="platingCell"></param>
 
-         /// <param name="platingCellPartTime"></param>
 
-         /// <returns></returns>
 
-         public int CalculatePlatingCellUsed(string platingCell,SchedulerModulePartTime platingCellPartTime)
 
-         {
 
-             int usedCount = _platingCellScheduleTimeDic.ContainsKey(platingCell) ? _platingCellScheduleTimeDic[platingCell].Count : 0;
 
-             return platingCellPartTime.GetModuleUsedCount(platingCell) + usedCount;
 
-         }
 
-         /// <summary>
 
-         /// 按照计划时间排序
 
-         /// </summary>
 
-         /// <param name="modules"></param>
 
-         /// <returns></returns>
 
-         public List<ModuleName> ResetModuleOrderBySchedulerEndTime(List<IModuleEntity> modules)
 
-         {
 
-             List<SchedulerModuleEndTime> schedulerModuleUses = new List<SchedulerModuleEndTime>();
 
-             foreach (IModuleEntity module in modules)
 
-             {
 
-                 SchedulerModuleEndTime moduleEndTime = new SchedulerModuleEndTime();
 
-                 moduleEndTime.ModuleName = module.Module;
 
-                 if (_platingCellScheduleTimeDic.ContainsKey(module.Module.ToString()))
 
-                 {
 
-                     List<SchedulerTime> schedulerTimes = _platingCellScheduleTimeDic[module.Module.ToString()].OrderBy(O=>O.ScheduleStartTime).ToList();
 
-                     SchedulerTime lastSchedulerTime = schedulerTimes.Last();
 
-                     DateTime lastSchedulerEndTime = lastSchedulerTime.ScheduleStartTime.AddSeconds(lastSchedulerTime.ProcessTimeLength);
 
-                     moduleEndTime.SchedulerEndTime = lastSchedulerEndTime;
 
-                 }
 
-                 else
 
-                 {
 
-                     moduleEndTime.SchedulerEndTime = DateTime.MinValue;
 
-                 }
 
-                 schedulerModuleUses.Add(moduleEndTime);
 
-             }
 
-             List<ModuleName> results = schedulerModuleUses.OrderBy(O => O.SchedulerEndTime).Select(O => O.ModuleName).ToList();
 
-             return results;
 
-         }
 
-         /// <summary>
 
-         /// 获取最后的时间轴对象
 
-         /// </summary>
 
-         /// <param name="platingCell"></param>
 
-         /// <returns></returns>
 
-         public SchedulerTime GetLastSchedulerTime(string platingCell)
 
-         {
 
-             if (_platingCellScheduleTimeDic.ContainsKey(platingCell))
 
-             {
 
-                 List<SchedulerTime> schedulerTimes = _platingCellScheduleTimeDic[platingCell].OrderBy(O=>O.ScheduleStartTime).ToList();
 
-                 if (schedulerTimes.Count != 0)
 
-                 {
 
-                     return schedulerTimes.Last();
 
-                 }
 
-                 else
 
-                 {
 
-                     return null;
 
-                 }
 
-             }
 
-             else
 
-             {
 
-                 return null;
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 增加
 
-         /// </summary>
 
-         /// <param name="platingCell"></param>
 
-         /// <param name="waferHolderId"></param>
 
-         /// <param name="schedulerStartTime"></param>
 
-         /// <param name="processTimeLength"></param>
 
-         public void AddPlatingCellScheduler(string platingCell,string waferHolderId,int schedulerIndex,DateTime schedulerStartTime,int processTimeLength,bool writePlatingCellLog=true)
 
-         {
 
-             if (!_platingCellScheduleTimeDic.ContainsKey(platingCell))
 
-             {
 
-                 SchedulerTime platingCellTime = new SchedulerTime();
 
-                 platingCellTime.WaferHolderId = waferHolderId;
 
-                 platingCellTime.ScheduleStartTime = schedulerStartTime;
 
-                 platingCellTime.ProcessTimeLength = processTimeLength;
 
-                 platingCellTime.SchedulerIndex = schedulerIndex;
 
-                 List<SchedulerTime> schedulerPlatingCellTimes = new List<SchedulerTime>();
 
-                 schedulerPlatingCellTimes.Add(platingCellTime);
 
-                 _platingCellScheduleTimeDic.TryAdd(platingCell, schedulerPlatingCellTimes);
 
-             }
 
-             else
 
-             {
 
-                 List<SchedulerTime> schedulerPlatingCellTimes = _platingCellScheduleTimeDic[platingCell];
 
-                 if(schedulerPlatingCellTimes.Find(O=>O.WaferHolderId==waferHolderId&&O.SchedulerIndex==schedulerIndex) == null)
 
-                 {
 
-                     SchedulerTime platingCellTime = new SchedulerTime();
 
-                     platingCellTime.WaferHolderId = waferHolderId;
 
-                     platingCellTime.ScheduleStartTime = schedulerStartTime;
 
-                     platingCellTime.ProcessTimeLength = processTimeLength;
 
-                     platingCellTime.SchedulerIndex = schedulerIndex;
 
-                     schedulerPlatingCellTimes.Add(platingCellTime);
 
-                 }
 
-             }
 
-             if (writePlatingCellLog)
 
-             {
 
-                 WritePlatingCellSchedulerTimeLog();
 
-             }
 
-             LOG.WriteLog(eEvent.INFO_METAL, platingCell, $"add wafer shuttle {waferHolderId} scheduler {schedulerIndex} platingCell {platingCell} in scheduler time");
 
-         }
 
-         /// <summary>
 
-         /// 写PlatingCell调度时间轴日志
 
-         /// </summary>
 
-         public void WritePlatingCellSchedulerTimeLog()
 
-         {
 
-             List<string> keys = _platingCellScheduleTimeDic.Keys.ToList();
 
-             foreach (string key in keys)
 
-             {
 
-                 List<SchedulerTime> schedulerPlatingCellTimes = _platingCellScheduleTimeDic[key].OrderBy(O=>O.ScheduleStartTime).ToList();
 
-                 foreach (SchedulerTime item in schedulerPlatingCellTimes)
 
-                 {
 
-                     DateTime startTime = item.ScheduleStartTime;
 
-                     DateTime endTime = startTime.AddSeconds(item.ProcessTimeLength);
 
-                     LOG.WriteLog(eEvent.INFO_METAL, key, $"wafer shuttle {item.WaferHolderId} scheduler {item.SchedulerIndex} platingCell {key} start time {startTime} end time {endTime} processLength {item.ProcessTimeLength} s");
 
-                 }
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 更新PlatingCell实际启动时间
 
-         /// </summary>
 
-         /// <param name="platingCell"></param>
 
-         /// <param name="startTime"></param>
 
-         public void UpdatePlatingCellStartTime(string platingCell,string waferHolderId,int schedulerIndex,DateTime startTime)
 
-         {
 
-             if (_platingCellScheduleTimeDic.ContainsKey(platingCell))
 
-             {
 
-                 List<SchedulerTime> schedulerPlatingCellTimes= _platingCellScheduleTimeDic[platingCell];
 
-                 SchedulerTime schedulerPlatingCellTime=schedulerPlatingCellTimes.Find(O=>O.WaferHolderId==waferHolderId&&O.SchedulerIndex==schedulerIndex);
 
-                 if (schedulerPlatingCellTime != null)
 
-                 {
 
-                     schedulerPlatingCellTime.StartTime = startTime;
 
-                     if (schedulerPlatingCellTime.StartTime > schedulerPlatingCellTime.ScheduleStartTime)
 
-                     {
 
-                         LOG.WriteLog(eEvent.INFO_METAL, platingCell, $"wafer shuttle {waferHolderId} scheduler {schedulerIndex} platingCell {platingCell} start time {startTime} after scheduler start time {schedulerPlatingCellTime.ScheduleStartTime}");
 
-                         double interSeconds = schedulerPlatingCellTime.StartTime.Subtract(schedulerPlatingCellTime.ScheduleStartTime).TotalSeconds;
 
-                         schedulerPlatingCellTime.ScheduleStartTime = schedulerPlatingCellTime.StartTime;
 
-                         DelayPlatingCellSchedulerStartTime(waferHolderId,schedulerIndex, interSeconds);
 
-                         SchedulerQdrTimeManager.Instance.DelayQdrSchedulerStartTime(waferHolderId, schedulerIndex, interSeconds);
 
-                         SchedulerDryerTimeManager.Instance.DelayDryerSchedulerStartTime(waferHolderId, schedulerIndex, interSeconds);
 
-                         SchedulerTransporterTimeManager.Instance.DelayTransporterSchedulerStartTime(waferHolderId, schedulerIndex, interSeconds);
 
-                         SchedulerWaferHolderTimeManager.Instance.DelayWaferHolderSchedulerStartTime(waferHolderId, schedulerIndex, interSeconds);
 
-                     }
 
-                     LOG.WriteLog(eEvent.INFO_METAL, platingCell, $"update wafer shuttle {waferHolderId} scheduler {schedulerIndex} platingCell {platingCell} start time {startTime}");
 
-                 }
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 延后platingCell后续时间
 
-         /// </summary>
 
-         /// <param name="waferHolderId"></param>
 
-         /// <param name="schedulerIndex"></param>
 
-         /// <param name="seconds"></param>
 
-         public void DelayPlatingCellSchedulerStartTime(string waferHolderId,int schedulerIndex,double seconds)
 
-         {
 
-             List<string> keys = _platingCellScheduleTimeDic.Keys.ToList();
 
-             foreach(string key in keys)
 
-             {
 
-                 List<SchedulerTime> schedulerTimes= _platingCellScheduleTimeDic[key];
 
-                 List<SchedulerTime> postSchedulerTimes= schedulerTimes.FindAll(O => O.WaferHolderId == waferHolderId && O.SchedulerIndex > schedulerIndex);
 
-                 foreach(SchedulerTime schedulerTime in postSchedulerTimes)
 
-                 {
 
-                     schedulerTime.ScheduleStartTime=schedulerTime.ScheduleStartTime.AddSeconds(seconds);
 
-                 }
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 是否为第一个PlatingCell
 
-         /// </summary>
 
-         /// <param name="waferHolderId"></param>
 
-         /// <param name="scheduleIndex"></param>
 
-         /// <returns></returns>
 
-         private bool IsFirstPlatingCell(string waferHolderId,int scheduleIndex)
 
-         {
 
-             return false;
 
-         }
 
-         /// <summary>
 
-         /// 移除
 
-         /// </summary>
 
-         /// <param name="platingCell"></param>
 
-         public void RemovePlatingCellStartTime(string platingCell,string waferHolderId,int schedulerIndex)
 
-         {
 
-             if (_platingCellScheduleTimeDic.ContainsKey(platingCell))
 
-             {
 
-                 List<SchedulerTime> schedulerPlatingCellTimes = _platingCellScheduleTimeDic[platingCell]; 
 
-                 SchedulerTime schedulerPlatingCellTime = schedulerPlatingCellTimes.Find(O => O.WaferHolderId == waferHolderId && O.SchedulerIndex == schedulerIndex);
 
-                 if (schedulerPlatingCellTime != null)
 
-                 {
 
-                     LOG.WriteLog(eEvent.INFO_RINSE, platingCell, $"remove wafer shuttle {waferHolderId} scheduler {schedulerIndex} platingCell {platingCell} in scheduler time");
 
-                     schedulerPlatingCellTimes.Remove(schedulerPlatingCellTime);
 
-                 }
 
-                 if (schedulerPlatingCellTimes.Count == 0)
 
-                 {
 
-                     _platingCellScheduleTimeDic.TryRemove(platingCell, out schedulerPlatingCellTimes);
 
-                     LOG.WriteLog(eEvent.INFO_METAL, platingCell, $"delete wafer shuttle {waferHolderId} scheduler {schedulerIndex} platingCell {platingCell} in scheduler time");
 
-                 }
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 检验PlatingCell是否冲突
 
-         /// </summary>
 
-         /// <param name="waferHolderId"></param>
 
-         /// <param name="schedulerStartTime"></param>
 
-         /// <param name="processTimeLength"></param>
 
-         /// <returns></returns>
 
-         public (bool conflict,string waferHolderId,int schedluerIndex) CheckPlatingCellConflict(string platingCell,string waferHolderId, DateTime schedulerStartTime, int processTimeLength)
 
-         {
 
-             if (!_platingCellScheduleTimeDic.ContainsKey(platingCell))
 
-             {
 
-                 return (false, "", -1);
 
-             }
 
-             List<SchedulerTime> schedulerPlatingCellTimes= _platingCellScheduleTimeDic[platingCell];
 
-             foreach(SchedulerTime item in schedulerPlatingCellTimes)
 
-             {
 
-                 if (item.WaferHolderId == waferHolderId)
 
-                 {
 
-                     continue;
 
-                 }
 
-                 //if (WaferHolderManager.Instance.HasWaferHolder(platingCell))
 
-                 //{
 
-                 //    WaferHolderInfo waferHolderInfo = WaferHolderManager.Instance.GetWaferHolder(platingCell);
 
-                 //    if (waferHolderInfo==null)
 
-                 //    { 
 
-                 //        return (true, "", -1);
 
-                 //    } 
 
-                 //    WaferHolderTask waferHolderTask= WaferHolderTaskManager.Instance.GetWaferHolderTaskByWaferHolderId(waferHolderInfo.Id);
 
-                 //    if (waferHolderTask != null)
 
-                 //    {
 
-                 //        return (true, waferHolderInfo.Id, waferHolderTask.GetCurrentSchedulerIndex());
 
-                 //    }
 
-                 //    return (true, "", -1);
 
-                 //}
 
-                 bool result=CheckPlatingCellTimeConflict(item,schedulerStartTime, processTimeLength);
 
-                 if (result)
 
-                 {
 
-                     return (true,item.WaferHolderId,item.SchedulerIndex);
 
-                 }
 
-             }
 
-             return (false, "", -1);
 
-         }
 
-         /// <summary>
 
-         /// 判定时间是否冲突
 
-         /// </summary>
 
-         /// <param name="schedulerPlatingCellTime"></param>
 
-         /// <param name="schedulerStartTime"></param>
 
-         /// <param name="processTimeLength"></param>
 
-         /// <returns></returns>
 
-         private bool CheckPlatingCellTimeConflict(SchedulerTime schedulerPlatingCellTime, DateTime schedulerStartTime, int processTimeLength)
 
-         {
 
-             int transporterTransferSeconds = SC.GetValue<int>("Transporter.TransporterTransferSeconds");
 
-             DateTime schedulerEndTime = schedulerStartTime.AddSeconds(processTimeLength);
 
-             DateTime platingCellEndTime = schedulerPlatingCellTime.ScheduleStartTime.AddSeconds(schedulerPlatingCellTime.ProcessTimeLength);
 
-             DateTime platingCellStartTime= schedulerPlatingCellTime.ScheduleStartTime;
 
-             if (schedulerStartTime > platingCellEndTime.AddSeconds(transporterTransferSeconds))
 
-             {
 
-                 return false;
 
-             }
 
-             if (schedulerEndTime.AddSeconds(transporterTransferSeconds) < platingCellStartTime)
 
-             {
 
-                 return false;
 
-             }
 
-             return true;
 
-         }
 
-         /// <summary>
 
-         /// 清除所有
 
-         /// </summary>
 
-         public void RemoveAll()
 
-         {
 
-             List<string> keys = _platingCellScheduleTimeDic.Keys.ToList();
 
-             foreach (string key in keys)
 
-             {
 
-                 List<SchedulerTime> schedulerTimes = _platingCellScheduleTimeDic[key];
 
-                 schedulerTimes.Clear();
 
-             }
 
-             _platingCellScheduleTimeDic.Clear();
 
-             LOG.Write(eEvent.INFO_RINSE,"System", "Remove all platingCell scheduler time");
 
-         }
 
-         /// <summary>
 
-         /// 计算数量
 
-         /// </summary>
 
-         /// <param name="platingCell"></param>
 
-         /// <returns></returns>
 
-         public DateTime CalculateSchedulerEndTime(string platingCell)
 
-         {
 
-             if (_platingCellScheduleTimeDic.ContainsKey(platingCell))
 
-             {
 
-                 DateTime dateTime = DateTime.MinValue;
 
-                 foreach(var item in _platingCellScheduleTimeDic[platingCell])
 
-                 {
 
-                     DateTime startTime =  item.ScheduleStartTime;
 
-                     if (startTime.AddSeconds(item.ProcessTimeLength) > dateTime)
 
-                     {
 
-                         dateTime= startTime.AddSeconds(item.ProcessTimeLength);
 
-                     }
 
-                 }
 
-                 return dateTime;
 
-             }
 
-             else
 
-             {
 
-                 return DateTime.MinValue;
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 是否包含
 
-         /// </summary>
 
-         /// <param name="platingCell"></param>
 
-         /// <returns></returns>
 
-         public bool ContainedPlatingCell(string platingCell)
 
-         {
 
-             return _platingCellScheduleTimeDic.ContainsKey(platingCell);
 
-         }
 
-     }
 
- }
 
 
  |