SchedulerPlatingCellTimeManager.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. using Aitex.Core.RT.Fsm;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.SCCore;
  4. using Aitex.Core.Util;
  5. using PunkHPX8_RT.Dispatch;
  6. using MECF.Framework.Common.Equipment;
  7. using System;
  8. using System.Collections.Concurrent;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace PunkHPX8_RT.Schedulers
  14. {
  15. public class SchedulerPlatingCellTimeManager: Singleton<SchedulerPlatingCellTimeManager>
  16. {
  17. #region 内部变量
  18. private ConcurrentDictionary<string, List<SchedulerTime>> _platingCellScheduleTimeDic = new ConcurrentDictionary<string, List<SchedulerTime>>();
  19. #endregion
  20. /// <summary>
  21. /// 计算PlatingCell已经使用次数
  22. /// </summary>
  23. /// <param name="platingCell"></param>
  24. /// <param name="platingCellPartTime"></param>
  25. /// <returns></returns>
  26. public int CalculatePlatingCellUsed(string platingCell,SchedulerModulePartTime platingCellPartTime)
  27. {
  28. int usedCount = _platingCellScheduleTimeDic.ContainsKey(platingCell) ? _platingCellScheduleTimeDic[platingCell].Count : 0;
  29. return platingCellPartTime.GetModuleUsedCount(platingCell) + usedCount;
  30. }
  31. /// <summary>
  32. /// 按照计划时间排序
  33. /// </summary>
  34. /// <param name="modules"></param>
  35. /// <returns></returns>
  36. public List<ModuleName> ResetModuleOrderBySchedulerEndTime(List<IModuleEntity> modules)
  37. {
  38. List<SchedulerModuleEndTime> schedulerModuleUses = new List<SchedulerModuleEndTime>();
  39. foreach (IModuleEntity module in modules)
  40. {
  41. SchedulerModuleEndTime moduleEndTime = new SchedulerModuleEndTime();
  42. moduleEndTime.ModuleName = module.Module;
  43. if (_platingCellScheduleTimeDic.ContainsKey(module.Module.ToString()))
  44. {
  45. List<SchedulerTime> schedulerTimes = _platingCellScheduleTimeDic[module.Module.ToString()].OrderBy(O=>O.ScheduleStartTime).ToList();
  46. SchedulerTime lastSchedulerTime = schedulerTimes.Last();
  47. DateTime lastSchedulerEndTime = lastSchedulerTime.ScheduleStartTime.AddSeconds(lastSchedulerTime.ProcessTimeLength);
  48. moduleEndTime.SchedulerEndTime = lastSchedulerEndTime;
  49. }
  50. else
  51. {
  52. moduleEndTime.SchedulerEndTime = DateTime.MinValue;
  53. }
  54. schedulerModuleUses.Add(moduleEndTime);
  55. }
  56. List<ModuleName> results = schedulerModuleUses.OrderBy(O => O.SchedulerEndTime).Select(O => O.ModuleName).ToList();
  57. return results;
  58. }
  59. /// <summary>
  60. /// 获取最后的时间轴对象
  61. /// </summary>
  62. /// <param name="platingCell"></param>
  63. /// <returns></returns>
  64. public SchedulerTime GetLastSchedulerTime(string platingCell)
  65. {
  66. if (_platingCellScheduleTimeDic.ContainsKey(platingCell))
  67. {
  68. List<SchedulerTime> schedulerTimes = _platingCellScheduleTimeDic[platingCell].OrderBy(O=>O.ScheduleStartTime).ToList();
  69. if (schedulerTimes.Count != 0)
  70. {
  71. return schedulerTimes.Last();
  72. }
  73. else
  74. {
  75. return null;
  76. }
  77. }
  78. else
  79. {
  80. return null;
  81. }
  82. }
  83. /// <summary>
  84. /// 增加
  85. /// </summary>
  86. /// <param name="platingCell"></param>
  87. /// <param name="waferHolderId"></param>
  88. /// <param name="schedulerStartTime"></param>
  89. /// <param name="processTimeLength"></param>
  90. public void AddPlatingCellScheduler(string platingCell,string waferHolderId,int schedulerIndex,DateTime schedulerStartTime,int processTimeLength,bool writePlatingCellLog=true)
  91. {
  92. if (!_platingCellScheduleTimeDic.ContainsKey(platingCell))
  93. {
  94. SchedulerTime platingCellTime = new SchedulerTime();
  95. platingCellTime.WaferHolderId = waferHolderId;
  96. platingCellTime.ScheduleStartTime = schedulerStartTime;
  97. platingCellTime.ProcessTimeLength = processTimeLength;
  98. platingCellTime.SchedulerIndex = schedulerIndex;
  99. List<SchedulerTime> schedulerPlatingCellTimes = new List<SchedulerTime>();
  100. schedulerPlatingCellTimes.Add(platingCellTime);
  101. _platingCellScheduleTimeDic.TryAdd(platingCell, schedulerPlatingCellTimes);
  102. }
  103. else
  104. {
  105. List<SchedulerTime> schedulerPlatingCellTimes = _platingCellScheduleTimeDic[platingCell];
  106. if(schedulerPlatingCellTimes.Find(O=>O.WaferHolderId==waferHolderId&&O.SchedulerIndex==schedulerIndex) == null)
  107. {
  108. SchedulerTime platingCellTime = new SchedulerTime();
  109. platingCellTime.WaferHolderId = waferHolderId;
  110. platingCellTime.ScheduleStartTime = schedulerStartTime;
  111. platingCellTime.ProcessTimeLength = processTimeLength;
  112. platingCellTime.SchedulerIndex = schedulerIndex;
  113. schedulerPlatingCellTimes.Add(platingCellTime);
  114. }
  115. }
  116. if (writePlatingCellLog)
  117. {
  118. WritePlatingCellSchedulerTimeLog();
  119. }
  120. LOG.WriteLog(eEvent.INFO_METAL, platingCell, $"add wafer shuttle {waferHolderId} scheduler {schedulerIndex} platingCell {platingCell} in scheduler time");
  121. }
  122. /// <summary>
  123. /// 写PlatingCell调度时间轴日志
  124. /// </summary>
  125. public void WritePlatingCellSchedulerTimeLog()
  126. {
  127. List<string> keys = _platingCellScheduleTimeDic.Keys.ToList();
  128. foreach (string key in keys)
  129. {
  130. List<SchedulerTime> schedulerPlatingCellTimes = _platingCellScheduleTimeDic[key].OrderBy(O=>O.ScheduleStartTime).ToList();
  131. foreach (SchedulerTime item in schedulerPlatingCellTimes)
  132. {
  133. DateTime startTime = item.ScheduleStartTime;
  134. DateTime endTime = startTime.AddSeconds(item.ProcessTimeLength);
  135. 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");
  136. }
  137. }
  138. }
  139. /// <summary>
  140. /// 更新PlatingCell实际启动时间
  141. /// </summary>
  142. /// <param name="platingCell"></param>
  143. /// <param name="startTime"></param>
  144. public void UpdatePlatingCellStartTime(string platingCell,string waferHolderId,int schedulerIndex,DateTime startTime)
  145. {
  146. if (_platingCellScheduleTimeDic.ContainsKey(platingCell))
  147. {
  148. List<SchedulerTime> schedulerPlatingCellTimes= _platingCellScheduleTimeDic[platingCell];
  149. SchedulerTime schedulerPlatingCellTime=schedulerPlatingCellTimes.Find(O=>O.WaferHolderId==waferHolderId&&O.SchedulerIndex==schedulerIndex);
  150. if (schedulerPlatingCellTime != null)
  151. {
  152. schedulerPlatingCellTime.StartTime = startTime;
  153. if (schedulerPlatingCellTime.StartTime > schedulerPlatingCellTime.ScheduleStartTime)
  154. {
  155. LOG.WriteLog(eEvent.INFO_METAL, platingCell, $"wafer shuttle {waferHolderId} scheduler {schedulerIndex} platingCell {platingCell} start time {startTime} after scheduler start time {schedulerPlatingCellTime.ScheduleStartTime}");
  156. double interSeconds = schedulerPlatingCellTime.StartTime.Subtract(schedulerPlatingCellTime.ScheduleStartTime).TotalSeconds;
  157. schedulerPlatingCellTime.ScheduleStartTime = schedulerPlatingCellTime.StartTime;
  158. DelayPlatingCellSchedulerStartTime(waferHolderId,schedulerIndex, interSeconds);
  159. SchedulerQdrTimeManager.Instance.DelayQdrSchedulerStartTime(waferHolderId, schedulerIndex, interSeconds);
  160. SchedulerDryerTimeManager.Instance.DelayDryerSchedulerStartTime(waferHolderId, schedulerIndex, interSeconds);
  161. SchedulerTransporterTimeManager.Instance.DelayTransporterSchedulerStartTime(waferHolderId, schedulerIndex, interSeconds);
  162. SchedulerWaferHolderTimeManager.Instance.DelayWaferHolderSchedulerStartTime(waferHolderId, schedulerIndex, interSeconds);
  163. }
  164. LOG.WriteLog(eEvent.INFO_METAL, platingCell, $"update wafer shuttle {waferHolderId} scheduler {schedulerIndex} platingCell {platingCell} start time {startTime}");
  165. }
  166. }
  167. }
  168. /// <summary>
  169. /// 延后platingCell后续时间
  170. /// </summary>
  171. /// <param name="waferHolderId"></param>
  172. /// <param name="schedulerIndex"></param>
  173. /// <param name="seconds"></param>
  174. public void DelayPlatingCellSchedulerStartTime(string waferHolderId,int schedulerIndex,double seconds)
  175. {
  176. List<string> keys = _platingCellScheduleTimeDic.Keys.ToList();
  177. foreach(string key in keys)
  178. {
  179. List<SchedulerTime> schedulerTimes= _platingCellScheduleTimeDic[key];
  180. List<SchedulerTime> postSchedulerTimes= schedulerTimes.FindAll(O => O.WaferHolderId == waferHolderId && O.SchedulerIndex > schedulerIndex);
  181. foreach(SchedulerTime schedulerTime in postSchedulerTimes)
  182. {
  183. schedulerTime.ScheduleStartTime=schedulerTime.ScheduleStartTime.AddSeconds(seconds);
  184. }
  185. }
  186. }
  187. /// <summary>
  188. /// 是否为第一个PlatingCell
  189. /// </summary>
  190. /// <param name="waferHolderId"></param>
  191. /// <param name="scheduleIndex"></param>
  192. /// <returns></returns>
  193. private bool IsFirstPlatingCell(string waferHolderId,int scheduleIndex)
  194. {
  195. return false;
  196. }
  197. /// <summary>
  198. /// 移除
  199. /// </summary>
  200. /// <param name="platingCell"></param>
  201. public void RemovePlatingCellStartTime(string platingCell,string waferHolderId,int schedulerIndex)
  202. {
  203. if (_platingCellScheduleTimeDic.ContainsKey(platingCell))
  204. {
  205. List<SchedulerTime> schedulerPlatingCellTimes = _platingCellScheduleTimeDic[platingCell];
  206. SchedulerTime schedulerPlatingCellTime = schedulerPlatingCellTimes.Find(O => O.WaferHolderId == waferHolderId && O.SchedulerIndex == schedulerIndex);
  207. if (schedulerPlatingCellTime != null)
  208. {
  209. LOG.WriteLog(eEvent.INFO_RINSE, platingCell, $"remove wafer shuttle {waferHolderId} scheduler {schedulerIndex} platingCell {platingCell} in scheduler time");
  210. schedulerPlatingCellTimes.Remove(schedulerPlatingCellTime);
  211. }
  212. if (schedulerPlatingCellTimes.Count == 0)
  213. {
  214. _platingCellScheduleTimeDic.TryRemove(platingCell, out schedulerPlatingCellTimes);
  215. LOG.WriteLog(eEvent.INFO_METAL, platingCell, $"delete wafer shuttle {waferHolderId} scheduler {schedulerIndex} platingCell {platingCell} in scheduler time");
  216. }
  217. }
  218. }
  219. /// <summary>
  220. /// 检验PlatingCell是否冲突
  221. /// </summary>
  222. /// <param name="waferHolderId"></param>
  223. /// <param name="schedulerStartTime"></param>
  224. /// <param name="processTimeLength"></param>
  225. /// <returns></returns>
  226. public (bool conflict,string waferHolderId,int schedluerIndex) CheckPlatingCellConflict(string platingCell,string waferHolderId, DateTime schedulerStartTime, int processTimeLength)
  227. {
  228. if (!_platingCellScheduleTimeDic.ContainsKey(platingCell))
  229. {
  230. return (false, "", -1);
  231. }
  232. List<SchedulerTime> schedulerPlatingCellTimes= _platingCellScheduleTimeDic[platingCell];
  233. foreach(SchedulerTime item in schedulerPlatingCellTimes)
  234. {
  235. if (item.WaferHolderId == waferHolderId)
  236. {
  237. continue;
  238. }
  239. //if (WaferHolderManager.Instance.HasWaferHolder(platingCell))
  240. //{
  241. // WaferHolderInfo waferHolderInfo = WaferHolderManager.Instance.GetWaferHolder(platingCell);
  242. // if (waferHolderInfo==null)
  243. // {
  244. // return (true, "", -1);
  245. // }
  246. // WaferHolderTask waferHolderTask= WaferHolderTaskManager.Instance.GetWaferHolderTaskByWaferHolderId(waferHolderInfo.Id);
  247. // if (waferHolderTask != null)
  248. // {
  249. // return (true, waferHolderInfo.Id, waferHolderTask.GetCurrentSchedulerIndex());
  250. // }
  251. // return (true, "", -1);
  252. //}
  253. bool result=CheckPlatingCellTimeConflict(item,schedulerStartTime, processTimeLength);
  254. if (result)
  255. {
  256. return (true,item.WaferHolderId,item.SchedulerIndex);
  257. }
  258. }
  259. return (false, "", -1);
  260. }
  261. /// <summary>
  262. /// 判定时间是否冲突
  263. /// </summary>
  264. /// <param name="schedulerPlatingCellTime"></param>
  265. /// <param name="schedulerStartTime"></param>
  266. /// <param name="processTimeLength"></param>
  267. /// <returns></returns>
  268. private bool CheckPlatingCellTimeConflict(SchedulerTime schedulerPlatingCellTime, DateTime schedulerStartTime, int processTimeLength)
  269. {
  270. int transporterTransferSeconds = SC.GetValue<int>("Transporter.TransporterTransferSeconds");
  271. DateTime schedulerEndTime = schedulerStartTime.AddSeconds(processTimeLength);
  272. DateTime platingCellEndTime = schedulerPlatingCellTime.ScheduleStartTime.AddSeconds(schedulerPlatingCellTime.ProcessTimeLength);
  273. DateTime platingCellStartTime= schedulerPlatingCellTime.ScheduleStartTime;
  274. if (schedulerStartTime > platingCellEndTime.AddSeconds(transporterTransferSeconds))
  275. {
  276. return false;
  277. }
  278. if (schedulerEndTime.AddSeconds(transporterTransferSeconds) < platingCellStartTime)
  279. {
  280. return false;
  281. }
  282. return true;
  283. }
  284. /// <summary>
  285. /// 清除所有
  286. /// </summary>
  287. public void RemoveAll()
  288. {
  289. List<string> keys = _platingCellScheduleTimeDic.Keys.ToList();
  290. foreach (string key in keys)
  291. {
  292. List<SchedulerTime> schedulerTimes = _platingCellScheduleTimeDic[key];
  293. schedulerTimes.Clear();
  294. }
  295. _platingCellScheduleTimeDic.Clear();
  296. LOG.Write(eEvent.INFO_RINSE,"System", "Remove all platingCell scheduler time");
  297. }
  298. /// <summary>
  299. /// 计算数量
  300. /// </summary>
  301. /// <param name="platingCell"></param>
  302. /// <returns></returns>
  303. public DateTime CalculateSchedulerEndTime(string platingCell)
  304. {
  305. if (_platingCellScheduleTimeDic.ContainsKey(platingCell))
  306. {
  307. DateTime dateTime = DateTime.MinValue;
  308. foreach(var item in _platingCellScheduleTimeDic[platingCell])
  309. {
  310. DateTime startTime = item.ScheduleStartTime;
  311. if (startTime.AddSeconds(item.ProcessTimeLength) > dateTime)
  312. {
  313. dateTime= startTime.AddSeconds(item.ProcessTimeLength);
  314. }
  315. }
  316. return dateTime;
  317. }
  318. else
  319. {
  320. return DateTime.MinValue;
  321. }
  322. }
  323. /// <summary>
  324. /// 是否包含
  325. /// </summary>
  326. /// <param name="platingCell"></param>
  327. /// <returns></returns>
  328. public bool ContainedPlatingCell(string platingCell)
  329. {
  330. return _platingCellScheduleTimeDic.ContainsKey(platingCell);
  331. }
  332. }
  333. }