WmsApi.cs 20 KB

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