CarrierDataRecorder.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Text;
  6. using Aitex.Core.RT.DBCore;
  7. using Aitex.Core.RT.Event;
  8. using Aitex.Core.RT.Log;
  9. using Aitex.Sorter.Common;
  10. namespace Aitex.Sorter.RT.Module.DBRecorder
  11. {
  12. /*
  13. */
  14. public class CarrierDataRecorder
  15. {
  16. /// <summary>
  17. ///
  18. /// </summary>
  19. /// <param name="guid">唯一</param>
  20. /// <param name="station">位置</param>
  21. public static void Loaded(string guid, string station)
  22. {
  23. string sql = string.Format("INSERT INTO \"carrier_data\"(\"guid\", \"load_time\", \"station\" )VALUES ('{0}', '{1}', '{2}');",
  24. guid,
  25. DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"),
  26. station);
  27. DB.Insert(sql);
  28. }
  29. public static void UpdateCarrierId(string guid, string rfid)
  30. {
  31. string sql = string.Format(
  32. "UPDATE \"carrier_data\" SET \"rfid\"='{0}' WHERE \"guid\"='{1}';",
  33. rfid, guid);
  34. DB.Insert(sql);
  35. }
  36. public static void UpdateLotId(string guid, string lotId)
  37. {
  38. string sql = string.Format(
  39. "UPDATE \"carrier_data\" SET \"lot_id\"='{0}' WHERE \"guid\"='{1}';",
  40. lotId, guid);
  41. DB.Insert(sql);
  42. }
  43. public static void UpdateProductCategory(string guid, string productCategory)
  44. {
  45. string sql = string.Format(
  46. "UPDATE \"carrier_data\" SET \"product_category\"='{0}' WHERE \"guid\"='{1}';",
  47. productCategory, guid);
  48. DB.Insert(sql);
  49. }
  50. public static void Unloaded(string guid)
  51. {
  52. string sql = string.Format(
  53. "UPDATE \"carrier_data\" SET \"unload_time\"='{0}' WHERE \"guid\"='{1}';",
  54. DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"),
  55. guid);
  56. DB.Insert(sql);
  57. }
  58. public static List<HistoryProcessData> QueryDBProcessCarrier(string sql)
  59. {
  60. List<HistoryProcessData> result = new List<HistoryProcessData>();
  61. try
  62. {
  63. DataSet ds = DB.ExecuteDataset(sql);
  64. if (ds == null)
  65. return result;
  66. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  67. {
  68. HistoryProcessData ev = new HistoryProcessData();
  69. ev.Guid = ds.Tables[0].Rows[i]["guid"].ToString();
  70. ev.Rfid = ds.Tables[0].Rows[i]["rfid"].ToString();
  71. ev.RecipeName = ds.Tables[0].Rows[i]["rfid"].ToString();
  72. ev.LotId = ds.Tables[0].Rows[i]["lot_id"].ToString();
  73. ev.ProductCategory = ds.Tables[0].Rows[i]["product_category"].ToString();
  74. ev.Station = ds.Tables[0].Rows[i]["station"].ToString();
  75. if (!ds.Tables[0].Rows[i]["load_time"].Equals(DBNull.Value))
  76. ev.StartTime = ((DateTime)ds.Tables[0].Rows[i]["load_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
  77. if (!ds.Tables[0].Rows[i]["unload_time"].Equals(DBNull.Value))
  78. ev.EndTime = ((DateTime)ds.Tables[0].Rows[i]["unload_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
  79. result.Add(ev);
  80. }
  81. }
  82. catch (Exception ex)
  83. {
  84. LOG.Write(ex);
  85. }
  86. return result;
  87. }
  88. public static List<HistoryProcessData> QueryDBProcessLot(string sql)
  89. {
  90. List<HistoryProcessData> result = new List<HistoryProcessData>();
  91. try
  92. {
  93. DataSet ds = DB.ExecuteDataset(sql);
  94. if (ds == null)
  95. return result;
  96. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  97. {
  98. HistoryProcessData ev = new HistoryProcessData();
  99. ev.Guid = ds.Tables[0].Rows[i]["guid"].ToString();
  100. ev.RecipeName = ds.Tables[0].Rows[i]["name"].ToString();
  101. if (!ds.Tables[0].Rows[i]["start_time"].Equals(DBNull.Value))
  102. ev.StartTime = ((DateTime)ds.Tables[0].Rows[i]["start_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
  103. if (!ds.Tables[0].Rows[i]["end_time"].Equals(DBNull.Value))
  104. ev.EndTime = ((DateTime)ds.Tables[0].Rows[i]["end_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
  105. result.Add(ev);
  106. }
  107. }
  108. catch (Exception ex)
  109. {
  110. LOG.Write(ex);
  111. }
  112. return result;
  113. }
  114. public static List<HistoryCarrierData> QueryDBCarrier(string sql)
  115. {
  116. List<HistoryCarrierData> result = new List<HistoryCarrierData>();
  117. try
  118. {
  119. DataSet ds = DB.ExecuteDataset(sql);
  120. if (ds == null)
  121. return result;
  122. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  123. {
  124. HistoryCarrierData ev = new HistoryCarrierData();
  125. ev.Guid = ds.Tables[0].Rows[i]["guid"].ToString();
  126. ev.Rfid = ds.Tables[0].Rows[i]["rfid"].ToString();
  127. ev.LotId = ds.Tables[0].Rows[i]["lot_id"].ToString();
  128. ev.ProductCategory = ds.Tables[0].Rows[i]["product_category"].ToString();
  129. ev.Station = ds.Tables[0].Rows[i]["station"].ToString();
  130. if (!ds.Tables[0].Rows[i]["load_time"].Equals(DBNull.Value))
  131. ev.LoadTime = ((DateTime)ds.Tables[0].Rows[i]["load_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
  132. if (!ds.Tables[0].Rows[i]["unload_time"].Equals(DBNull.Value))
  133. ev.UnloadTime = ((DateTime)ds.Tables[0].Rows[i]["unload_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
  134. result.Add(ev);
  135. }
  136. }
  137. catch (Exception ex)
  138. {
  139. LOG.Write(ex);
  140. }
  141. return result;
  142. }
  143. public static List<WaferHistoryLot> QueryWaferHistoryLotsBySql(string sql)
  144. {
  145. List<WaferHistoryLot> result = new List<WaferHistoryLot>();
  146. try
  147. {
  148. DataSet dataSet = DB.ExecuteDataset(sql);
  149. if (dataSet == null)
  150. return result;
  151. if (dataSet.Tables.Count == 0 || dataSet.Tables[0].Rows.Count == 0)
  152. return result;
  153. for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
  154. {
  155. WaferHistoryLot item = new WaferHistoryLot();
  156. if (!dataSet.Tables[0].Rows[i]["lot_id"].Equals(DBNull.Value))
  157. {
  158. item.CarrierID = dataSet.Tables[0].Rows[i]["lot_id"].ToString();
  159. item.Name = dataSet.Tables[0].Rows[i]["lot_id"].ToString();
  160. }
  161. else
  162. {
  163. continue;
  164. }
  165. item.ID = dataSet.Tables[0].Rows[i]["guid"].ToString();
  166. item.Type = WaferHistoryItemType.Lot;
  167. if (!dataSet.Tables[0].Rows[i]["rfid"].Equals(DBNull.Value))
  168. item.Rfid = dataSet.Tables[0].Rows[i]["rfid"].ToString();
  169. if (!dataSet.Tables[0].Rows[i]["load_time"].Equals(DBNull.Value))
  170. item.StartTime = DateTime.Parse(dataSet.Tables[0].Rows[i]["load_time"].ToString());
  171. if (!dataSet.Tables[0].Rows[i]["unload_time"].Equals(DBNull.Value))
  172. item.EndTime = DateTime.Parse(dataSet.Tables[0].Rows[i]["unload_time"].ToString());
  173. DataSet subDataSet = DB.ExecuteDataset(string.Format("SELECT * FROM \"wafer_data\" Where \"carrier_data_guid\"='{0}' ;", item.ID));
  174. if (subDataSet != null && subDataSet.Tables.Count != 0 && subDataSet.Tables[0].Rows.Count != 0)
  175. {
  176. item.WaferCount = subDataSet.Tables[0].Rows.Count;
  177. item.FaultWaferCount = subDataSet.Tables[0].Select("process_status='Failed'").Length;
  178. }
  179. result.Add(item);
  180. }
  181. }
  182. catch (Exception e)
  183. {
  184. LOG.Write(e);
  185. }
  186. return result;
  187. }
  188. public static List<WaferHistoryLot> GetWaferHistoryLots(DateTime startTime, DateTime endTime, string keyWord)
  189. {
  190. List<WaferHistoryLot> result = new List<WaferHistoryLot>();
  191. try
  192. {
  193. string sqlFilter = "";
  194. if (keyWord != null && !string.IsNullOrEmpty(keyWord.Trim()))
  195. {
  196. sqlFilter = "and (";
  197. var keyStrings = keyWord.Split(',');
  198. for (int i = 0; i < keyStrings.Length; i++)
  199. {
  200. sqlFilter += $"\"lot_id\" like '%{keyStrings[i].Trim()}%'";
  201. if (i < keyStrings.Length - 1)
  202. {
  203. sqlFilter += " or ";
  204. }
  205. }
  206. sqlFilter += ")";
  207. }
  208. string sql = string.Format("SELECT * FROM \"carrier_data\" where (\"unload_time\" is null and \"load_time\" >= '{2}') or (\"load_time\" >= '{0}' and \"load_time\" <= '{1}') or (\"unload_time\" >= '{0}' and \"unload_time\" <= '{1}') or (\"load_time\" <= '{0}' and \"unload_time\" >= '{1}') {3} order by \"station\" ASC, \"load_time\" ASC limit 1000;", startTime.ToString("yyyy/MM/dd HH:mm:ss.fff"), startTime.AddDays(-1).ToString("yyyy/MM/dd HH:mm:ss.fff"), endTime.ToString("yyyy/MM/dd HH:mm:ss.fff"), sqlFilter);
  209. DataSet dataSet = DB.ExecuteDataset(sql);
  210. if (dataSet == null)
  211. return result;
  212. if (dataSet.Tables.Count == 0 || dataSet.Tables[0].Rows.Count == 0)
  213. return result;
  214. for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
  215. {
  216. WaferHistoryLot item = new WaferHistoryLot();
  217. if (!dataSet.Tables[0].Rows[i]["lot_id"].Equals(DBNull.Value))
  218. {
  219. item.CarrierID = dataSet.Tables[0].Rows[i]["lot_id"].ToString();
  220. item.Name = dataSet.Tables[0].Rows[i]["lot_id"].ToString();
  221. }
  222. else
  223. {
  224. continue;
  225. }
  226. item.ID = dataSet.Tables[0].Rows[i]["guid"].ToString();
  227. item.Type = WaferHistoryItemType.Lot;
  228. if (!dataSet.Tables[0].Rows[i]["rfid"].Equals(DBNull.Value))
  229. item.Rfid = dataSet.Tables[0].Rows[i]["rfid"].ToString();
  230. if (!dataSet.Tables[0].Rows[i]["load_time"].Equals(DBNull.Value))
  231. item.StartTime = DateTime.Parse(dataSet.Tables[0].Rows[i]["load_time"].ToString());
  232. if (!dataSet.Tables[0].Rows[i]["unload_time"].Equals(DBNull.Value))
  233. item.EndTime = DateTime.Parse(dataSet.Tables[0].Rows[i]["unload_time"].ToString());
  234. DataSet subDataSet = DB.ExecuteDataset(string.Format("SELECT * FROM \"wafer_data\" Where \"carrier_data_guid\"='{0}' ;", item.ID));
  235. if (subDataSet != null && subDataSet.Tables.Count != 0 && subDataSet.Tables[0].Rows.Count != 0)
  236. {
  237. item.WaferCount = subDataSet.Tables[0].Rows.Count;
  238. item.FaultWaferCount = subDataSet.Tables[0].Select("process_status='Failed'").Length;
  239. }
  240. result.Add(item);
  241. }
  242. }
  243. catch (Exception e)
  244. {
  245. LOG.Write(e);
  246. }
  247. return result;
  248. }
  249. }
  250. }