WmsApi.cs 19 KB

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