AgvApi.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. /// 满托入库
  135. /// </summary>
  136. /// <param name="position">取货站台</param>
  137. /// <param name="taskCode">WMS任务号</param>
  138. /// <param name="station">放货站台</param>
  139. /// <returns></returns>
  140. public static GenAgvSchedulingTaskResponse 满托入库(string startPosition, string taskCode, string station)
  141. {
  142. var position = "";
  143. var position1 = "";
  144. position = startPosition;
  145. position1 = station;
  146. return GenAgvSchedulingTask("iwms_third", "", "4", new List<positionCodeClass>()
  147. {
  148. new positionCodeClass(){ //取货机台
  149. positionCode=position,
  150. type="00"
  151. },
  152. new positionCodeClass(){ //预分配放货点
  153. positionCode=position1,
  154. type="00"
  155. }
  156. }, "1", taskCode, "ZTGT69", "1");
  157. }
  158. /// <summary>
  159. /// Agv任务单生成接口
  160. /// </summary>
  161. /// <param name="clienCode">客户端编号</param>
  162. /// <param name="ctnrCode">容器编号</param>
  163. /// <param name="ctnrTyp">容器类型</param>
  164. /// <param name="positionCodePath">路径</param>
  165. /// <param name="priority">优先级</param>
  166. /// <param name="taskCode">任务单号</param>
  167. /// <param name="taskType">任务类型</param>
  168. /// <param name="hjTaskTy">合金任务模板</param>
  169. /// <returns></returns>
  170. /// <exception cref="KnownException"></exception>
  171. public static GenAgvSchedulingTaskResponse GenAgvSchedulingTask(string clienCode, string ctnrCode, string ctnrTyp, List<positionCodeClass> positionCodePath, string priority, string taskCode, string taskType, string hjTaskTy)
  172. {
  173. var res = APICaller.CallApi2<GenAgvSchedulingTaskResponse>(AgvUrl + "/rcms/services/rest/hikRpcService/genAgvSchedulingTask", new GenAgvSchedulingTaskRequest
  174. {
  175. clientCode = clienCode,
  176. ctnrCode = ctnrCode,
  177. ctnrTyp = ctnrTyp,
  178. interfaceName = "genAgvSchedulingTask",
  179. positionCodePath = positionCodePath,
  180. priority = priority,
  181. reqCode = Guid.NewGuid().ToString().Replace("-", ""),
  182. taskCode = taskCode,
  183. taskTyp = taskType,
  184. hjTaskTy = hjTaskTy,
  185. tokenCode = "56898661ea976b748f328cefa6960434",
  186. });
  187. if (res.code != AgvResponseCode.Success)
  188. {
  189. if (res.message.Contains("未知的呼叫站点"))
  190. {
  191. if (taskType == "ZTGT35")
  192. {
  193. res.message = res.message + positionCodePath[1].positionCode;
  194. }
  195. else if (taskType == "ZTGT31")
  196. {
  197. res.message = res.message + positionCodePath[0].positionCode;
  198. }
  199. }
  200. throw new KnownException($"AGV返回错误:{res.message}", LogLevelEnum.High);
  201. }
  202. return res;
  203. }
  204. #endregion 任务单生成
  205. #region 继续执行任务
  206. /// <summary>
  207. /// 继续执行任务
  208. /// </summary>
  209. /// <param name="taskCode">AGV任务号</param>
  210. /// <param name="nextPositionCode">下一个地址</param>
  211. /// <returns>接口返回结果</returns>
  212. /// <exception cref="KnownException"></exception>
  213. public static ContinueTaskResponse ContinueTask(string taskCode, string nextPositionCode)
  214. {
  215. var res = APICaller.CallApi2<ContinueTaskResponse>(AgvUrl + "/rcms/services/rest/hikRpcService/continueTask", new ContinueTaskRequest
  216. {
  217. reqCode = Guid.NewGuid().ToString().Replace("-", ""),
  218. taskCode = taskCode,
  219. nextPositionCode = new positionCodeClass()
  220. {
  221. positionCode = nextPositionCode,
  222. type = "00"
  223. }
  224. });
  225. if (res.message.Contains("状态出错"))
  226. {
  227. res.message = "任务" + taskCode + res.message + "请检查对应是否有误";
  228. }
  229. if (res.code != AgvResponseCode.Success)
  230. {
  231. throw new KnownException(res.message, LogLevelEnum.High);
  232. }
  233. return res;
  234. }
  235. #endregion 继续执行任务
  236. /// <summary>
  237. /// 取消任务
  238. /// </summary>
  239. /// <param name="AGVtaskCode">AGV任务号</param>
  240. /// <returns></returns>
  241. /// <exception cref="KnownException"></exception>
  242. public static CancelTaskResponse CancelAgvTask(string AGVtaskCode)
  243. {
  244. var res = APICaller.CallApi2<CancelTaskResponse>(AgvUrl + "/rcms/services/rest/hikRpcService/cancelTask", new CancelTaskRequest
  245. {
  246. reqCode = Guid.NewGuid().ToString().Replace("-", ""),
  247. taskCode = AGVtaskCode,
  248. forceCancel = "0",
  249. });
  250. if (res.code != AgvResponseCode.Success)
  251. {
  252. throw new KnownException(res.message, LogLevelEnum.High);
  253. }
  254. return res;
  255. }
  256. /// <summary>
  257. /// AGV取消任务验证
  258. /// </summary>
  259. /// <param name="sRes"></param>
  260. /// <param name="id"></param>
  261. /// <param name="agvTask">需要取消任务的AGV任务号</param>
  262. /// <returns></returns>
  263. public static CancelTaskResponse? CancelAgvTask(SRes<HandleTaskResponse> sRes, int id, string agvTask)
  264. {
  265. try
  266. {
  267. var res = AgvApi.CancelAgvTask(agvTask);
  268. return res;
  269. }
  270. catch (Exception ex)
  271. {
  272. sRes.ResDataList.Add(new HandleTaskResponse()
  273. {
  274. IsSuccess = false,
  275. TaskNo = id,
  276. Message = $"AGV错误:{ex.Message}",
  277. });
  278. return null;
  279. }
  280. }
  281. }
  282. }