Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

187 linhas
7.1 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 Newtonsoft.Json;
  13. using HBLConsole.Communication;
  14. namespace HBLConsole.Business.AbstractServer
  15. {
  16. public class Base : AbstractMessageServer
  17. {
  18. public override void AddOrder<T>(T orderInfo)
  19. {
  20. if (orderInfo == null) return;
  21. if (orderInfo is MorkOrderPush morkOrderpush)
  22. {
  23. OrderData order = Json<KeepDataBase>.Data.orderLists.FirstOrDefault(par => par.OrderPush?.SuborderId == morkOrderpush.SuborderId);
  24. if (order == null)//防止重复订单
  25. {
  26. ActionManage.GetInstance.Send("AddOrder", morkOrderpush);
  27. GeneralConfig.morkOrderPushes.Enqueue(morkOrderpush);
  28. //ActionManage.GetInstance.Send("DataParse", morkOrderpush);
  29. }
  30. }
  31. }
  32. /// <summary>
  33. /// 接收来自MQTT 推送的物料信息
  34. /// </summary>
  35. /// <typeparam name="T"></typeparam>
  36. /// <param name="batchingInfo"></param>
  37. public override void GetBatchingInfo<T>(T batchingInfo)
  38. {
  39. if (batchingInfo == null) return;
  40. if (batchingInfo is OrderMaterialDelivery BatchingInfos)
  41. {
  42. Json<BatchingInfoPar>.Data.orderMaterialDelivery = BatchingInfos;
  43. MessageLog.GetInstance.Show("收到推送的物料信息");
  44. BatchingInfoDisplay();
  45. }
  46. }
  47. private void GetMake()
  48. {
  49. //http://localhost:5000/GetDeviceMake
  50. }
  51. /// <summary>
  52. /// 通过接口获取物料信息
  53. /// </summary>
  54. /// <param name="clientId"></param>
  55. public override void GetBatchingInfo(int clientId)
  56. {
  57. string result = string.Empty;
  58. for (int i = 0; i < 2; i++)
  59. {
  60. try
  61. {
  62. int PushType = i;//0:主料 1:辅料
  63. var jsondata = new { clientId, PushType };
  64. string header = $"[{InternetInfo.StockServer}/GetItemInfo]_[{DateTime.Now.Ticks}]";
  65. //string url = $"{InternetInfo.ApiAddress}{InternetInfo.StockServer}/GetItemInfo";
  66. //string url = $"http://192.168.0.62:7000{InternetInfo.StockServer}/GetItemInfo";
  67. string url = $"{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. MessageLog.GetInstance.Show("接收到辅料信息");
  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.ShowEx(ex.ToString());
  83. }
  84. }
  85. BatchingInfoDisplay();
  86. //MessageLog.GetInstance.Show("【物料信息】");
  87. //Json<BatchingInfoPar>.Data.orderMaterialDelivery?.BatchingInfo?.ForEach(x =>
  88. //{
  89. // MessageLog.GetInstance.Show($"物料ID:=[{x.BatchingId}],{x.BatchingLoc}号位置:{x.BatchingCount}");
  90. //});
  91. }
  92. private void BatchingInfoDisplay()
  93. {
  94. MessageLog.GetInstance.Show("【物料信息】");
  95. Json<BatchingInfoPar>.Data.orderMaterialDelivery?.BatchingInfo?.ForEach(x =>
  96. {
  97. MessageLog.GetInstance.Show($"物料ID:=[{x.BatchingId}],{x.BatchingLoc}号位置:{x.BatchingCount}");
  98. });
  99. }
  100. /// <summary>
  101. /// 接收MQTT 推送过来的辅料信息
  102. /// </summary>
  103. /// <typeparam name="T"></typeparam>
  104. /// <param name="recipeBomInfo"></param>
  105. public override void GetRecipeBom<T>(T recipeBomInfo)
  106. {
  107. if (recipeBomInfo == null) return;
  108. if (recipeBomInfo is RecipeBoms recipeBom)
  109. {
  110. Json<BatchingInfoPar>.Data.recipeBoms = recipeBom;
  111. MessageLog.GetInstance.Show("接收到辅料信息");
  112. ActionManage.GetInstance.Send("recipeBom");
  113. Json<BatchingInfoPar>.Data.recipeBoms.RecipeIds.ForEach(x =>
  114. {
  115. //MessageLog.GetInstance.Show($"辅料ID:=[{x.RecipeBomId}],{x.RecipeBomLoc}号位置:{x.RecipeBomCount}");
  116. });
  117. }
  118. }
  119. /// <summary>
  120. /// 订单状态改变
  121. /// </summary>
  122. /// <param name="subOrderId"></param>
  123. /// <param name="status"></param>
  124. /// <returns></returns>
  125. public override bool OrderStatusChange(string subOrderId, ORDER_STATUS status)
  126. {
  127. return false;
  128. string result = string.Empty;
  129. OrderStatusChange orderStatusChange = new OrderStatusChange() { CookingStatus = status, SuborderId = subOrderId };
  130. try
  131. {
  132. string header = $"[{InternetInfo.OrderServer}/order/robotstatuschange]_[{DateTime.Now.Ticks}]";
  133. //string url = $"{InternetInfo.ApiAddress}{InternetInfo.OrderServer}/order/robotstatuschange";
  134. string url = $"{InternetInfo.OrderServer}robotstatuschange";
  135. result = APIHelper.GetInstance.HttpRequest(url, header, orderStatusChange, RequestType.POST);
  136. }
  137. catch (Exception ex)
  138. {
  139. MessageLog.GetInstance.ShowEx(ex.ToString());
  140. }
  141. var res = JsonConvert.DeserializeObject<OrderStatusRsp>(result);
  142. return res == null ? false : res.isSuccess;
  143. }
  144. /// <summary>
  145. /// 退单消息
  146. /// </summary>
  147. /// <typeparam name="T"></typeparam>
  148. /// <param name="chargebackInfo"></param>
  149. /// <exception cref="NotImplementedException"></exception>
  150. public override void Chargeback<T>(T chargebackInfo)
  151. {
  152. if (chargebackInfo == null) return;
  153. if (chargebackInfo is Chargeback chargeback)
  154. {
  155. ActionManage.GetInstance.Send("chargeback", chargeback.SubOrderId);
  156. }
  157. }
  158. public class OrderStatusRsp
  159. {
  160. /// <summary>
  161. /// 子订单ID
  162. /// </summary>
  163. public string SuborderId { get; set; }
  164. /// <summary>
  165. /// 订单状态
  166. /// </summary>
  167. public int Result { get; set; } = 0;
  168. public bool isSuccess { get; set; }
  169. public bool data { get; set; }
  170. public string msg { get; set; }
  171. }
  172. }
  173. }