WmsApi.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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. /// <returns></returns>
  47. /// <exception cref="Exception"></exception>
  48. public static SRes EditorialFlow(FjEditorialFlowRequest req)
  49. {
  50. var res = APICaller.CallApi2<SRes>(WmsUrl + "/api/FJ/EditorialFlow", new FjEditorialFlowRequest
  51. {
  52. LocCode = req.LocCode,
  53. TaskId = req.TaskId,
  54. WareCode = req.WareCode
  55. });
  56. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  57. {
  58. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  59. }
  60. return res;
  61. }
  62. /// <summary>
  63. /// 分配货位
  64. /// </summary>
  65. /// <param name="wcsTaskNum">WMS任务ID</param>
  66. /// <param name="tunnel">货位</param>
  67. /// <param name="device">设备号</param>
  68. /// <param name="size"></param>
  69. /// <returns></returns>
  70. /// <exception cref="Exception"></exception>
  71. public static SRes<ApplyStockInLocResponse> GetLocalIn(int wcsTaskNum, string tunnel, string device, int size)
  72. {
  73. var res = APICaller.CallApi2<SRes<ApplyStockInLocResponse>>(WmsUrl + "/api/FJ/ApplyStockInLoc", new ApplyStockInLocRequest
  74. {
  75. TaskNum = wcsTaskNum,
  76. TunnelNum = tunnel.GetLastDigit(),
  77. PickUpEquipmentNo = device.ToString(),
  78. Height = size
  79. });
  80. return res;
  81. }
  82. /// <summary>
  83. /// 环型库分配货位
  84. /// </summary>
  85. /// <param name="wcsTaskNum">WMS任务ID</param>
  86. /// <param name="tunnel">货位</param>
  87. /// <param name="device">设备号</param>
  88. /// <param name="size"></param>
  89. /// <returns></returns>
  90. /// <exception cref="Exception"></exception>
  91. public static SRes<FJApplyStockInLocResponse> RingApplyStockInLoc(int wcsTaskNum, string tunnel, string device, int size)
  92. {
  93. var res = APICaller.CallApi2<SRes<FJApplyStockInLocResponse>>(WmsUrl + "/api/FJ/RingApplyStockInLoc", new FJApplyStockInLocRequest
  94. {
  95. TaskNum = wcsTaskNum,
  96. PickUpEquipmentNo = device,
  97. Height = size
  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<FJApplyStockInLocResponse> FindAvailableFlatStorageSlot(int wcsTaskNum, string tunnel, string device, int size)
  111. {
  112. var res = APICaller.CallApi2<SRes<FJApplyStockInLocResponse>>(WmsUrl + "/api/FJ/RingApplyStockInLoc", new FJApplyStockInLocRequest
  113. {
  114. TaskNum = wcsTaskNum,
  115. PickUpEquipmentNo = device,
  116. Height = size
  117. });
  118. return res;
  119. }
  120. /// <summary>
  121. /// 堆垛机出库任务执行完成
  122. /// </summary>
  123. /// <param name="taskNum"></param>
  124. /// <returns></returns>
  125. /// <exception cref="KnownException"></exception>
  126. public static SRes<int> SrmPickOutCompleted(int taskNum)
  127. {
  128. var res = APICaller.CallApi2<SRes<int>>(WmsUrl + "/api/FJ/SrmPickOutCompleted", new SrmPickOutCompletedRequest
  129. {
  130. TaskNum = taskNum,
  131. });
  132. return res;
  133. }
  134. /// <summary>
  135. /// 申请出库任务
  136. /// </summary>
  137. /// <returns></returns>
  138. /// <exception cref="KnownException"></exception>
  139. public static SRes ApplyEmptyPalletGroupOutStorage(string addto, int tunnel, PalletType type)
  140. {
  141. var request = new ApplyStockOutTaskRequest
  142. {
  143. Tunnel = tunnel,
  144. FJPalletType = type,
  145. AddTo = addto
  146. };
  147. var res = APICaller.CallApi2<SRes>(WmsUrl + "/api/fj/ApplyEmptyPalletGroupOutStorage", request);
  148. return res;
  149. }
  150. /// <summary>
  151. /// 完成任务
  152. /// </summary>
  153. /// <param name="taskNo"></param>
  154. /// <returns></returns>
  155. /// <exception cref="KnownException"></exception>
  156. public static SRes<int> CompleteTask(int taskNo)
  157. {
  158. var res = APICaller.CallApi2<SRes<int>>(WmsUrl + "/api/fj/CompleteTask", new CompleteTaskRequest
  159. {
  160. TaskNum = taskNo,
  161. OperationType = Models.WMS.Request.CompleteTask.自动完成,
  162. WCSUpdateName = "WCS"
  163. });
  164. return res;
  165. }
  166. public static SRes<int> CancelTask(int taskNo)
  167. {
  168. var res = APICaller.CallApi2<SRes<int>>(WmsUrl + "/api/fj/CancelTask", new CompleteTaskRequest
  169. {
  170. TaskNum = taskNo,
  171. OperationType = Models.WMS.Request.CompleteTask.自动完成,
  172. WCSUpdateName = "WCS"
  173. });
  174. return res;
  175. }
  176. /// <summary>
  177. /// 处理任务验证接口
  178. /// </summary>
  179. /// <param name="taskNo">需要处理的任务进行验证</param>
  180. /// <param name="state">目标状态</param>
  181. /// <returns></returns>
  182. /// <exception cref="KnownException"></exception>
  183. public static SRes HandleTaskVerify(List<int> taskNo, int state)
  184. {
  185. var res = APICaller.CallApi2<SRes>(WmsUrl + "/api/fj/CancelTaskVerify", new CancelTaskVerifyRequest
  186. {
  187. TaskNo = taskNo,
  188. State = state
  189. });
  190. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  191. {
  192. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  193. }
  194. return res;
  195. }
  196. /// <summary>
  197. /// 处理任务接口
  198. /// </summary>
  199. /// <param name="taskNo">处理</param>
  200. /// <param name="state">目标状态</param>
  201. /// <returns></returns>
  202. /// <exception cref="KnownException"></exception>
  203. public static SRes CarryTaskInfo(List<int> taskNo, int state)
  204. {
  205. var res = APICaller.CallApi2<SRes>(WmsUrl + "/api/fj/CarryTaskInfo", new CancelTaskVerifyRequest
  206. {
  207. TaskNo = taskNo,
  208. State = state
  209. });
  210. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  211. {
  212. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  213. }
  214. return res;
  215. }
  216. /// <summary>
  217. /// WMS完成或取消任务验证
  218. /// </summary>
  219. /// <param name="sRes"></param>
  220. /// <param name="id"></param>
  221. /// <param name="type">99完成,106取消</param>
  222. /// <returns></returns>
  223. public static SRes? HandleTaskVerify(SRes<HandleTaskResponse> sRes, int id, int type)
  224. {
  225. try
  226. {
  227. var res = WmsApi.HandleTaskVerify(new List<int>() { id }, type);
  228. return res;
  229. }
  230. catch (Exception ex)
  231. {
  232. sRes.ResDataList.Add(new HandleTaskResponse()
  233. {
  234. IsSuccess = false,
  235. TaskNo = id,
  236. Message = $"WMS错误:{ex.Message}",
  237. });
  238. return null;
  239. }
  240. }
  241. /// <summary>
  242. /// 一楼扫码入库
  243. /// </summary>
  244. /// <param name="codeList">工字轮条码组</param>
  245. /// <returns></returns>
  246. /// <exception cref="KnownException"></exception>
  247. public static SRes? OneFloorWorkerBuildEmptyPalletsStock(OneFloorWorkerBuildEmptyPalletsStockRequest reqDto)
  248. {
  249. var res = APICaller.CallApi2<SRes>(WmsUrl + "/api/FJ/OneFloorWorkerBuildEmptyPalletsStock", new OneFloorWorkerBuildEmptyPalletsStockRequest
  250. {
  251. PalletCode = reqDto.PalletCode,
  252. PalletType = reqDto.PalletType,
  253. StartLoc = reqDto.StartLoc,
  254. WareCode = reqDto.StartLoc.GetWareCode(),
  255. PalletNum = "1"
  256. });
  257. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  258. {
  259. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  260. }
  261. return res;
  262. }
  263. /// <summary>
  264. /// 正常结盘
  265. /// </summary>
  266. /// <param name="palletCode"></param>
  267. /// <param name="taskCodes"></param>
  268. /// <param name="warehouseCode"></param>
  269. /// <param name="loc"></param>
  270. /// <returns></returns>
  271. /// <exception cref="KnownException"></exception>
  272. public static SRes FinishBingPallet(string palletCode, List<string> taskCodes, string warehouseCode, string loc) => BingPallet(palletCode, taskCodes, warehouseCode, loc, false, "", true, false);
  273. /// <summary>
  274. /// 需要二次绑盘的结盘
  275. /// </summary>
  276. /// <param name="palletCode"></param>
  277. /// <param name="taskCodes"></param>
  278. /// <param name="warehouseCode"></param>
  279. /// <param name="loc"></param>
  280. /// <returns></returns>
  281. /// <exception cref="KnownException"></exception>
  282. public static SRes SecondaryBingPallet(string palletCode, List<string> taskCodes, string warehouseCode, string loc) => BingPallet(palletCode, taskCodes, warehouseCode, loc, false, "二次绑盘", true, true);
  283. /// <summary>
  284. /// 异常结盘
  285. /// </summary>
  286. /// <param name="palletCode"></param>
  287. /// <param name="taskCodes"></param>
  288. /// <param name="warehouseCode"></param>
  289. /// <param name="loc"></param>
  290. /// <returns></returns>
  291. /// <exception cref="KnownException"></exception>
  292. public static SRes ForceFinishBingPallet(string palletCode, List<string> taskCodes, string warehouseCode, string loc) => BingPallet(palletCode, taskCodes, warehouseCode, loc, true, "强制码垛结束", true, false);
  293. /// <summary>
  294. /// 绑盘
  295. /// </summary>
  296. /// <param name="palletCode"></param>
  297. /// <param name="taskCodes"></param>
  298. /// <param name="warehouseCode"></param>
  299. /// <param name="loc"></param>
  300. /// <returns></returns>
  301. /// <exception cref="KnownException"></exception>
  302. public static SRes BingPallet(string palletCode, List<string> taskCodes, string warehouseCode, string loc) => BingPallet(palletCode, taskCodes, warehouseCode, loc, false, "", false, false);
  303. /// <summary>
  304. /// 绑盘
  305. /// </summary>
  306. /// <param name="palletCode"></param>
  307. /// <param name="taskCodes"></param>
  308. /// <param name="warehouseCode"></param>
  309. /// <param name="loc"></param>
  310. /// <param name="isFail"></param>
  311. /// <param name="failReason"></param>
  312. /// <returns></returns>
  313. /// <exception cref="KnownException"></exception>
  314. public static SRes BingPallet(string palletCode, List<string> taskCodes, string warehouseCode, string loc, bool isFail, string failReason, bool isFinish, bool isItHalf)
  315. {
  316. var res = APICaller.CallApi2<SRes>(WmsUrl + "/api/FJ/BingPallet", new FJBingPalletRequest
  317. {
  318. PalletCode = palletCode,
  319. TaskCode = taskCodes,
  320. WarehouseCode = warehouseCode,
  321. loc = loc,
  322. IsFail = isFail,
  323. FailReason = failReason,
  324. IsFinish = isFinish,
  325. IsItHalf = isItHalf
  326. });
  327. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  328. {
  329. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  330. }
  331. return res;
  332. }
  333. /// <summary>
  334. /// 绑盘
  335. /// </summary>
  336. /// <param name="warehouseCode"></param>
  337. /// <returns></returns>
  338. /// <exception cref="KnownException"></exception>
  339. public static SRes<int> GetTwoPallet(string warehouseCode, int taskId)
  340. {
  341. var res = APICaller.CallApi<SRes<int>>(WmsUrl + "/api/FJ/GetTwoPallet", new FJGetTwoPalletDto
  342. {
  343. WarehouseCode = warehouseCode,
  344. TaskId = taskId
  345. });
  346. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  347. {
  348. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  349. }
  350. return res;
  351. }
  352. /// <summary>
  353. /// 环形库申请码垛任务
  354. /// </summary>
  355. /// <param name="loc"></param>
  356. /// <param name="robotCode"></param>
  357. /// <returns></returns>
  358. /// <exception cref="KnownException"></exception>
  359. public static SRes ApplyPalletizingStockOut(string loc, string robotCode)
  360. {
  361. var res = APICaller.CallApi2<SRes>(WmsUrl + "/api/FJ/ApplyPalletizingStockOut", new wms.dto.request.fj.RingApplyPalletizingStockOutRequest(loc.GetWareCode(), loc, robotCode));
  362. return res;
  363. }
  364. /// <summary>
  365. /// 码垛工资轮创建异常任务信息
  366. /// </summary>
  367. /// <param name="loc">位置</param>
  368. /// <param name="type">类型</param>
  369. /// <param name="errType">异常类型</param>
  370. /// <returns></returns>
  371. /// <exception cref="KnownException"></exception>
  372. public static SRes PalletizingCreateseErrorTasks(string loc, string type, int errType = 0)
  373. {
  374. var res = APICaller.CallApi2<SRes>(WmsUrl + "/api/FJ/PalletizingCreateseErrorTasks", new Models.WMS.Request.PalletizingCreateseErrorTasksRequest(loc, type, loc.GetWareCode(), errType));
  375. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  376. {
  377. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  378. }
  379. return res;
  380. }
  381. }
  382. public class FJGetTwoPalletDto : BaseRequest
  383. {
  384. /// <summary>
  385. /// 仓库号
  386. /// </summary>
  387. public string WarehouseCode { get; set; }
  388. /// <summary>
  389. /// 仓库号
  390. /// </summary>
  391. public int TaskId { get; set; }
  392. }
  393. /// <summary>
  394. /// 变更流向
  395. /// </summary>
  396. public class FjEditorialFlowRequest : BaseRequest
  397. {
  398. /// <summary>
  399. /// 任务号
  400. /// </summary>
  401. public int TaskId { get; set; }
  402. /// <summary>
  403. /// 目标仓库
  404. /// </summary>
  405. public string WareCode { get; set; }
  406. /// <summary>
  407. /// 位置
  408. /// </summary>
  409. public string LocCode { get; set; }
  410. }
  411. }