WMS.cs 11 KB

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