ProcessDataRecorder.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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)
  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\")VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}','{7}' ,'{8}','{9}');",
  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. );
  124. DB.Insert(sql);
  125. }
  126. public List<string> GetHistoryRecipeList(DateTime begin, DateTime end)
  127. {
  128. List<string> result = new List<string>();
  129. string sql = string.Format("SELECT * FROM \"RecipeRunHistory\" where \"ProcessBeginTime\" >= '{0}' and \"ProcessBeginTime\" <= '{1}' order by \"ProcessBeginTime\" ASC;",
  130. begin.ToString("yyyy/MM/dd HH:mm:ss.fff"), end.ToString("yyyy/MM/dd HH:mm:ss.fff"));
  131. DataSet ds = DB.ExecuteDataset(sql);
  132. if (ds == null)
  133. return result;
  134. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  135. {
  136. string recipe = ds.Tables[0].Rows[i]["RecipeName"].ToString();
  137. if (!result.Contains(recipe))
  138. result.Add(recipe);
  139. }
  140. ds.Clear();
  141. return result;
  142. }
  143. public static List<HistoryProcessData> QueryDBProcess(string sql)
  144. {
  145. List<HistoryProcessData> result = new List<HistoryProcessData>();
  146. try
  147. {
  148. DataSet ds = DB.ExecuteDataset(sql);
  149. if (ds == null)
  150. return result;
  151. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  152. {
  153. HistoryProcessData ev = new HistoryProcessData();
  154. ev.RecipeName = ds.Tables[0].Rows[i]["recipe_name"].ToString();
  155. ev.Result = ds.Tables[0].Rows[i]["process_status"].ToString();
  156. ev.Guid = ds.Tables[0].Rows[i]["guid"].ToString();
  157. if (!ds.Tables[0].Rows[i]["process_begin_time"].Equals(DBNull.Value))
  158. ev.StartTime = ((DateTime)ds.Tables[0].Rows[i]["process_begin_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
  159. if (!ds.Tables[0].Rows[i]["process_end_time"].Equals(DBNull.Value))
  160. ev.EndTime = ((DateTime)ds.Tables[0].Rows[i]["process_end_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
  161. result.Add(ev);
  162. }
  163. }
  164. catch (Exception ex)
  165. {
  166. LOG.WriteExeption(ex);
  167. }
  168. return result;
  169. }
  170. public static List<HistoryDataItem> GetHistoryDataFromStartToEnd(IEnumerable<string> keys, DateTime begin, DateTime end, string module)
  171. {
  172. List<HistoryDataItem> result = new List<HistoryDataItem>();
  173. try
  174. {
  175. DateTime begintime = new DateTime(begin.Year, begin.Month, begin.Day, begin.Hour, begin.Minute, begin.Second, begin.Millisecond);
  176. DateTime endtime = new DateTime(begin.Year, begin.Month, end.Day, end.Hour, end.Minute, end.Second, end.Millisecond);
  177. string sql = "select time AS InternalTimeStamp";
  178. foreach (var dataId in keys)
  179. {
  180. sql += "," + string.Format("\"{0}\"", dataId);
  181. }
  182. sql += string.Format(" from \"{0}\" where time > {1} and time <= {2} order by time asc LIMIT 86400;",
  183. begin.ToString("yyyyMMdd") + "." + module, begintime.Ticks, endtime.Ticks);
  184. DataSet dataSet = DB.ExecuteDataset(sql);
  185. if (dataSet == null)
  186. return result;
  187. if (dataSet.Tables.Count == 0 || dataSet.Tables[0].Rows.Count == 0)
  188. return result;
  189. DateTime dt = new DateTime();
  190. Dictionary<int, string> colName = new Dictionary<int, string>();
  191. for (int colNo = 0; colNo < dataSet.Tables[0].Columns.Count; colNo++)
  192. colName.Add(colNo, dataSet.Tables[0].Columns[colNo].ColumnName);
  193. for (int rowNo = 0; rowNo < dataSet.Tables[0].Rows.Count; rowNo++)
  194. {
  195. var row = dataSet.Tables[0].Rows[rowNo];
  196. for (int i = 0; i < dataSet.Tables[0].Columns.Count; i++)
  197. {
  198. HistoryDataItem data = new HistoryDataItem();
  199. if (i == 0)
  200. {
  201. long ticks = (long)row[i];
  202. dt = new DateTime(ticks);
  203. continue;
  204. }
  205. else
  206. {
  207. string dataId = colName[i];
  208. if (row[i] is DBNull || row[i] == null)
  209. {
  210. data.dateTime = dt;
  211. data.dbName = colName[i];
  212. data.value = 0;
  213. }
  214. else if (row[i] is bool)
  215. {
  216. data.dateTime = dt;
  217. data.dbName = colName[i];
  218. data.value = (bool)row[i] ? 1 : 0;
  219. }
  220. else
  221. {
  222. data.dateTime = dt;
  223. data.dbName = colName[i];
  224. data.value = float.Parse(row[i].ToString());
  225. }
  226. }
  227. result.Add(data);
  228. }
  229. }
  230. dataSet.Clear();
  231. }
  232. catch (Exception ex)
  233. {
  234. LOG.WriteExeption(ex);
  235. }
  236. return result;
  237. }
  238. public static List<HistoryDataItem> GetOneDayHistoryData(IEnumerable<string> keys, DateTime begin, string module)
  239. {
  240. List<HistoryDataItem> result = new List<HistoryDataItem>();
  241. try
  242. {
  243. DateTime begintime = new DateTime(begin.Year, begin.Month, begin.Day, 0, 0, 0, 0);
  244. DateTime endtime = new DateTime(begin.Year, begin.Month, begin.Day, 23, 59, 59, 999);
  245. string sql = "select time AS InternalTimeStamp";
  246. foreach (var dataId in keys)
  247. {
  248. sql += "," + string.Format("\"{0}\"", dataId);
  249. }
  250. sql += string.Format(" from \"{0}\" where time > {1} and time <= {2} order by time asc LIMIT 86400;",
  251. begin.ToString("yyyyMMdd") + "." + module, begintime.Ticks, endtime.Ticks);
  252. DataSet dataSet = DB.ExecuteDataset(sql);
  253. if (dataSet == null)
  254. return result;
  255. if (dataSet.Tables.Count == 0 || dataSet.Tables[0].Rows.Count == 0)
  256. return result;
  257. DateTime dt = new DateTime();
  258. Dictionary<int, string> colName = new Dictionary<int, string>();
  259. for (int colNo = 0; colNo < dataSet.Tables[0].Columns.Count; colNo++)
  260. colName.Add(colNo, dataSet.Tables[0].Columns[colNo].ColumnName);
  261. for (int rowNo = 0; rowNo < dataSet.Tables[0].Rows.Count; rowNo++)
  262. {
  263. var row = dataSet.Tables[0].Rows[rowNo];
  264. for (int i = 0; i < dataSet.Tables[0].Columns.Count; i++)
  265. {
  266. HistoryDataItem data = new HistoryDataItem();
  267. if (i == 0)
  268. {
  269. long ticks = (long)row[i];
  270. dt = new DateTime(ticks);
  271. continue;
  272. }
  273. else
  274. {
  275. string dataId = colName[i];
  276. if (row[i] is DBNull || row[i] == null)
  277. {
  278. data.dateTime = dt;
  279. data.dbName = colName[i];
  280. data.value = 0;
  281. }
  282. else if (row[i] is bool)
  283. {
  284. data.dateTime = dt;
  285. data.dbName = colName[i];
  286. data.value = (bool)row[i] ? 1 : 0;
  287. }
  288. else
  289. {
  290. data.dateTime = dt;
  291. data.dbName = colName[i];
  292. data.value = float.Parse(row[i].ToString());
  293. }
  294. }
  295. result.Add(data);
  296. }
  297. }
  298. dataSet.Clear();
  299. }
  300. catch (Exception ex)
  301. {
  302. LOG.WriteExeption(ex);
  303. }
  304. return result;
  305. }
  306. public static List<HistoryDataItem> GetHistoryData(IEnumerable<string> keys, string recipeRunGuid, string module)
  307. {
  308. List<HistoryDataItem> result = new List<HistoryDataItem>();
  309. try
  310. {
  311. string sql = string.Format("SELECT * FROM \"process_data\" where \"guid\" = '{0}'",
  312. recipeRunGuid);
  313. DataSet ds = DB.ExecuteDataset(sql);
  314. if (ds == null)
  315. return result;
  316. if (ds.Tables[0].Rows.Count == 0)
  317. return result;
  318. object from = ds.Tables[0].Rows[0]["process_begin_time"];
  319. if (from is DBNull)
  320. {
  321. //LOG.Write(string.Format("{0} not set start time", recipeRunGuid));
  322. return result;
  323. }
  324. DateTime begin = (DateTime)from;
  325. begin = begin.AddSeconds(-10);
  326. object to = ds.Tables[0].Rows[0]["process_end_time"];
  327. if (to is DBNull)
  328. {
  329. to = new DateTime(begin.Year, begin.Month, begin.Day, 23, 59, 59, 999);
  330. }
  331. DateTime end = (DateTime)to;
  332. end = end.AddSeconds(10);
  333. sql = "select time AS InternalTimeStamp";
  334. foreach (var dataId in keys)
  335. {
  336. sql += "," + string.Format("\"{0}\"", dataId);
  337. }
  338. sql += string.Format(" from \"{0}\" where time > {1} and time <= {2} order by time asc LIMIT 2000;",
  339. begin.ToString("yyyyMMdd") + "." + module, begin.Ticks, end.Ticks);
  340. DataSet dataSet = DB.ExecuteDataset(sql);
  341. if (dataSet == null)
  342. return result;
  343. if (dataSet.Tables.Count == 0 || dataSet.Tables[0].Rows.Count == 0)
  344. return result;
  345. DateTime dt = new DateTime();
  346. Dictionary<int, string> colName = new Dictionary<int, string>();
  347. for (int colNo = 0; colNo < dataSet.Tables[0].Columns.Count; colNo++)
  348. colName.Add(colNo, dataSet.Tables[0].Columns[colNo].ColumnName);
  349. for (int rowNo = 0; rowNo < dataSet.Tables[0].Rows.Count; rowNo++)
  350. {
  351. var row = dataSet.Tables[0].Rows[rowNo];
  352. for (int i = 0; i < dataSet.Tables[0].Columns.Count; i++)
  353. {
  354. HistoryDataItem data = new HistoryDataItem();
  355. if (i == 0)
  356. {
  357. long ticks = (long)row[i];
  358. dt = new DateTime(ticks);
  359. continue;
  360. }
  361. else
  362. {
  363. string dataId = colName[i];
  364. if (row[i] is DBNull || row[i] == null)
  365. {
  366. data.dateTime = dt;
  367. data.dbName = colName[i];
  368. data.value = 0;
  369. }
  370. else if (row[i] is bool)
  371. {
  372. data.dateTime = dt;
  373. data.dbName = colName[i];
  374. data.value = (bool)row[i] ? 1 : 0;
  375. }
  376. else
  377. {
  378. data.dateTime = dt;
  379. data.dbName = colName[i];
  380. data.value = float.Parse(row[i].ToString());
  381. }
  382. }
  383. result.Add(data);
  384. }
  385. }
  386. dataSet.Clear();
  387. }
  388. catch (Exception ex)
  389. {
  390. LOG.WriteExeption(ex);
  391. }
  392. return result;
  393. }
  394. public static void StepStart(string recipeGuid, int stepNumber, string stepName, float stepTime)
  395. {
  396. string guid = Guid.NewGuid().ToString();
  397. 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}' );";
  398. //System.Diagnostics.Trace.WriteLine(sql);
  399. DB.Insert(sql);
  400. }
  401. public static List<HistoryStepItem> GetHistoryStepList(DateTime begin, DateTime end)
  402. {
  403. List<HistoryStepItem> result = new List<HistoryStepItem>();
  404. 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;",
  405. begin.ToString("yyyy/MM/dd HH:mm:ss.fff"), end.ToString("yyyy/MM/dd HH:mm:ss.fff"));
  406. DataSet ds = DB.ExecuteDataset(sql);
  407. if (ds == null)
  408. return result;
  409. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  410. {
  411. var recipeIds = ds.Tables[0].Rows[i]["step_name"].ToString().Split(':');
  412. result.Add(new HistoryStepItem()
  413. {
  414. StartTime = Convert.ToDateTime(ds.Tables[0].Rows[i]["step_begin_time"]),
  415. EndTime = DateTime.Now,
  416. StepHoldTime=Convert.ToInt32(ds.Tables[0].Rows[i]["step_time"]),
  417. RecipeId= recipeIds.Length>0? recipeIds[0]:"",
  418. StepNo =$"Step{Convert.ToInt32(ds.Tables[0].Rows[i]["step_number"])}"
  419. });
  420. }
  421. ds.Clear();
  422. return result;
  423. }
  424. }
  425. }