AgvController.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. using Microsoft.AspNetCore.Mvc;
  2. using PlcSiemens.Core.Extension;
  3. using ServiceCenter.SqlSugars;
  4. using WCS.Core;
  5. using WCS.Entity;
  6. using WCS.Entity.Protocol.Station;
  7. using WCS.WorkEngineering.Extensions;
  8. using WCS.WorkEngineering.Systems;
  9. using WCS.WorkEngineering.WebApi.Models.AGV;
  10. using WCS.WorkEngineering.WebApi.Models.AGV.Request;
  11. using WCS.WorkEngineering.WebApi.Models.AGV.Response;
  12. namespace WCS.WorkEngineering.WebApi.Controllers
  13. {
  14. /// <summary>
  15. /// AGV相关接口控制器
  16. /// </summary>
  17. [ApiController]
  18. [Route("api/[controller]/[action]")]
  19. public class AgvController : ControllerBase
  20. {
  21. /// <summary>
  22. /// AGV任务下发测试
  23. /// </summary>
  24. /// <param name="type">任务类型</param>
  25. /// <param name="code">RFID</param>
  26. /// <param name="pos">目标位置</param>
  27. /// <returns></returns>
  28. [HttpPost]
  29. public string AgvDebug(int type, string code, string pos)
  30. {
  31. try
  32. {
  33. switch (type)
  34. {
  35. case 1:
  36. AgvApi.机台补空(pos, code, "1");
  37. break;
  38. case 2:
  39. //AgvApi.机台补满();
  40. break;
  41. case 3:
  42. AgvApi.满轮入库(code, pos, Guid.NewGuid().ToString().Replace("-", ""), "1");
  43. break;
  44. default:
  45. break;
  46. }
  47. return "成功";
  48. }
  49. catch (Exception ex)
  50. {
  51. return $"Error-----" +
  52. $"{ex.Message}------" +
  53. $"{ex.StackTrace}";
  54. }
  55. }
  56. /// <summary>
  57. /// 背负式agv请求出库任务
  58. /// </summary>
  59. /// <param name="reqDto">请求参数</param>
  60. /// <returns></returns>
  61. [HttpPost]
  62. public ApplyEmptySpoolResponse ApplyEmptySpool([FromBody] AgvFillEmptySpaceRequest reqDto)
  63. {
  64. ApplyEmptySpoolResponse agvFill = new ApplyEmptySpoolResponse();
  65. var obj = World.GetSystemInstance<GetDeviceSystem>().Invoke("输送机") as List<Station>;
  66. // 检测三个站台是否有货
  67. obj = obj.Where(v => v.Entity.Code is "1012" or "1014" or "1016").Where(v => v.Data3.Status.HasFlag(StatusEunm.PH_Status)).ToList();
  68. if (!obj.Any())
  69. {
  70. agvFill.ResCode = Models.WMS.Response.ResponseStatusCodeEnum.DataSaveErr;
  71. agvFill.ResMsg = "无空轮";
  72. return agvFill;
  73. }
  74. var res = WmsApi.GetTunnelEmptyConCount();
  75. foreach (var item in res.ResDataList)
  76. {
  77. var station = Device.All.Where(v => v.Code == "TY" + item.Tunnel.ToString())
  78. .Select(v => v.Targets).SelectMany(v => v)
  79. .Where(v => v.HasProtocol(typeof(IStation520)))
  80. .Where(v => v.Code is "1012" or "1014" or "1016")
  81. .FirstOrDefault();
  82. item.Tunnel = station.ToInt();
  83. }
  84. var stationNo = res.ResDataList.OrderBy(v => v.Count).Select(v => v.Tunnel.ToString()).ToList();
  85. agvFill.ResCode = Models.WMS.Response.ResponseStatusCodeEnum.Sucess;
  86. agvFill.LocCode = obj.MinBy(v => stationNo.IndexOf(v.Entity.Code)).Entity.Code;
  87. agvFill.SpoolType = "4";
  88. agvFill.ResMsg = "";
  89. return agvFill;
  90. }
  91. /// <summary>
  92. /// AGV执行回调
  93. /// </summary>
  94. /// <param name="reqDto"></param>
  95. /// <returns></returns>
  96. [HttpPost]
  97. public AgvCallbackResponse AgvCallback([FromBody] AgvCallbackRequest reqDto)
  98. {
  99. var msg = "成功";
  100. var code = AgvResponseCode.Success;
  101. try
  102. {
  103. SqlSugarHelper.Do(db =>
  104. {
  105. //跟据AGVid找到对应的AGV任务
  106. var agvTask = db.Default.Queryable<WCS_AgvTaskInfo>().SplitTable(tabs => tabs.Take(1)).First(v => v.AgvID == reqDto.taskCode);
  107. if (agvTask == null)
  108. {
  109. msg = "未找到对应的AGV任务";
  110. code = AgvResponseCode.Fail;
  111. }
  112. switch (reqDto.method)
  113. {
  114. case "applyContinue": //表示请求巷道
  115. agvTask.Status = AGVTaskStatus.RequestOrPermission1;
  116. break;
  117. case "applySecurity": //表示请求放货或取货
  118. agvTask.Status = AGVTaskStatus.RequestOrPermission2;
  119. break;
  120. case "hjend_2": //补空任务完成
  121. agvTask.Status = AGVTaskStatus.MissionCompleted;
  122. break;
  123. case "endhjBM": //取满任务完成
  124. agvTask.Status = AGVTaskStatus.MissionCompleted;
  125. break;
  126. case "tcEnd": //机台补空任务完成
  127. agvTask.Status = AGVTaskStatus.MissionCompleted;
  128. break;
  129. case "applyEmpty": //申请补空任务
  130. db.Default.Insertable(new WCS_AgvTaskInfo()
  131. {
  132. AgvID = reqDto.taskCode,
  133. TaskType = AGVTaskType.CallForMaterial,
  134. Status = AGVTaskStatus.NewBuild,
  135. }).AddQueue();
  136. AgvApi.缓存架补空(reqDto.taskCode, "1016");
  137. break;
  138. case "exc_end": //异常信息上抛-值不匹配
  139. agvTask.Status = AGVTaskStatus.MissionCompleted;
  140. break;
  141. default:
  142. break;
  143. }
  144. db.Default.Updateable(agvTask).SplitTable().ExecuteCommand();
  145. });
  146. }
  147. catch (Exception ex)
  148. {
  149. code = AgvResponseCode.Error;
  150. msg = ex.Message;
  151. }
  152. var res = new AgvCallbackResponse() { code = code, message = msg };
  153. return res;
  154. }
  155. }
  156. }