WmsApi.cs 16 KB

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