WMS.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. using DBHelper;
  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 static string Url = "http://192.168.249.120:8016";
  12. public static I_WCS_GetInTaskResponse InBound(string barcode, string devCode, bool getTunnel = false)
  13. {
  14. var warehouse = "mwhouseputong";
  15. if (devCode.StartsWith("MW_") || devCode == "2088" || devCode == "3001")
  16. warehouse = "mwhouseyuanzhi";
  17. var res = APICaller.CallApi<I_WCS_GetInTaskResponse>(Url + "/api/Task/I_WCS_GetInTask", new I_WCS_GetInTaskRequest
  18. {
  19. ContainerBarCode = barcode,
  20. WareHouseId = warehouse,
  21. EquipmentNo = devCode,
  22. Memo1 = getTunnel ? "1" : "" //1:分巷道 2:分货位
  23. });
  24. if (!res.ResType)
  25. {
  26. TaskException(devCode, res.ResMessage);
  27. throw new Exception(res.ResMessage);
  28. }
  29. return res;
  30. }
  31. public static I_WCS_GetInTaskResponse PalletInbound(DB db, string barcode, string dev)
  32. {
  33. var res = APICaller.CallApi<Result>(Url + "/api/PDA/PVCSemiFinishedProductContainerReBack", new PVCSemiFinishedProductReBackRequest
  34. {
  35. BarCode = barcode,
  36. ContainerCode = barcode,
  37. Quantity = 1
  38. });
  39. if (res.StatusCode != Result.Success && res.StatusCode != 4004)
  40. {
  41. TaskException(dev, res.Message);
  42. throw new Exception(res.Message);
  43. }
  44. return InBound(barcode, dev);
  45. }
  46. public static short GetPalletType(string rollCode)
  47. {
  48. return 1;
  49. }
  50. public static I_WCS_GetWareCellResponse GetLocalIn(int wmstaskid, string tunnel, string device)
  51. {
  52. var res = APICaller.CallApi<I_WCS_GetWareCellResponse>(Url + "/api/Task/I_WCS_GetWareCell", new I_WCS_GetWareCellRequest
  53. {
  54. PickUpEquipmentNo = device,
  55. TunnelNum = tunnel.Last().ToString(),
  56. WMSTaskNum = wmstaskid.ToString()
  57. });
  58. if (!res.ResType)
  59. {
  60. TaskException(device, res.ResMessage);
  61. throw new Exception(res.ResMessage);
  62. }
  63. return res;
  64. }
  65. public static void UpdateTask(int wmstaskid, int status, string addnext, int size = -1)
  66. {
  67. var res = APICaller.CallApi<List<I_WCS_PutTaskStepResponse>>(Url + "/api/Task/I_WCS_PutTaskStep", new List<I_WCS_TASKRequest>
  68. {
  69. new I_WCS_TASKRequest
  70. {
  71. TASK_WKSTATUS = status,
  72. TASK_WMSNO = wmstaskid.ToString(),
  73. Size=size,
  74. TASK_POSIDNEXT=addnext
  75. }
  76. });
  77. if (res == null || res.Count == 0)
  78. {
  79. throw new Exception("I_WCS_PutTaskStep调用失败");
  80. }
  81. if (!res.First().ResType)
  82. throw new Exception(res.First().ResMessage);
  83. }
  84. public static GetProductInfoResponse GetProductInfo(string barcode, string dev)
  85. {
  86. var res = APICaller.CallApi<GetProductInfoResponse>(Url + "/api/Task/GetProductInfo", new GetProductInfoRequest
  87. {
  88. BarCode = barcode
  89. });
  90. try
  91. {
  92. if (!res.ResType)
  93. throw new Exception(res.ResMessage);
  94. if (res.ChildContainerType <= 0 || res.ChildContainerType > 9)
  95. throw new Exception("托盘类型错误");
  96. if (res.LoadCount <= 0)
  97. throw new Exception("最大组盘数量错误");
  98. if (res.DocId == 0)
  99. throw new Exception("单据ID错误");
  100. if (res.ProLine < 1 || res.ProLine > 9)
  101. throw new Exception("产线编号" + res.ProLine + "错误");
  102. }
  103. catch (Exception ex)
  104. {
  105. TaskException(dev, ex.Message);
  106. throw;
  107. }
  108. return res;
  109. }
  110. public static I_WCS_GetOutTaskResponseSingle GetPalletOutTask(short palletType, string devCode)
  111. {
  112. var warehouse = "mwhouseputong";
  113. if (devCode.StartsWith("MW_"))
  114. warehouse = "mwhouseyuanzhi";
  115. var res = APICaller.CallApi<I_WCS_GetOutTaskResponseSingle>(Url + "/api/Task/I_WCS_GetOutTask", new I_WCS_GetOutTaskRequest
  116. {
  117. OutType = 2,
  118. Memo2 = palletType.ToString(),
  119. WareHouseId = warehouse,
  120. OutEndPostion = devCode
  121. });
  122. if (!res.ResType)
  123. {
  124. TaskException(devCode, res.ResMessage);
  125. throw new Exception(res.ResMessage);
  126. }
  127. var tcode = (warehouse == "mwhouseputong" ? "TM" : "TY") + res.TunnelNum;
  128. var tunnel = Device.Find(tcode);
  129. var next = tunnel.GetNext(devCode);
  130. res.Memo1 = next.CODE;
  131. res.TunnelNum = tunnel.CODE;
  132. return res;
  133. }
  134. public static I_WCS_GetOutTaskResponseSingle GetOutTask(string position, string devCode)
  135. {
  136. var warehouse = "mwhouseputong";
  137. var ws = int.Parse(position.Split('_')[1]);
  138. //if (ws > 3)
  139. warehouse = "mwhouseyuanzhi";
  140. var res = APICaller.CallApi<I_WCS_GetOutTaskResponseSingle>(Url + "/api/Task/I_WCS_GetOutTask", new I_WCS_GetOutTaskRequest
  141. {
  142. OutType = 1,
  143. WareHouseId = warehouse,
  144. OutEndPostion = position
  145. });
  146. if (!res.ResType)
  147. {
  148. TaskException(position, res.ResMessage);
  149. throw new Exception(res.ResMessage);
  150. }
  151. var tcode = (warehouse == "mwhouseputong" ? "TM" : "TY") + res.TunnelNum;
  152. var tunnel = Device.Find(tcode);
  153. var next = tunnel.GetNext(devCode);
  154. res.Memo1 = next.CODE;
  155. res.TunnelNum = tunnel.CODE;
  156. return res;
  157. }
  158. public static WcsContractApiResponse AutoBuildUpGroupStock(string containerCode, string barcode, string dev)
  159. {
  160. var res = APICaller.CallApi<WcsContractApiResponse>(Url + "/api/Task/AutoBuildUpGroupStock", new
  161. {
  162. ContainerCode = containerCode,
  163. BarCode = barcode
  164. });
  165. if (!res.ResType)
  166. {
  167. TaskException(dev, res.ResMessage);
  168. throw new Exception(res.ResMessage);
  169. }
  170. return res;
  171. }
  172. public static I_WCS_GetTunnelListResponse GetTunnelList(int wmsTaskId, string dev)
  173. {
  174. var res = APICaller.CallApi<I_WCS_GetTunnelListResponse>(Url + "/api/Task/I_WCS_GetTunnelList", new I_WCS_GetTunnelListRequest
  175. {
  176. WMSTaskNum = wmsTaskId.ToString()
  177. });
  178. if (!res.ResType)
  179. {
  180. TaskException(dev, res.ResMessage);
  181. throw new Exception(res.ResMessage);
  182. }
  183. return res;
  184. }
  185. /// <summary>
  186. /// 上一个成功上传重量的任务号
  187. /// </summary>
  188. public static int lastWMSTaskId = 0;
  189. /// <summary>
  190. /// 上传重量
  191. /// </summary>
  192. /// <param name="wmsTaskId">WMS任务号</param>
  193. /// <param name="weight">重量</param>
  194. /// <param name="dev">调用方法的设备</param>
  195. /// <returns></returns>
  196. /// <exception cref="Exception"></exception>
  197. public static void GetWeight(int wmsTaskId, int weight, string dev)
  198. {
  199. if (lastWMSTaskId == wmsTaskId) return;
  200. var res = APICaller.CallApi<I_WCS_GetWeightResponse>(Url + "/api/Task/I_WCS_GetWeight", new I_WCS_GetWeightRequest
  201. {
  202. WMSTaskNum = wmsTaskId.ToString(),
  203. Weight = weight
  204. });
  205. if (!res.ResType)
  206. {
  207. TaskException(dev, res.ResMessage);
  208. throw new Exception(res.ResMessage);
  209. }
  210. else
  211. {
  212. lastWMSTaskId = wmsTaskId;
  213. }
  214. }
  215. public static void TaskException(string device, string exMsg)
  216. {
  217. if (exMsg == "接口调用中")
  218. return;
  219. Task.Run(() =>
  220. {
  221. try
  222. {
  223. Console.WriteLine(device + ":" + exMsg);
  224. var res = APICaller.CallApi2<I_WCS_GetExcTaskResponse>(Url + "/api/Task/I_WCS_GetExcTask", new I_WCS_GetExcTaskRequest
  225. {
  226. ExcCode = exMsg,
  227. EquipmentNo = device,
  228. ExcMessage = exMsg,
  229. });
  230. if (!res.ResType)
  231. throw new Exception(res.ResMessage);
  232. }
  233. catch (Exception ex)
  234. {
  235. }
  236. });
  237. }
  238. private static List<I_WCS_PutDevInfoRequest> DevInfoList = new List<I_WCS_PutDevInfoRequest>();
  239. public static void DevInfo(string device, string exMsg)
  240. {
  241. DevInfoList.Add(new I_WCS_PutDevInfoRequest
  242. {
  243. STA_EQUIPMENTNO = device,
  244. STA_ALARMSMSG = exMsg
  245. });
  246. }
  247. public static void UploadDevInfo()
  248. {
  249. try
  250. {
  251. var res = APICaller.CallApi<I_WCS_PutDevInfoResponse>(Url + "/api/Task/I_WCS_PutDevInfo", DevInfoList);
  252. if (!res.ResType)
  253. throw new Exception(res.ResMessage);
  254. }
  255. catch (Exception ex)
  256. {
  257. Console.WriteLine("I_WCS_PutDevInfo" + "接口调用失败");
  258. }
  259. finally
  260. {
  261. DevInfoList.Clear();
  262. }
  263. }
  264. public static void UnBound(string barcode)
  265. {
  266. try
  267. {
  268. var res = APICaller.CallApi<I_WCS_GetTunnelListResponse>(Url + "/api/PDA/UnboundMwGroupStock", new
  269. {
  270. containerCode = barcode
  271. });
  272. }
  273. catch { }
  274. }
  275. }
  276. }