SchedulerDBCallback.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Aitex.Core.Common;
  7. using Aitex.Core.RT.SCCore;
  8. using MECF.Framework.Common.DBCore;
  9. using MECF.Framework.Common.Equipment;
  10. using MECF.Framework.Common.Jobs;
  11. using MECF.Framework.Common.SubstrateTrackings;
  12. using FurnaceRT.Equipments.PMs.RecipeExecutions;
  13. using Aitex.Core.RT.Log;
  14. namespace FurnaceRT.Equipments.Schedulers
  15. {
  16. class SchedulerDBCallback : ISchedulerDBCallback
  17. {
  18. private ProcessJobInfo _processJobInfo;
  19. public void LotCreated(ControlJobInfo cj)
  20. {
  21. if (string.IsNullOrEmpty(cj.Module))
  22. return;
  23. ModuleName module = ModuleHelper.Converter(cj.Module);
  24. Guid carrierGuid = CarrierManager.Instance.GetCarrier(cj.Module).InnerId;
  25. LotDataRecorder.StartLot(cj.LotInnerId.ToString(), carrierGuid.ToString(), "", cj.LotName, cj.Module, cj.Module, cj.LotWafers.Count);
  26. foreach (var waferInfo in cj.LotWafers)
  27. {
  28. LotDataRecorder.InsertLotWafer(cj.LotInnerId.ToString(), waferInfo.InnerId.ToString());
  29. WaferDataRecorder.SetWaferSequence(waferInfo.InnerId.ToString(), waferInfo.PPID);
  30. }
  31. }
  32. public void LotFinished(ControlJobInfo cj)
  33. {
  34. int unprocessed = 0;
  35. int aborted = 0;
  36. foreach (var waferInfo in cj.LotWafers)
  37. {
  38. if (waferInfo.ProcessState == EnumWaferProcessStatus.Failed)
  39. {
  40. aborted++;
  41. continue;
  42. }
  43. if (waferInfo.ProcessState != EnumWaferProcessStatus.Completed)
  44. {
  45. unprocessed++;
  46. continue;
  47. }
  48. }
  49. LotDataRecorder.EndLot(cj.LotInnerId.ToString(), aborted, unprocessed);
  50. }
  51. public void PjCreated(params object[] objs)
  52. {
  53. var param = (Dictionary<string, object>)objs[0];
  54. string jobName = (string)param["JobRecipe"];
  55. string recipeName = (string)param["ProcessRecipe"];
  56. string layoutName = (string)param["LayoutRecipe"];
  57. string form = (string)param["Form"];
  58. string batchId = "";
  59. if (param.ContainsKey("Batch"))
  60. {
  61. batchId = $"Batch{(string)param["Batch"]}{DateTime.Now.ToString("yyyyMMddHHmmssffff")}";
  62. }
  63. else
  64. {
  65. batchId = DateTime.Now.ToString("yyyyMMddHHmmssffff");
  66. }
  67. _processJobInfo = new ProcessJobInfo();
  68. _processJobInfo.Name = jobName;
  69. _processJobInfo.LotName = jobName;
  70. _processJobInfo.InnerId = Guid.NewGuid();
  71. RecipeParser.LayoutRecipeParse(layoutName, ModuleName.PM1.ToString(), out RecipeLayoutEntityNormal layoutRecipeDataNormal, out RecipeLayoutEntityExpert layoutRecipeDataExpert, out string reason);
  72. string layoutData = String.Join(",", layoutRecipeDataExpert.Items);
  73. JobDataRecorder.CreatePJ(_processJobInfo.InnerId.ToString(), batchId, jobName, recipeName, layoutName, layoutData, form);
  74. }
  75. public void PjCreated(string batch, string jobRecipe, string processRecipe, string layoutRecipe)
  76. {
  77. string batchId = "";
  78. if (!string.IsNullOrEmpty(batch))
  79. {
  80. batchId = $"Batch{batch}{DateTime.Now.ToString("yyyyMMddHHmmssffff")}";
  81. }
  82. else
  83. {
  84. batchId = DateTime.Now.ToString("yyyyMMddHHmmssffff");
  85. }
  86. _processJobInfo = new ProcessJobInfo();
  87. _processJobInfo.Name = jobRecipe;
  88. _processJobInfo.LotName = jobRecipe;
  89. _processJobInfo.InnerId = Guid.NewGuid();
  90. RecipeParser.LayoutRecipeParse(layoutRecipe, ModuleName.PM1.ToString(), out RecipeLayoutEntityNormal layoutRecipeDataNormal, out RecipeLayoutEntityExpert layoutRecipeDataExpert, out string reason);
  91. string layoutData = String.Join(",", layoutRecipeDataExpert.Items);
  92. JobDataRecorder.CreatePJ(_processJobInfo.InnerId.ToString(), batchId, jobRecipe, processRecipe, layoutRecipe, layoutData, "Normal");
  93. }
  94. public void PjCreated(ProcessJobInfo pj)
  95. {
  96. _processJobInfo = new ProcessJobInfo();
  97. _processJobInfo.Name = pj.Name;
  98. _processJobInfo.LotName = pj.LotName;
  99. _processJobInfo.InnerId = pj.InnerId;
  100. _processJobInfo.JobRecipe = pj.JobRecipe;
  101. _processJobInfo.ProcessRecipe = pj.ProcessRecipe;
  102. _processJobInfo.LayoutRecipe = pj.LayoutRecipe;
  103. var batchId = DateTime.Now.ToString("yyyyMMddHHmmssffff");
  104. RecipeParser.LayoutRecipeParse(_processJobInfo.LayoutRecipe, ModuleName.PM1.ToString(),
  105. out RecipeLayoutEntityNormal layoutRecipeDataNormal, out RecipeLayoutEntityExpert layoutRecipeDataExpert, out string reason);
  106. string layoutData = String.Join(",", layoutRecipeDataExpert.Items);
  107. JobDataRecorder.CreatePJ(_processJobInfo.InnerId.ToString(), batchId,
  108. _processJobInfo.JobRecipe, _processJobInfo.ProcessRecipe, _processJobInfo.LayoutRecipe, layoutData, "Normal");
  109. }
  110. public void PjCreated(string processName)
  111. {
  112. string form = "process";
  113. string batchId = $"process{DateTime.Now.ToString("yyyyMMddHHmmssffff")}";
  114. _processJobInfo = new ProcessJobInfo();
  115. _processJobInfo.Name = processName;
  116. _processJobInfo.LotName = processName;
  117. _processJobInfo.InnerId = Guid.NewGuid();
  118. JobDataRecorder.CreatePJ(_processJobInfo.InnerId.ToString(), batchId, "", processName, "", "", form);
  119. }
  120. public void PjStart()
  121. {
  122. JobDataRecorder.StartPJ(_processJobInfo.InnerId.ToString());
  123. }
  124. public void PjUpdated()
  125. {
  126. var wafers = WaferManager.Instance.GetWafers(ModuleName.PM1);
  127. List<string> layoutDatas = new List<string>();
  128. List<string> waferDatas = new List<string>();
  129. //StringBuilder waferData = new StringBuilder();
  130. int waferCount = 0;
  131. for (int i = 0; i < wafers.Length; i++)
  132. {
  133. if (wafers[i].IsEmpty)
  134. {
  135. layoutDatas.Add("");
  136. continue;
  137. }
  138. switch (wafers[i].WaferType)
  139. {
  140. case WaferType.P:
  141. case WaferType.M:
  142. case WaferType.M1:
  143. case WaferType.M2:
  144. case WaferType.SD:
  145. case WaferType.ED:
  146. layoutDatas.Add($"{wafers[i].WaferType}-{wafers[i].LotId}-{wafers[i].WaferOrigin.Replace("Stocker", "")}");
  147. //layoutDatas.Add($"{wafers[i].WaferType}-{wafers[i].WaferOrigin}");
  148. break;
  149. default:
  150. layoutDatas.Add("");
  151. break;
  152. }
  153. waferDatas.Add($"{wafers[i].WaferType}:{wafers[i].WaferOrigin}:{wafers[i].LotId}");
  154. //waferData.Append(wafers[i].WaferType.ToString() + ":");
  155. //waferData.Append(wafers[i].WaferOrigin + ",");
  156. waferCount++;
  157. }
  158. string layoutData = String.Join(",", layoutDatas);
  159. string waferData = String.Join(",", waferDatas);
  160. if(_processJobInfo != null)
  161. JobDataRecorder.UpdatePJ(_processJobInfo.InnerId.ToString(), layoutData, waferData, waferCount);
  162. }
  163. public string GetFirstPJId()
  164. {
  165. if (_processJobInfo != null) return _processJobInfo.InnerId.ToString();
  166. return "";
  167. }
  168. public void PjFinished(string endStatus = "Normal")
  169. {
  170. if (_processJobInfo != null)
  171. JobDataRecorder.EndPJ(_processJobInfo.InnerId.ToString(), endStatus);
  172. }
  173. public void JobCreated(ControlJobInfo cj, ProcessJobInfo pj)
  174. {
  175. List<string> carrierInnerIdLst = new List<string>();
  176. List<string> stockerModuleLst = new List<string>();
  177. List<int> stockerWaferCountLst = new List<int>();
  178. foreach (var s in pj.Stockers)
  179. {
  180. var type = SC.GetStringValue($"System.Stocker.{s.Item1}WaferType");
  181. if (!string.IsNullOrEmpty(type) && (type.Contains("P") || type.Contains("M")))
  182. {
  183. ModuleName module = ModuleHelper.Converter(s.Item1);
  184. var carrier = CarrierManager.Instance.GetCarrier(s.Item1, 0);
  185. if (carrier != null && !carrier.IsEmpty)
  186. {
  187. var waferCount = WaferManager.Instance.GetWafers(module).ToList().Where(x => !x.IsEmpty).Count();
  188. carrierInnerIdLst.Add(carrier.InnerId.ToString());
  189. stockerModuleLst.Add(s.Item1);
  190. stockerWaferCountLst.Add(waferCount);
  191. }
  192. }
  193. }
  194. JobDataRecorder.StartPJ(pj.InnerId.ToString(), string.Join(";", carrierInnerIdLst), cj.InnerId.ToString(), cj.LotName, pj.Name, string.Join(";", stockerModuleLst), string.Join(";", stockerModuleLst), stockerWaferCountLst.Sum(), pj.JobRecipe);
  195. }
  196. }
  197. }