AgvApi.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. using ServiceCenter.Logs;
  2. using ServiceCenter.Redis;
  3. using ServiceCenter.WebApi;
  4. using WCS.WorkEngineering.WebApi.Models.AGV;
  5. using WCS.WorkEngineering.WebApi.Models.AGV.Request;
  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 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="ctnrCode">RFID</param>
  38. /// <param name="position">取货机台</param>
  39. /// <param name="taskCode">WMS任务号</param>
  40. /// <param name="priority">优先级</param>
  41. /// <returns></returns>
  42. public static GenAgvSchedulingTaskResponse 满轮入库(string ctnrCode, string position, string taskCode, string priority)
  43. {
  44. return GenAgvSchedulingTask("iwms_third", ctnrCode, "4", new List<positionCodeClass>()
  45. {
  46. new positionCodeClass(){ //取货机台
  47. positionCode=position,
  48. type="00"
  49. },
  50. new positionCodeClass(){ //巷道分配点
  51. positionCode="HJLK",
  52. type="00"
  53. },
  54. new positionCodeClass(){ //预分配放货点
  55. positionCode="1015",
  56. type="00"
  57. }
  58. }, priority, taskCode, "ZTGT03", "1");
  59. }
  60. /// <summary>
  61. /// 机台补空
  62. /// </summary>
  63. /// <param name="position">补空机台</param>
  64. /// <param name="taskCode">WMS任务号</param>
  65. /// <param name="priority">优先级</param>
  66. /// <returns></returns>
  67. public static GenAgvSchedulingTaskResponse 机台补空(string position, string taskCode, string priority)
  68. {
  69. return GenAgvSchedulingTask("iWMS", "", "4", new List<positionCodeClass>()
  70. {
  71. new positionCodeClass(){ //合金库空区域
  72. positionCode="21",
  73. type="04"
  74. },
  75. new positionCodeClass(){ //目标机台
  76. positionCode=position,
  77. type="00"
  78. }
  79. }, priority, taskCode, "ZTGT03", "0");
  80. }
  81. /// <summary>
  82. /// 缓存架补空
  83. /// </summary>
  84. /// <param name="taskCode">任务号</param>
  85. /// <param name="nextPositionCode">取货地址</param>
  86. /// <returns></returns>
  87. public static ContinueTaskResponse 缓存架补空(string taskCode, string nextPositionCode)
  88. {
  89. return ContinueTask(taskCode, nextPositionCode);
  90. }
  91. /// <summary>
  92. /// 机台补满
  93. /// </summary>
  94. /// <param name="ctnrCode">RFID</param>
  95. /// <param name="position1">取货站台</param>
  96. /// <param name="position2">放货机台</param>
  97. /// <param name="taskCode">WMS任务号</param>
  98. /// <param name="priority">优先级</param>
  99. /// <returns></returns>
  100. public static GenAgvSchedulingTaskResponse 机台补满(string ctnrCode, string position1, string position2, string taskCode, string priority)
  101. {
  102. return GenAgvSchedulingTask("iWMS", ctnrCode, "1", new List<positionCodeClass>()
  103. {
  104. new positionCodeClass(){ //取货站台
  105. positionCode=position1,
  106. type="00"
  107. },
  108. new positionCodeClass(){ //放货机台
  109. positionCode=position2,
  110. type="00"
  111. }
  112. }, priority, taskCode, "ZTGT21", "-1");
  113. }
  114. /// <summary>
  115. /// Agv任务单生成接口
  116. /// </summary>
  117. /// <param name="clienCode">客户端编号</param>
  118. /// <param name="ctnrCode">容器编号</param>
  119. /// <param name="ctnrTyp">容器类型</param>
  120. /// <param name="positionCodePath">路径</param>
  121. /// <param name="priority">优先级</param>
  122. /// <param name="taskCode">任务单号</param>
  123. /// <param name="taskType">任务类型</param>
  124. /// <param name="hjTaskTy">合金任务模板</param>
  125. /// <returns></returns>
  126. /// <exception cref="KnownException"></exception>
  127. public static GenAgvSchedulingTaskResponse GenAgvSchedulingTask(string clienCode, string ctnrCode, string ctnrTyp, List<positionCodeClass> positionCodePath, string priority, string taskCode, string taskType, string hjTaskTy)
  128. {
  129. var res = APICaller.CallApi2<GenAgvSchedulingTaskResponse>(AgvUrl + "/rcms/services/rest/hikRpcService/genAgvSchedulingTask", new GenAgvSchedulingTaskRequest
  130. {
  131. clientCode = clienCode,
  132. ctnrCode = ctnrCode,
  133. ctnrTyp = ctnrTyp,
  134. interfaceName = "genAgvSchedulingTask",
  135. positionCodePath = positionCodePath,
  136. priority = priority,
  137. reqCode = Guid.NewGuid().ToString().Replace("-", ""),
  138. taskCode = taskCode,
  139. taskTyp = taskType,
  140. hjTaskTy = hjTaskTy,
  141. tokenCode = "56898661ea976b748f328cefa6960434",
  142. });
  143. if (res.code != AgvResponseCode.Success)
  144. {
  145. throw new KnownException(res.message, LogLevelEnum.High);
  146. }
  147. return res;
  148. }
  149. #endregion 任务单生成
  150. #region 继续执行任务
  151. /// <summary>
  152. /// 继续执行任务
  153. /// </summary>
  154. /// <param name="taskCode">AGV任务号</param>
  155. /// <param name="nextPositionCode">下一个地址</param>
  156. /// <returns>接口返回结果</returns>
  157. /// <exception cref="KnownException"></exception>
  158. public static ContinueTaskResponse ContinueTask(string taskCode, string nextPositionCode)
  159. {
  160. var res = APICaller.CallApi2<ContinueTaskResponse>(AgvUrl + "/rcms/services/rest/hikRpcService/continueTask", new ContinueTaskRequest
  161. {
  162. reqCode = Guid.NewGuid().ToString().Replace("-", ""),
  163. taskCode = taskCode,
  164. nextPositionCode = new positionCodeClass()
  165. {
  166. positionCode = nextPositionCode,
  167. type = "00"
  168. }
  169. });
  170. if (res.code != AgvResponseCode.Success)
  171. {
  172. throw new KnownException(res.message, LogLevelEnum.High);
  173. }
  174. return res;
  175. }
  176. #endregion
  177. /// <summary>
  178. /// 取消任务
  179. /// </summary>
  180. /// <param name="AGVtaskCode">AGV任务号</param>
  181. /// <returns></returns>
  182. /// <exception cref="KnownException"></exception>
  183. public static CancelTaskResponse CancelAgvTask(string AGVtaskCode)
  184. {
  185. var res = APICaller.CallApi2<CancelTaskResponse>(AgvUrl + "/rcms/services/rest/hikRpcService/cancelTask", new CancelTaskRequest
  186. {
  187. reqCode = Guid.NewGuid().ToString().Replace("-", ""),
  188. taskCode = AGVtaskCode,
  189. forceCancel = "0",
  190. });
  191. if (res.code != AgvResponseCode.Success)
  192. {
  193. throw new KnownException(res.message, LogLevelEnum.High);
  194. }
  195. return res;
  196. }
  197. /// <summary>
  198. /// AGV取消任务验证
  199. /// </summary>
  200. /// <param name="sRes"></param>
  201. /// <param name="id"></param>
  202. /// <param name="agvTask">需要取消任务的AGV任务号</param>
  203. /// <returns></returns>
  204. public static CancelTaskResponse? CancelAgvTask(SRes<HandleTaskResponse> sRes, int id, string agvTask)
  205. {
  206. try
  207. {
  208. var res = AgvApi.CancelAgvTask(agvTask);
  209. return res;
  210. }
  211. catch (Exception ex)
  212. {
  213. sRes.ResDataList.Add(new HandleTaskResponse()
  214. {
  215. IsSuccess = false,
  216. TaskNo = id,
  217. Message = $"AGV错误:{ex.Message}",
  218. });
  219. return null;
  220. }
  221. }
  222. }
  223. }