WmsApi.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  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. return res;
  159. }
  160. /// <summary>
  161. /// 申请出库任务
  162. /// </summary>
  163. /// <returns></returns>
  164. /// <exception cref="KnownException"></exception>
  165. public static SRes ApplyEmptyPalletGroupOutStorage(string addto, int tunnel, PalletType type)
  166. {
  167. var request = new ApplyStockOutTaskRequest
  168. {
  169. Tunnel = tunnel,
  170. FJPalletType = type,
  171. AddTo = addto
  172. };
  173. var res = APICaller.CallApi2<SRes>(WmsUrl + "/api/fj/ApplyEmptyPalletGroupOutStorage", request);
  174. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  175. {
  176. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  177. }
  178. return res;
  179. }
  180. /// <summary>
  181. /// 完成任务
  182. /// </summary>
  183. /// <param name="taskNo"></param>
  184. /// <returns></returns>
  185. /// <exception cref="KnownException"></exception>
  186. public static SRes<int> CompleteTask(int taskNo)
  187. {
  188. var res = APICaller.CallApi2<SRes<int>>(WmsUrl + "/api/fj/CompleteTask", new CompleteTaskRequest
  189. {
  190. TaskNum = taskNo,
  191. OperationType = Models.WMS.Request.CompleteTask.自动完成,
  192. WCSUpdateName = "WCS"
  193. });
  194. return res;
  195. }
  196. /// <summary>
  197. /// 处理任务验证接口
  198. /// </summary>
  199. /// <param name="taskNo">需要处理的任务进行验证</param>
  200. /// <param name="state">目标状态</param>
  201. /// <returns></returns>
  202. /// <exception cref="KnownException"></exception>
  203. public static SRes HandleTaskVerify(List<int> taskNo, int state)
  204. {
  205. var res = APICaller.CallApi2<SRes>(WmsUrl + "/api/Hj/CancelTaskVerify", new CancelTaskVerifyRequest
  206. {
  207. TaskNo = taskNo,
  208. State = state
  209. });
  210. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  211. {
  212. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  213. }
  214. return res;
  215. }
  216. /// <summary>
  217. /// 处理任务接口
  218. /// </summary>
  219. /// <param name="taskNo">处理</param>
  220. /// <param name="state">目标状态</param>
  221. /// <returns></returns>
  222. /// <exception cref="KnownException"></exception>
  223. public static SRes CarryTaskInfo(List<int> taskNo, int state)
  224. {
  225. var res = APICaller.CallApi2<SRes>(WmsUrl + "/api/Hj/CarryTaskInfo", new CancelTaskVerifyRequest
  226. {
  227. TaskNo = taskNo,
  228. State = state
  229. });
  230. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  231. {
  232. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  233. }
  234. return res;
  235. }
  236. /// <summary>
  237. /// WMS完成或取消任务验证
  238. /// </summary>
  239. /// <param name="sRes"></param>
  240. /// <param name="id"></param>
  241. /// <param name="type">99完成,106取消</param>
  242. /// <returns></returns>
  243. public static SRes? HandleTaskVerify(SRes<HandleTaskResponse> sRes, int id, int type)
  244. {
  245. try
  246. {
  247. var res = WmsApi.HandleTaskVerify(new List<int>() { id }, type);
  248. return res;
  249. }
  250. catch (Exception ex)
  251. {
  252. sRes.ResDataList.Add(new HandleTaskResponse()
  253. {
  254. IsSuccess = false,
  255. TaskNo = id,
  256. Message = $"WMS错误:{ex.Message}",
  257. });
  258. return null;
  259. }
  260. }
  261. /// <summary>
  262. /// WMS完成或取消任务执行
  263. /// </summary>
  264. /// <param name="sRes"></param>
  265. /// <param name="id"></param>
  266. /// <param name="type">99完成,106取消</param>
  267. /// <returns></returns>
  268. public static SRes? CarryTaskInfo(SRes<HandleTaskResponse> sRes, int id, int type)
  269. {
  270. try
  271. {
  272. var res = WmsApi.CarryTaskInfo(new List<int>() { id }, type);
  273. return res;
  274. }
  275. catch (Exception ex)
  276. {
  277. sRes.ResDataList.Add(new HandleTaskResponse()
  278. {
  279. IsSuccess = false,
  280. TaskNo = id,
  281. Message = $"WMS错误:{ex.Message}",
  282. });
  283. return null;
  284. }
  285. }
  286. /// <summary>
  287. /// 一楼扫码入库
  288. /// </summary>
  289. /// <param name="codeList">工字轮条码组</param>
  290. /// <returns></returns>
  291. /// <exception cref="KnownException"></exception>
  292. public static SRes? OneFloorWorkerBuildEmptyPalletsStock(OneFloorWorkerBuildEmptyPalletsStockRequest reqDto)
  293. {
  294. var res = APICaller.CallApi2<SRes>(WmsUrl + "/api/FJ/OneFloorWorkerBuildEmptyPalletsStock", new OneFloorWorkerBuildEmptyPalletsStockRequest
  295. {
  296. PalletCode = reqDto.PalletCode,
  297. PalletType = reqDto.PalletType,
  298. StartLoc = reqDto.StartLoc,
  299. WareCode = reqDto.StartLoc.GetWareCode(),
  300. PalletNum = "1"
  301. });
  302. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  303. {
  304. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  305. }
  306. return res;
  307. }
  308. /// <summary>
  309. /// 工字轮/芯股进入主线扫码
  310. /// </summary>
  311. /// <param name="reqDto"></param>
  312. /// <param name="equNo"></param>
  313. /// <returns></returns>
  314. /// <exception cref="KnownException"></exception>
  315. public static SRes EnteMainLine(List<string> reqDto, string equNo)
  316. {
  317. var res = APICaller.CallApi<SRes>(WmsUrl + "/api/FJ/EnteMainLine", new FJEnteMainLineRequest
  318. {
  319. IShapedWheelCodes = reqDto,
  320. equNo = equNo
  321. });
  322. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  323. {
  324. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  325. }
  326. return res;
  327. }
  328. /// <summary>
  329. /// 生成空托盘组盘任务
  330. /// </summary>
  331. /// <param name="palletCode"></param>
  332. /// <param name="loc"></param>
  333. /// <returns></returns>
  334. /// <exception cref="KnownException"></exception>
  335. public static SRes GroupTask(string palletCode, string loc)
  336. {
  337. var res = APICaller.CallApi<SRes>(WmsUrl + "/api/FJ/GroupTask", new FJBuildEmptyPalletsStockRequest
  338. {
  339. PalletCode = palletCode,
  340. PalletType = FJPalletType.Pallet09,
  341. PalletNum = "1",
  342. StartLoc = loc,
  343. WareCode = loc.GetWareCode(),
  344. BusType = TaskBusType.组盘_托盘
  345. });
  346. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  347. {
  348. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  349. }
  350. return res;
  351. }
  352. /// <summary>
  353. /// 绑盘
  354. /// </summary>
  355. /// <param name="palletCode"></param>
  356. /// <param name="taskCodes"></param>
  357. /// <param name="warehouseCode"></param>
  358. /// <param name="loc"></param>
  359. /// <returns></returns>
  360. /// <exception cref="KnownException"></exception>
  361. public static SRes BingPallet(string palletCode, List<string> taskCodes, string warehouseCode, string loc) => BingPallet(palletCode, taskCodes, warehouseCode, loc, false, "");
  362. /// <summary>
  363. /// 绑盘
  364. /// </summary>
  365. /// <param name="palletCode"></param>
  366. /// <param name="taskCodes"></param>
  367. /// <param name="warehouseCode"></param>
  368. /// <param name="loc"></param>
  369. /// <param name="isFail"></param>
  370. /// <param name="failReason"></param>
  371. /// <returns></returns>
  372. /// <exception cref="KnownException"></exception>
  373. public static SRes BingPallet(string palletCode, List<string> taskCodes, string warehouseCode, string loc, bool isFail, string failReason)
  374. {
  375. var res = APICaller.CallApi<SRes>(WmsUrl + "/api/FJ/BingPallet", new FJBingPalletRequest
  376. {
  377. PalletCode = palletCode,
  378. TaskCode = taskCodes,
  379. WarehouseCode = warehouseCode,
  380. loc = loc,
  381. IsFail = isFail,
  382. FailReason = failReason
  383. });
  384. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  385. {
  386. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  387. }
  388. return res;
  389. }
  390. /// <summary>
  391. /// 环形库申请码垛任务
  392. /// </summary>
  393. /// <param name="loc"></param>
  394. /// <param name="robotCode"></param>
  395. /// <returns></returns>
  396. /// <exception cref="KnownException"></exception>
  397. public static SRes ApplyPalletizingStockOut(string loc, string robotCode)
  398. {
  399. var res = APICaller.CallApi<SRes>(WmsUrl + "/api/FJ/ApplyPalletizingStockOut", new wms.dto.request.fj.RingApplyPalletizingStockOutRequest(loc.GetWareCode(), loc, robotCode));
  400. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  401. {
  402. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  403. }
  404. return res;
  405. }
  406. /// <summary>
  407. /// 码垛工资轮创建异常任务信息
  408. /// </summary>
  409. /// <param name="loc"></param>
  410. /// <param name="type"></param>
  411. /// <returns></returns>
  412. /// <exception cref="KnownException"></exception>
  413. public static SRes PalletizingCreateseErrorTasks(string loc, string type)
  414. {
  415. var res = APICaller.CallApi<SRes>(WmsUrl + "/api/FJ/PalletizingCreateseErrorTasks", new Models.WMS.Request.PalletizingCreateseErrorTasksRequest(loc, type, loc.GetWareCode()));
  416. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  417. {
  418. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  419. }
  420. return res;
  421. }
  422. }
  423. }