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.
 
 

167 lines
6.5 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.AbstractServer
  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. OrderData order = Json<KeepDataBase>.Data.orderLists.FirstOrDefault(par => par.OrderPush?.SuborderId == morkOrderpush.SuborderId);
  37. if (order == null)//防止重复订单
  38. {
  39. Json<KeepDataBase>.Data.orderLists.Add(new OrderData()
  40. {
  41. OrderStatus = ORDER_STATUS.WAIT,
  42. IsSelected = true,
  43. OrderPush = morkOrderpush
  44. });
  45. ActionManage.GetInstance.Send("AddOrder", morkOrderpush);
  46. ActionManage.GetInstance.Send("DataParse", morkOrderpush);
  47. }
  48. }
  49. }
  50. /// <summary>
  51. /// 接收来自MQTT 推送的物料信息
  52. /// </summary>
  53. /// <typeparam name="T"></typeparam>
  54. /// <param name="batchingInfo"></param>
  55. public override void GetBatchingInfo<T>(T batchingInfo)
  56. {
  57. if (batchingInfo == null) return;
  58. if (batchingInfo is OrderMaterialDelivery BatchingInfos)
  59. {
  60. Json<BatchingInfoPar>.Data.orderMaterialDelivery = BatchingInfos;
  61. MessageLog.GetInstance.Show("收到推送的物料信息");
  62. }
  63. }
  64. /// <summary>
  65. /// 通过接口获取物料信息
  66. /// </summary>
  67. /// <param name="ClientId"></param>
  68. public override void GetBatchingInfo(int ClientId)
  69. {
  70. string result = string.Empty;
  71. for (int i = 0; i < 2; i++)
  72. {
  73. try
  74. {
  75. int PushType = i;//0:主料 1:辅料
  76. var jsondata = new { ClientId, PushType };
  77. string header = $"[{InternetInfo.StockServer}/GetItemInfo]_[{DateTime.Now.Ticks}]".AESEncrypt();
  78. string url = $"{InternetInfo.ApiAddress}{InternetInfo.StockServer}/GetItemInfo";
  79. //string url = $"http://192.168.0.62:7000{InternetInfo.StockServer}/GetItemInfo";
  80. result = APIHelper.GetInstance.HttpRequest(url, header, jsondata, RequestType.POST);
  81. if (PushType == 1)
  82. {
  83. Json<BatchingInfoPar>.Data.recipeBoms = JsonConvert.DeserializeObject<RecipeBoms>(result);
  84. ActionManage.GetInstance.Send("recipeBom");
  85. MessageLog.GetInstance.Show("接收到辅料信息");
  86. }
  87. else if (PushType == 0)
  88. {
  89. Json<BatchingInfoPar>.Data.orderMaterialDelivery = JsonConvert.DeserializeObject<OrderMaterialDelivery>(result);
  90. }
  91. }
  92. catch (Exception ex)
  93. {
  94. MessageLog.GetInstance.Show(ex.ToString());
  95. }
  96. }
  97. MessageLog.GetInstance.Show("【物料信息】");
  98. Json<BatchingInfoPar>.Data.orderMaterialDelivery?.BatchingInfo?.ForEach(x =>
  99. {
  100. MessageLog.GetInstance.Show($"[{x.BatchingId}]{x.BatchingLoc}号位置:{x.BatchingCount}");
  101. });
  102. }
  103. /// <summary>
  104. /// 接收MQTT 推送过来的辅料信息
  105. /// </summary>
  106. /// <typeparam name="T"></typeparam>
  107. /// <param name="recipeBomInfo"></param>
  108. public override void GetRecipeBom<T>(T recipeBomInfo)
  109. {
  110. if (recipeBomInfo == null) return;
  111. if (recipeBomInfo is RecipeBoms recipeBom)
  112. {
  113. Json<BatchingInfoPar>.Data.recipeBoms = recipeBom;
  114. MessageLog.GetInstance.Show("接收到辅料信息");
  115. ActionManage.GetInstance.Send("recipeBom");
  116. }
  117. }
  118. /// <summary>
  119. /// 订单状态改变
  120. /// </summary>
  121. /// <param name="subOrderId"></param>
  122. /// <param name="status"></param>
  123. /// <returns></returns>
  124. public override bool OrderStatusChange(string subOrderId, ORDER_STATUS status)
  125. {
  126. string result = string.Empty;
  127. OrderStatusChange orderStatusChange = new OrderStatusChange() { CookingStatus = status, SuborderId = subOrderId };
  128. try
  129. {
  130. string header = $"[{InternetInfo.OrderServer}/order/robotstatuschange]_[{DateTime.Now.Ticks}]".AESEncrypt();
  131. string url = $"{InternetInfo.ApiAddress}{InternetInfo.OrderServer}/order/robotstatuschange";
  132. result = APIHelper.GetInstance.HttpRequest(url, header, orderStatusChange, RequestType.POST);
  133. }
  134. catch (Exception ex)
  135. {
  136. MessageLog.GetInstance.Show(ex.ToString());
  137. }
  138. var res = JsonConvert.DeserializeObject<OrderStatusRsp>(result);
  139. return res == null ? false : res.isSuccess;
  140. }
  141. public class OrderStatusRsp
  142. {
  143. /// <summary>
  144. /// 子订单ID
  145. /// </summary>
  146. public string SuborderId { get; set; }
  147. /// <summary>
  148. /// 订单状态
  149. /// </summary>
  150. public int Result { get; set; } = 0;
  151. public bool isSuccess { get; set; }
  152. public bool data { get; set; }
  153. public string msg { get; set; }
  154. }
  155. }
  156. }