WmsApi.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  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. /// <param name="wcsTaskNum">WMS任务ID</param>
  83. /// <returns></returns>
  84. /// <exception cref="Exception"></exception>
  85. public static SRes<string> GetTunnelPriorityList(int wcsTaskNum)
  86. {
  87. var res = APICaller.CallApi2<SRes<string>>(WmsUrl + "/api/Hj/GetTunnelPriorityList", new GetTunnelPriorityListRequest
  88. {
  89. TaskNum = wcsTaskNum,
  90. });
  91. return res;
  92. }
  93. /// <summary>
  94. /// 分配货位
  95. /// </summary>
  96. /// <param name="wcsTaskNum">WMS任务ID</param>
  97. /// <param name="tunnel">货位</param>
  98. /// <param name="device">设备号</param>
  99. /// <param name="size"></param>
  100. /// <returns></returns>
  101. /// <exception cref="Exception"></exception>
  102. public static SRes<ApplyStockInLocResponse> GetLocalIn(int wcsTaskNum, string tunnel, string device, int size)
  103. {
  104. var res = APICaller.CallApi2<SRes<ApplyStockInLocResponse>>(WmsUrl + "/api/FJ/ApplyStockInLoc", new ApplyStockInLocRequest
  105. {
  106. TaskNum = wcsTaskNum,
  107. TunnelNum = tunnel.GetLastDigit(),
  108. PickUpEquipmentNo = device.ToString(),
  109. Height = size
  110. });
  111. return res;
  112. }
  113. /// <summary>
  114. /// 分配货位
  115. /// </summary>
  116. /// <param name="wcsTaskNum">WMS任务ID</param>
  117. /// <param name="tunnel">货位</param>
  118. /// <param name="device">设备号</param>
  119. /// <param name="size"></param>
  120. /// <returns></returns>
  121. /// <exception cref="Exception"></exception>
  122. public static SRes<FJApplyStockInLocResponse> RingApplyStockInLoc(int wcsTaskNum, string tunnel, string device, int size)
  123. {
  124. var res = APICaller.CallApi2<SRes<FJApplyStockInLocResponse>>(WmsUrl + "/api/FJ/RingApplyStockInLoc", new FJApplyStockInLocRequest
  125. {
  126. TaskNum = wcsTaskNum,
  127. PickUpEquipmentNo = device,
  128. Height = size
  129. });
  130. return res;
  131. }
  132. /// <summary>
  133. /// 堆垛机出库任务执行完成
  134. /// </summary>
  135. /// <param name="taskNum"></param>
  136. /// <returns></returns>
  137. /// <exception cref="KnownException"></exception>
  138. public static SRes<int> SrmPickOutCompleted(int taskNum)
  139. {
  140. var res = APICaller.CallApi2<SRes<int>>(WmsUrl + "/api/FJ/SrmPickOutCompleted", new SrmPickOutCompletedRequest
  141. {
  142. TaskNum = taskNum,
  143. });
  144. return res;
  145. }
  146. /// <summary>
  147. /// 申请出库任务
  148. /// </summary>
  149. /// <returns></returns>
  150. /// <exception cref="KnownException"></exception>
  151. public static SRes ApplyEmptyPalletGroupOutStorage(string addto, int tunnel, PalletType type)
  152. {
  153. var request = new ApplyStockOutTaskRequest
  154. {
  155. Tunnel = tunnel,
  156. FJPalletType = type,
  157. AddTo = addto
  158. };
  159. var res = APICaller.CallApi2<SRes>(WmsUrl + "/api/fj/ApplyEmptyPalletGroupOutStorage", request);
  160. return res;
  161. }
  162. /// <summary>
  163. /// 完成任务
  164. /// </summary>
  165. /// <param name="taskNo"></param>
  166. /// <returns></returns>
  167. /// <exception cref="KnownException"></exception>
  168. public static SRes<int> CompleteTask(int taskNo)
  169. {
  170. var res = APICaller.CallApi2<SRes<int>>(WmsUrl + "/api/fj/CompleteTask", new CompleteTaskRequest
  171. {
  172. TaskNum = taskNo,
  173. OperationType = Models.WMS.Request.CompleteTask.自动完成,
  174. WCSUpdateName = "WCS"
  175. });
  176. return res;
  177. }
  178. /// <summary>
  179. /// 处理任务验证接口
  180. /// </summary>
  181. /// <param name="taskNo">需要处理的任务进行验证</param>
  182. /// <param name="state">目标状态</param>
  183. /// <returns></returns>
  184. /// <exception cref="KnownException"></exception>
  185. public static SRes HandleTaskVerify(List<int> taskNo, int state)
  186. {
  187. var res = APICaller.CallApi2<SRes>(WmsUrl + "/api/Hj/CancelTaskVerify", new CancelTaskVerifyRequest
  188. {
  189. TaskNo = taskNo,
  190. State = state
  191. });
  192. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  193. {
  194. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  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 CarryTaskInfo(List<int> taskNo, int state)
  206. {
  207. var res = APICaller.CallApi2<SRes>(WmsUrl + "/api/Hj/CarryTaskInfo", 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. /// WMS完成或取消任务验证
  220. /// </summary>
  221. /// <param name="sRes"></param>
  222. /// <param name="id"></param>
  223. /// <param name="type">99完成,106取消</param>
  224. /// <returns></returns>
  225. public static SRes? HandleTaskVerify(SRes<HandleTaskResponse> sRes, int id, int type)
  226. {
  227. try
  228. {
  229. var res = WmsApi.HandleTaskVerify(new List<int>() { id }, type);
  230. return res;
  231. }
  232. catch (Exception ex)
  233. {
  234. sRes.ResDataList.Add(new HandleTaskResponse()
  235. {
  236. IsSuccess = false,
  237. TaskNo = id,
  238. Message = $"WMS错误:{ex.Message}",
  239. });
  240. return null;
  241. }
  242. }
  243. /// <summary>
  244. /// WMS完成或取消任务执行
  245. /// </summary>
  246. /// <param name="sRes"></param>
  247. /// <param name="id"></param>
  248. /// <param name="type">99完成,106取消</param>
  249. /// <returns></returns>
  250. public static SRes? CarryTaskInfo(SRes<HandleTaskResponse> sRes, int id, int type)
  251. {
  252. try
  253. {
  254. var res = WmsApi.CarryTaskInfo(new List<int>() { id }, type);
  255. return res;
  256. }
  257. catch (Exception ex)
  258. {
  259. sRes.ResDataList.Add(new HandleTaskResponse()
  260. {
  261. IsSuccess = false,
  262. TaskNo = id,
  263. Message = $"WMS错误:{ex.Message}",
  264. });
  265. return null;
  266. }
  267. }
  268. /// <summary>
  269. /// 一楼扫码入库
  270. /// </summary>
  271. /// <param name="codeList">工字轮条码组</param>
  272. /// <returns></returns>
  273. /// <exception cref="KnownException"></exception>
  274. public static SRes? OneFloorWorkerBuildEmptyPalletsStock(OneFloorWorkerBuildEmptyPalletsStockRequest reqDto)
  275. {
  276. var res = APICaller.CallApi2<SRes>(WmsUrl + "/api/FJ/OneFloorWorkerBuildEmptyPalletsStock", new OneFloorWorkerBuildEmptyPalletsStockRequest
  277. {
  278. PalletCode = reqDto.PalletCode,
  279. PalletType = reqDto.PalletType,
  280. StartLoc = reqDto.StartLoc,
  281. WareCode = reqDto.StartLoc.GetWareCode(),
  282. PalletNum = "1"
  283. });
  284. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  285. {
  286. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  287. }
  288. return res;
  289. }
  290. /// <summary>
  291. /// 工字轮/芯股进入主线扫码
  292. /// </summary>
  293. /// <param name="reqDto"></param>
  294. /// <param name="equNo"></param>
  295. /// <returns></returns>
  296. /// <exception cref="KnownException"></exception>
  297. public static SRes EnteMainLine(List<string> reqDto, string equNo)
  298. {
  299. var res = APICaller.CallApi<SRes>(WmsUrl + "/api/FJ/EnteMainLine", new FJEnteMainLineRequest
  300. {
  301. IShapedWheelCodes = reqDto,
  302. equNo = equNo
  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="palletCode"></param>
  314. /// <param name="loc"></param>
  315. /// <returns></returns>
  316. /// <exception cref="KnownException"></exception>
  317. public static SRes GroupTask(string palletCode, string loc)
  318. {
  319. var res = APICaller.CallApi<SRes>(WmsUrl + "/api/FJ/GroupTask", new FJBuildEmptyPalletsStockRequest
  320. {
  321. PalletCode = palletCode,
  322. PalletType = FJPalletType.Pallet09,
  323. PalletNum = "1",
  324. StartLoc = loc,
  325. WareCode = loc.GetWareCode(),
  326. BusType = TaskBusType.组盘_托盘
  327. });
  328. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  329. {
  330. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  331. }
  332. return res;
  333. }
  334. /// <summary>
  335. /// 正常结盘
  336. /// </summary>
  337. /// <param name="palletCode"></param>
  338. /// <param name="taskCodes"></param>
  339. /// <param name="warehouseCode"></param>
  340. /// <param name="loc"></param>
  341. /// <returns></returns>
  342. /// <exception cref="KnownException"></exception>
  343. public static SRes FinishBingPallet(string palletCode, List<string> taskCodes, string warehouseCode, string loc) => BingPallet(palletCode, taskCodes, warehouseCode, loc, false, "", true, false);
  344. /// <summary>
  345. /// 需要二次绑盘的结盘
  346. /// </summary>
  347. /// <param name="palletCode"></param>
  348. /// <param name="taskCodes"></param>
  349. /// <param name="warehouseCode"></param>
  350. /// <param name="loc"></param>
  351. /// <returns></returns>
  352. /// <exception cref="KnownException"></exception>
  353. public static SRes SecondaryBingPallet(string palletCode, List<string> taskCodes, string warehouseCode, string loc) => BingPallet(palletCode, taskCodes, warehouseCode, loc, false, "二次绑盘", true, true);
  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 ForceFinishBingPallet(string palletCode, List<string> taskCodes, string warehouseCode, string loc) => BingPallet(palletCode, taskCodes, warehouseCode, loc, true, "强制码垛结束", 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 BingPallet(string palletCode, List<string> taskCodes, string warehouseCode, string loc) => BingPallet(palletCode, taskCodes, warehouseCode, loc, false, "", false, false);
  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. /// <param name="isFail"></param>
  382. /// <param name="failReason"></param>
  383. /// <returns></returns>
  384. /// <exception cref="KnownException"></exception>
  385. public static SRes BingPallet(string palletCode, List<string> taskCodes, string warehouseCode, string loc, bool isFail, string failReason, bool isFinish, bool isItHalf)
  386. {
  387. var res = APICaller.CallApi2<SRes>(WmsUrl + "/api/FJ/BingPallet", new FJBingPalletRequest
  388. {
  389. PalletCode = palletCode,
  390. TaskCode = taskCodes,
  391. WarehouseCode = warehouseCode,
  392. loc = loc,
  393. IsFail = isFail,
  394. FailReason = failReason,
  395. IsFinish = isFinish,
  396. IsItHalf = isItHalf
  397. });
  398. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  399. {
  400. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  401. }
  402. return res;
  403. }
  404. /// <summary>
  405. /// 绑盘
  406. /// </summary>
  407. /// <param name="warehouseCode"></param>
  408. /// <returns></returns>
  409. /// <exception cref="KnownException"></exception>
  410. public static SRes<int> GetTwoPallet(string warehouseCode, int taskId)
  411. {
  412. var res = APICaller.CallApi<SRes<int>>(WmsUrl + "/api/FJ/GetTwoPallet", new FJGetTwoPalletDto
  413. {
  414. WarehouseCode = warehouseCode,
  415. TaskId = taskId
  416. });
  417. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  418. {
  419. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  420. }
  421. return res;
  422. }
  423. /// <summary>
  424. /// 环形库申请码垛任务
  425. /// </summary>
  426. /// <param name="loc"></param>
  427. /// <param name="robotCode"></param>
  428. /// <returns></returns>
  429. /// <exception cref="KnownException"></exception>
  430. public static SRes ApplyPalletizingStockOut(string loc, string robotCode)
  431. {
  432. var res = APICaller.CallApi2<SRes>(WmsUrl + "/api/FJ/ApplyPalletizingStockOut", new wms.dto.request.fj.RingApplyPalletizingStockOutRequest(loc.GetWareCode(), loc, robotCode));
  433. return res;
  434. }
  435. /// <summary>
  436. /// 码垛工资轮创建异常任务信息
  437. /// </summary>
  438. /// <param name="loc">位置</param>
  439. /// <param name="type">类型</param>
  440. /// <param name="errType">异常类型</param>
  441. /// <returns></returns>
  442. /// <exception cref="KnownException"></exception>
  443. public static SRes PalletizingCreateseErrorTasks(string loc, string type, int errType = 0)
  444. {
  445. var res = APICaller.CallApi2<SRes>(WmsUrl + "/api/FJ/PalletizingCreateseErrorTasks", new Models.WMS.Request.PalletizingCreateseErrorTasksRequest(loc, type, loc.GetWareCode(),errType));
  446. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  447. {
  448. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  449. }
  450. return res;
  451. }
  452. }
  453. public class FJGetTwoPalletDto : BaseRequest
  454. {
  455. /// <summary>
  456. /// 仓库号
  457. /// </summary>
  458. public string WarehouseCode { get; set; }
  459. /// <summary>
  460. /// 仓库号
  461. /// </summary>
  462. public int TaskId { get; set; }
  463. }
  464. }