WmsApi.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. using ServiceCenter;
  2. using ServiceCenter.Extensions;
  3. using ServiceCenter.Logs;
  4. using ServiceCenter.Redis;
  5. using ServiceCenter.WebApi;
  6. using WCS.WorkEngineering.WebApi.Models.AGV.Response;
  7. using WCS.WorkEngineering.WebApi.Models.WCS.Response;
  8. using WCS.WorkEngineering.WebApi.Models.WMS.Request;
  9. using WCS.WorkEngineering.WebApi.Models.WMS.Response;
  10. namespace WCS.WorkEngineering.WebApi.Controllers
  11. {
  12. /// <summary>
  13. /// AGV相关接口控制器
  14. /// </summary>
  15. public static class WmsApi
  16. {
  17. private static string _WMSUrl = null!;
  18. private static string _wareHouseId = null!;
  19. private static string wmsUrl = "http://10.30.43.158:8089";
  20. /// <summary>
  21. /// WMS URL
  22. /// </summary>
  23. public static string WMSUrl
  24. {
  25. get
  26. {
  27. _WMSUrl ??= RedisHub.Default.Check("WMSUrl");
  28. if (string.IsNullOrEmpty(_WMSUrl))
  29. {
  30. throw new KnownException($"请在Redis配置WMSUrl", LogLevelEnum.High);
  31. }
  32. return _WMSUrl;
  33. }
  34. }
  35. /// <summary>
  36. /// 仓库编号
  37. /// </summary>
  38. public static string wareHouseId = ServiceHub.WarehouseName;
  39. /// <summary>
  40. /// 上传重量等信息
  41. /// </summary>
  42. /// <param name="taskCode">任务号</param>
  43. /// <param name="weight">rfid</param>
  44. /// <returns></returns>
  45. public static SRes WcsUploadInfo(int taskCode, decimal weight) => WcsUploadInfo(taskCode, weight, "");
  46. /// <summary>
  47. /// 上传重量等信息
  48. /// </summary>
  49. /// <param name="taskCode">任务号</param>
  50. /// <param name="RFID">重量</param>
  51. /// <returns></returns>
  52. public static SRes WcsUploadInfo(int taskCode, string RFID) => WcsUploadInfo(taskCode, 0, RFID);
  53. /// <summary>
  54. /// 上传重量等信息
  55. /// </summary>
  56. /// <param name="taskCode">任务号</param>
  57. /// <param name="weight">重量</param>
  58. /// <param name="RFID">rfid</param>
  59. /// <returns></returns>
  60. /// <exception cref="KnownException"></exception>
  61. public static SRes WcsUploadInfo(int taskCode, decimal weight, string RFID)
  62. {
  63. var res = APICaller.CallApi2<SRes>(WMSUrl + "/api/Hj/WcsUploadInfo", new WcsUploadInfoRequest
  64. {
  65. TaskCode = taskCode,
  66. Weight = weight,
  67. RFID = RFID
  68. });
  69. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  70. {
  71. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  72. }
  73. return res;
  74. }
  75. /// <summary>
  76. /// 获取巷道
  77. /// </summary>
  78. /// <param name="wcsTaskNum">WMS任务ID</param>
  79. /// <returns></returns>
  80. /// <exception cref="Exception"></exception>
  81. public static SRes<string> GetTunnelPriorityList(int wcsTaskNum)
  82. {
  83. var res = APICaller.CallApi2<SRes<string>>(wmsUrl + "/api/Cp/GetTunnelPriorityList", new GetTunnelPriorityListRequest
  84. {
  85. TaskNum = wcsTaskNum,
  86. });
  87. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  88. {
  89. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  90. }
  91. return res;
  92. }
  93. /// <summary>
  94. /// 分配货位
  95. /// </summary>
  96. /// <param name="wcsTaskNum">WMS任务ID</param>
  97. /// <param name="tunnel">货位</param>
  98. /// <param name="device">设备号</param>
  99. /// <param name="size"></param>
  100. /// <returns></returns>
  101. /// <exception cref="Exception"></exception>
  102. public static SRes<ApplyStockInLocResponse> GetLocalIn(int wcsTaskNum, string tunnel, string device)
  103. {
  104. var res = APICaller.CallApi2<SRes<ApplyStockInLocResponse>>(wmsUrl + "/api/Cp/ApplyStockInLoc", new ApplyStockInLocRequest
  105. {
  106. TaskNum = wcsTaskNum,
  107. TunnelNum = tunnel.GetLastDigit(),
  108. PickUpEquipmentNo = device.ToString(),
  109. });
  110. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  111. {
  112. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  113. }
  114. return res;
  115. }
  116. /// <summary>
  117. /// 堆垛机出库任务执行完成
  118. /// </summary>
  119. /// <param name="taskNum"></param>
  120. /// <returns></returns>
  121. /// <exception cref="KnownException"></exception>
  122. public static SRes<int> SrmPickOutCompleted(int taskNum)
  123. {
  124. var res = APICaller.CallApi2<SRes<int>>(wmsUrl + "/api/Cp/SrmPickOutCompleted", new SrmPickOutCompletedRequest
  125. {
  126. TaskNum = taskNum,
  127. });
  128. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  129. {
  130. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  131. }
  132. return res;
  133. }
  134. /// <summary>
  135. /// 一楼空工字轮申请出库
  136. /// </summary>
  137. /// <param name="outEndPostion">出库位置</param>
  138. /// <returns></returns>
  139. public static SRes ApplyStockOutTask(string outEndPostion) => ApplyStockOutTask(outEndPostion, 2);
  140. /// <summary>
  141. /// 申请出库任务
  142. /// </summary>
  143. /// <param name="outEndPostion">出库位置</param>
  144. /// <param name="outType">出库类型</param>
  145. /// <returns></returns>
  146. /// <exception cref="KnownException"></exception>
  147. public static SRes ApplyStockOutTask(string outEndPostion, int outType)
  148. {
  149. var request = new ApplyStockOutTaskRequest
  150. {
  151. OutEndPostion = outEndPostion,
  152. OutType = outType,
  153. WarehouseCode = wareHouseId,
  154. };
  155. switch (outEndPostion)
  156. {
  157. case "1012":
  158. request.Tunnel = "1";
  159. break;
  160. case "1014":
  161. request.Tunnel = "2";
  162. break;
  163. case "1016":
  164. request.Tunnel = "3";
  165. break;
  166. }
  167. var res = APICaller.CallApi2<SRes>(WMSUrl + "/api/Hj/ApplyStockOutTask", request);
  168. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  169. {
  170. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  171. }
  172. return res;
  173. }
  174. /// <summary>
  175. /// 获取各巷道剩余空轮数量
  176. /// </summary>
  177. /// <returns></returns>
  178. /// <exception cref="KnownException"></exception>
  179. public static SRes<GetTunnelEmptyConResponse> GetTunnelEmptyConCount()
  180. {
  181. var res = APICaller.CallApi2<SRes<GetTunnelEmptyConResponse>>(WMSUrl + "/api/Hj/GetTunnelEmptyConCount", new GetTunnelEmptyConCountRequest { });
  182. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  183. {
  184. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  185. }
  186. return res;
  187. }
  188. /// <summary>
  189. /// 完成任务
  190. /// </summary>
  191. /// <param name="taskNo"></param>
  192. /// <returns></returns>
  193. /// <exception cref="KnownException"></exception>
  194. public static SRes<int> CompleteTask(int taskNo)
  195. {
  196. var res = APICaller.CallApi2<SRes<int>>(wmsUrl + "/api/Cp/CompleteTask", new CompleteTaskRequest
  197. {
  198. TaskNum = taskNo,
  199. OperationType = Models.WMS.Request.CompleteTask.自动完成,
  200. WCSUpdateName = "WCS"
  201. });
  202. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  203. {
  204. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  205. }
  206. return res;
  207. }
  208. /// <summary>
  209. /// 二深位获取移库任务
  210. /// </summary>
  211. /// <param name="taskNo">任务</param>
  212. /// <returns></returns>
  213. /// <exception cref="KnownException"></exception>
  214. public static SRes<AddWcsMoveTaskResponse> AddWcsMoveTask(int taskNo)
  215. {
  216. var res = APICaller.CallApi2<SRes<AddWcsMoveTaskResponse>>(wmsUrl + "/api/Cp/AddWcsMoveTask", new CompleteTaskRequest
  217. {
  218. TaskNum = taskNo,
  219. });
  220. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  221. {
  222. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  223. }
  224. return res;
  225. }
  226. /// <summary>
  227. /// 向WMS获取入库任务 一次单卷
  228. /// </summary>
  229. /// <param name="barcode">产品条码</param>
  230. /// <param name="devCode">设备条码</param>
  231. /// <param name="getTunnel"></param>
  232. /// <returns></returns>
  233. /// <exception cref="Exception"></exception>
  234. public static SRes I_WCS_GetInTask(string barcode, string devCode, bool getTunnel = false)
  235. {
  236. try
  237. {
  238. var res = APICaller.CallApi<SRes>("http://10.30.43.158:8089/api/Cp/WCS_InTaskInfo", new GetInTaskInfoRequest()
  239. {
  240. Code = barcode,
  241. Equip = devCode,
  242. WareHouse = "cphouse"
  243. });
  244. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  245. {
  246. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  247. }
  248. return res;
  249. }
  250. catch (Exception ex)
  251. {
  252. throw new KnownException(ex.Message, LogLevelEnum.High)
  253. ;
  254. }
  255. }
  256. /// <summary>
  257. /// 处理任务验证接口
  258. /// </summary>
  259. /// <param name="taskNo">需要处理的任务进行验证</param>
  260. /// <param name="state">目标状态</param>
  261. /// <returns></returns>
  262. /// <exception cref="KnownException"></exception>
  263. public static SRes HandleTaskVerify(List<int> taskNo, int state)
  264. {
  265. var res = APICaller.CallApi2<SRes>(WMSUrl + "/api/Hj/CancelTaskVerify", new CancelTaskVerifyRequest
  266. {
  267. TaskNo = taskNo,
  268. State = state
  269. });
  270. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  271. {
  272. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  273. }
  274. return res;
  275. }
  276. /// <summary>
  277. /// 处理任务接口
  278. /// </summary>
  279. /// <param name="taskNo">处理</param>
  280. /// <param name="state">目标状态</param>
  281. /// <returns></returns>
  282. /// <exception cref="KnownException"></exception>
  283. public static SRes CarryTaskInfo(List<int> taskNo, int state)
  284. {
  285. var res = APICaller.CallApi2<SRes>(WMSUrl + "/api/Pt/CarryTaskInfo", new CancelTaskVerifyRequest
  286. {
  287. TaskNo = taskNo,
  288. State = state
  289. });
  290. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  291. {
  292. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  293. }
  294. return res;
  295. }
  296. /// <summary>
  297. /// WMS完成或取消任务验证
  298. /// </summary>
  299. /// <param name="sRes"></param>
  300. /// <param name="id"></param>
  301. /// <param name="type">99完成,106取消</param>
  302. /// <returns></returns>
  303. public static SRes? HandleTaskVerify(SRes<HandleTaskResponse> sRes, int id, int type)
  304. {
  305. try
  306. {
  307. var res = WmsApi.HandleTaskVerify(new List<int>() { id }, type);
  308. return res;
  309. }
  310. catch (Exception ex)
  311. {
  312. sRes.ResDataList.Add(new HandleTaskResponse()
  313. {
  314. IsSuccess = false,
  315. TaskNo = id,
  316. Message = $"WMS错误:{ex.Message}",
  317. });
  318. return null;
  319. }
  320. }
  321. /// <summary>
  322. /// WMS完成或取消任务执行
  323. /// </summary>
  324. /// <param name="sRes"></param>
  325. /// <param name="id"></param>
  326. /// <param name="type">99完成,106取消</param>
  327. /// <returns></returns>
  328. public static SRes? CarryTaskInfo(SRes<HandleTaskResponse> sRes, int id, int type)
  329. {
  330. try
  331. {
  332. var res = WmsApi.CarryTaskInfo(new List<int>() { id }, type);
  333. return res;
  334. }
  335. catch (Exception ex)
  336. {
  337. sRes.ResDataList.Add(new HandleTaskResponse()
  338. {
  339. IsSuccess = false,
  340. TaskNo = id,
  341. Message = $"WMS错误:{ex.Message}",
  342. });
  343. return null;
  344. }
  345. }
  346. /// <summary>
  347. /// 工字轮/芯股进入主线扫码
  348. /// </summary>
  349. /// <param name="codeList">工字轮条码组</param>
  350. /// <returns></returns>
  351. /// <exception cref="KnownException"></exception>
  352. public static SRes? OneFloorWorkerBuildEmptyPalletsStock(OneFloorWorkerBuildEmptyPalletsStockRequest reqDto)
  353. {
  354. var res = APICaller.CallApi2<SRes>(WMSUrl + "/api/FJ/OneFloorWorkerBuildEmptyPalletsStock", new OneFloorWorkerBuildEmptyPalletsStockRequest
  355. {
  356. PalletCode = reqDto.PalletCode,
  357. PalletType = reqDto.PalletType,
  358. StartLoc = reqDto.StartLoc,
  359. WareCode = GetWareCode(reqDto.StartLoc),
  360. PalletNum = "1"
  361. });
  362. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  363. {
  364. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  365. }
  366. return res;
  367. }
  368. /// <summary>
  369. /// 获取仓库号
  370. /// </summary>
  371. public static string GetWareCode(string add)
  372. {
  373. return add switch
  374. {
  375. "2532" => "1N",
  376. "2527" => "1N",
  377. "2528" => "1N",
  378. "2732" => "1S",
  379. "2727" => "1S",
  380. "2728" => "1S",
  381. _ => "",
  382. };
  383. }
  384. /// <summary>
  385. /// 工字轮/芯股进入主线扫码
  386. /// </summary>
  387. /// <param name="reqDto"></param>
  388. /// <param name="equNo"></param>
  389. /// <returns></returns>
  390. /// <exception cref="KnownException"></exception>
  391. public static SRes EnteMainLine(List<string> reqDto, string equNo)
  392. {
  393. var res = APICaller.CallApi<SRes>(WMSUrl + "/api/FJ/EnteMainLine", new FJEnteMainLineRequest
  394. {
  395. IShapedWheelCodes = reqDto,
  396. equNo = equNo
  397. });
  398. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  399. {
  400. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  401. }
  402. return res;
  403. }
  404. }
  405. }