You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

179 lines
6.7 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using HBLConsole.Abstract;
  7. using BPA.Message;
  8. using HBLConsole.Model;
  9. using HBLConsole.Service;
  10. using BPA.Message.Enum;
  11. using HBLConsole.GVL;
  12. using BPA.Utility;
  13. using Newtonsoft.Json;
  14. using HBLConsole.Communication;
  15. namespace HBLConsole.Business.MessageServer
  16. {
  17. public class Base : AbstractMessageServer
  18. {
  19. public override void AddOrder<T>(T orderInfo)
  20. {
  21. if (orderInfo == null) return;
  22. if (orderInfo is MorkOrderPush morkOrderpush)
  23. {
  24. OrderData order = Json<MorkOrderPushPar>.Data.morkOrderPushes.Find(par => par.OrderPush?.SuborderId == morkOrderpush.SuborderId);
  25. if (order == null)//防止重复订单
  26. {
  27. Json<MorkOrderPushPar>.Data.morkOrderPushes.Add(new OrderData()
  28. {
  29. OrderStatus = ORDER_STATUS.WAIT,
  30. IsSelected = true,
  31. OrderPush = morkOrderpush
  32. });
  33. ActionManage.GetInstance.Send("AddOrder", morkOrderpush);
  34. ActionManage.GetInstance.Send("DataParse", morkOrderpush);
  35. }
  36. }
  37. }
  38. /// <summary>
  39. /// 接收来自MQTT 推送的物料信息
  40. /// </summary>
  41. /// <typeparam name="T"></typeparam>
  42. /// <param name="batchingInfo"></param>
  43. public override void GetBatchingInfo<T>(T batchingInfo)
  44. {
  45. if (batchingInfo == null) return;
  46. if (batchingInfo is OrderMaterialDelivery BatchingInfos)
  47. {
  48. Json<BatchingInfoPar>.Data.orderMaterialDelivery = BatchingInfos;
  49. MessageLog.GetInstance.Show("收到推送的物料信息");
  50. }
  51. }
  52. /// <summary>
  53. /// 通过接口获取物料信息
  54. /// </summary>
  55. /// <param name="ClientId"></param>
  56. public override void GetBatchingInfo(int ClientId)
  57. {
  58. string result = string.Empty;
  59. for (int i = 0; i < 2; i++)
  60. {
  61. try
  62. {
  63. int PushType = i;//0:主料 1:辅料
  64. var jsondata = new { ClientId, PushType };
  65. string header = $"[{InternetInfo.StockServer}/GetItemInfo]_[{DateTime.Now.Ticks}]".AESEncrypt();
  66. string url = $"{InternetInfo.ApiAddress}{InternetInfo.StockServer}/GetItemInfo";
  67. //string url = $"http://192.168.0.62:7000{InternetInfo.StockServer}/GetItemInfo";
  68. result = APIHelper.GetInstance.HttpRequest(url, header, jsondata, RequestType.POST);
  69. if (PushType == 1)
  70. {
  71. Json<BatchingInfoPar>.Data.recipeBoms = JsonConvert.DeserializeObject<RecipeBoms>(result);
  72. ActionManage.GetInstance.Send("recipeBom");
  73. //WritePlcData();
  74. }
  75. else if (PushType == 0)
  76. {
  77. Json<BatchingInfoPar>.Data.orderMaterialDelivery = JsonConvert.DeserializeObject<OrderMaterialDelivery>(result);
  78. }
  79. }
  80. catch (Exception ex)
  81. {
  82. MessageLog.GetInstance.Show(ex.ToString());
  83. }
  84. }
  85. MessageLog.GetInstance.Show("【物料信息】");
  86. Json<BatchingInfoPar>.Data.orderMaterialDelivery?.BatchingInfo?.ForEach(x =>
  87. {
  88. MessageLog.GetInstance.Show($"[{x.BatchingId}]{x.BatchingLoc}号位置:{x.BatchingCount}");
  89. });
  90. }
  91. /// <summary>
  92. /// 接收MQTT 推送过来的辅料信息
  93. /// </summary>
  94. /// <typeparam name="T"></typeparam>
  95. /// <param name="recipeBomInfo"></param>
  96. public override void GetRecipeBom<T>(T recipeBomInfo)
  97. {
  98. if (recipeBomInfo == null) return;
  99. if (recipeBomInfo is RecipeBoms recipeBom)
  100. {
  101. Json<BatchingInfoPar>.Data.recipeBoms = recipeBom;
  102. MessageLog.GetInstance.Show("接收到辅料信息");
  103. ActionManage.GetInstance.Send("recipeBom");
  104. }
  105. //WritePlcData();
  106. }
  107. /// <summary>
  108. /// 写配方数据到PLC
  109. /// </summary>
  110. //private void WritePlcData()
  111. //{
  112. // return;
  113. // //写配方数据到PLC
  114. // List<ushort> recipeBoms = new List<ushort>();
  115. // foreach (var item in Json<BatchingInfoPar>.Data.recipeBoms.RecipeIds)
  116. // {
  117. // foreach (var rec in item.Recipes)
  118. // {
  119. // recipeBoms.Add((ushort)rec);
  120. // }
  121. // }
  122. // if (recipeBoms.Count > 0)
  123. // {
  124. // if (ModbusTcpHelper.GetInstance.Write(1100, WriteType.HoldingRegisters, recipeBoms.ToArray()))
  125. // {
  126. // MessageLog.GetInstance.Show("成功写入配方数据");
  127. // }
  128. // }
  129. //}
  130. /// <summary>
  131. /// 订单状态改变
  132. /// </summary>
  133. /// <param name="subOrderId"></param>
  134. /// <param name="status"></param>
  135. /// <returns></returns>
  136. public override bool OrderStatusChange(string subOrderId, ORDER_STATUS status)
  137. {
  138. string result = string.Empty;
  139. OrderStatusChange orderStatusChange = new OrderStatusChange() { CookingStatus = status, SuborderId = subOrderId };
  140. try
  141. {
  142. string header = $"[{InternetInfo.OrderServer}/order/robotstatuschange]_[{DateTime.Now.Ticks}]".AESEncrypt();
  143. string url = $"{InternetInfo.ApiAddress}{InternetInfo.OrderServer}/order/robotstatuschange";
  144. result = APIHelper.GetInstance.HttpRequest(url, header, orderStatusChange, RequestType.POST);
  145. }
  146. catch (Exception ex)
  147. {
  148. MessageLog.GetInstance.Show(ex.ToString());
  149. }
  150. var res = JsonConvert.DeserializeObject<OrderStatusRsp>(result);
  151. return res == null ? false : res.isSuccess;
  152. }
  153. public class OrderStatusRsp
  154. {
  155. /// <summary>
  156. /// 子订单ID
  157. /// </summary>
  158. public string SuborderId { get; set; }
  159. /// <summary>
  160. /// 订单状态
  161. /// </summary>
  162. public int Result { get; set; } = 0;
  163. public bool isSuccess { get; set; }
  164. public bool data { get; set; }
  165. public string msg { get; set; }
  166. }
  167. }
  168. }