AgvApi.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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.Request;
  10. using WCS.WorkEngineering.WebApi.Models.WMS.Response;
  11. namespace WCS.WorkEngineering.WebApi.Controllers
  12. {
  13. /// <summary>
  14. /// AGV接口
  15. /// </summary>
  16. public static class AgvApi
  17. {
  18. private static string _AgvUrl = null!;
  19. /// <summary>
  20. /// AGV地址
  21. /// </summary>
  22. public static string AgvUrl
  23. {
  24. get
  25. {
  26. _AgvUrl ??= RedisHub.Default.Check("AgvUrl");
  27. if (string.IsNullOrEmpty(_AgvUrl))
  28. {
  29. throw new KnownException($"请在Redis配置AgvUrl", LogLevelEnum.High);
  30. }
  31. return _AgvUrl;
  32. }
  33. }
  34. #region 任务单生成
  35. ///// <summary>
  36. ///// 盘条入库
  37. ///// </summary>
  38. ///// <param name="position">取货机台</param>
  39. ///// <param name="ctnrCode">容器编码</param>
  40. ///// <param name="taskCode">WMS任务号</param>
  41. ///// <param name="priority">优先级</param>
  42. ///// <returns></returns>
  43. //public static GenAgvSchedulingTaskResponse 盘条入库( string position, string ctnrCode, string taskCode, string priority)
  44. //{
  45. // return GenAgvSchedulingTask("iwms_third", ctnrCode,"4", new List<positionCodeClass>()
  46. // {
  47. // new positionCodeClass(){ //取货机台
  48. // positionCode=position,
  49. // type="00"
  50. // },
  51. // new positionCodeClass(){ //巷道分配点
  52. // positionCode="DD3",
  53. // type="00"
  54. // },
  55. // new positionCodeClass(){ //预分配终点
  56. // positionCode="JT1",
  57. // type="00"
  58. // }
  59. // }, priority, taskCode, "PT05", "1");
  60. //}
  61. //public static GenAgvSchedulingTaskResponse 叫料出库(string ctnrCode, string position, string taskCode, string priority)
  62. //{
  63. // return GenAgvSchedulingTask("iwms_third", ctnrCode, "4", new List<positionCodeClass>()
  64. // {
  65. // new positionCodeClass(){ //取货机台
  66. // positionCode=position,
  67. // type="00"
  68. // },
  69. // new positionCodeClass(){ //巷道分配点
  70. // positionCode="DD3",
  71. // type="00"
  72. // }
  73. // }, priority, taskCode, "PT04", "1");
  74. //}
  75. //public static GenAgvSchedulingTaskResponse 搬运(string ctnrCode, string position, string taskCode, string priority)
  76. //{
  77. // return GenAgvSchedulingTask("iwms_third", ctnrCode, "4", new List<positionCodeClass>()
  78. // {
  79. // new positionCodeClass(){ //取货机台
  80. // positionCode=position,
  81. // type="00"
  82. // },
  83. // new positionCodeClass(){ //放货站点
  84. // positionCode="JT4",
  85. // type="00"
  86. // }
  87. // }, priority, taskCode, "PT04", "1");
  88. //}
  89. //public static GenAgvSchedulingTaskResponse 搬运_wms(string ctnrCode, string position, string taskCode, string priority)
  90. //{
  91. // return GenAgvSchedulingTask("iwms_third", ctnrCode, "4", new List<positionCodeClass>()
  92. // {
  93. // new positionCodeClass(){ //取货机台
  94. // positionCode="JT1",
  95. // type="00"
  96. // },
  97. // new positionCodeClass(){ //放货站点
  98. // positionCode=position,
  99. // type="00"
  100. // }
  101. // }, priority, taskCode, "PT03", "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>("http://10.16.237.230:8181/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(res.message, LogLevelEnum.High);
  135. // }
  136. // return res;
  137. //}
  138. #endregion 任务单生成
  139. #region 任务单生成测试
  140. /// <summary>
  141. /// 盘条入库
  142. /// </summary>
  143. /// <param name="position1">取货位置</param>
  144. /// <param name="position2">下个位置</param>
  145. /// <param name="position3">终点位置</param>
  146. /// <param name="ctnrCode">容器编码</param>
  147. /// <param name="taskCode">agv任务号</param>
  148. /// <param name="priority">优先级</param>
  149. /// <returns></returns>
  150. public static GenAgvSchedulingTaskResponse 盘条入库(string position1,string position2,string position3, string ctnrCode, string taskCode, string priority)
  151. {
  152. return GenAgvSchedulingTask("iwms_third", ctnrCode, "4", new List<positionCodeClass>()
  153. {
  154. new positionCodeClass(){ //取货机台
  155. positionCode=position1,
  156. type="00"
  157. },
  158. new positionCodeClass(){ //巷道分配点
  159. positionCode=position2,
  160. type="00"
  161. },
  162. new positionCodeClass(){ //预分配终点
  163. positionCode=position3,
  164. type="00"
  165. }
  166. }, priority, taskCode, "ZTGT30", "1");
  167. }
  168. /// <summary>
  169. /// 缓存区到出库口
  170. /// </summary>
  171. /// <param name="ctnrCode">容器编码</param>
  172. /// <param name="position1">取货位置</param>
  173. /// <param name="position2">放货位置</param>
  174. /// <param name="taskCode">任务号</param>
  175. /// <param name="priority">优先级</param>
  176. /// <returns></returns>
  177. public static GenAgvSchedulingTaskResponse 搬运_wmsEnd(string ctnrCode, string position1, string position2, string taskCode, string priority)
  178. {
  179. return GenAgvSchedulingTask("iwms_third", ctnrCode, "4", new List<positionCodeClass>()
  180. {
  181. new positionCodeClass(){ //取货机台
  182. positionCode=position1,
  183. type="00"
  184. },
  185. new positionCodeClass(){ //放货站点
  186. positionCode=position2,
  187. type="00"
  188. }
  189. }, priority, taskCode, "PT02", "1");
  190. }
  191. public static GenAgvSchedulingTaskResponse 搬运_wmsStart(string ctnrCode, string position1, string position2, string taskCode, string priority)
  192. {
  193. return GenAgvSchedulingTask("iwms_third", ctnrCode, "4", new List<positionCodeClass>()
  194. {
  195. new positionCodeClass(){ //取货机台
  196. positionCode=position1,
  197. type="00"
  198. },
  199. new positionCodeClass(){ //放货站点
  200. positionCode=position2,
  201. type="00"
  202. }
  203. }, priority, taskCode, "PT03", "1");
  204. }
  205. //取放都校验
  206. public static GenAgvSchedulingTaskResponse 搬运(string ctnrCode, string position1, string position2, string taskCode, string priority)
  207. {
  208. return GenAgvSchedulingTask("iwms_third", ctnrCode, "4", new List<positionCodeClass>()
  209. {
  210. new positionCodeClass(){ //取货机台
  211. positionCode=position1,
  212. type="00"
  213. },
  214. new positionCodeClass(){ //放货站点
  215. positionCode=position2,
  216. type="00"
  217. }
  218. }, priority, taskCode, "PT04", "1");
  219. }
  220. public static GenAgvSchedulingTaskResponse 出库搬运_wms(string ctnrCode, string position1, string position2, string taskCode, string priority)
  221. {
  222. return GenAgvSchedulingTask("iwms_third", ctnrCode, "4", new List<positionCodeClass>()
  223. {
  224. new positionCodeClass(){ //取货机台
  225. positionCode=position1,
  226. type="00"
  227. },
  228. new positionCodeClass(){ //放货站点
  229. positionCode=position2,
  230. type="00"
  231. }
  232. }, priority, taskCode, "PT05", "1");
  233. }
  234. /// <summary>
  235. /// 叫料出库
  236. /// </summary>
  237. /// <param name="ctnrCode">容器编码</param>
  238. /// <param name="position1">取货位置</param>
  239. /// <param name="position2">放货位置</param>
  240. /// <param name="taskCode">任务号</param>
  241. /// <param name="priority">优先级</param>
  242. /// <returns></returns>
  243. public static GenAgvSchedulingTaskResponse 叫料出库(string ctnrCode, string position1, string position2, string taskCode, string priority)
  244. {
  245. return GenAgvSchedulingTask("iwms_third", ctnrCode, "4", new List<positionCodeClass>()
  246. {
  247. new positionCodeClass(){ //取货机台
  248. positionCode=position1,
  249. type="00"
  250. },
  251. new positionCodeClass(){ //取货机台
  252. positionCode="DD4",
  253. type="00"
  254. },
  255. new positionCodeClass(){ //放货站台
  256. positionCode=position2,
  257. type="00"
  258. }
  259. }, priority, taskCode, "PT05", "1");
  260. }
  261. /// <summary>
  262. /// Agv任务单生成接口
  263. /// </summary>
  264. /// <param name="clienCode">客户端编号</param>
  265. /// <param name="ctnrCode">容器编号</param>
  266. /// <param name="ctnrTyp">容器类型</param>
  267. /// <param name="positionCodePath">路径</param>
  268. /// <param name="priority">优先级</param>
  269. /// <param name="taskCode">任务单号</param>
  270. /// <param name="taskType">任务类型</param>
  271. /// <param name="hjTaskTy">合金任务模板</param>
  272. /// <returns></returns>
  273. /// <exception cref="KnownException"></exception>
  274. public static GenAgvSchedulingTaskResponse GenAgvSchedulingTask(string clienCode, string ctnrCode, string ctnrTyp, List<positionCodeClass> positionCodePath, string priority, string taskCode, string taskType, string hjTaskTy)
  275. {
  276. var res = APICaller.CallApi2<GenAgvSchedulingTaskResponse>("http://10.16.237.230:8181/rcms/services/rest/hikRpcService/genAgvSchedulingTask", new GenAgvSchedulingTaskRequest
  277. {
  278. clientCode = clienCode,
  279. ctnrCode = ctnrCode,
  280. ctnrTyp = ctnrTyp,
  281. interfaceName = "genAgvSchedulingTask",
  282. positionCodePath = positionCodePath,
  283. priority = priority,
  284. reqCode = Guid.NewGuid().ToString().Replace("-", ""),
  285. taskCode = taskCode,
  286. taskTyp = taskType,
  287. hjTaskTy = hjTaskTy,
  288. tokenCode = "56898661ea976b748f328cefa6960434",
  289. });
  290. if (res.code != AgvResponseCode.Success)
  291. {
  292. throw new KnownException(res.message, LogLevelEnum.High);
  293. }
  294. return res;
  295. }
  296. #endregion
  297. #region 继续执行任务
  298. /// <summary>
  299. /// 继续执行任务
  300. /// </summary>
  301. /// <param name="taskCode">AGV任务号</param>
  302. /// <param name="nextPositionCode">下一个地址</param>
  303. /// <returns>接口返回结果</returns>
  304. /// <exception cref="KnownException"></exception>
  305. public static ContinueTaskResponse ContinueTask(string taskCode, string nextPositionCode)
  306. {
  307. var res = APICaller.CallApi2<ContinueTaskResponse>("http://10.16.237.230:8181/rcms/services/rest/hikRpcService/continueTask", new ContinueTaskRequest
  308. {
  309. reqCode = Guid.NewGuid().ToString().Replace("-", ""),
  310. taskCode = taskCode,
  311. nextPositionCode = new positionCodeClass()
  312. {
  313. positionCode = nextPositionCode,
  314. type = "00"
  315. }
  316. });
  317. if (res.code != AgvResponseCode.Success)
  318. {
  319. throw new KnownException(res.message, LogLevelEnum.High);
  320. }
  321. return res;
  322. }
  323. #endregion
  324. /// <summary>
  325. /// 取消任务
  326. /// </summary>
  327. /// <param name="AGVtaskCode">AGV任务号</param>
  328. /// <returns></returns>
  329. /// <exception cref="KnownException"></exception>
  330. public static CancelTaskResponse CancelAgvTask(string AGVtaskCode)
  331. {
  332. var res = APICaller.CallApi2<CancelTaskResponse>(AgvUrl + "/rcms/services/rest/hikRpcService/cancelTask", new CancelTaskRequest
  333. {
  334. reqCode = Guid.NewGuid().ToString().Replace("-", ""),
  335. taskCode = AGVtaskCode,
  336. forceCancel = "0",
  337. });
  338. if (res.code != AgvResponseCode.Success)
  339. {
  340. throw new KnownException(res.message, LogLevelEnum.High);
  341. }
  342. return res;
  343. }
  344. /// <summary>
  345. /// AGV取消任务验证
  346. /// </summary>
  347. /// <param name="sRes"></param>
  348. /// <param name="id"></param>
  349. /// <param name="agvTask">需要取消任务的AGV任务号</param>
  350. /// <returns></returns>
  351. public static CancelTaskResponse? CancelAgvTask(SRes<HandleTaskResponse> sRes, int id, string agvTask)
  352. {
  353. try
  354. {
  355. var res = AgvApi.CancelAgvTask(agvTask);
  356. return res;
  357. }
  358. catch (Exception ex)
  359. {
  360. sRes.ResDataList.Add(new HandleTaskResponse()
  361. {
  362. IsSuccess = false,
  363. TaskNo = id,
  364. Message = $"AGV错误:{ex.Message}",
  365. });
  366. return null;
  367. }
  368. }
  369. }
  370. }