WmsApi.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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. /// <summary>
  20. /// WMS URL
  21. /// </summary>
  22. public static string WMSUrl
  23. {
  24. get
  25. {
  26. _WMSUrl ??= RedisHub.Default.Check("WMSUrl");
  27. if (string.IsNullOrEmpty(_WMSUrl))
  28. {
  29. throw new KnownException($"请在Redis配置WMSUrl", LogLevelEnum.High);
  30. }
  31. return _WMSUrl;
  32. }
  33. }
  34. /// <summary>
  35. /// 仓库编号
  36. /// </summary>
  37. public static string wareHouseId = ServiceHub.WarehouseName;
  38. /// <summary>
  39. /// 上传重量等信息
  40. /// </summary>
  41. /// <param name="taskCode">任务号</param>
  42. /// <param name="weight">rfid</param>
  43. /// <returns></returns>
  44. public static SRes WcsUploadInfo(int taskCode, decimal weight) => WcsUploadInfo(taskCode, weight, "");
  45. /// <summary>
  46. /// 上传重量等信息
  47. /// </summary>
  48. /// <param name="taskCode">任务号</param>
  49. /// <param name="RFID">重量</param>
  50. /// <returns></returns>
  51. public static SRes WcsUploadInfo(int taskCode, string RFID) => WcsUploadInfo(taskCode, 0, RFID);
  52. /// <summary>
  53. /// 上传重量等信息
  54. /// </summary>
  55. /// <param name="taskCode">任务号</param>
  56. /// <param name="weight">重量</param>
  57. /// <param name="RFID">rfid</param>
  58. /// <returns></returns>
  59. /// <exception cref="KnownException"></exception>
  60. public static SRes WcsUploadInfo(int taskCode, decimal weight, string RFID)
  61. {
  62. var res = APICaller.CallApi2<SRes>(WMSUrl + "/api/Hj/WcsUploadInfo", new WcsUploadInfoRequest
  63. {
  64. TaskCode = taskCode,
  65. Weight = weight,
  66. RFID = RFID
  67. });
  68. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  69. {
  70. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  71. }
  72. return res;
  73. }
  74. /// <summary>
  75. /// 获取巷道
  76. /// </summary>
  77. /// <param name="wcsTaskNum">WMS任务ID</param>
  78. /// <returns></returns>
  79. /// <exception cref="Exception"></exception>
  80. public static SRes<string> GetTunnelPriorityList(int wcsTaskNum)
  81. {
  82. var res = APICaller.CallApi2<SRes<string>>(WMSUrl + "/api/Hj/GetTunnelPriorityList", new GetTunnelPriorityListRequest
  83. {
  84. TaskNum = wcsTaskNum,
  85. });
  86. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  87. {
  88. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  89. }
  90. return res;
  91. }
  92. /// <summary>
  93. /// 分配货位
  94. /// </summary>
  95. /// <param name="wcsTaskNum">WMS任务ID</param>
  96. /// <param name="tunnel">货位</param>
  97. /// <param name="device">设备号</param>
  98. /// <param name="size"></param>
  99. /// <returns></returns>
  100. /// <exception cref="Exception"></exception>
  101. public static SRes<ApplyStockInLocResponse> GetLocalIn(int wcsTaskNum, string tunnel, string device, int size)
  102. {
  103. var res = APICaller.CallApi2<SRes<ApplyStockInLocResponse>>(WMSUrl + "/api/FJ/ApplyStockInLoc", new ApplyStockInLocRequest
  104. {
  105. TaskNum = wcsTaskNum,
  106. TunnelNum = tunnel.GetLastDigit(),
  107. PickUpEquipmentNo = device.ToString(),
  108. Height = size
  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/Hj/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/fj/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/Hj/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. var res = APICaller.CallApi<SRes>(WMSUrl + "/api/Task/I_WCS_GetInTask", new List<I_WCS_GetInTaskRequest>()
  237. {
  238. new I_WCS_GetInTaskRequest(){
  239. ContainerBarCode = barcode,
  240. WareHouseId = wareHouseId,
  241. EquipmentNo = devCode,
  242. Memo1 = getTunnel ? "1" : "" //1:分巷道 2:分货位
  243. }
  244. });
  245. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  246. {
  247. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  248. }
  249. return res;
  250. }
  251. /// <summary>
  252. /// 处理任务验证接口
  253. /// </summary>
  254. /// <param name="taskNo">需要处理的任务进行验证</param>
  255. /// <param name="state">目标状态</param>
  256. /// <returns></returns>
  257. /// <exception cref="KnownException"></exception>
  258. public static SRes HandleTaskVerify(List<int> taskNo, int state)
  259. {
  260. var res = APICaller.CallApi2<SRes>(WMSUrl + "/api/Hj/CancelTaskVerify", new CancelTaskVerifyRequest
  261. {
  262. TaskNo = taskNo,
  263. State = state
  264. });
  265. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  266. {
  267. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  268. }
  269. return res;
  270. }
  271. /// <summary>
  272. /// 处理任务接口
  273. /// </summary>
  274. /// <param name="taskNo">处理</param>
  275. /// <param name="state">目标状态</param>
  276. /// <returns></returns>
  277. /// <exception cref="KnownException"></exception>
  278. public static SRes CarryTaskInfo(List<int> taskNo, int state)
  279. {
  280. var res = APICaller.CallApi2<SRes>(WMSUrl + "/api/Hj/CarryTaskInfo", new CancelTaskVerifyRequest
  281. {
  282. TaskNo = taskNo,
  283. State = state
  284. });
  285. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  286. {
  287. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  288. }
  289. return res;
  290. }
  291. /// <summary>
  292. /// WMS完成或取消任务验证
  293. /// </summary>
  294. /// <param name="sRes"></param>
  295. /// <param name="id"></param>
  296. /// <param name="type">99完成,106取消</param>
  297. /// <returns></returns>
  298. public static SRes? HandleTaskVerify(SRes<HandleTaskResponse> sRes, int id, int type)
  299. {
  300. try
  301. {
  302. var res = WmsApi.HandleTaskVerify(new List<int>() { id }, type);
  303. return res;
  304. }
  305. catch (Exception ex)
  306. {
  307. sRes.ResDataList.Add(new HandleTaskResponse()
  308. {
  309. IsSuccess = false,
  310. TaskNo = id,
  311. Message = $"WMS错误:{ex.Message}",
  312. });
  313. return null;
  314. }
  315. }
  316. /// <summary>
  317. /// WMS完成或取消任务执行
  318. /// </summary>
  319. /// <param name="sRes"></param>
  320. /// <param name="id"></param>
  321. /// <param name="type">99完成,106取消</param>
  322. /// <returns></returns>
  323. public static SRes? CarryTaskInfo(SRes<HandleTaskResponse> sRes, int id, int type)
  324. {
  325. try
  326. {
  327. var res = WmsApi.CarryTaskInfo(new List<int>() { id }, type);
  328. return res;
  329. }
  330. catch (Exception ex)
  331. {
  332. sRes.ResDataList.Add(new HandleTaskResponse()
  333. {
  334. IsSuccess = false,
  335. TaskNo = id,
  336. Message = $"WMS错误:{ex.Message}",
  337. });
  338. return null;
  339. }
  340. }
  341. /// <summary>
  342. /// 工字轮/芯股进入主线扫码
  343. /// </summary>
  344. /// <param name="codeList">工字轮条码组</param>
  345. /// <returns></returns>
  346. /// <exception cref="KnownException"></exception>
  347. public static SRes? OneFloorWorkerBuildEmptyPalletsStock(OneFloorWorkerBuildEmptyPalletsStockRequest reqDto)
  348. {
  349. var res = APICaller.CallApi2<SRes>(WMSUrl + "/api/FJ/OneFloorWorkerBuildEmptyPalletsStock", new OneFloorWorkerBuildEmptyPalletsStockRequest
  350. {
  351. PalletCode = reqDto.PalletCode,
  352. PalletType = reqDto.PalletType,
  353. StartLoc = reqDto.StartLoc,
  354. WareCode = GetWareCode(reqDto.StartLoc),
  355. PalletNum = "1"
  356. });
  357. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  358. {
  359. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  360. }
  361. return res;
  362. }
  363. /// <summary>
  364. /// 获取仓库号
  365. /// </summary>
  366. public static string GetWareCode(string add)
  367. {
  368. return add switch
  369. {
  370. "2532" => "1N",
  371. "2527" => "1N",
  372. "2528" => "1N",
  373. "2732" => "1S",
  374. "2727" => "1S",
  375. "2728" => "1S",
  376. _ => "",
  377. };
  378. }
  379. /// <summary>
  380. /// 工字轮/芯股进入主线扫码
  381. /// </summary>
  382. /// <param name="reqDto"></param>
  383. /// <param name="equNo"></param>
  384. /// <returns></returns>
  385. /// <exception cref="KnownException"></exception>
  386. public static SRes EnteMainLine(List<string> reqDto, string equNo)
  387. {
  388. var res = APICaller.CallApi<SRes>(WMSUrl + "/api/FJ/EnteMainLine", new FJEnteMainLineRequest
  389. {
  390. IShapedWheelCodes = reqDto,
  391. equNo = equNo
  392. });
  393. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  394. {
  395. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  396. }
  397. return res;
  398. }
  399. }
  400. }