WMS.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. using Logs;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using WCS.Service.Entity;
  7. namespace WCS.Service
  8. {
  9. public class WMS
  10. {
  11. private const string Url = "http://192.168.249.150:8026";
  12. //private static string Url = "http://127.0.0.1:8026";
  13. private const string WareHouseId = "opphouse";
  14. /// <summary>
  15. /// 向WMS获取入库任务 一次单卷
  16. /// </summary>
  17. /// <param name="barcode">产品条码</param>
  18. /// <param name="devCode">设备条码</param>
  19. /// <param name="getTunnel"></param>
  20. /// <returns></returns>
  21. /// <exception cref="Exception"></exception>
  22. public static List<I_WCS_GetInTaskResponseItem> I_WCS_GetInTask(string barcode, string devCode, bool getTunnel = false)
  23. {
  24. var res = APICaller.CallApi<I_WCS_GetInTaskResponse>(Url + "/api/Task/I_WCS_GetInTask", new List<I_WCS_GetInTaskRequest>()
  25. {
  26. new(){
  27. ContainerBarCode = barcode,
  28. WareHouseId = WareHouseId,
  29. EquipmentNo = devCode,
  30. Memo1 = getTunnel ? "1" : "" //1:分巷道 2:分货位
  31. }
  32. });
  33. if (res.ResType) return res.TaskList;
  34. TaskException(devCode, res.ResMessage);
  35. throw new WarnException(res.ResMessage);
  36. }
  37. /// <summary>
  38. /// 向WMS获取入库任务 一次双卷
  39. /// </summary>
  40. /// <param name="barcode1">产品1条码</param>
  41. /// <param name="devCode1">设备1编号</param>
  42. /// <param name="getTunnel1">产品1是否直接分配巷道</param>
  43. /// <param name="barcode2">产品2条码</param>
  44. /// <param name="devCode2">设备2编号</param>
  45. /// <param name="getTunnel2">产品2是否直接分配巷道</param>
  46. /// <exception cref="WarnException"></exception>
  47. /// <returns></returns>
  48. public static List<I_WCS_GetInTaskResponseItem> I_WCS_GetInTask(string barcode1, string devCode1, string barcode2, string devCode2, bool getTunnel1 = false, bool getTunnel2 = false)
  49. {
  50. var res = APICaller.CallApi<I_WCS_GetInTaskResponse>(Url + "/api/Task/I_WCS_GetInTask", new List<I_WCS_GetInTaskRequest>()
  51. {
  52. new(){
  53. ContainerBarCode = barcode1,
  54. WareHouseId = WareHouseId,
  55. EquipmentNo = devCode1,
  56. Memo1 = getTunnel1 ? "1" : "" //1:分巷道 2:分货位
  57. },
  58. new(){
  59. ContainerBarCode = barcode2,
  60. WareHouseId = WareHouseId,
  61. EquipmentNo = devCode2,
  62. Memo1 = getTunnel2 ? "1" : "" //1:分巷道 2:分货位
  63. },
  64. });
  65. if (res.ResType) return res.TaskList;
  66. TaskException($"G{devCode1}", res.ResMessage);
  67. throw new WarnException(res.ResMessage);
  68. }
  69. /// <summary>
  70. /// 分配货位
  71. /// </summary>
  72. /// <param name="wmstaskid">WMS任务ID</param>
  73. /// <param name="tunnel">巷道</param>
  74. /// <param name="device">设备号</param>
  75. /// <param name="ForkNum">申请任务对应的货叉</param>
  76. /// <exception cref="WarnException"></exception>
  77. /// <returns></returns>
  78. public static I_WCS_GetWareCellResponse GetLocalIn(int wmstaskid, string tunnel, string device, WareCellForkNum ForkNum)
  79. {
  80. var res = APICaller.CallApi<I_WCS_GetWareCellResponse>(Url + "/api/Task/I_WCS_GetWareCell", new I_WCS_GetWareCellRequest
  81. {
  82. PickUpEquipmentNo = device,
  83. TunnelNum = tunnel.Last().ToString(),
  84. WMSTaskNum = wmstaskid.ToString(),
  85. ForkNum = ForkNum
  86. });
  87. if (res.ResType) return res;
  88. TaskException(device, res.ResMessage);
  89. throw new WarnException(res.ResMessage);
  90. }
  91. public static void UpdateTask(string POSIDNEXT, int wmstaskid, int status, int size = -1)
  92. {
  93. var res = APICaller.CallApi<List<I_WCS_PutTaskStepResponse>>(Url + "/api/Task/I_WCS_PutTaskStep", new List<I_WCS_TASKRequest>
  94. {
  95. new()
  96. {
  97. TASK_WKSTATUS = status,
  98. TASK_WMSNO = wmstaskid.ToString(),
  99. TASK_POSIDNEXT=POSIDNEXT,
  100. Size=size
  101. }
  102. });
  103. if (res == null || res.Count == 0)
  104. {
  105. throw new WarnException("I_WCS_PutTaskStep调用失败");
  106. }
  107. if (!res.First().ResType)
  108. throw new WarnException(res.First().ResMessage);
  109. }
  110. public static GetProductInfoResponse GetProductInfo(string barcode, string dev)
  111. {
  112. var res = APICaller.CallApi<GetProductInfoResponse>(Url + "/api/Task/GetProductInfo", new GetProductInfoRequest
  113. {
  114. BarCode = barcode
  115. });
  116. try
  117. {
  118. if (!res.ResType)
  119. throw new WarnException(res.ResMessage);
  120. if (res.ChildContainerType is <= 0 or > 9)
  121. throw new WarnException("托盘类型错误");
  122. if (res.LoadCount <= 0)
  123. throw new WarnException("最大组盘数量错误");
  124. if (res.DocId == 0)
  125. throw new WarnException("单据ID错误");
  126. if (res.ProLine is < 1 or > 9)
  127. throw new WarnException("产线编号" + res.ProLine + "错误");
  128. }
  129. catch (Exception ex)
  130. {
  131. TaskException(dev, ex.Message);
  132. throw;
  133. }
  134. return res;
  135. }
  136. /// <summary>
  137. /// 获取出库任务
  138. /// </summary>
  139. /// <param name="position">出库位置</param>
  140. /// <param name="devCode">调用方法的设备号</param>
  141. /// <returns></returns>
  142. /// <exception cref="Exception"></exception>
  143. public static List<I_WCS_GetOutTaskResponseSingle> GetOutTask(string position, string devCode)
  144. {
  145. var res = APICaller.CallApi<I_WCS_GetOutTaskResponse>(Url + "/api/Task/I_WCS_GetOutTask", new I_WCS_GetOutTaskRequest
  146. {
  147. OutType = 1,
  148. WareHouseId = WareHouseId,
  149. OutEndPostion = position
  150. });
  151. if (!res.ResType)
  152. {
  153. TaskException(position, res.ResMessage);
  154. throw new WarnException(res.ResMessage);
  155. }
  156. res.WMSTasks.ForEach(v =>
  157. {
  158. var tcode = "TY" + v.TunnelNum;
  159. var tunnel = Device.Find(tcode);
  160. //var next = tunnel.GetPath(devCode);
  161. //v.Memo1 = next.CODE;
  162. v.TunnelNum = tunnel.CODE;
  163. });
  164. return res.WMSTasks;
  165. }
  166. public static WcsContractApiResponse AutoBuildUpGroupStock(string containerCode, string barcode, string dev)
  167. {
  168. var res = APICaller.CallApi<WcsContractApiResponse>(Url + "/api/Task/AutoBuildUpGroupStock", new
  169. {
  170. ContainerCode = containerCode,
  171. BarCode = barcode
  172. });
  173. if (res.ResType) return res;
  174. TaskException(dev, res.ResMessage);
  175. throw new WarnException(res.ResMessage);
  176. }
  177. /// <summary>
  178. /// 获取巷道
  179. /// </summary>
  180. /// <param name="WMSTaskId">WMS任务号集合</param>
  181. /// <param name="dev">请求设备号</param>
  182. /// <returns></returns>
  183. /// <exception cref="Exception"></exception>
  184. public static I_WCS_GetTunnelListResponse GetTunnelList(List<string> WMSTaskId, string dev)
  185. {
  186. var res = APICaller.CallApi<I_WCS_GetTunnelListResponse>(Url + "/api/Task/I_WCS_GetTunnelList", new I_WCS_GetTunnelListRequest
  187. {
  188. WMSTaskNum = WMSTaskId
  189. });
  190. if (res.ResType) return res;
  191. TaskException(dev, res.ResMessage);
  192. throw new WarnException(res.ResMessage);
  193. }
  194. public static void TaskException(string device, string exMsg)
  195. {
  196. if (exMsg == "接口调用中")
  197. return;
  198. Task.Run(() =>
  199. {
  200. try
  201. {
  202. Console.WriteLine(device + ":" + exMsg);
  203. var res = APICaller.CallApi2<I_WCS_GetExcTaskResponse>(Url + "/api/Task/I_WCS_GetExcTask", new I_WCS_GetExcTaskRequest
  204. {
  205. ExcCode = exMsg,
  206. EquipmentNo = device,
  207. ExcMessage = exMsg,
  208. });
  209. InfoLog.INFO_I_WCS_GetExcTask(device + ":" + exMsg);
  210. if (!res.ResType) throw new WarnException(res.ResMessage);
  211. }
  212. catch (Exception)
  213. {
  214. }
  215. });
  216. }
  217. private static List<I_WCS_PutDevInfoRequest> DevInfoList = new();
  218. public static void DevInfo(string device, string exMsg)
  219. {
  220. DevInfoList.Add(new I_WCS_PutDevInfoRequest
  221. {
  222. STA_EQUIPMENTNO = device,
  223. STA_ALARMSMSG = exMsg
  224. });
  225. }
  226. public static void UploadDevInfo()
  227. {
  228. return;
  229. try
  230. {
  231. var res = APICaller.CallApi<I_WCS_PutDevInfoResponse>(Url + "/api/Task/I_WCS_PutDevInfo", DevInfoList);
  232. if (!res.ResType)
  233. throw new WarnException(res.ResMessage);
  234. }
  235. catch (Exception)
  236. {
  237. Console.WriteLine("I_WCS_PutDevInfo" + "接口调用失败");
  238. }
  239. finally
  240. {
  241. DevInfoList.Clear();
  242. }
  243. }
  244. public static void UnBound(string barcode)
  245. {
  246. try
  247. {
  248. var res = APICaller.CallApi<I_WCS_GetTunnelListResponse>(Url + "/api/PDA/UnboundMwGroupStock", new
  249. {
  250. containerCode = barcode
  251. });
  252. }
  253. catch { }
  254. }
  255. }
  256. }