WmsApi.cs 20 KB

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