AgvApi.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. using ServiceCenter.Extensions;
  2. using ServiceCenter.Logs;
  3. using ServiceCenter.Redis;
  4. using ServiceCenter.WebApi;
  5. using WCS.WorkEngineering.WebApi.Models.AGV;
  6. using WCS.WorkEngineering.WebApi.Models.AGV.Request;
  7. using WCS.WorkEngineering.WebApi.Models.AGV.Response;
  8. using WCS.WorkEngineering.WebApi.Models.WCS.Response;
  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 AgvApi
  16. {
  17. private static string _AgvUrl = null!;
  18. /// <summary>
  19. /// AGV地址
  20. /// </summary>
  21. public static string AgvUrl
  22. {
  23. get
  24. {
  25. _AgvUrl ??= RedisHub.Default.Check("AgvUrl")!;
  26. if (string.IsNullOrEmpty(_AgvUrl))
  27. {
  28. throw new KnownException($"请在Redis配置AgvUrl", LogLevelEnum.High);
  29. }
  30. return _AgvUrl;
  31. }
  32. }
  33. #region 任务单生成
  34. /// <summary>
  35. /// 测试路径
  36. /// </summary>
  37. /// <param name="position">取货机台</param>
  38. /// <param name="taskCode">WMS任务号</param>
  39. /// <returns></returns>
  40. public static GenAgvSchedulingTaskResponse 测试路径(string position, string taskCode)
  41. {
  42. return GenAgvSchedulingTask("iwms_third", "", "4", new List<positionCodeClass>()
  43. {
  44. new positionCodeClass(){ //取货机台
  45. positionCode=position,
  46. type="00"
  47. },
  48. new positionCodeClass(){ //巷道分配点
  49. positionCode="LX002",
  50. type="00"
  51. },
  52. new positionCodeClass(){ //预分配放货点
  53. positionCode="2501",
  54. type="00"
  55. }
  56. }, "1", taskCode, "LX03", "1");
  57. }
  58. /// <summary>
  59. /// 机台叫料
  60. /// </summary>
  61. /// <param name="SPosition">起始点</param>
  62. /// <param name="EPosition">目标点</param>
  63. /// <param name="taskCode">WMS任务号</param>
  64. /// <returns></returns>
  65. public static GenAgvSchedulingTaskResponse 机台叫料(string SPosition, string EPosition, string taskCode)
  66. {
  67. return GenAgvSchedulingTask("iwms_third", "", "4", new List<positionCodeClass>()
  68. {
  69. new positionCodeClass(){ //取货机台
  70. positionCode=SPosition,
  71. type="00"
  72. },
  73. new positionCodeClass(){ //巷道分配点
  74. positionCode=EPosition,
  75. type="00"
  76. }
  77. }, "1", taskCode, "ZTGT35", "1");
  78. }
  79. /// <summary>
  80. /// 托盘回库
  81. /// </summary>
  82. /// <param name="position">取货机台</param>
  83. /// <param name="taskCode">WMS任务号</param>
  84. /// <param name="station">站台</param>
  85. /// <returns></returns>
  86. public static GenAgvSchedulingTaskResponse 托盘回库(string position, string taskCode, string station)
  87. {
  88. var position1 = "";
  89. var position2 = "";
  90. switch (station)
  91. {
  92. case "2501": //分拣一北
  93. position1 = "LX002";
  94. position2 = "2501";
  95. break;
  96. case "2701": //分拣一南
  97. position1 = "LX004";
  98. position2 = "2701";
  99. break;
  100. case "2901": //分拣二北
  101. position1 = "LX006";
  102. position2 = "2901";
  103. break;
  104. case "3101": //分拣二南
  105. position1 = "LX008";
  106. position2 = "3101";
  107. break;
  108. case "3301": //分拣三北
  109. position1 = "LX010";
  110. position2 = "3301";
  111. break;
  112. case "3501": //分拣三南
  113. position1 = "LX012";
  114. position2 = "3501";
  115. break;
  116. }
  117. return GenAgvSchedulingTask("iwms_third", "", "4", new List<positionCodeClass>()
  118. {
  119. new positionCodeClass(){ //取货机台
  120. positionCode=position,
  121. type="00"
  122. },
  123. new positionCodeClass(){ //巷道分配点
  124. positionCode=position1,
  125. type="00"
  126. },
  127. new positionCodeClass(){ //预分配放货点
  128. positionCode=position2,
  129. type="00"
  130. }
  131. }, "1", taskCode, "ZTGT31", "1");
  132. }
  133. /// <summary>
  134. /// Agv任务单生成接口
  135. /// </summary>
  136. /// <param name="clienCode">客户端编号</param>
  137. /// <param name="ctnrCode">容器编号</param>
  138. /// <param name="ctnrTyp">容器类型</param>
  139. /// <param name="positionCodePath">路径</param>
  140. /// <param name="priority">优先级</param>
  141. /// <param name="taskCode">任务单号</param>
  142. /// <param name="taskType">任务类型</param>
  143. /// <param name="hjTaskTy">合金任务模板</param>
  144. /// <returns></returns>
  145. /// <exception cref="KnownException"></exception>
  146. public static GenAgvSchedulingTaskResponse GenAgvSchedulingTask(string clienCode, string ctnrCode, string ctnrTyp, List<positionCodeClass> positionCodePath, string priority, string taskCode, string taskType, string hjTaskTy)
  147. {
  148. var res = APICaller.CallApi2<GenAgvSchedulingTaskResponse>(AgvUrl + "/rcms/services/rest/hikRpcService/genAgvSchedulingTask", new GenAgvSchedulingTaskRequest
  149. {
  150. clientCode = clienCode,
  151. ctnrCode = ctnrCode,
  152. ctnrTyp = ctnrTyp,
  153. interfaceName = "genAgvSchedulingTask",
  154. positionCodePath = positionCodePath,
  155. priority = priority,
  156. reqCode = Guid.NewGuid().ToString().Replace("-", ""),
  157. taskCode = taskCode,
  158. taskTyp = taskType,
  159. hjTaskTy = hjTaskTy,
  160. tokenCode = "56898661ea976b748f328cefa6960434",
  161. });
  162. if (res.code != AgvResponseCode.Success)
  163. {
  164. if (res.message.Contains("未知的呼叫站点"))
  165. {
  166. if (taskType == "ZTGT35")
  167. {
  168. res.message = positionCodePath[1].positionCode + res.message;
  169. }
  170. else if (taskType == "ZTGT31")
  171. {
  172. res.message = positionCodePath[0].positionCode + res.message;
  173. }
  174. }
  175. throw new KnownException($"AGV返回错误:{res.message}", LogLevelEnum.High);
  176. }
  177. return res;
  178. }
  179. #endregion 任务单生成
  180. #region 继续执行任务
  181. /// <summary>
  182. /// 继续执行任务
  183. /// </summary>
  184. /// <param name="taskCode">AGV任务号</param>
  185. /// <param name="nextPositionCode">下一个地址</param>
  186. /// <returns>接口返回结果</returns>
  187. /// <exception cref="KnownException"></exception>
  188. public static ContinueTaskResponse ContinueTask(string taskCode, string nextPositionCode)
  189. {
  190. var res = APICaller.CallApi2<ContinueTaskResponse>(AgvUrl + "/rcms/services/rest/hikRpcService/continueTask", new ContinueTaskRequest
  191. {
  192. reqCode = Guid.NewGuid().ToString().Replace("-", ""),
  193. taskCode = taskCode,
  194. nextPositionCode = new positionCodeClass()
  195. {
  196. positionCode = nextPositionCode,
  197. type = "00"
  198. }
  199. });
  200. if (res.code != AgvResponseCode.Success)
  201. {
  202. throw new KnownException(res.message, LogLevelEnum.High);
  203. }
  204. return res;
  205. }
  206. #endregion 继续执行任务
  207. /// <summary>
  208. /// 取消任务
  209. /// </summary>
  210. /// <param name="AGVtaskCode">AGV任务号</param>
  211. /// <returns></returns>
  212. /// <exception cref="KnownException"></exception>
  213. public static CancelTaskResponse CancelAgvTask(string AGVtaskCode)
  214. {
  215. var res = APICaller.CallApi2<CancelTaskResponse>(AgvUrl + "/rcms/services/rest/hikRpcService/cancelTask", new CancelTaskRequest
  216. {
  217. reqCode = Guid.NewGuid().ToString().Replace("-", ""),
  218. taskCode = AGVtaskCode,
  219. forceCancel = "0",
  220. });
  221. if (res.code != AgvResponseCode.Success)
  222. {
  223. throw new KnownException(res.message, LogLevelEnum.High);
  224. }
  225. return res;
  226. }
  227. /// <summary>
  228. /// AGV取消任务验证
  229. /// </summary>
  230. /// <param name="sRes"></param>
  231. /// <param name="id"></param>
  232. /// <param name="agvTask">需要取消任务的AGV任务号</param>
  233. /// <returns></returns>
  234. public static CancelTaskResponse? CancelAgvTask(SRes<HandleTaskResponse> sRes, int id, string agvTask)
  235. {
  236. try
  237. {
  238. var res = AgvApi.CancelAgvTask(agvTask);
  239. return res;
  240. }
  241. catch (Exception ex)
  242. {
  243. sRes.ResDataList.Add(new HandleTaskResponse()
  244. {
  245. IsSuccess = false,
  246. TaskNo = id,
  247. Message = $"AGV错误:{ex.Message}",
  248. });
  249. return null;
  250. }
  251. }
  252. }
  253. }