WmsApi.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  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="taskNum"></param>
  141. /// <returns></returns>
  142. /// <exception cref="KnownException"></exception>
  143. public static SRes<int> SrmPickOutCompleted(int taskNum)
  144. {
  145. var res = APICaller.CallApi2<SRes<int>>(WmsUrl + "/api/FJ/SrmPickOutCompleted", new SrmPickOutCompletedRequest
  146. {
  147. TaskNum = taskNum,
  148. });
  149. return res;
  150. }
  151. /// <summary>
  152. /// 申请出库任务
  153. /// </summary>
  154. /// <returns></returns>
  155. /// <exception cref="KnownException"></exception>
  156. public static SRes ApplyEmptyPalletGroupOutStorage(string addto, int tunnel, PalletType type)
  157. {
  158. var request = new ApplyStockOutTaskRequest
  159. {
  160. Tunnel = tunnel,
  161. FJPalletType = type,
  162. AddTo = addto
  163. };
  164. var res = APICaller.CallApi2<SRes>(WmsUrl + "/api/fj/ApplyEmptyPalletGroupOutStorage", request);
  165. return res;
  166. }
  167. /// <summary>
  168. /// 完成任务
  169. /// </summary>
  170. /// <param name="taskNo"></param>
  171. /// <returns></returns>
  172. /// <exception cref="KnownException"></exception>
  173. public static SRes<int> CompleteTask(int taskNo)
  174. {
  175. var res = APICaller.CallApi2<SRes<int>>(WmsUrl + "/api/fj/CompleteTask", new CompleteTaskRequest
  176. {
  177. TaskNum = taskNo,
  178. OperationType = Models.WMS.Request.CompleteTask.自动完成,
  179. WCSUpdateName = "WCS"
  180. });
  181. return res;
  182. }
  183. public static SRes<int> CancelTask(int taskNo)
  184. {
  185. var res = APICaller.CallApi2<SRes<int>>(WmsUrl + "/api/fj/CancelTask", new CompleteTaskRequest
  186. {
  187. TaskNum = taskNo,
  188. OperationType = Models.WMS.Request.CompleteTask.自动完成,
  189. WCSUpdateName = "WCS"
  190. });
  191. return res;
  192. }
  193. /// <summary>
  194. /// 处理任务验证接口
  195. /// </summary>
  196. /// <param name="taskNo">需要处理的任务进行验证</param>
  197. /// <param name="state">目标状态</param>
  198. /// <returns></returns>
  199. /// <exception cref="KnownException"></exception>
  200. public static SRes HandleTaskVerify(List<int> taskNo, int state)
  201. {
  202. var res = APICaller.CallApi2<SRes>(WmsUrl + "/api/fj/CancelTaskVerify", new CancelTaskVerifyRequest
  203. {
  204. TaskNo = taskNo,
  205. State = state
  206. });
  207. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  208. {
  209. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  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 CarryTaskInfo(List<int> taskNo, int state)
  221. {
  222. var res = APICaller.CallApi2<SRes>(WmsUrl + "/api/fj/CarryTaskInfo", 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. /// WMS完成或取消任务验证
  235. /// </summary>
  236. /// <param name="sRes"></param>
  237. /// <param name="id"></param>
  238. /// <param name="type">99完成,106取消</param>
  239. /// <returns></returns>
  240. public static SRes? HandleTaskVerify(SRes<HandleTaskResponse> sRes, int id, int type)
  241. {
  242. try
  243. {
  244. var res = WmsApi.HandleTaskVerify(new List<int>() { id }, type);
  245. return res;
  246. }
  247. catch (Exception ex)
  248. {
  249. sRes.ResDataList.Add(new HandleTaskResponse()
  250. {
  251. IsSuccess = false,
  252. TaskNo = id,
  253. Message = $"WMS错误:{ex.Message}",
  254. });
  255. return null;
  256. }
  257. }
  258. /// <summary>
  259. /// WMS完成或取消任务执行
  260. /// </summary>
  261. /// <param name="sRes"></param>
  262. /// <param name="id"></param>
  263. /// <param name="type">99完成,106取消</param>
  264. /// <returns></returns>
  265. public static SRes? CarryTaskInfo(SRes<HandleTaskResponse> sRes, int id, int type)
  266. {
  267. try
  268. {
  269. var res = WmsApi.CarryTaskInfo(new List<int>() { id }, type);
  270. return res;
  271. }
  272. catch (Exception ex)
  273. {
  274. sRes.ResDataList.Add(new HandleTaskResponse()
  275. {
  276. IsSuccess = false,
  277. TaskNo = id,
  278. Message = $"WMS错误:{ex.Message}",
  279. });
  280. return null;
  281. }
  282. }
  283. /// <summary>
  284. /// 一楼扫码入库
  285. /// </summary>
  286. /// <param name="codeList">工字轮条码组</param>
  287. /// <returns></returns>
  288. /// <exception cref="KnownException"></exception>
  289. public static SRes? OneFloorWorkerBuildEmptyPalletsStock(OneFloorWorkerBuildEmptyPalletsStockRequest reqDto)
  290. {
  291. var res = APICaller.CallApi2<SRes>(WmsUrl + "/api/FJ/OneFloorWorkerBuildEmptyPalletsStock", new OneFloorWorkerBuildEmptyPalletsStockRequest
  292. {
  293. PalletCode = reqDto.PalletCode,
  294. PalletType = reqDto.PalletType,
  295. StartLoc = reqDto.StartLoc,
  296. WareCode = reqDto.StartLoc.GetWareCode(),
  297. PalletNum = "1"
  298. });
  299. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  300. {
  301. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  302. }
  303. return res;
  304. }
  305. /// <summary>
  306. /// 工字轮/芯股进入主线扫码
  307. /// </summary>
  308. /// <param name="reqDto"></param>
  309. /// <param name="equNo"></param>
  310. /// <returns></returns>
  311. /// <exception cref="KnownException"></exception>
  312. public static SRes EnteMainLine(List<string> reqDto, string equNo)
  313. {
  314. var res = APICaller.CallApi<SRes>(WmsUrl + "/api/FJ/EnteMainLine", new FJEnteMainLineRequest
  315. {
  316. IShapedWheelCodes = reqDto,
  317. equNo = equNo
  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="palletCode"></param>
  329. /// <param name="loc"></param>
  330. /// <returns></returns>
  331. /// <exception cref="KnownException"></exception>
  332. public static SRes GroupTask(string palletCode, string loc)
  333. {
  334. var res = APICaller.CallApi<SRes>(WmsUrl + "/api/FJ/GroupTask", new FJBuildEmptyPalletsStockRequest
  335. {
  336. PalletCode = palletCode,
  337. PalletType = FJPalletType.Pallet09,
  338. PalletNum = "1",
  339. StartLoc = loc,
  340. WareCode = loc.GetWareCode(),
  341. BusType = TaskBusType.组盘_托盘
  342. });
  343. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  344. {
  345. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  346. }
  347. return res;
  348. }
  349. /// <summary>
  350. /// 正常结盘
  351. /// </summary>
  352. /// <param name="palletCode"></param>
  353. /// <param name="taskCodes"></param>
  354. /// <param name="warehouseCode"></param>
  355. /// <param name="loc"></param>
  356. /// <returns></returns>
  357. /// <exception cref="KnownException"></exception>
  358. public static SRes FinishBingPallet(string palletCode, List<string> taskCodes, string warehouseCode, string loc) => BingPallet(palletCode, taskCodes, warehouseCode, loc, false, "", true, false);
  359. /// <summary>
  360. /// 需要二次绑盘的结盘
  361. /// </summary>
  362. /// <param name="palletCode"></param>
  363. /// <param name="taskCodes"></param>
  364. /// <param name="warehouseCode"></param>
  365. /// <param name="loc"></param>
  366. /// <returns></returns>
  367. /// <exception cref="KnownException"></exception>
  368. public static SRes SecondaryBingPallet(string palletCode, List<string> taskCodes, string warehouseCode, string loc) => BingPallet(palletCode, taskCodes, warehouseCode, loc, false, "二次绑盘", true, true);
  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 ForceFinishBingPallet(string palletCode, List<string> taskCodes, string warehouseCode, string loc) => BingPallet(palletCode, taskCodes, warehouseCode, loc, true, "强制码垛结束", 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 BingPallet(string palletCode, List<string> taskCodes, string warehouseCode, string loc) => BingPallet(palletCode, taskCodes, warehouseCode, loc, false, "", false, false);
  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. /// <param name="isFail"></param>
  397. /// <param name="failReason"></param>
  398. /// <returns></returns>
  399. /// <exception cref="KnownException"></exception>
  400. public static SRes BingPallet(string palletCode, List<string> taskCodes, string warehouseCode, string loc, bool isFail, string failReason, bool isFinish, bool isItHalf)
  401. {
  402. var res = APICaller.CallApi2<SRes>(WmsUrl + "/api/FJ/BingPallet", new FJBingPalletRequest
  403. {
  404. PalletCode = palletCode,
  405. TaskCode = taskCodes,
  406. WarehouseCode = warehouseCode,
  407. loc = loc,
  408. IsFail = isFail,
  409. FailReason = failReason,
  410. IsFinish = isFinish,
  411. IsItHalf = isItHalf
  412. });
  413. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  414. {
  415. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  416. }
  417. return res;
  418. }
  419. /// <summary>
  420. /// 绑盘
  421. /// </summary>
  422. /// <param name="warehouseCode"></param>
  423. /// <returns></returns>
  424. /// <exception cref="KnownException"></exception>
  425. public static SRes<int> GetTwoPallet(string warehouseCode, int taskId)
  426. {
  427. var res = APICaller.CallApi<SRes<int>>(WmsUrl + "/api/FJ/GetTwoPallet", new FJGetTwoPalletDto
  428. {
  429. WarehouseCode = warehouseCode,
  430. TaskId = taskId
  431. });
  432. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  433. {
  434. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  435. }
  436. return res;
  437. }
  438. /// <summary>
  439. /// 环形库申请码垛任务
  440. /// </summary>
  441. /// <param name="loc"></param>
  442. /// <param name="robotCode"></param>
  443. /// <returns></returns>
  444. /// <exception cref="KnownException"></exception>
  445. public static SRes ApplyPalletizingStockOut(string loc, string robotCode)
  446. {
  447. var res = APICaller.CallApi2<SRes>(WmsUrl + "/api/FJ/ApplyPalletizingStockOut", new wms.dto.request.fj.RingApplyPalletizingStockOutRequest(loc.GetWareCode(), loc, robotCode));
  448. return res;
  449. }
  450. /// <summary>
  451. /// 码垛工资轮创建异常任务信息
  452. /// </summary>
  453. /// <param name="loc">位置</param>
  454. /// <param name="type">类型</param>
  455. /// <param name="errType">异常类型</param>
  456. /// <returns></returns>
  457. /// <exception cref="KnownException"></exception>
  458. public static SRes PalletizingCreateseErrorTasks(string loc, string type, int errType = 0)
  459. {
  460. var res = APICaller.CallApi2<SRes>(WmsUrl + "/api/FJ/PalletizingCreateseErrorTasks", new Models.WMS.Request.PalletizingCreateseErrorTasksRequest(loc, type, loc.GetWareCode(), errType));
  461. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  462. {
  463. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  464. }
  465. return res;
  466. }
  467. }
  468. public class FJGetTwoPalletDto : BaseRequest
  469. {
  470. /// <summary>
  471. /// 仓库号
  472. /// </summary>
  473. public string WarehouseCode { get; set; }
  474. /// <summary>
  475. /// 仓库号
  476. /// </summary>
  477. public int TaskId { get; set; }
  478. }
  479. /// <summary>
  480. /// 变更流向
  481. /// </summary>
  482. public class FjEditorialFlowRequest : BaseRequest
  483. {
  484. /// <summary>
  485. /// 任务号
  486. /// </summary>
  487. public int TaskId { get; set; }
  488. /// <summary>
  489. /// 目标仓库
  490. /// </summary>
  491. public string WareCode { get; set; }
  492. /// <summary>
  493. /// 位置
  494. /// </summary>
  495. public string LocCode { get; set; }
  496. }
  497. }