ProcessDataRecorder.cs 18 KB

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