ProcessDataRecorder.cs 18 KB

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