1
wangxinhui
6 天以前 fdf7bb595ee00e5fef7b4e110fbe32f637c069f6
ÏîÄ¿´úÂë/WCS/WCSServices/WIDESEAWCS_Server/Controllers/AGV/AGVController.cs
@@ -44,42 +44,38 @@
        /// <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())
                if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
                {
                    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
@@ -195,56 +191,30 @@
        /// <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.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
                        {
                            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;
                            if (!content.Status)
                            {
                                throw new Exception(content.Message);
                            };
                            return agvResponse.OK("成功", "0");
                        }
                        break;
                    case "getSafetySignal"://安全信号申请
                    case "2"://入库根据这个信号判断放货完成
                        if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
                        {
                            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站台未定义");
@@ -252,29 +222,25 @@
                            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");
                        }
                        else if(task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
                        {
                            _taskService.TaskCompleted(task.TaskNum);
                            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);
        }
@@ -287,45 +253,36 @@
        [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);
            }
        }
@@ -370,45 +327,36 @@
        [HttpPost, HttpGet, Route("TakeRequest"), AllowAnonymous]
        public WebResponseContent TakeRequest(string code)
        {
            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 WebResponseContent.Instance.Error($"未找到站台配置{code}");
                }
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode);
                if (device == null)
                {
                    return WebResponseContent.Instance.Error($"未找到对应设备");
                    return WebResponseContent.Instance.Error($"未找到对应设备{stationManger.StationDeviceCode}");
                }
                OtherDevice otherDevice = (OtherDevice)device;
                bool canPut = otherDevice.GetValue<GroundStationDBName, bool>(GroundStationDBName.R_IsCanTake, stationManger.StationCode);
                if (canPut)
                short Command = otherDevice.GetValue<R_ConveyorLineCPDB, short>(R_ConveyorLineCPDB.Command, stationManger.StationCode);
                if (Command == 2)
                {
                    otherDevice.SetValue(GroundStationDBName.W_TakeRequest, true, stationManger.StationCode);
                    return WebResponseContent.Instance.OK();
                    content.OK("允许取料");
                }
                else
                {
                    otherDevice.SetValue(GroundStationDBName.W_TakeRequest, true, stationManger.StationCode);
                    Thread.Sleep(1000);
                    canPut = otherDevice.GetValue<GroundStationDBName, bool>(GroundStationDBName.R_IsCanTake, 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);
            }
        }
@@ -423,7 +371,7 @@
        {
            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($"未找到站台配置");
@@ -435,9 +383,10 @@
                }
                OtherDevice otherDevice = (OtherDevice)device;
                otherDevice.SetValue(GroundStationDBName.W_TakeFinish, true, stationManger.StationCode);
                Thread.Sleep(1000);
                otherDevice.SetValue(GroundStationDBName.W_TakeFinish, false, stationManger.StationCode);
                if (device.DeviceCode.Contains("CP"))
                {
                    otherDevice.SetValue(W_ConveyorLineCPDB.W_Command, 2, stationManger.StationCode);
                }
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)