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.
 
 

158 lines
5.8 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. Json<MorkOrderPushPar>.Data.morkOrderPushes.Add(new OrderData()
  25. {
  26. OrderStatus = ORDER_STATUS.WAIT,
  27. IsSelected = true,
  28. OrderPush = morkOrderpush
  29. });
  30. ActionOperate.GetInstance.Send("AddOrder", morkOrderpush);
  31. ActionOperate.GetInstance.Send("DataParse", morkOrderpush);
  32. }
  33. }
  34. /// <summary>
  35. /// 接收来自MQTT 推送的物料信息
  36. /// </summary>
  37. /// <typeparam name="T"></typeparam>
  38. /// <param name="batchingInfo"></param>
  39. public override void GetBatchingInfo<T>(T batchingInfo)
  40. {
  41. if (batchingInfo == null) return;
  42. if (batchingInfo is OrderMaterialDelivery BatchingInfos)
  43. {
  44. Json<BatchingInfoPar>.Data.orderMaterialDelivery = BatchingInfos;
  45. MessageLog.GetInstance.Show("收到推送的物料信息");
  46. }
  47. }
  48. /// <summary>
  49. /// 通过接口获取物料信息
  50. /// </summary>
  51. /// <param name="ClientId"></param>
  52. public override void GetBatchingInfo(int ClientId)
  53. {
  54. string result = string.Empty;
  55. for (int i = 0; i < 2; i++)
  56. {
  57. try
  58. {
  59. int PushType = i;//0:主料 1:辅料
  60. var jsondata = new { ClientId, PushType };
  61. string header = $"[{InternetInfo.StockServer}/GetItemInfo]_[{DateTime.Now.Ticks}]".AESEncrypt();
  62. string url = $"{InternetInfo.ApiAddress}{InternetInfo.StockServer}/GetItemInfo";
  63. //string url = $"http://192.168.0.62:7000{InternetInfo.StockServer}/GetItemInfo";
  64. result = APIHelper.GetInstance.HttpRequest(url, header, jsondata, RequestType.POST);
  65. if (PushType == 1)
  66. {
  67. Json<BatchingInfoPar>.Data.recipeBoms = JsonConvert.DeserializeObject<RecipeBoms>(result);
  68. WritePlcData();
  69. }
  70. else if (PushType == 0)
  71. {
  72. Json<BatchingInfoPar>.Data.orderMaterialDelivery = JsonConvert.DeserializeObject<OrderMaterialDelivery>(result);
  73. }
  74. }
  75. catch (Exception ex)
  76. {
  77. MessageLog.GetInstance.Show(ex.ToString());
  78. }
  79. }
  80. MessageLog.GetInstance.Show("【物料信息】");
  81. Json<BatchingInfoPar>.Data.orderMaterialDelivery?.BatchingInfo?.ForEach(x =>
  82. {
  83. MessageLog.GetInstance.Show($"{x.BatchingLoc}号位置:{x.BatchingCount}");
  84. });
  85. }
  86. /// <summary>
  87. /// 接收MQTT 推送过来的辅料信息
  88. /// </summary>
  89. /// <typeparam name="T"></typeparam>
  90. /// <param name="recipeBomInfo"></param>
  91. public override void GetRecipeBom<T>(T recipeBomInfo)
  92. {
  93. if (recipeBomInfo == null) return;
  94. if (recipeBomInfo is RecipeBoms recipeBom)
  95. {
  96. Json<BatchingInfoPar>.Data.recipeBoms = recipeBom;
  97. MessageLog.GetInstance.Show("接收到辅料信息");
  98. }
  99. WritePlcData();
  100. }
  101. /// <summary>
  102. /// 写配方数据到PLC
  103. /// </summary>
  104. private void WritePlcData()
  105. {
  106. return;
  107. //写配方数据到PLC
  108. List<ushort> recipeBoms = new List<ushort>();
  109. foreach (var item in Json<BatchingInfoPar>.Data.recipeBoms.RecipeIds)
  110. {
  111. foreach (var rec in item.Recipes)
  112. {
  113. recipeBoms.Add((ushort)rec);
  114. }
  115. }
  116. if (recipeBoms.Count > 0)
  117. {
  118. if (ModbusTcpHelper.GetInstance.Write(1100, WriteType.HoldingRegisters, recipeBoms.ToArray()))
  119. {
  120. MessageLog.GetInstance.Show("成功写入配方数据");
  121. }
  122. }
  123. }
  124. /// <summary>
  125. /// 订单状态改变
  126. /// </summary>
  127. /// <param name="subOrderId"></param>
  128. /// <param name="status"></param>
  129. /// <returns></returns>
  130. public override bool OrderStatusChange(string subOrderId, ORDER_STATUS status)
  131. {
  132. string result = string.Empty;
  133. OrderStatusChange orderStatusChange = new OrderStatusChange() { CookingStatus = status, SuborderId = subOrderId };
  134. try
  135. {
  136. string header = $"[{InternetInfo.OrderServer}/order/robotstatuschange]_[{DateTime.Now.Ticks}]".AESEncrypt();
  137. string url = $"{InternetInfo.ApiAddress}{InternetInfo.OrderServer}/order/robotstatuschange";
  138. result = APIHelper.GetInstance.HttpRequest(url, header, orderStatusChange, RequestType.POST);
  139. }
  140. catch (Exception ex)
  141. {
  142. MessageLog.GetInstance.Show(ex.ToString());
  143. }
  144. var res = JsonConvert.DeserializeObject<OrderStatusChangeRsp>(result);
  145. return res?.Result == 2;
  146. }
  147. }
  148. }