| | |
| | | using Microsoft.AspNetCore.Authorization; |
| | | using Microsoft.AspNetCore.Http; |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using WIDESEA_DTO.Agv; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.Enums; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_IBasicInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoService; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_QuartzJob; |
| | | using WIDESEAWCS_Tasks; |
| | |
| | | public class AGVController : ControllerBase |
| | | { |
| | | private readonly IStationMangerRepository _stationMangerRepository; |
| | | private readonly ITaskService _taskService; |
| | | private readonly ITaskRepository _taskRepository; |
| | | |
| | | public AGVController(IStationMangerRepository stationMangerRepository) |
| | | public AGVController(IStationMangerRepository stationMangerRepository, ITaskService taskService, ITaskRepository taskRepository) |
| | | { |
| | | _stationMangerRepository = stationMangerRepository; |
| | | _taskService = taskService; |
| | | _taskRepository = taskRepository; |
| | | } |
| | | /// <summary> |
| | | /// å®å
¨ä¿¡å·ç³è¯· AGV-WCS |
| | | /// </summary> |
| | | /// <param name="secureApplyModel"></param> |
| | | /// <returns></returns> |
| | | [HttpPost, HttpGet, Route("AgvSecureApply"), AllowAnonymous] |
| | | public AgvResponseContent AgvSecureApply([FromBody] AgvSecureApplyDTO secureApplyModel) |
| | | { |
| | | AgvResponseContent agvResponseContent = new AgvResponseContent(); |
| | | agvResponseContent.ReqCode = secureApplyModel.ReqCode; |
| | | try |
| | | { |
| | | var task = _taskRepository.QueryFirst(x => secureApplyModel.TaskCode.ObjToInt() == x.TaskNum); |
| | | if (task == null) throw new Exception("æªæ¾å°ä»»å¡"); |
| | | if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt()) |
| | | { |
| | | var content = TakeRequest(task.CurrentAddress); |
| | | if (!content.Status) |
| | | { |
| | | throw new Exception(content.Message); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | var content = PutRequest(task.NextAddress, task.PalletType); |
| | | if (!content.Status) |
| | | { |
| | | throw new Exception(content.Message); |
| | | } |
| | | } |
| | | task.TaskState = TaskStatusEnum.AGV_WaitToExecute.ObjToInt(); |
| | | var up = _taskRepository.UpdateData(task); |
| | | agvResponseContent.Code = up ? "0" : "1"; |
| | | agvResponseContent.Message = up ? "æå" : "失败"; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | agvResponseContent.Code = "1"; |
| | | agvResponseContent.Message = ex.Message; |
| | | } |
| | | return agvResponseContent; |
| | | //return _taskService.AgvSecureApply(secureApplyModel); |
| | | } |
| | | /// <summary> |
| | | /// AGV任塿´æ°/宿 |
| | | /// </summary> |
| | | /// <param name="agvUpdateModel"></param> |
| | | /// <returns></returns> |
| | | [HttpPost, HttpGet, Route("AgvCallback"), AllowAnonymous] |
| | | public AgvResponseContent AgvUpdateTask([FromBody] AgvUpdateDTO agvUpdateModel) |
| | | { |
| | | AgvResponseContent agvResponseContent = new AgvResponseContent(); |
| | | try |
| | | { |
| | | if (agvUpdateModel == null) throw new Exception("æªè·åå°è¯·æ±åæ°"); |
| | | agvResponseContent.ReqCode = agvUpdateModel.ReqCode; |
| | | var task = _taskRepository.QueryFirst(x => agvUpdateModel.TaskCode.ObjToInt() == x.TaskNum); |
| | | if (task == null) throw new Exception("æªæ¾å°ä»»å¡"); |
| | | switch (agvUpdateModel.Method) |
| | | { |
| | | case "start": |
| | | break; |
| | | case "outbin"://åºåºæ ¹æ®è¿ä¸ªä¿¡å·å¤æåè´§å®æ |
| | | if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt()) |
| | | { |
| | | var content = TakeFinish(task.CurrentAddress); |
| | | if (!content.Status) throw new Exception(content.Message); |
| | | task.TaskState = TaskStatusEnum.AGV_Finish.ObjToInt(); |
| | | var up = _taskRepository.DeleteAndMoveIntoHty(task, OperateTypeEnum.èªå¨å®æ); |
| | | _taskService.TaskCompleted(task.TaskNum); |
| | | agvResponseContent.Code = up ? "0" : "1"; |
| | | agvResponseContent.Message = up ? "æå" : "失败"; |
| | | return agvResponseContent; |
| | | } |
| | | break; |
| | | case "end"://å
¥åºæ ¹æ®è¿ä¸ªä¿¡å·å¤ææ¾è´§å®æ |
| | | if (task.TaskType != TaskTypeEnum.Outbound.ObjToInt()) |
| | | { |
| | | var content = PutFinish(task.NextAddress); |
| | | if (!content.Status) throw new Exception(content.Message); |
| | | task.CurrentAddress = task.NextAddress; |
| | | task.NextAddress = ""; |
| | | task.TaskState = TaskStatusEnum.SC_Execute.ObjToInt(); |
| | | var up = _taskRepository.UpdateData(task); |
| | | agvResponseContent.Code = up ? "0" : "1"; |
| | | agvResponseContent.Message = up ? "æå" : "失败"; |
| | | return agvResponseContent; |
| | | } |
| | | break; |
| | | case "cancel": |
| | | task.TaskState = TaskStatusEnum.Cancel.ObjToInt(); |
| | | _taskRepository.UpdateData(task); |
| | | break; |
| | | default: |
| | | throw new Exception($"æªå®ä¹æ¹æ³åã{agvUpdateModel.Method}ã"); |
| | | } |
| | | agvResponseContent.Code = "0"; |
| | | agvResponseContent.Message = "æå"; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | agvResponseContent.Code = "1"; |
| | | agvResponseContent.Message = ex.Message; |
| | | } |
| | | return agvResponseContent; |
| | | //return _taskService.AgvUpdateTask(agvUpdateModel); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¾è´§è¯·æ± |
| | | /// </summary> |
| | | /// <param name="code"></param> |
| | | /// <param name="palletType"></param> |
| | | /// <returns></returns> |
| | | [HttpPost, HttpGet, Route("PutRequest"), AllowAnonymous] |
| | | public WebResponseContent PutRequest(string code, int palletType) |
| | | { |
| | |
| | | else |
| | | { |
| | | otherDevice.SetValue(GroundStationDBName.W_PutRequest, true, stationManger.StationCode); |
| | | otherDevice.SetValue(GroundStationDBName.W_PutPalletType, (short)palletType, stationManger.StationCode); |
| | | Thread.Sleep(1000); |
| | | canPut = otherDevice.GetValue<GroundStationDBName, bool>(GroundStationDBName.R_IsCanPut, stationManger.StationCode); |
| | | if (canPut) |
| | |
| | | } |
| | | } |
| | | |
| | | //[HttpPost, HttpGet, Route("PutFinish"), AllowAnonymous] |
| | | /// <summary> |
| | | /// æ¾è´§å®æ |
| | | /// </summary> |
| | | /// <param name="code"></param> |
| | | /// <returns></returns> |
| | | [HttpPost, HttpGet, Route("PutFinish"), AllowAnonymous] |
| | | public WebResponseContent PutFinish(string code) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | //[HttpPost, HttpGet, Route("TakeRequest"), AllowAnonymous] |
| | | /// <summary> |
| | | /// åè´§è¯·æ± |
| | | /// </summary> |
| | | /// <param name="code"></param> |
| | | /// <returns></returns> |
| | | [HttpPost, HttpGet, Route("TakeRequest"), AllowAnonymous] |
| | | public WebResponseContent TakeRequest(string code) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | //[HttpPost, HttpGet, Route("TakeFinish"), AllowAnonymous] |
| | | /// <summary> |
| | | /// åè´§å®æ |
| | | /// </summary> |
| | | /// <param name="code"></param> |
| | | /// <returns></returns> |
| | | [HttpPost, HttpGet, Route("TakeFinish"), AllowAnonymous] |
| | | public WebResponseContent TakeFinish(string code) |
| | | { |