ProcessDataRecorder.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using Aitex.Core.RT.DBCore;
  5. using Aitex.Core.RT.Log;
  6. using Aitex.Core.UI.ControlDataContext;
  7. using Aitex.Sorter.Common;
  8. using DocumentFormat.OpenXml.Drawing;
  9. using MECF.Framework.Common.CommonData;
  10. using MECF.Framework.Common.Equipment;
  11. using Venus_Core;
  12. namespace MECF.Framework.Common.DBCore
  13. {
  14. public class ProcessDataRecorder
  15. {
  16. public static void Start(string guid, string recipeName )
  17. {
  18. string sql = string.Format(
  19. "INSERT INTO \"process_data\"(\"guid\", \"process_begin_time\", \"recipe_name\" )VALUES ('{0}', '{1}', '{2}' );",
  20. guid,
  21. DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"),
  22. recipeName );
  23. DB.Insert(sql);
  24. }
  25. public static void Start(string guid, string recipeName, string waferDataGuid, string processIn)
  26. {
  27. string sql = string.Format(
  28. "INSERT INTO \"process_data\"(\"guid\", \"process_begin_time\", \"recipe_name\" , \"wafer_data_guid\", \"process_in\" )VALUES ('{0}', '{1}', '{2}', '{3}', '{4}' );",
  29. guid,
  30. DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"),
  31. recipeName,
  32. waferDataGuid,
  33. processIn);
  34. DB.Insert(sql);
  35. }
  36. public static void Start(string guid, string recipeName, string waferDataGuid, string processIn,string lotID,string slotID)
  37. {
  38. string sql = string.Format(
  39. "INSERT INTO \"process_data\"(\"guid\", \"process_begin_time\", \"recipe_name\" , \"wafer_data_guid\", \"process_in\", \"lot_id\", \"slot_id\" )VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}' );",
  40. guid,
  41. DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"),
  42. recipeName,
  43. waferDataGuid,
  44. processIn,
  45. lotID,
  46. string.IsNullOrEmpty(slotID) ? "" : (int.Parse(slotID) + 1).ToString());
  47. DB.Insert(sql);
  48. }
  49. public static void UpdateStatus(string guid, string status)
  50. {
  51. string sql = string.Format(
  52. "UPDATE \"process_data\" SET \"process_status\"='{0}' WHERE \"guid\"='{1}';",
  53. status,
  54. guid);
  55. DB.Insert(sql);
  56. }
  57. public static void UpdateRecipeSettingTime(string guid, float time)
  58. {
  59. string sql = string.Format(
  60. "UPDATE \"process_data\" SET \"recipe_setting_time\"='{0}' WHERE \"guid\"='{1}';",
  61. time,
  62. guid);
  63. DB.Insert(sql);
  64. }
  65. public static void UpdateStatus(string guid, string status, string chamber)
  66. {
  67. string sql = string.Format(
  68. "UPDATE \"process_data\" SET \"process_status\"='{0}' WHERE \"guid\"='{1}' and \"process_in\"='{2}';",
  69. status, guid, chamber);
  70. DB.Insert(sql);
  71. }
  72. public static void End(string guid, string status)
  73. {
  74. string sql = string.Format(
  75. "UPDATE \"process_data\" SET \"process_end_time\"='{0}',\"process_status\"='{1}' WHERE \"guid\"='{2}';",
  76. DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"),
  77. status,
  78. guid);
  79. DB.Insert(sql);
  80. }
  81. public static void End(string guid, string status, string chamber)
  82. {
  83. string sql = string.Format(
  84. "UPDATE \"process_data\" SET \"process_end_time\"='{0}',\"process_status\"='{1}' WHERE \"guid\"='{2}' and \"process_in\"='{3}';",
  85. DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"), status, guid, chamber);
  86. DB.Insert(sql);
  87. }
  88. public static void End(string guid)
  89. {
  90. string sql = string.Format(
  91. "UPDATE \"process_data\" SET \"process_end_time\"='{0}' WHERE \"guid\"='{1}';",
  92. DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"),
  93. guid);
  94. DB.Insert(sql);
  95. }
  96. public static void StepEnd(string recipeGuid, int stepNumber, List<FdcDataItem> stepData = null)
  97. {
  98. string sql = $"UPDATE \"recipe_step_data\" SET \"step_end_time\"='{DateTime.Now:yyyy/MM/dd HH:mm:ss.fff}' WHERE \"process_data_guid\"='{recipeGuid}' and \"step_number\"='{stepNumber}';";
  99. DB.Insert(sql);
  100. if (stepData != null && stepData.Count > 0)
  101. {
  102. foreach (var item in stepData)
  103. {
  104. sql = $"INSERT INTO \"step_fdc_data\"(\"process_data_guid\", \"create_time\", \"step_number\" , \"parameter_name\", \"sample_count\", \"min_value\", \"max_value\", \"setpoint\", \"std_value\", \"mean_value\")VALUES ('{recipeGuid}', '{DateTime.Now:yyyy/MM/dd HH:mm:ss.fff}', '{stepNumber}', '{item.Name}', '{item.SampleCount}', '{item.MinValue}', '{item.MaxValue}', '{item.SetPoint}', '{item.StdValue}', '{item.MeanValue}' );";
  105. DB.Insert(sql);
  106. }
  107. }
  108. }
  109. public static void RecordPrecess(string guid, DateTime startTime, DateTime endTime, string recipeName,string status, string waferDataGuid, string processIn, string lotID, string slotID, string recipe_type,string carrierId,string lotType)
  110. {
  111. string sql = string.Format(
  112. "INSERT INTO \"process_data\"(\"guid\", \"process_begin_time\",\"process_end_time\", \"recipe_name\" ,\"process_status\", \"wafer_data_guid\", \"process_in\", \"lot_id\", \"slot_id\", \"recipe_type\", \"carrier_id\", \"lot_type\")VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}','{7}' ,'{8}','{9}','{10}','{11}');",
  113. guid,
  114. startTime.ToString("yyyy/MM/dd HH:mm:ss.fff"),
  115. endTime.ToString("yyyy/MM/dd HH:mm:ss.fff"),
  116. recipeName,
  117. status,
  118. waferDataGuid,
  119. processIn,
  120. lotID,
  121. string.IsNullOrEmpty(slotID) ? "" : (int.Parse(slotID) + 1).ToString(),
  122. recipe_type,
  123. carrierId,
  124. lotType
  125. );
  126. DB.Insert(sql);
  127. }
  128. public List<string> GetHistoryRecipeList(DateTime begin, DateTime end)
  129. {
  130. List<string> result = new List<string>();
  131. string sql = string.Format("SELECT * FROM \"RecipeRunHistory\" where \"ProcessBeginTime\" >= '{0}' and \"ProcessBeginTime\" <= '{1}' order by \"ProcessBeginTime\" ASC;",
  132. begin.ToString("yyyy/MM/dd HH:mm:ss.fff"), end.ToString("yyyy/MM/dd HH:mm:ss.fff"));
  133. DataSet ds = DB.ExecuteDataset(sql);
  134. if (ds == null)
  135. return result;
  136. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  137. {
  138. string recipe = ds.Tables[0].Rows[i]["RecipeName"].ToString();
  139. if (!result.Contains(recipe))
  140. result.Add(recipe);
  141. }
  142. ds.Clear();
  143. return result;
  144. }
  145. public static List<HistoryProcessData> QueryDBProcess(string sql)
  146. {
  147. List<HistoryProcessData> result = new List<HistoryProcessData>();
  148. try
  149. {
  150. DataSet ds = DB.ExecuteDataset(sql);
  151. if (ds == null)
  152. return result;
  153. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  154. {
  155. HistoryProcessData ev = new HistoryProcessData();
  156. ev.RecipeName = ds.Tables[0].Rows[i]["recipe_name"].ToString();
  157. ev.Result = ds.Tables[0].Rows[i]["process_status"].ToString();
  158. ev.Guid = ds.Tables[0].Rows[i]["guid"].ToString();
  159. if (!ds.Tables[0].Rows[i]["process_begin_time"].Equals(DBNull.Value))
  160. ev.StartTime = ((DateTime)ds.Tables[0].Rows[i]["process_begin_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
  161. if (!ds.Tables[0].Rows[i]["process_end_time"].Equals(DBNull.Value))
  162. ev.EndTime = ((DateTime)ds.Tables[0].Rows[i]["process_end_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
  163. result.Add(ev);
  164. }
  165. }
  166. catch (Exception ex)
  167. {
  168. LOG.WriteExeption(ex);
  169. }
  170. return result;
  171. }
  172. public static List<HistoryDataItem> GetHistoryDataFromStartToEnd(IEnumerable<string> keys, DateTime begin, DateTime end, string module)
  173. {
  174. List<HistoryDataItem> result = new List<HistoryDataItem>();
  175. try
  176. {
  177. DateTime begintime = new DateTime(begin.Year, begin.Month, begin.Day, begin.Hour, begin.Minute, begin.Second, begin.Millisecond);
  178. DateTime endtime = new DateTime(begin.Year, begin.Month, end.Day, end.Hour, end.Minute, end.Second, end.Millisecond);
  179. string sql = "select time AS InternalTimeStamp";
  180. foreach (var dataId in keys)
  181. {
  182. sql += "," + string.Format("\"{0}\"", dataId);
  183. }
  184. sql += string.Format(" from \"{0}\" where time > {1} and time <= {2} order by time asc LIMIT 86400;",
  185. begin.ToString("yyyyMMdd") + "." + module, begintime.Ticks, endtime.Ticks);
  186. DataSet dataSet = DB.ExecuteDataset(sql);
  187. if (dataSet == null)
  188. return result;
  189. if (dataSet.Tables.Count == 0 || dataSet.Tables[0].Rows.Count == 0)
  190. return result;
  191. DateTime dt = new DateTime();
  192. Dictionary<int, string> colName = new Dictionary<int, string>();
  193. for (int colNo = 0; colNo < dataSet.Tables[0].Columns.Count; colNo++)
  194. colName.Add(colNo, dataSet.Tables[0].Columns[colNo].ColumnName);
  195. for (int rowNo = 0; rowNo < dataSet.Tables[0].Rows.Count; rowNo++)
  196. {
  197. var row = dataSet.Tables[0].Rows[rowNo];
  198. for (int i = 0; i < dataSet.Tables[0].Columns.Count; i++)
  199. {
  200. HistoryDataItem data = new HistoryDataItem();
  201. if (i == 0)
  202. {
  203. long ticks = (long)row[i];
  204. dt = new DateTime(ticks);
  205. continue;
  206. }
  207. else
  208. {
  209. string dataId = colName[i];
  210. if (row[i] is DBNull || row[i] == null)
  211. {
  212. data.dateTime = dt;
  213. data.dbName = colName[i];
  214. data.value = 0;
  215. }
  216. else if (row[i] is bool)
  217. {
  218. data.dateTime = dt;
  219. data.dbName = colName[i];
  220. data.value = (bool)row[i] ? 1 : 0;
  221. }
  222. else
  223. {
  224. data.dateTime = dt;
  225. data.dbName = colName[i];
  226. data.value = float.Parse(row[i].ToString());
  227. }
  228. }
  229. result.Add(data);
  230. }
  231. }
  232. dataSet.Clear();
  233. }
  234. catch (Exception ex)
  235. {
  236. LOG.WriteExeption(ex);
  237. }
  238. return result;
  239. }
  240. public static List<HistoryDataItem> GetOneDayHistoryData(IEnumerable<string> keys, DateTime begin, string module)
  241. {
  242. List<HistoryDataItem> result = new List<HistoryDataItem>();
  243. try
  244. {
  245. DateTime begintime = new DateTime(begin.Year, begin.Month, begin.Day, 0, 0, 0, 0);
  246. DateTime endtime = new DateTime(begin.Year, begin.Month, begin.Day, 23, 59, 59, 999);
  247. string sql = "select time AS InternalTimeStamp";
  248. foreach (var dataId in keys)
  249. {
  250. sql += "," + string.Format("\"{0}\"", dataId);
  251. }
  252. sql += string.Format(" from \"{0}\" where time > {1} and time <= {2} order by time asc LIMIT 86400;",
  253. begin.ToString("yyyyMMdd") + "." + module, begintime.Ticks, endtime.Ticks);
  254. DataSet dataSet = DB.ExecuteDataset(sql);
  255. if (dataSet == null)
  256. return result;
  257. if (dataSet.Tables.Count == 0 || dataSet.Tables[0].Rows.Count == 0)
  258. return result;
  259. DateTime dt = new DateTime();
  260. Dictionary<int, string> colName = new Dictionary<int, string>();
  261. for (int colNo = 0; colNo < dataSet.Tables[0].Columns.Count; colNo++)
  262. colName.Add(colNo, dataSet.Tables[0].Columns[colNo].ColumnName);
  263. for (int rowNo = 0; rowNo < dataSet.Tables[0].Rows.Count; rowNo++)
  264. {
  265. var row = dataSet.Tables[0].Rows[rowNo];
  266. for (int i = 0; i < dataSet.Tables[0].Columns.Count; i++)
  267. {
  268. HistoryDataItem data = new HistoryDataItem();
  269. if (i == 0)
  270. {
  271. long ticks = (long)row[i];
  272. dt = new DateTime(ticks);
  273. continue;
  274. }
  275. else
  276. {
  277. string dataId = colName[i];
  278. if (row[i] is DBNull || row[i] == null)
  279. {
  280. data.dateTime = dt;
  281. data.dbName = colName[i];
  282. data.value = 0;
  283. }
  284. else if (row[i] is bool)
  285. {
  286. data.dateTime = dt;
  287. data.dbName = colName[i];
  288. data.value = (bool)row[i] ? 1 : 0;
  289. }
  290. else
  291. {
  292. data.dateTime = dt;
  293. data.dbName = colName[i];
  294. data.value = float.Parse(row[i].ToString());
  295. }
  296. }
  297. result.Add(data);
  298. }
  299. }
  300. dataSet.Clear();
  301. }
  302. catch (Exception ex)
  303. {
  304. LOG.WriteExeption(ex);
  305. }
  306. return result;
  307. }
  308. public static List<HistoryDataItem> GetHistoryData(IEnumerable<string> keys, string recipeRunGuid, string module)
  309. {
  310. List<HistoryDataItem> result = new List<HistoryDataItem>();
  311. try
  312. {
  313. string sql = string.Format("SELECT * FROM \"process_data\" where \"guid\" = '{0}'",
  314. recipeRunGuid);
  315. DataSet ds = DB.ExecuteDataset(sql);
  316. if (ds == null)
  317. return result;
  318. if (ds.Tables[0].Rows.Count == 0)
  319. return result;
  320. object from = ds.Tables[0].Rows[0]["process_begin_time"];
  321. if (from is DBNull)
  322. {
  323. //LOG.Write(string.Format("{0} not set start time", recipeRunGuid));
  324. return result;
  325. }
  326. DateTime begin = (DateTime)from;
  327. begin = begin.AddSeconds(-10);
  328. object to = ds.Tables[0].Rows[0]["process_end_time"];
  329. if (to is DBNull)
  330. {
  331. to = new DateTime(begin.Year, begin.Month, begin.Day, 23, 59, 59, 999);
  332. }
  333. DateTime end = (DateTime)to;
  334. end = end.AddSeconds(10);
  335. sql = "select time AS InternalTimeStamp";
  336. foreach (var dataId in keys)
  337. {
  338. sql += "," + string.Format("\"{0}\"", dataId);
  339. }
  340. sql += string.Format(" from \"{0}\" where time > {1} and time <= {2} order by time asc LIMIT 2000;",
  341. begin.ToString("yyyyMMdd") + "." + module, begin.Ticks, end.Ticks);
  342. DataSet dataSet = DB.ExecuteDataset(sql);
  343. if (dataSet == null)
  344. return result;
  345. if (dataSet.Tables.Count == 0 || dataSet.Tables[0].Rows.Count == 0)
  346. return result;
  347. DateTime dt = new DateTime();
  348. Dictionary<int, string> colName = new Dictionary<int, string>();
  349. for (int colNo = 0; colNo < dataSet.Tables[0].Columns.Count; colNo++)
  350. colName.Add(colNo, dataSet.Tables[0].Columns[colNo].ColumnName);
  351. for (int rowNo = 0; rowNo < dataSet.Tables[0].Rows.Count; rowNo++)
  352. {
  353. var row = dataSet.Tables[0].Rows[rowNo];
  354. for (int i = 0; i < dataSet.Tables[0].Columns.Count; i++)
  355. {
  356. HistoryDataItem data = new HistoryDataItem();
  357. if (i == 0)
  358. {
  359. long ticks = (long)row[i];
  360. dt = new DateTime(ticks);
  361. continue;
  362. }
  363. else
  364. {
  365. string dataId = colName[i];
  366. if (row[i] is DBNull || row[i] == null)
  367. {
  368. data.dateTime = dt;
  369. data.dbName = colName[i];
  370. data.value = 0;
  371. }
  372. else if (row[i] is bool)
  373. {
  374. data.dateTime = dt;
  375. data.dbName = colName[i];
  376. data.value = (bool)row[i] ? 1 : 0;
  377. }
  378. else
  379. {
  380. data.dateTime = dt;
  381. data.dbName = colName[i];
  382. data.value = float.Parse(row[i].ToString());
  383. }
  384. }
  385. result.Add(data);
  386. }
  387. }
  388. dataSet.Clear();
  389. }
  390. catch (Exception ex)
  391. {
  392. LOG.WriteExeption(ex);
  393. }
  394. return result;
  395. }
  396. public static void StepStart(string recipeGuid, int stepNumber, string stepName, float stepTime)
  397. {
  398. string guid = Guid.NewGuid().ToString();
  399. string sql = $"INSERT INTO \"recipe_step_data\"(\"guid\", \"step_begin_time\", \"step_name\" , \"step_time\", \"process_data_guid\", \"step_number\")VALUES ('{guid}', '{DateTime.Now:yyyy/MM/dd HH:mm:ss.fff}', '{stepName}', '{stepTime}', '{recipeGuid}', '{stepNumber}' );";
  400. //System.Diagnostics.Trace.WriteLine(sql);
  401. DB.Insert(sql);
  402. }
  403. public static List<HistoryStepItem> GetHistoryStepList(DateTime begin, DateTime end)
  404. {
  405. List<HistoryStepItem> result = new List<HistoryStepItem>();
  406. string sql = string.Format("SELECT * FROM \"recipe_step_data\" where \"step_begin_time\" >= '{0}' and \"step_begin_time\" <= '{1}' order by \"step_begin_time\" ASC;",
  407. begin.ToString("yyyy/MM/dd HH:mm:ss.fff"), end.ToString("yyyy/MM/dd HH:mm:ss.fff"));
  408. DataSet ds = DB.ExecuteDataset(sql);
  409. if (ds == null)
  410. return result;
  411. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  412. {
  413. var recipeIds = ds.Tables[0].Rows[i]["step_name"].ToString().Split(':');
  414. result.Add(new HistoryStepItem()
  415. {
  416. StartTime = Convert.ToDateTime(ds.Tables[0].Rows[i]["step_begin_time"]),
  417. EndTime = DateTime.Now,
  418. StepHoldTime=Convert.ToInt32(ds.Tables[0].Rows[i]["step_time"]),
  419. RecipeId= recipeIds.Length>0? recipeIds[0]:"",
  420. StepNo =$"Step{Convert.ToInt32(ds.Tables[0].Rows[i]["step_number"])}"
  421. });
  422. }
  423. ds.Clear();
  424. return result;
  425. }
  426. }
  427. }