WMS.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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.CallApi<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. TaskException(position, res.ResMessage);
  182. throw new WarnException(res.ResMessage);
  183. }
  184. res.WMSTasks.ForEach(v =>
  185. {
  186. var tcode = "TY" + v.TunnelNum;
  187. var tunnel = Device.Find(tcode);
  188. //var next = tunnel.GetPath(devCode);
  189. //v.Memo1 = next.CODE;
  190. v.TunnelNum = tunnel.CODE;
  191. });
  192. return res.WMSTasks;
  193. }
  194. public static WcsContractApiResponse AutoBuildUpGroupStock(string containerCode, string barcode, string dev)
  195. {
  196. var res = APICaller.CallApi<WcsContractApiResponse>(Url + "/api/Task/AutoBuildUpGroupStock", new
  197. {
  198. ContainerCode = containerCode,
  199. BarCode = barcode
  200. });
  201. if (!res.ResType)
  202. {
  203. TaskException(dev, res.ResMessage);
  204. throw new WarnException(res.ResMessage);
  205. }
  206. return res;
  207. }
  208. /// <summary>
  209. /// 获取巷道
  210. /// </summary>
  211. /// <param name="WMSTaskId">WMS任务号集合</param>
  212. /// <param name="dev">请求设备号</param>
  213. /// <returns></returns>
  214. /// <exception cref="Exception"></exception>
  215. public static I_WCS_GetTunnelListResponse GetTunnelList(List<string> WMSTaskId, string dev)
  216. {
  217. var res = APICaller.CallApi<I_WCS_GetTunnelListResponse>(Url + "/api/Task/I_WCS_GetTunnelList", new I_WCS_GetTunnelListRequest
  218. {
  219. WMSTaskNum = WMSTaskId
  220. });
  221. if (!res.ResType)
  222. {
  223. TaskException(dev, res.ResMessage);
  224. throw new WarnException(res.ResMessage);
  225. }
  226. return res;
  227. }
  228. public static void TaskException(string device, string exMsg)
  229. {
  230. if (exMsg == "接口调用中")
  231. return;
  232. Task.Run(() =>
  233. {
  234. try
  235. {
  236. Console.WriteLine(device + ":" + exMsg);
  237. var res = APICaller.CallApi2<I_WCS_GetExcTaskResponse>(Url + "/api/Task/I_WCS_GetExcTask", new I_WCS_GetExcTaskRequest
  238. {
  239. ExcCode = exMsg,
  240. EquipmentNo = device,
  241. ExcMessage = exMsg,
  242. });
  243. InfoLog.INFO_I_WCS_GetExcTask(device + ":" + exMsg);
  244. if (!res.ResType) throw new WarnException(res.ResMessage);
  245. }
  246. catch (Exception)
  247. {
  248. }
  249. });
  250. }
  251. private static List<I_WCS_PutDevInfoRequest> DevInfoList = new List<I_WCS_PutDevInfoRequest>();
  252. public static void DevInfo(string device, string exMsg)
  253. {
  254. DevInfoList.Add(new I_WCS_PutDevInfoRequest
  255. {
  256. STA_EQUIPMENTNO = device,
  257. STA_ALARMSMSG = exMsg
  258. });
  259. }
  260. public static void UploadDevInfo()
  261. {
  262. try
  263. {
  264. var res = APICaller.CallApi<I_WCS_PutDevInfoResponse>(Url + "/api/Task/I_WCS_PutDevInfo", DevInfoList);
  265. if (!res.ResType)
  266. throw new WarnException(res.ResMessage);
  267. }
  268. catch (Exception)
  269. {
  270. Console.WriteLine("I_WCS_PutDevInfo" + "接口调用失败");
  271. }
  272. finally
  273. {
  274. DevInfoList.Clear();
  275. }
  276. }
  277. public static void UnBound(string barcode)
  278. {
  279. try
  280. {
  281. var res = APICaller.CallApi<I_WCS_GetTunnelListResponse>(Url + "/api/PDA/UnboundMwGroupStock", new
  282. {
  283. containerCode = barcode
  284. });
  285. }
  286. catch { }
  287. }
  288. }
  289. }