| | |
| | | using WIDESEA_DTO.Agv; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_Core.Enums; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_DTO.Agv; |
| | |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_QuartzJob; |
| | | using WIDESEAWCS_Tasks; |
| | | using static Dm.net.buffer.ByteArrayBuffer; |
| | | |
| | | namespace WIDESEAWCS_Server.Controllers |
| | | { |
| | |
| | | private readonly IStationMangerRepository _stationMangerRepository; |
| | | private readonly ITaskService _taskService; |
| | | private readonly ITaskRepository _taskRepository; |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | |
| | | public CTU_AGVController(IStationMangerRepository stationMangerRepository, ITaskService taskService, ITaskRepository taskRepository) |
| | | public CTU_AGVController(IStationMangerRepository stationMangerRepository, ITaskService taskService, ITaskRepository taskRepository,IUnitOfWorkManage unitOfWorkManage) |
| | | { |
| | | _stationMangerRepository = stationMangerRepository; |
| | | _taskService = taskService; |
| | | _taskRepository = taskRepository; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | } |
| | | [HttpPost, HttpGet, Route("AGVFinish"), AllowAnonymous] |
| | | public WebResponseContent AGVFinish(string barcode) |
| | |
| | | if (agvUpdateModel == null) throw new Exception("æªè·åå°è¯·æ±åæ°"); |
| | | agvResponseContent.ReqCode = agvUpdateModel.ReqCode; |
| | | var task = _taskRepository.QueryFirst(x => agvUpdateModel.TaskCode == x.AgvTaskNum); |
| | | //æ¯å¦åå¨è¾é线ä½å¾
AGVæ¬è¿ä»»å¡ |
| | | var taskExecutes = _taskRepository.QueryData(x => x.NextAddress == task.CurrentAddress && x.TaskState == TaskStatusEnum.Line_Executing.ObjToInt() && x.TaskType == TaskTypeEnum.InProduct.ObjToInt()); |
| | | if (task == null) throw new Exception($"æªæ¾å°ä»»å¡,ä»»å¡å·ã{agvUpdateModel.TaskCode}ã"); |
| | | |
| | | switch (agvUpdateModel.Method) |
| | | |
| | | switch (agvUpdateModel.Method.ToUpper()) |
| | | { |
| | | case "end": |
| | | case "END": |
| | | if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt() || task.TaskType == TaskTypeEnum.OutEmpty.ObjToInt() |
| | | || task.TaskType == TaskTypeEnum.OutAllocate.ObjToInt() || task.TaskType == TaskTypeEnum.OutProduct.ObjToInt()) |
| | | PutFinish(task.NextAddress); |
| | | _taskService.TaskCompleted(task.TaskNum); |
| | | break; |
| | | case "applyToAgv": |
| | | case "APPLYTOAGV": |
| | | //æ´æ¹æåå
¥åºAGVåè´§ä»»å¡ç¶æ |
| | | if (task.TaskType == TaskTypeEnum.InProduct.ObjToInt() || task.TaskType == TaskTypeEnum.InProductBack.ObjToInt()) |
| | | { |
| | | _taskService.UpdateTask(task,TaskStatusEnum.AGV_WaitToExecute); |
| | | //for (int i = 0; i < 100; i++) |
| | | //{ |
| | | // task.TaskState = TaskStatusEnum.AGV_WaitToExecute.ObjToInt(); |
| | | // task.Remark = task.TaskState.ToString(); |
| | | // _taskRepository.UpdateData(task); |
| | | // var taskOk = _taskRepository.QueryFirst(x => agvUpdateModel.TaskCode == x.AgvTaskNum); |
| | | // if (taskOk.TaskState==TaskStatusEnum.AGV_WaitToExecute.ObjToInt() || taskOk.Remark.Contains("320")) |
| | | // { |
| | | // agvResponseContent.Code = "0"; |
| | | // agvResponseContent.Message = ""+i; |
| | | // break; |
| | | // } |
| | | //} |
| | | //æ¯å¦åå¨è¾é线ä½å¾
AGVæ¬è¿ä»»å¡ |
| | | if (taskExecutes.Count > 0) |
| | | { |
| | | string address = task.CurrentAddress switch |
| | | { |
| | | "5206" => "5105", |
| | | "5212" => "5111", |
| | | "5218" => "5117", |
| | | }; |
| | | //è°ç¨AGVé¢è°åº¦æ¥å£ |
| | | AgvScheduleTaskDTO agvScheduleTask = new AgvScheduleTaskDTO() |
| | | { |
| | | PositionCode = address, |
| | | NextTask = "90", |
| | | UseableLayers = "1", |
| | | CacheCount = "1", |
| | | Update = "0", |
| | | AgvTyp = "11", |
| | | PreTaskQty = "1", |
| | | ReqCode = Guid.NewGuid().ToString().Replace("-", ""), |
| | | ReqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), |
| | | }; |
| | | WebResponseContent content = _taskService.AgvPreScheduleTask(agvScheduleTask); |
| | | if (!content.Status) |
| | | { |
| | | agvResponseContent.Code = "1"; |
| | | agvResponseContent.Message = content.Message; |
| | | return agvResponseContent; |
| | | } |
| | | } |
| | | Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == task.CurrentAddress); |
| | | if (stationManger==null) |
| | | { |
| | | agvResponseContent.Code = "1"; |
| | | agvResponseContent.Message = "æªæ¾å°ç«å°"; |
| | | return agvResponseContent; |
| | | } |
| | | IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode); |
| | | if (device == null) |
| | | { |
| | | agvResponseContent.Code = "1"; |
| | | agvResponseContent.Message = $"æªæ¾è®¾å¤{stationManger.StationDeviceCode}"; |
| | | return agvResponseContent; |
| | | } |
| | | OtherDevice otherDevice = (OtherDevice)device; |
| | | short canTake = otherDevice.GetValue<GroundStationDBName, short>(GroundStationDBName.R_IsCanTake, stationManger.StationCode); |
| | | if (canTake == 1) |
| | | { |
| | | //è·åè°å
¥åæ° |
| | | AGVBoxApplyPassDTO boxApplyPassDTO = new AGVBoxApplyPassDTO() |
| | | { |
| | | ReqCode = Guid.NewGuid().ToString().Replace("-", ""), |
| | | ReqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), |
| | | TaskCode = task.AgvTaskNum |
| | | }; |
| | | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup) |
| | | { |
| | | boxApplyPassDTO.Type = "1"; |
| | | } |
| | | else |
| | | { |
| | | boxApplyPassDTO.Type = "2"; |
| | | } |
| | | //è¯·æ±æç®±åè°æ¥å£ |
| | | WebResponseContent content = _taskService.AgvBoxApplyPass(boxApplyPassDTO); |
| | | if (content.Status && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup) |
| | | { |
| | | _taskService.UpdateTask(task, TaskStatusEnum.AGV_Executing); |
| | | } |
| | | else |
| | | { |
| | | task.ExceptionMessage = content.Message; |
| | | _taskService.UpdateTask(task, TaskStatusEnum.Exception); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | task.TaskState = TaskStatusEnum.AGV_WaitToExecute.ObjToInt(); |
| | | task.Remark = task.TaskState.ToString(); |
| | | _taskRepository.UpdateData(task); |
| | | } |
| | | } |
| | | break; |
| | | case "applyFromAgv": |
| | | case "APPLYFROMAGV": |
| | | //æ´æ¹æååºAGVæ¾è´§ä»»å¡ç¶æ |
| | | if (task.TaskType == TaskTypeEnum.OutProduct.ObjToInt()) |
| | | { |
| | | _taskService.UpdateTask(task, TaskStatusEnum.AGV_WaitToExecute); |
| | | } |
| | | break; |
| | | case "outbin": |
| | | case "OUTBIN": |
| | | if (task.TaskType == TaskTypeEnum.InProduct.ObjToInt() || task.TaskType == TaskTypeEnum.InProductBack.ObjToInt()) |
| | | { |
| | | TakeFinish(task.CurrentAddress); |
| | | _taskService.UpdateTask(task, TaskStatusEnum.AGV_Executing); |
| | | //_taskService.UpdateTask(task, TaskStatusEnum.AGV_Executing); |
| | | } |
| | | else if(task.TaskType == TaskTypeEnum.OutProduct.ObjToInt()) |
| | | { |
| | |
| | | } |
| | | break; |
| | | default: |
| | | break; |
| | | throw new Exception($"æ¹æ³{agvUpdateModel.Method}åæ°ä¸åå¨"); |
| | | } |
| | | agvResponseContent.Code = "0"; |
| | | agvResponseContent.Message = "æå"; |