AgvApi.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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, "LX01", "1");
  78. }
  79. /// <summary>
  80. /// 托盘回库
  81. /// </summary>
  82. /// <param name="position">取货机台</param>
  83. /// <param name="taskCode">WMS任务号</param>
  84. /// <returns></returns>
  85. public static GenAgvSchedulingTaskResponse 托盘回库(string position, string taskCode)
  86. {
  87. return GenAgvSchedulingTask("iwms_third", "", "4", new List<positionCodeClass>()
  88. {
  89. new positionCodeClass(){ //取货机台
  90. positionCode=position,
  91. type="00"
  92. },
  93. new positionCodeClass(){ //巷道分配点
  94. positionCode="LX002",
  95. type="00"
  96. },
  97. new positionCodeClass(){ //预分配放货点
  98. positionCode="LXSS1",
  99. type="00"
  100. }
  101. }, "1", taskCode, "ZTGT31", "1");
  102. }
  103. /// <summary>
  104. /// Agv任务单生成接口
  105. /// </summary>
  106. /// <param name="clienCode">客户端编号</param>
  107. /// <param name="ctnrCode">容器编号</param>
  108. /// <param name="ctnrTyp">容器类型</param>
  109. /// <param name="positionCodePath">路径</param>
  110. /// <param name="priority">优先级</param>
  111. /// <param name="taskCode">任务单号</param>
  112. /// <param name="taskType">任务类型</param>
  113. /// <param name="hjTaskTy">合金任务模板</param>
  114. /// <returns></returns>
  115. /// <exception cref="KnownException"></exception>
  116. public static GenAgvSchedulingTaskResponse GenAgvSchedulingTask(string clienCode, string ctnrCode, string ctnrTyp, List<positionCodeClass> positionCodePath, string priority, string taskCode, string taskType, string hjTaskTy)
  117. {
  118. var res = APICaller.CallApi2<GenAgvSchedulingTaskResponse>(AgvUrl + "/rcms/services/rest/hikRpcService/genAgvSchedulingTask", new GenAgvSchedulingTaskRequest
  119. {
  120. clientCode = clienCode,
  121. ctnrCode = ctnrCode,
  122. ctnrTyp = ctnrTyp,
  123. interfaceName = "genAgvSchedulingTask",
  124. positionCodePath = positionCodePath,
  125. priority = priority,
  126. reqCode = Guid.NewGuid().ToString().Replace("-", ""),
  127. taskCode = taskCode,
  128. taskTyp = taskType,
  129. hjTaskTy = hjTaskTy,
  130. tokenCode = "56898661ea976b748f328cefa6960434",
  131. });
  132. if (res.code != AgvResponseCode.Success)
  133. {
  134. throw new KnownException($"AGV返回错误:{res.message}", LogLevelEnum.High);
  135. }
  136. return res;
  137. }
  138. #endregion 任务单生成
  139. #region 继续执行任务
  140. /// <summary>
  141. /// 继续执行任务
  142. /// </summary>
  143. /// <param name="taskCode">AGV任务号</param>
  144. /// <param name="nextPositionCode">下一个地址</param>
  145. /// <returns>接口返回结果</returns>
  146. /// <exception cref="KnownException"></exception>
  147. public static ContinueTaskResponse ContinueTask(string taskCode, string nextPositionCode)
  148. {
  149. var res = APICaller.CallApi2<ContinueTaskResponse>(AgvUrl + "/rcms/services/rest/hikRpcService/continueTask", new ContinueTaskRequest
  150. {
  151. reqCode = Guid.NewGuid().ToString().Replace("-", ""),
  152. taskCode = taskCode,
  153. nextPositionCode = new positionCodeClass()
  154. {
  155. positionCode = nextPositionCode,
  156. type = "00"
  157. }
  158. });
  159. if (res.code != AgvResponseCode.Success)
  160. {
  161. throw new KnownException(res.message, LogLevelEnum.High);
  162. }
  163. return res;
  164. }
  165. #endregion 继续执行任务
  166. /// <summary>
  167. /// 取消任务
  168. /// </summary>
  169. /// <param name="AGVtaskCode">AGV任务号</param>
  170. /// <returns></returns>
  171. /// <exception cref="KnownException"></exception>
  172. public static CancelTaskResponse CancelAgvTask(string AGVtaskCode)
  173. {
  174. var res = APICaller.CallApi2<CancelTaskResponse>(AgvUrl + "/rcms/services/rest/hikRpcService/cancelTask", new CancelTaskRequest
  175. {
  176. reqCode = Guid.NewGuid().ToString().Replace("-", ""),
  177. taskCode = AGVtaskCode,
  178. forceCancel = "0",
  179. });
  180. if (res.code != AgvResponseCode.Success)
  181. {
  182. throw new KnownException(res.message, LogLevelEnum.High);
  183. }
  184. return res;
  185. }
  186. /// <summary>
  187. /// AGV取消任务验证
  188. /// </summary>
  189. /// <param name="sRes"></param>
  190. /// <param name="id"></param>
  191. /// <param name="agvTask">需要取消任务的AGV任务号</param>
  192. /// <returns></returns>
  193. public static CancelTaskResponse? CancelAgvTask(SRes<HandleTaskResponse> sRes, int id, string agvTask)
  194. {
  195. try
  196. {
  197. var res = AgvApi.CancelAgvTask(agvTask);
  198. return res;
  199. }
  200. catch (Exception ex)
  201. {
  202. sRes.ResDataList.Add(new HandleTaskResponse()
  203. {
  204. IsSuccess = false,
  205. TaskNo = id,
  206. Message = $"AGV错误:{ex.Message}",
  207. });
  208. return null;
  209. }
  210. }
  211. }
  212. }