WmsApi.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. using ServiceCenter;
  2. using ServiceCenter.Extensions;
  3. using ServiceCenter.Logs;
  4. using ServiceCenter.Redis;
  5. using ServiceCenter.WebApi;
  6. using WCS.WorkEngineering.WebApi.Models.AGV.Response;
  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. namespace WCS.WorkEngineering.WebApi.Controllers
  11. {
  12. /// <summary>
  13. /// AGV相关接口控制器
  14. /// </summary>
  15. public static class WmsApi
  16. {
  17. private static string _WMSUrl = null!;
  18. private static string _wareHouseId = null!;
  19. /// <summary>
  20. /// WMS URL
  21. /// </summary>
  22. public static string WMSUrl
  23. {
  24. get
  25. {
  26. _WMSUrl ??= RedisHub.Default.Check("WMSUrl");
  27. if (string.IsNullOrEmpty(_WMSUrl))
  28. {
  29. throw new KnownException($"请在Redis配置WMSUrl", LogLevelEnum.High);
  30. }
  31. return _WMSUrl;
  32. }
  33. }
  34. /// <summary>
  35. /// 仓库编号
  36. /// </summary>
  37. public static string wareHouseId = ServiceHub.WarehouseName;
  38. /// <summary>
  39. /// 上传重量等信息
  40. /// </summary>
  41. /// <param name="taskCode">任务号</param>
  42. /// <param name="weight">rfid</param>
  43. /// <returns></returns>
  44. public static SRes WcsUploadInfo(int taskCode, decimal weight) => WcsUploadInfo(taskCode, weight, "");
  45. /// <summary>
  46. /// 上传重量等信息
  47. /// </summary>
  48. /// <param name="taskCode">任务号</param>
  49. /// <param name="RFID">重量</param>
  50. /// <returns></returns>
  51. public static SRes WcsUploadInfo(int taskCode, string RFID) => WcsUploadInfo(taskCode, 0, RFID);
  52. /// <summary>
  53. /// 上传重量等信息
  54. /// </summary>
  55. /// <param name="taskCode">任务号</param>
  56. /// <param name="weight">重量</param>
  57. /// <param name="RFID">rfid</param>
  58. /// <returns></returns>
  59. /// <exception cref="KnownException"></exception>
  60. public static SRes WcsUploadInfo(int taskCode, decimal weight, string RFID)
  61. {
  62. var res = APICaller.CallApi2<SRes>(WMSUrl + "/api/Hj/WcsUploadInfo", new WcsUploadInfoRequest
  63. {
  64. TaskCode = taskCode,
  65. Weight = weight,
  66. RFID = RFID
  67. });
  68. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  69. {
  70. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  71. }
  72. return res;
  73. }
  74. /// <summary>
  75. /// 获取巷道
  76. /// </summary>
  77. /// <param name="wcsTaskNum">WMS任务ID</param>
  78. /// <returns></returns>
  79. /// <exception cref="Exception"></exception>
  80. public static SRes<string> GetTunnelPriorityList(int wcsTaskNum)
  81. {
  82. var res = APICaller.CallApi2<SRes<string>>(WMSUrl + "/api/Hj/GetTunnelPriorityList", new GetTunnelPriorityListRequest
  83. {
  84. TaskNum = wcsTaskNum,
  85. });
  86. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  87. {
  88. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  89. }
  90. return res;
  91. }
  92. /// <summary>
  93. /// 分配货位
  94. /// </summary>
  95. /// <param name="wcsTaskNum">WMS任务ID</param>
  96. /// <param name="tunnel">货位</param>
  97. /// <param name="device">设备号</param>
  98. /// <param name="size"></param>
  99. /// <returns></returns>
  100. /// <exception cref="Exception"></exception>
  101. public static SRes<ApplyStockInLocResponse> GetLocalIn(int wcsTaskNum, string tunnel, string device, int size)
  102. {
  103. var res = APICaller.CallApi2<SRes<ApplyStockInLocResponse>>(WMSUrl + "/api/FJ/ApplyStockInLoc", new ApplyStockInLocRequest
  104. {
  105. TaskNum = wcsTaskNum,
  106. TunnelNum = tunnel.GetLastDigit(),
  107. PickUpEquipmentNo = device.ToString(),
  108. Height = size
  109. });
  110. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  111. {
  112. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  113. }
  114. return res;
  115. }
  116. /// <summary>
  117. /// 堆垛机出库任务执行完成
  118. /// </summary>
  119. /// <param name="taskNum"></param>
  120. /// <returns></returns>
  121. /// <exception cref="KnownException"></exception>
  122. public static SRes<int> SrmPickOutCompleted(int taskNum)
  123. {
  124. var res = APICaller.CallApi2<SRes<int>>(WMSUrl + "/api/Hj/SrmPickOutCompleted", new SrmPickOutCompletedRequest
  125. {
  126. TaskNum = taskNum,
  127. });
  128. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  129. {
  130. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  131. }
  132. return res;
  133. }
  134. /// <summary>
  135. /// 一楼空工字轮申请出库
  136. /// </summary>
  137. /// <param name="outEndPostion">出库位置</param>
  138. /// <returns></returns>
  139. public static SRes ApplyStockOutTask(string outEndPostion) => ApplyStockOutTask(outEndPostion, 2);
  140. /// <summary>
  141. /// 申请出库任务
  142. /// </summary>
  143. /// <param name="outEndPostion">出库位置</param>
  144. /// <param name="outType">出库类型</param>
  145. /// <returns></returns>
  146. /// <exception cref="KnownException"></exception>
  147. public static SRes ApplyStockOutTask(string outEndPostion, int outType)
  148. {
  149. var request = new ApplyStockOutTaskRequest
  150. {
  151. OutEndPostion = outEndPostion,
  152. OutType = outType,
  153. WarehouseCode = wareHouseId,
  154. };
  155. switch (outEndPostion)
  156. {
  157. case "1012":
  158. request.Tunnel = "1";
  159. break;
  160. case "1014":
  161. request.Tunnel = "2";
  162. break;
  163. case "1016":
  164. request.Tunnel = "3";
  165. break;
  166. }
  167. var res = APICaller.CallApi2<SRes>(WMSUrl + "/api/Hj/ApplyStockOutTask", request);
  168. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  169. {
  170. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  171. }
  172. return res;
  173. }
  174. /// <summary>
  175. /// 获取各巷道剩余空轮数量
  176. /// </summary>
  177. /// <returns></returns>
  178. /// <exception cref="KnownException"></exception>
  179. public static SRes<GetTunnelEmptyConResponse> GetTunnelEmptyConCount()
  180. {
  181. var res = APICaller.CallApi2<SRes<GetTunnelEmptyConResponse>>(WMSUrl + "/api/Hj/GetTunnelEmptyConCount", new GetTunnelEmptyConCountRequest { });
  182. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  183. {
  184. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  185. }
  186. return res;
  187. }
  188. /// <summary>
  189. /// 完成任务
  190. /// </summary>
  191. /// <param name="taskNo"></param>
  192. /// <returns></returns>
  193. /// <exception cref="KnownException"></exception>
  194. public static SRes<int> CompleteTask(int taskNo)
  195. {
  196. var res = APICaller.CallApi2<SRes<int>>(WMSUrl + "/api/fj/CompleteTask", new CompleteTaskRequest
  197. {
  198. TaskNum = taskNo,
  199. OperationType = Models.WMS.Request.CompleteTask.自动完成,
  200. WCSUpdateName = "WCS"
  201. });
  202. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  203. {
  204. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  205. }
  206. return res;
  207. }
  208. /// <summary>
  209. /// 二深位获取移库任务
  210. /// </summary>
  211. /// <param name="taskNo">任务</param>
  212. /// <returns></returns>
  213. /// <exception cref="KnownException"></exception>
  214. public static SRes<AddWcsMoveTaskResponse> AddWcsMoveTask(int taskNo)
  215. {
  216. var res = APICaller.CallApi2<SRes<AddWcsMoveTaskResponse>>(WMSUrl + "/api/Hj/AddWcsMoveTask", new CompleteTaskRequest
  217. {
  218. TaskNum = taskNo,
  219. });
  220. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  221. {
  222. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  223. }
  224. return res;
  225. }
  226. /// <summary>
  227. /// 向WMS获取入库任务 一次单卷
  228. /// </summary>
  229. /// <param name="barcode">产品条码</param>
  230. /// <param name="devCode">设备条码</param>
  231. /// <param name="getTunnel"></param>
  232. /// <returns></returns>
  233. /// <exception cref="Exception"></exception>
  234. public static I_WCS_GetInTaskResponse I_WCS_GetInTask(string barcode, string devCode, bool getTunnel = false)
  235. {
  236. var res = APICaller.CallApi<I_WCS_GetInTaskResponse>(WMSUrl + "/api/Task/I_WCS_GetInTask", new List<I_WCS_GetInTaskRequest>()
  237. {
  238. new I_WCS_GetInTaskRequest(){
  239. ContainerBarCode = barcode,
  240. WareHouseId = wareHouseId,
  241. EquipmentNo = devCode,
  242. Memo1 = getTunnel ? "1" : "" //1:分巷道 2:分货位
  243. }
  244. });
  245. if (!res.ResType) throw new KnownException(res.ResMessage, LogLevelEnum.High);
  246. return res;
  247. }
  248. /// <summary>
  249. /// 处理任务验证接口
  250. /// </summary>
  251. /// <param name="taskNo">需要处理的任务进行验证</param>
  252. /// <param name="state">目标状态</param>
  253. /// <returns></returns>
  254. /// <exception cref="KnownException"></exception>
  255. public static SRes HandleTaskVerify(List<int> taskNo, int state)
  256. {
  257. var res = APICaller.CallApi2<SRes>(WMSUrl + "/api/Hj/CancelTaskVerify", new CancelTaskVerifyRequest
  258. {
  259. TaskNo = taskNo,
  260. State = state
  261. });
  262. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  263. {
  264. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  265. }
  266. return res;
  267. }
  268. /// <summary>
  269. /// 处理任务接口
  270. /// </summary>
  271. /// <param name="taskNo">处理</param>
  272. /// <param name="state">目标状态</param>
  273. /// <returns></returns>
  274. /// <exception cref="KnownException"></exception>
  275. public static SRes CarryTaskInfo(List<int> taskNo, int state)
  276. {
  277. var res = APICaller.CallApi2<SRes>(WMSUrl + "/api/Hj/CarryTaskInfo", new CancelTaskVerifyRequest
  278. {
  279. TaskNo = taskNo,
  280. State = state
  281. });
  282. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  283. {
  284. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  285. }
  286. return res;
  287. }
  288. /// <summary>
  289. /// WMS完成或取消任务验证
  290. /// </summary>
  291. /// <param name="sRes"></param>
  292. /// <param name="id"></param>
  293. /// <param name="type">99完成,106取消</param>
  294. /// <returns></returns>
  295. public static SRes? HandleTaskVerify(SRes<HandleTaskResponse> sRes, int id, int type)
  296. {
  297. try
  298. {
  299. var res = WmsApi.HandleTaskVerify(new List<int>() { id }, type);
  300. return res;
  301. }
  302. catch (Exception ex)
  303. {
  304. sRes.ResDataList.Add(new HandleTaskResponse()
  305. {
  306. IsSuccess = false,
  307. TaskNo = id,
  308. Message = $"WMS错误:{ex.Message}",
  309. });
  310. return null;
  311. }
  312. }
  313. /// <summary>
  314. /// WMS完成或取消任务执行
  315. /// </summary>
  316. /// <param name="sRes"></param>
  317. /// <param name="id"></param>
  318. /// <param name="type">99完成,106取消</param>
  319. /// <returns></returns>
  320. public static SRes? CarryTaskInfo(SRes<HandleTaskResponse> sRes, int id, int type)
  321. {
  322. try
  323. {
  324. var res = WmsApi.CarryTaskInfo(new List<int>() { id }, type);
  325. return res;
  326. }
  327. catch (Exception ex)
  328. {
  329. sRes.ResDataList.Add(new HandleTaskResponse()
  330. {
  331. IsSuccess = false,
  332. TaskNo = id,
  333. Message = $"WMS错误:{ex.Message}",
  334. });
  335. return null;
  336. }
  337. }
  338. /// <summary>
  339. /// 工字轮/芯股进入主线扫码
  340. /// </summary>
  341. /// <param name="codeList">工字轮条码组</param>
  342. /// <returns></returns>
  343. /// <exception cref="KnownException"></exception>
  344. public static SRes? OneFloorWorkerBuildEmptyPalletsStock(OneFloorWorkerBuildEmptyPalletsStockRequest reqDto)
  345. {
  346. var res = APICaller.CallApi2<SRes>(WMSUrl + "/api/FJ/OneFloorWorkerBuildEmptyPalletsStock", new OneFloorWorkerBuildEmptyPalletsStockRequest
  347. {
  348. PalletCode = reqDto.PalletCode,
  349. PalletType = reqDto.PalletType,
  350. StartLoc = reqDto.StartLoc,
  351. WareCode = GetWareCode(reqDto.StartLoc),
  352. PalletNum = "1"
  353. });
  354. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  355. {
  356. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  357. }
  358. return res;
  359. }
  360. /// <summary>
  361. /// 获取仓库号
  362. /// </summary>
  363. public static string GetWareCode(string add)
  364. {
  365. return add switch
  366. {
  367. "2532" => "1N",
  368. "2527" => "1N",
  369. "2528" => "1N",
  370. "2732" => "1S",
  371. "2727" => "1S",
  372. "2728" => "1S",
  373. _ => "",
  374. };
  375. }
  376. /// <summary>
  377. /// 工字轮/芯股进入主线扫码
  378. /// </summary>
  379. /// <param name="reqDto"></param>
  380. /// <param name="equNo"></param>
  381. /// <returns></returns>
  382. /// <exception cref="KnownException"></exception>
  383. public static SRes EnteMainLine(List<string> reqDto, string equNo)
  384. {
  385. var res = APICaller.CallApi<SRes>(WMSUrl + "/api/FJ/EnteMainLine", new FJEnteMainLineRequest
  386. {
  387. IShapedWheelCodes = reqDto,
  388. equNo = equNo
  389. });
  390. if (res.ResCode != ResponseStatusCodeEnum.Sucess)
  391. {
  392. throw new KnownException(res.ResMsg, LogLevelEnum.High);
  393. }
  394. return res;
  395. }
  396. }
  397. }