WMS.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using WCS.Service.Entity;
  6. using WCS.Service.Log;
  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 I_WCS_GetInTaskRequest(){
  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. /// <returns></returns>
  50. /// <exception cref="Exception"></exception>
  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 I_WCS_GetInTaskRequest(){
  56. ContainerBarCode = barcode1,
  57. WareHouseId = wareHouseId,
  58. EquipmentNo = devCode1,
  59. Memo1 = getTunnel1 ? "1" : "" //1:分巷道 2:分货位
  60. },
  61. new I_WCS_GetInTaskRequest(){
  62. ContainerBarCode = barcode2,
  63. WareHouseId = wareHouseId,
  64. EquipmentNo = devCode2,
  65. Memo1 = getTunnel2 ? "1" : "" //1:分巷道 2:分货位
  66. },
  67. });
  68. if (!res.ResType)
  69. {
  70. TaskException($"G{devCode1}", res.ResMessage);
  71. throw new WarnException(res.ResMessage);
  72. }
  73. return res.TaskList;
  74. }
  75. //public static I_WCS_GetInTaskResponse PalletInbound(DB db, string barcode, string dev)
  76. //{
  77. // var res = APICaller.CallApi<Result>(Url + "/api/PDA/PVCSemiFinishedProductContainerReBack", new PVCSemiFinishedProductReBackRequest
  78. // {
  79. // BarCode = barcode,
  80. // ContainerCode = barcode,
  81. // Quantity = 1
  82. // });
  83. // if (res.StatusCode != Result.Success && res.StatusCode != 4004)
  84. // {
  85. // TaskException(dev, res.Message);
  86. // throw new Exception(res.Message);
  87. // }
  88. // return I_WCS_GetInTask(barcode, dev);
  89. //}
  90. public static short GetPalletType(string rollCode)
  91. {
  92. return 1;
  93. }
  94. /// <summary>
  95. /// 分配货位
  96. /// </summary>
  97. /// <param name="wmstaskid">WMS任务ID</param>
  98. /// <param name="tunnel">巷道</param>
  99. /// <param name="device">设备号</param>
  100. /// <param name="ForkNum">申请任务对应的货叉</param>
  101. /// <returns></returns>
  102. /// <exception cref="Exception"></exception>
  103. public static I_WCS_GetWareCellResponse GetLocalIn(int wmstaskid, string tunnel, string device, WareCellForkNum ForkNum)
  104. {
  105. var res = APICaller.CallApi2<I_WCS_GetWareCellResponse>(Url + "/api/Task/I_WCS_GetWareCell", new I_WCS_GetWareCellRequest
  106. {
  107. PickUpEquipmentNo = device,
  108. TunnelNum = tunnel.Last().ToString(),
  109. WMSTaskNum = wmstaskid.ToString(),
  110. ForkNum = ForkNum
  111. });
  112. if (!res.ResType)
  113. {
  114. TaskException(device, res.ResMessage);
  115. throw new WarnException(res.ResMessage);
  116. }
  117. return res;
  118. }
  119. public static void UpdateTask(string POSIDNEXT, int wmstaskid, int status, int size = -1)
  120. {
  121. var res = APICaller.CallApi<List<I_WCS_PutTaskStepResponse>>(Url + "/api/Task/I_WCS_PutTaskStep", new List<I_WCS_TASKRequest>
  122. {
  123. new I_WCS_TASKRequest
  124. {
  125. TASK_WKSTATUS = status,
  126. TASK_WMSNO = wmstaskid.ToString(),
  127. TASK_POSIDNEXT=POSIDNEXT,
  128. Size=size
  129. }
  130. });
  131. if (res == null || res.Count == 0)
  132. {
  133. throw new WarnException("I_WCS_PutTaskStep调用失败");
  134. }
  135. if (!res.First().ResType)
  136. throw new WarnException(res.First().ResMessage);
  137. }
  138. public static GetProductInfoResponse GetProductInfo(string barcode, string dev)
  139. {
  140. var res = APICaller.CallApi<GetProductInfoResponse>(Url + "/api/Task/GetProductInfo", new GetProductInfoRequest
  141. {
  142. BarCode = barcode
  143. });
  144. try
  145. {
  146. if (!res.ResType)
  147. throw new WarnException(res.ResMessage);
  148. if (res.ChildContainerType <= 0 || res.ChildContainerType > 9)
  149. throw new WarnException("托盘类型错误");
  150. if (res.LoadCount <= 0)
  151. throw new WarnException("最大组盘数量错误");
  152. if (res.DocId == 0)
  153. throw new WarnException("单据ID错误");
  154. if (res.ProLine < 1 || res.ProLine > 9)
  155. throw new WarnException("产线编号" + res.ProLine + "错误");
  156. }
  157. catch (Exception ex)
  158. {
  159. TaskException(dev, ex.Message);
  160. throw;
  161. }
  162. return res;
  163. }
  164. /// <summary>
  165. /// 获取出库任务
  166. /// </summary>
  167. /// <param name="position">出库位置</param>
  168. /// <param name="devCode">调用方法的设备号</param>
  169. /// <returns></returns>
  170. /// <exception cref="Exception"></exception>
  171. public static List<I_WCS_GetOutTaskResponseSingle> GetOutTask(string position, string devCode)
  172. {
  173. var res = APICaller.CallApi<I_WCS_GetOutTaskResponse>(Url + "/api/Task/I_WCS_GetOutTask", new I_WCS_GetOutTaskRequest
  174. {
  175. OutType = 1,
  176. WareHouseId = wareHouseId,
  177. OutEndPostion = position
  178. });
  179. if (!res.ResType)
  180. {
  181. var msg = "";
  182. if (res.ResMessage.Contains("并发重复请求"))
  183. {
  184. msg = res.ResMessage + ",请使用WMS异常处理功能处理";
  185. TaskException(position, msg);
  186. }
  187. else
  188. {
  189. TaskException(position, res.ResMessage);
  190. }
  191. throw new WarnException(res.ResMessage);
  192. }
  193. res.WMSTasks.ForEach(v =>
  194. {
  195. var tcode = "TY" + v.TunnelNum;
  196. var tunnel = Device.Find(tcode);
  197. //var next = tunnel.GetPath(devCode);
  198. //v.Memo1 = next.CODE;
  199. v.TunnelNum = tunnel.CODE;
  200. });
  201. return res.WMSTasks;
  202. }
  203. public static WcsContractApiResponse AutoBuildUpGroupStock(string containerCode, string barcode, string dev)
  204. {
  205. var res = APICaller.CallApi<WcsContractApiResponse>(Url + "/api/Task/AutoBuildUpGroupStock", new
  206. {
  207. ContainerCode = containerCode,
  208. BarCode = barcode
  209. });
  210. if (!res.ResType)
  211. {
  212. TaskException(dev, res.ResMessage);
  213. throw new WarnException(res.ResMessage);
  214. }
  215. return res;
  216. }
  217. /// <summary>
  218. /// 获取巷道
  219. /// </summary>
  220. /// <param name="WMSTaskId">WMS任务号集合</param>
  221. /// <param name="dev">请求设备号</param>
  222. /// <returns></returns>
  223. /// <exception cref="Exception"></exception>
  224. public static I_WCS_GetTunnelListResponse GetTunnelList(List<string> WMSTaskId, string dev)
  225. {
  226. var res = APICaller.CallApi2<I_WCS_GetTunnelListResponse>(Url + "/api/Task/I_WCS_GetTunnelList", new I_WCS_GetTunnelListRequest
  227. {
  228. WMSTaskNum = WMSTaskId
  229. });
  230. if (!res.ResType)
  231. {
  232. TaskException(dev, res.ResMessage);
  233. throw new WarnException(res.ResMessage);
  234. }
  235. return res;
  236. }
  237. public static I_WCS_MergeinfoResponse GetSingleOrDouble(string barcode, string dev)
  238. {
  239. var res = APICaller.CallApi<I_WCS_MergeinfoResponse>(Url + "/api/Task/I_WCS_Mergeinfo", new I_WCS_MergeinfoRequest
  240. {
  241. ContainerBarCode = barcode,
  242. EquipmentNo = dev
  243. });
  244. if (!res.ResType)
  245. {
  246. TaskException(dev, res.ResMessage);
  247. throw new WarnException(res.ResMessage);
  248. }
  249. return res;
  250. }
  251. public static void TaskException(string device, string exMsg)
  252. {
  253. if (exMsg == "接口调用中")
  254. return;
  255. Task.Run(() =>
  256. {
  257. try
  258. {
  259. Console.WriteLine(device + ":" + exMsg);
  260. var res = APICaller.CallApi2<I_WCS_GetExcTaskResponse>(Url + "/api/Task/I_WCS_GetExcTask", new I_WCS_GetExcTaskRequest
  261. {
  262. ExcCode = exMsg,
  263. EquipmentNo = device,
  264. ExcMessage = exMsg,
  265. });
  266. InfoLog.INFO_I_WCS_GetExcTask(device + ":" + exMsg);
  267. if (!res.ResType) throw new WarnException(res.ResMessage);
  268. }
  269. catch (Exception)
  270. {
  271. }
  272. });
  273. }
  274. private static List<I_WCS_PutDevInfoRequest> DevInfoList = new List<I_WCS_PutDevInfoRequest>();
  275. public static void DevInfo(string device, string exMsg)
  276. {
  277. DevInfoList.Add(new I_WCS_PutDevInfoRequest
  278. {
  279. STA_EQUIPMENTNO = device,
  280. STA_ALARMSMSG = exMsg
  281. });
  282. }
  283. public static void UploadDevInfo()
  284. {
  285. try
  286. {
  287. var res = APICaller.CallApi<I_WCS_PutDevInfoResponse>(Url + "/api/Task/I_WCS_PutDevInfo", DevInfoList);
  288. if (!res.ResType)
  289. throw new WarnException(res.ResMessage);
  290. }
  291. catch (Exception)
  292. {
  293. Console.WriteLine("I_WCS_PutDevInfo" + "接口调用失败");
  294. }
  295. finally
  296. {
  297. DevInfoList.Clear();
  298. }
  299. }
  300. public static void UnBound(string barcode)
  301. {
  302. try
  303. {
  304. var res = APICaller.CallApi<I_WCS_GetTunnelListResponse>(Url + "/api/PDA/UnboundMwGroupStock", new
  305. {
  306. containerCode = barcode
  307. });
  308. }
  309. catch { }
  310. }
  311. }
  312. }