JCFabAuto.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using Newtonsoft.Json;
  2. using System.Collections.Generic;
  3. using System.Net;
  4. using System.Text;
  5. namespace Aitex.Core.MES.JC
  6. {
  7. public class JCFabAuto: FabAutoComm
  8. {
  9. public List<string> m_lotList=new List<string>();
  10. private List<LotInformation> m_lotInformationList=new List<LotInformation>();
  11. public string m_userId;
  12. private string m_recipe;
  13. private string m_batchID;
  14. //public JCFabAuto(List<string> lotList, string userId)
  15. //{
  16. // m_lotList=lotList;
  17. // m_userId = userId;
  18. //}
  19. public JCFabAuto()
  20. {
  21. }
  22. /// <summary>
  23. /// 根据扫码信息获取Recipe
  24. /// </summary>
  25. /// <returns></returns>
  26. public override string GetRecipeByLot(List<string> list)
  27. {
  28. try
  29. {
  30. list.ForEach(x =>
  31. {
  32. string url = "http://api.mes.com/WIP/GetLotByLot";
  33. IDictionary<string, string> para = new Dictionary<string, string>();
  34. para.Add("lot", x);
  35. string urlStr = HttpClient.HttpPost(url, para);
  36. if (urlStr != "")
  37. {
  38. m_lotInformationList.Add(JsonConvert.DeserializeObject<LotInformation>(urlStr));
  39. }
  40. });
  41. m_recipe = m_lotInformationList[0].Data.Lot.RuncardRecipe;
  42. return m_recipe;
  43. }
  44. catch (System.Exception)
  45. {
  46. return string.Empty;
  47. }
  48. }
  49. /// <summary>
  50. /// 进站
  51. /// </summary>
  52. /// <returns></returns>
  53. public override bool CheckIn()
  54. {
  55. try
  56. {
  57. string url = "http://api-eqpauto.mes.com/API/WIP/CheckIn";
  58. IDictionary<string, string> para = new Dictionary<string, string>();
  59. string equipmentName = Dns.GetHostName();
  60. StringBuilder sLots = new StringBuilder();
  61. StringBuilder sComponents = new StringBuilder();
  62. StringBuilder sLotTags = new StringBuilder();
  63. m_lotInformationList.ForEach(lotInformation =>
  64. {
  65. if (lotInformation == m_lotInformationList[m_lotInformationList.Count - 1])
  66. {
  67. lotInformation.Data.Components.ForEach(x =>
  68. {
  69. sComponents.Append(x.ComponentID);
  70. });
  71. sLotTags.Append(lotInformation.Data.Lot.TAG);
  72. }
  73. else
  74. {
  75. lotInformation.Data.Components.ForEach(x =>
  76. {
  77. sComponents.Append(x.ComponentID + ",");
  78. });
  79. sLotTags.Append(lotInformation.Data.Lot.TAG + ",");
  80. }
  81. });
  82. m_lotList.ForEach(lot =>
  83. {
  84. if (lot == m_lotList[m_lotList.Count - 1])
  85. {
  86. sLots.Append(lot);
  87. }
  88. else
  89. {
  90. sLots.Append(lot + ",");
  91. }
  92. });
  93. para.Add("equipmentName", equipmentName);
  94. para.Add("sLots", sLots.ToString());
  95. para.Add("sComponents", sComponents.ToString());
  96. para.Add("sLotTags", sLotTags.ToString());
  97. para.Add("userID", m_userId);
  98. para.Add("recipe", m_recipe);
  99. string urlStr = HttpClient.HttpPost(url, para);
  100. if (urlStr != "")
  101. {
  102. var checkInInformation = JsonConvert.DeserializeObject<CheckInInformation>(urlStr);
  103. m_batchID = checkInInformation.data.BATCHID;
  104. return true;
  105. }
  106. else
  107. {
  108. return false;
  109. }
  110. }
  111. catch
  112. {
  113. return false;
  114. }
  115. }
  116. /// <summary>
  117. /// 出站
  118. /// </summary>
  119. /// <returns></returns>
  120. public override bool CheckOut()
  121. {
  122. try
  123. {
  124. string url = "http://api-eqpauto.mes.com/API/WIP/CheckOut";
  125. IDictionary<string, string> para = new Dictionary<string, string>();
  126. para.Add("batchID", m_batchID);
  127. para.Add("userId", m_userId);
  128. string urlStr = HttpClient.HttpPost(url, para);
  129. if (urlStr != "")
  130. {
  131. return true;
  132. }
  133. else
  134. {
  135. return false;
  136. }
  137. }
  138. catch
  139. {
  140. return false;
  141. }
  142. }
  143. }
  144. }