Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 

201 рядки
7.9 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. //try
  50. //{
  51. // string result = string.Empty;
  52. // string DeviceSeries = GVL.GeneralConfig.DeviceType.ToString();
  53. // string Version = "1.0.0.0";
  54. // var jsondata = new { DeviceSeries, Version };
  55. // string header = $"[{InternetInfo.StockServer}/GetItemInfo]_[{DateTime.Now.Ticks}]";
  56. // string url = $"{InternetInfo.StockServer}GetDeviceMake";
  57. // result = APIHelper.GetInstance.HttpRequest(url, header, jsondata, RequestType.POST);
  58. //}
  59. //catch (Exception ex)
  60. //{
  61. // MessageLog.GetInstance.ShowEx(ex.ToString());
  62. //}
  63. }
  64. /// <summary>
  65. /// 通过接口获取物料信息
  66. /// </summary>
  67. /// <param name="clientId"></param>
  68. public override void GetBatchingInfo(int clientId)
  69. {
  70. //GetMake();
  71. string result = string.Empty;
  72. for (int i = 0; i < 2; i++)
  73. {
  74. try
  75. {
  76. int PushType = i;//0:主料 1:辅料
  77. var jsondata = new { clientId, PushType };
  78. string header = $"[{InternetInfo.StockServer}/GetItemInfo]_[{DateTime.Now.Ticks}]";
  79. //string url = $"{InternetInfo.ApiAddress}{InternetInfo.StockServer}/GetItemInfo";
  80. //string url = $"http://192.168.0.62:7000{InternetInfo.StockServer}/GetItemInfo";
  81. string url = $"{InternetInfo.StockServer}GetItemInfo";
  82. result = APIHelper.GetInstance.HttpRequest(url, header, jsondata, RequestType.POST);
  83. // result = APIHelper.GetInstance.HttpRequest("https://bpa.black-pa.com:21527/stock/GetItemInfo", header, jsondata, RequestType.POST);
  84. if (PushType == 1)
  85. {
  86. Json<BatchingInfoPar>.Data.recipeBoms = JsonConvert.DeserializeObject<RecipeBoms>(result);
  87. ActionManage.GetInstance.Send("recipeBom");
  88. MessageLog.GetInstance.Show("接收到辅料信息");
  89. }
  90. else if (PushType == 0)
  91. {
  92. Json<BatchingInfoPar>.Data.orderMaterialDelivery = JsonConvert.DeserializeObject<OrderMaterialDelivery>(result);
  93. }
  94. }
  95. catch (Exception ex)
  96. {
  97. MessageLog.GetInstance.ShowEx(ex.ToString());
  98. }
  99. }
  100. BatchingInfoDisplay();
  101. //MessageLog.GetInstance.Show("【物料信息】");
  102. //Json<BatchingInfoPar>.Data.orderMaterialDelivery?.BatchingInfo?.ForEach(x =>
  103. //{
  104. // MessageLog.GetInstance.Show($"物料ID:=[{x.BatchingId}],{x.BatchingLoc}号位置:{x.BatchingCount}");
  105. //});
  106. }
  107. private void BatchingInfoDisplay()
  108. {
  109. MessageLog.GetInstance.Show("【物料信息】");
  110. Json<BatchingInfoPar>.Data.orderMaterialDelivery?.BatchingInfo?.ForEach(x =>
  111. {
  112. MessageLog.GetInstance.Show($"物料ID:=[{x.BatchingId}],{x.BatchingLoc}号位置:{x.BatchingCount}");
  113. });
  114. }
  115. /// <summary>
  116. /// 接收MQTT 推送过来的辅料信息
  117. /// </summary>
  118. /// <typeparam name="T"></typeparam>
  119. /// <param name="recipeBomInfo"></param>
  120. public override void GetRecipeBom<T>(T recipeBomInfo)
  121. {
  122. if (recipeBomInfo == null) return;
  123. if (recipeBomInfo is RecipeBoms recipeBom)
  124. {
  125. Json<BatchingInfoPar>.Data.recipeBoms = recipeBom;
  126. MessageLog.GetInstance.Show("接收到辅料信息");
  127. ActionManage.GetInstance.Send("recipeBom");
  128. Json<BatchingInfoPar>.Data.recipeBoms.RecipeIds.ForEach(x =>
  129. {
  130. //MessageLog.GetInstance.Show($"辅料ID:=[{x.RecipeBomId}],{x.RecipeBomLoc}号位置:{x.RecipeBomCount}");
  131. });
  132. }
  133. }
  134. /// <summary>
  135. /// 订单状态改变
  136. /// </summary>
  137. /// <param name="subOrderId"></param>
  138. /// <param name="status"></param>
  139. /// <returns></returns>
  140. public override bool OrderStatusChange(string subOrderId, ORDER_STATUS status)
  141. {
  142. string result = string.Empty;
  143. OrderStatusChange orderStatusChange = new OrderStatusChange() { CookingStatus = status, SuborderId = subOrderId };
  144. try
  145. {
  146. string header = $"[{InternetInfo.OrderServer}/order/robotstatuschange]_[{DateTime.Now.Ticks}]";
  147. //string url = $"{InternetInfo.ApiAddress}{InternetInfo.OrderServer}/order/robotstatuschange";
  148. string url = $"{InternetInfo.OrderServer}order/robotstatuschange";
  149. result = APIHelper.GetInstance.HttpRequest(url, header, orderStatusChange, RequestType.POST);
  150. }
  151. catch (Exception ex)
  152. {
  153. MessageLog.GetInstance.ShowEx(ex.ToString());
  154. }
  155. var res = JsonConvert.DeserializeObject<OrderStatusRsp>(result);
  156. return res == null ? false : res.isSuccess;
  157. }
  158. /// <summary>
  159. /// 退单消息
  160. /// </summary>
  161. /// <typeparam name="T"></typeparam>
  162. /// <param name="chargebackInfo"></param>
  163. /// <exception cref="NotImplementedException"></exception>
  164. public override void Chargeback<T>(T chargebackInfo)
  165. {
  166. if (chargebackInfo == null) return;
  167. if (chargebackInfo is Chargeback chargeback)
  168. {
  169. ActionManage.GetInstance.Send("chargeback", chargeback.SubOrderId);
  170. }
  171. }
  172. public class OrderStatusRsp
  173. {
  174. /// <summary>
  175. /// 子订单ID
  176. /// </summary>
  177. public string SuborderId { get; set; }
  178. /// <summary>
  179. /// 订单状态
  180. /// </summary>
  181. public int Result { get; set; } = 0;
  182. public bool isSuccess { get; set; }
  183. public bool data { get; set; }
  184. public string msg { get; set; }
  185. }
  186. }
  187. }