| | |
| | | using Microsoft.AspNetCore.Authorization; |
| | | using Microsoft.AspNetCore.Http; |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using System.Text; |
| | | using WIDESEA_DTO.Agv; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.Enums; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.LogHelper; |
| | | using WIDESEAWCS_DTO.Agv; |
| | | using WIDESEAWCS_IBasicInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoService; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_QuartzJob; |
| | | using WIDESEAWCS_QuartzJob.DTO; |
| | | using WIDESEAWCS_Tasks; |
| | | using WIDESEAWCS_Tasks.ConveyorLineJob; |
| | | using WIDESEAWCS_Tasks.DBNames; |
| | | |
| | | namespace WIDESEAWCS_Server.Controllers |
| | | { |
| | |
| | | /// <param name="secureApplyModel"></param> |
| | | /// <returns></returns> |
| | | [HttpPost, HttpGet, Route("AgvSecureApply"), AllowAnonymous] |
| | | public AgvResponseContent AgvSecureApply([FromBody] AgvSecureApplyDTO secureApplyModel) |
| | | public AgvResponse AgvSecureApply([FromBody] AgvSecureApplyDTO secureApplyModel) |
| | | { |
| | | AgvResponseContent agvResponseContent = new AgvResponseContent(); |
| | | agvResponseContent.ReqCode = secureApplyModel.ReqCode; |
| | | AgvResponse agvResponse = new AgvResponse(); |
| | | try |
| | | { |
| | | var task = _taskRepository.QueryFirst(x => secureApplyModel.TaskCode == x.AgvTaskNum); |
| | | var task = _taskRepository.QueryFirst(x => secureApplyModel.ReceiveTaskID.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); |
| | | //} |
| | | if (!content.Status) |
| | | { |
| | | throw new Exception(content.Message); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | var content = PutRequest(task.NextAddress, task.PalletType); |
| | | //if (!content.Status) |
| | | //{ |
| | | // throw new Exception(content.Message); |
| | | //} |
| | | if (!content.Status) |
| | | { |
| | | throw new Exception(content.Message); |
| | | } |
| | | } |
| | | task.TaskState = TaskStatusEnum.AGV_WaitToExecute.ObjToInt(); |
| | | task.TaskState = TaskStatusEnum.AGV_Puting.ObjToInt(); |
| | | var up = _taskRepository.UpdateData(task); |
| | | agvResponseContent.Code = up ? "0" : "1"; |
| | | agvResponseContent.Message = up ? "æå" : "失败"; |
| | | agvResponse.OK("æå","0"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | agvResponseContent.Code = "1"; |
| | | agvResponseContent.Message = ex.Message; |
| | | agvResponse.Error(ex.Message); |
| | | } |
| | | return agvResponseContent; |
| | | //return _taskService.AgvSecureApply(secureApplyModel); |
| | | return agvResponse; |
| | | } |
| | | /// <summary> |
| | | /// æåæºç³è¯· AGV-WCS |
| | | /// </summary> |
| | | /// <param name="secureApplyModel"></param> |
| | | /// <returns></returns> |
| | | [HttpPost, HttpGet, Route("AgvHoisterApply"), AllowAnonymous] |
| | | public AgvResponse AgvHoisterApply([FromBody] AgvHoisterApplyDTO agvHoisterApplyDTO) |
| | | { |
| | | AgvResponse agvResponse = new AgvResponse(); |
| | | try |
| | | { |
| | | IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == agvHoisterApplyDTO.HoisterCode); |
| | | if (device == null) |
| | | { |
| | | return agvResponse.Error($"æªæ¾å°å¯¹åºè®¾å¤{agvHoisterApplyDTO.HoisterCode}"); |
| | | } |
| | | OtherDevice otherDevice = (OtherDevice)device; |
| | | //è·å设å¤åè®® |
| | | DeviceProDTO? deviceProRead = otherDevice.DeviceProDTOs.Where(x => x.DeviceChildCode == device.DeviceCode && x.DeviceProParamType == nameof(R_HoisterDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | DeviceProDTO? deviceProWrite = otherDevice.DeviceProDTOs.Where(x => x.DeviceChildCode == device.DeviceCode && x.DeviceProParamType == nameof(W_HoisterDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | if (deviceProRead == null || deviceProWrite == null) |
| | | { |
| | | return agvResponse.Error($"æªæ¾å°è®¾å¤{device.DeviceCode}åè®®"); |
| | | } |
| | | //è·å读åååå
¥ |
| | | R_HoisterInfo r_HoisterInfo = otherDevice.Communicator.ReadCustomer<R_HoisterInfo>(deviceProRead.DeviceProAddress); |
| | | W_HoisterInfo w_HoisterInfo = otherDevice.Communicator.ReadCustomer<W_HoisterInfo>(deviceProWrite.DeviceProAddress); |
| | | if (r_HoisterInfo == null || w_HoisterInfo == null) |
| | | { |
| | | return agvResponse.Error($"æªè¯»åå°è®¾å¤{device.DeviceCode}ä¿¡å·"); |
| | | } |
| | | if (r_HoisterInfo.R_HoisterSysStatus!=3) |
| | | { |
| | | return agvResponse.Error($"设å¤ç¶æä¸ä¸ºèªå¨"); |
| | | } |
| | | QuartzLogger.WriteLogToFile("Info_" + device.DeviceCode, $"r_HoisterInfo:{r_HoisterInfo.Serialize()}{Environment.NewLine}w_HoisterInfo:{w_HoisterInfo.Serialize()}{Environment.NewLine}"); |
| | | bool IsSuccess = false; |
| | | switch (agvHoisterApplyDTO.Request) |
| | | { |
| | | case "1": |
| | | //夿æåæºæ¯å¦å¨å½åå± å¦æå½åå±ï¼å
³é¨ç¶æï¼æ è´§å¾
å½ç´æ¥åå
¥å¼é¨ä¿¡å· |
| | | if (r_HoisterInfo.R_HoisterCurrent == agvHoisterApplyDTO.CurrentLayer && r_HoisterInfo.R_HoisterLoadStatus == 2 && r_HoisterInfo.R_HoisterDoorStatus == 2) |
| | | { |
| | | otherDevice.SetValue(W_HoisterDB.W_HoisterDoorStatus, 1); |
| | | IsSuccess = true; |
| | | } |
| | | else if (r_HoisterInfo.R_HoisterCurrent == agvHoisterApplyDTO.CurrentLayer && r_HoisterInfo.R_HoisterLoadStatus == 2 && r_HoisterInfo.R_HoisterDoorStatus == 1) |
| | | { |
| | | IsSuccess = true; |
| | | } |
| | | else if (r_HoisterInfo.R_HoisterCurrent != agvHoisterApplyDTO.CurrentLayer && r_HoisterInfo.R_HoisterLoadStatus == 2 && r_HoisterInfo.R_HoisterDoorStatus == 1) |
| | | { |
| | | otherDevice.SetValue(W_HoisterDB.W_HoisterDoorStatus, 2); |
| | | } |
| | | //夿æåæºä¸å¨å½åå± å¦æä¸å¨å½åå±ï¼å
³é¨ç¶æï¼æ è´§å¾
å½ç´æ¥åå
¥ç§»å¨å¼é¨ä¿¡å·(å½å) |
| | | else if (r_HoisterInfo.R_HoisterCurrent != agvHoisterApplyDTO.CurrentLayer && r_HoisterInfo.R_HoisterLoadStatus == 2 && r_HoisterInfo.R_HoisterDoorStatus == 2) |
| | | { |
| | | otherDevice.SetValue(W_HoisterDB.W_HoisterTarget, agvHoisterApplyDTO.CurrentLayer); |
| | | otherDevice.SetValue(W_HoisterDB.W_HoisterTask, 99); |
| | | } |
| | | return IsSuccess ? agvResponse.OK($"请æ±{agvHoisterApplyDTO.Request}æå,ä»»å¡{agvHoisterApplyDTO.ReceiveTaskID}","1"): agvResponse.Error($"请æ±{agvHoisterApplyDTO.Request}失败,ä»»å¡{agvHoisterApplyDTO.ReceiveTaskID}"); |
| | | case "2": |
| | | //夿æåæºæ¯å¦å¨å½åå± å¦æå½åå±ï¼å¼é¨ç¶æï¼æ è´§å¾
å½ æ¾è¡ |
| | | if (r_HoisterInfo.R_HoisterCurrent == agvHoisterApplyDTO.CurrentLayer && r_HoisterInfo.R_HoisterLoadStatus == 2 && r_HoisterInfo.R_HoisterDoorStatus == 1) |
| | | { |
| | | IsSuccess = true; |
| | | } |
| | | return IsSuccess ? agvResponse.OK($"请æ±{agvHoisterApplyDTO.Request}æå,ä»»å¡{agvHoisterApplyDTO.ReceiveTaskID}", "2") : agvResponse.Error($"请æ±{agvHoisterApplyDTO.Request}失败,ä»»å¡{agvHoisterApplyDTO.ReceiveTaskID}"); |
| | | case "3": |
| | | //夿æåæºæ¯å¦å¨å½åå± å¦æå½åå±ï¼å¼é¨ç¶æï¼æè´§å¾
å½åå
¥å
³é¨ä¿¡å· |
| | | if (r_HoisterInfo.R_HoisterCurrent == agvHoisterApplyDTO.CurrentLayer && r_HoisterInfo.R_HoisterLoadStatus == 1 && r_HoisterInfo.R_HoisterDoorStatus == 1 && w_HoisterInfo.W_HoisterDoorStatus!=2) |
| | | { |
| | | otherDevice.SetValue(W_HoisterDB.W_HoisterDoorStatus, 2); |
| | | } |
| | | //夿æåæºæ¯å¦å¨å½åå± å¦æå½åå±ï¼å
³é¨ç¶æï¼æè´§å¾
å½åå
¥ç§»å¨å¼é¨ä¿¡å·(ç®ç) |
| | | if (r_HoisterInfo.R_HoisterCurrent == agvHoisterApplyDTO.CurrentLayer && r_HoisterInfo.R_HoisterLoadStatus == 1 && r_HoisterInfo.R_HoisterDoorStatus == 2) |
| | | { |
| | | otherDevice.SetValue(W_HoisterDB.W_HoisterTarget, agvHoisterApplyDTO.TargetLayer); |
| | | otherDevice.SetValue(W_HoisterDB.W_HoisterDoorStatus, 1); |
| | | otherDevice.SetValue(W_HoisterDB.W_HoisterTask, 99); |
| | | IsSuccess = true; |
| | | } |
| | | return IsSuccess ? agvResponse.OK($"请æ±{agvHoisterApplyDTO.Request}æå,ä»»å¡{agvHoisterApplyDTO.ReceiveTaskID}", "3") : agvResponse.Error($"请æ±{agvHoisterApplyDTO.Request}失败,ä»»å¡{agvHoisterApplyDTO.ReceiveTaskID}"); |
| | | case "4": |
| | | //夿æåæºæ¯å¦å¨ç®çå± å¦æç®çå±ï¼å¼é¨ç¶æï¼æè´§å¾
å½ æ¾è¡ |
| | | if (r_HoisterInfo.R_HoisterCurrent == agvHoisterApplyDTO.TargetLayer && r_HoisterInfo.R_HoisterLoadStatus == 1 && r_HoisterInfo.R_HoisterDoorStatus == 1) |
| | | { |
| | | IsSuccess = true; |
| | | } |
| | | return IsSuccess ? agvResponse.OK($"请æ±{agvHoisterApplyDTO.Request}æå,ä»»å¡{agvHoisterApplyDTO.ReceiveTaskID}", "4") : agvResponse.Error($"请æ±{agvHoisterApplyDTO.Request}失败,ä»»å¡{agvHoisterApplyDTO.ReceiveTaskID}"); |
| | | case "5": |
| | | //夿æåæºæ¯å¦å¨ç®çå± å¦æç®çå±ï¼å¼é¨ç¶æï¼æ è´§å¾
å½åå
¥å
³é¨ä¿¡å· |
| | | if (r_HoisterInfo.R_HoisterCurrent == agvHoisterApplyDTO.TargetLayer && r_HoisterInfo.R_HoisterLoadStatus == 2 && r_HoisterInfo.R_HoisterDoorStatus == 1) |
| | | { |
| | | otherDevice.SetValue(W_HoisterDB.W_HoisterDoorStatus, 2); |
| | | IsSuccess = true; |
| | | } |
| | | return IsSuccess ? agvResponse.OK($"请æ±{agvHoisterApplyDTO.Request}æå,ä»»å¡{agvHoisterApplyDTO.ReceiveTaskID}", "5") : agvResponse.Error($"请æ±{agvHoisterApplyDTO.Request}失败,ä»»å¡{agvHoisterApplyDTO.ReceiveTaskID}"); |
| | | default: |
| | | return agvResponse.Error($"æªæ¾å°å¯¹åºè¯·æ±,Request:{agvHoisterApplyDTO.Request}"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | agvResponse.Error($"请æ±{agvHoisterApplyDTO.Request}失败,é误{ex.Message},ä»»å¡{agvHoisterApplyDTO.ReceiveTaskID}"); |
| | | } |
| | | return agvResponse; |
| | | } |
| | | /// <summary> |
| | | /// AGV任塿´æ°/宿 |
| | |
| | | /// <param name="agvUpdateModel"></param> |
| | | /// <returns></returns> |
| | | [HttpPost, HttpGet, Route("AgvCallback"), AllowAnonymous] |
| | | public AgvResponseContent AgvUpdateTask([FromBody] AgvUpdateDTO agvUpdateModel) |
| | | public AgvResponse AgvCallback([FromBody] AgvUpdateDTO agvUpdateModel) |
| | | { |
| | | AgvResponseContent agvResponseContent = new AgvResponseContent(); |
| | | AgvResponse agvResponse = new AgvResponse(); |
| | | try |
| | | { |
| | | if (agvUpdateModel == null) throw new Exception("æªè·åå°è¯·æ±åæ°"); |
| | | agvResponseContent.ReqCode = agvUpdateModel.ReqCode; |
| | | var task = _taskRepository.QueryFirst(x => agvUpdateModel.TaskCode == x.AgvTaskNum); |
| | | if (task == null) throw new Exception($"æªæ¾å°ä»»å¡,ä»»å¡å·ã{agvUpdateModel.TaskCode}ã"); |
| | | switch (agvUpdateModel.Method) |
| | | var task = _taskRepository.QueryFirst(x => agvUpdateModel.ReceiveTaskID == x.TaskNum.ToString()); |
| | | if (task == null) throw new Exception($"æªæ¾å°ä»»å¡,ä»»å¡å·ã{agvUpdateModel.ReceiveTaskID}ã"); |
| | | switch (agvUpdateModel.GoodsState) |
| | | { |
| | | case "start": |
| | | break; |
| | | case "outbin"://åºåºæ ¹æ®è¿ä¸ªä¿¡å·å¤æåè´§å®æ |
| | | if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt()) |
| | | //case 1://åºåºæ ¹æ®è¿ä¸ªä¿¡å·å¤æåè´§å®æ |
| | | // 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); |
| | | // } |
| | | // break; |
| | | case 2://å
¥åºæ ¹æ®è¿ä¸ªä¿¡å·å¤ææ¾è´§å®æ |
| | | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup) |
| | | { |
| | | 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 "getSafetySignal"://å®å
¨ä¿¡å·ç³è¯· |
| | | { |
| | | 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 ? "æå" : "失败"; |
| | | return agvResponseContent; |
| | | } |
| | | case "end"://å
¥åºæ ¹æ®è¿ä¸ªä¿¡å·å¤ææ¾è´§å®æ |
| | | if (task.TaskType != TaskTypeEnum.Outbound.ObjToInt()) |
| | | { |
| | | var content = PutFinish(task.NextAddress); |
| | | if (!content.Status) throw new Exception(content.Message); |
| | | Dt_StationManger dt_Station = _stationMangerRepository.QueryFirst(x => x.AGVStationCode == task.NextAddress); |
| | | Dt_StationManger dt_Station = _stationMangerRepository.QueryFirst(x => x.StationCode == task.NextAddress); |
| | | if (dt_Station == null) |
| | | { |
| | | throw new Exception($"{task.NextAddress}AGVç«å°æªå®ä¹"); |
| | |
| | | task.CurrentAddress = dt_Station.StationCode; |
| | | task.NextAddress = ""; |
| | | task.TaskState = TaskStatusEnum.AGV_Finish.ObjToInt(); |
| | | task.DeviceCode = "SC01_CSJ"; |
| | | task.DeviceCode = dt_Station.StationDeviceCode; |
| | | var up = _taskRepository.UpdateData(task); |
| | | agvResponseContent.Code = up ? "0" : "1"; |
| | | agvResponseContent.Message = up ? "æå" : "失败"; |
| | | return agvResponseContent; |
| | | return agvResponse.OK("æå","0"); |
| | | } |
| | | break; |
| | | case "cancel": |
| | | task.TaskState = TaskStatusEnum.Cancel.ObjToInt(); |
| | | _taskRepository.UpdateData(task); |
| | | break; |
| | | default: |
| | | throw new Exception($"æªå®ä¹æ¹æ³åã{agvUpdateModel.Method}ã"); |
| | | throw new Exception($"æªå®ä¹æ¹æ³åã{agvUpdateModel.TaskState}ã"); |
| | | } |
| | | agvResponseContent.Code = "0"; |
| | | agvResponseContent.Message = "æå"; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | agvResponseContent.Code = "1"; |
| | | agvResponseContent.Message = ex.Message; |
| | | agvResponse.Error(ex.Message); |
| | | } |
| | | return agvResponseContent; |
| | | return agvResponse; |
| | | //return _taskService.AgvUpdateTask(agvUpdateModel); |
| | | } |
| | | |
| | |
| | | [HttpPost, HttpGet, Route("PutRequest"), AllowAnonymous] |
| | | public WebResponseContent PutRequest(string code, int palletType) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.AGVStationCode == code); |
| | | Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == code); |
| | | if (stationManger == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°ç«å°é
ç½®"); |
| | | return content.Error($"æªæ¾å°ç«å°é
ç½®"); |
| | | } |
| | | IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode); |
| | | if (device == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°å¯¹åºè®¾å¤"); |
| | | return content.Error($"æªæ¾å°å¯¹åºè®¾å¤"); |
| | | } |
| | | |
| | | OtherDevice otherDevice = (OtherDevice)device; |
| | | |
| | | bool canPut = otherDevice.GetValue<GroundStationDBName, bool>(GroundStationDBName.R_IsCanPut, stationManger.StationCode); |
| | | if (canPut) |
| | | short Command = otherDevice.GetValue<R_ConveyorLineCPDB, short>(R_ConveyorLineCPDB.Command, stationManger.StationCode); |
| | | if (Command == 3) |
| | | { |
| | | otherDevice.SetValue(GroundStationDBName.W_PutRequest, true, stationManger.StationCode); |
| | | return WebResponseContent.Instance.OK(); |
| | | content.OK("å
è®¸æ¾æ"); |
| | | } |
| | | else |
| | | { |
| | | otherDevice.SetValue(GroundStationDBName.W_PutRequest, true, stationManger.StationCode); |
| | | Thread.Sleep(1000); |
| | | canPut = otherDevice.GetValue<GroundStationDBName, bool>(GroundStationDBName.R_IsCanPut, stationManger.StationCode); |
| | | if (canPut) |
| | | { |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | else |
| | | { |
| | | return WebResponseContent.Instance.Error($"æ¾è´§ç³è¯·ä¸"); |
| | | } |
| | | return content.Error("ç¦æ¢æ¾æ"); |
| | | } |
| | | return content; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |