WMS.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. if (devCode == "3001")
  154. devCode = "3045";
  155. var next = tunnel.GetNext(devCode);
  156. res.Memo1 = next.CODE;
  157. res.TunnelNum = tunnel.CODE;
  158. return res;
  159. }
  160. public static WcsContractApiResponse AutoBuildUpGroupStock(string containerCode, string barcode, string dev)
  161. {
  162. var res = APICaller.CallApi<WcsContractApiResponse>(Url + "/api/Task/AutoBuildUpGroupStock", new
  163. {
  164. ContainerCode = containerCode,
  165. BarCode = barcode
  166. });
  167. if (!res.ResType)
  168. {
  169. TaskException(dev, res.ResMessage);
  170. throw new Exception(res.ResMessage);
  171. }
  172. return res;
  173. }
  174. public static I_WCS_GetTunnelListResponse GetTunnelList(int wmsTaskId, string dev)
  175. {
  176. var res = APICaller.CallApi<I_WCS_GetTunnelListResponse>(Url + "/api/Task/I_WCS_GetTunnelList", new I_WCS_GetTunnelListRequest
  177. {
  178. WMSTaskNum = wmsTaskId.ToString()
  179. });
  180. if (!res.ResType)
  181. {
  182. TaskException(dev, res.ResMessage);
  183. throw new Exception(res.ResMessage);
  184. }
  185. return res;
  186. }
  187. /// <summary>
  188. /// 上一个成功上传重量的任务号
  189. /// </summary>
  190. public static int lastWMSTaskId = 0;
  191. /// <summary>
  192. /// 上传重量
  193. /// </summary>
  194. /// <param name="wmsTaskId">WMS任务号</param>
  195. /// <param name="weight">重量</param>
  196. /// <param name="dev">调用方法的设备</param>
  197. /// <returns></returns>
  198. /// <exception cref="Exception"></exception>
  199. public static void GetWeight(int wmsTaskId, int weight, string dev)
  200. {
  201. if (lastWMSTaskId == wmsTaskId) return;
  202. var res = APICaller.CallApi<I_WCS_GetWeightResponse>(Url + "/api/Task/I_WCS_GetWeight", new I_WCS_GetWeightRequest
  203. {
  204. WMSTaskNum = wmsTaskId.ToString(),
  205. Weight = weight
  206. });
  207. if (!res.ResType)
  208. {
  209. TaskException(dev, res.ResMessage);
  210. throw new Exception(res.ResMessage);
  211. }
  212. else
  213. {
  214. lastWMSTaskId = wmsTaskId;
  215. }
  216. }
  217. public static void TaskException(string device, string exMsg)
  218. {
  219. if (exMsg == "接口调用中")
  220. return;
  221. Task.Run(() =>
  222. {
  223. try
  224. {
  225. Console.WriteLine(device + ":" + exMsg);
  226. var res = APICaller.CallApi2<I_WCS_GetExcTaskResponse>(Url + "/api/Task/I_WCS_GetExcTask", new I_WCS_GetExcTaskRequest
  227. {
  228. ExcCode = exMsg,
  229. EquipmentNo = device,
  230. ExcMessage = exMsg,
  231. });
  232. if (!res.ResType)
  233. throw new Exception(res.ResMessage);
  234. }
  235. catch (Exception ex)
  236. {
  237. }
  238. });
  239. }
  240. private static List<I_WCS_PutDevInfoRequest> DevInfoList = new List<I_WCS_PutDevInfoRequest>();
  241. public static void DevInfo(string device, string exMsg)
  242. {
  243. DevInfoList.Add(new I_WCS_PutDevInfoRequest
  244. {
  245. STA_EQUIPMENTNO = device,
  246. STA_ALARMSMSG = exMsg
  247. });
  248. }
  249. public static void UploadDevInfo()
  250. {
  251. try
  252. {
  253. var res = APICaller.CallApi<I_WCS_PutDevInfoResponse>(Url + "/api/Task/I_WCS_PutDevInfo", DevInfoList);
  254. if (!res.ResType)
  255. throw new Exception(res.ResMessage);
  256. }
  257. catch (Exception ex)
  258. {
  259. Console.WriteLine("I_WCS_PutDevInfo" + "接口调用失败");
  260. }
  261. finally
  262. {
  263. DevInfoList.Clear();
  264. }
  265. }
  266. public static void UnBound(string barcode)
  267. {
  268. try
  269. {
  270. var res = APICaller.CallApi<I_WCS_GetTunnelListResponse>(Url + "/api/PDA/UnboundMwGroupStock", new
  271. {
  272. containerCode = barcode
  273. });
  274. }
  275. catch { }
  276. }
  277. }
  278. }