WMS.cs 10 KB

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