huangxiaoqiang
5 天以前 bfd2cde0cc9b9871eeab1503c837beabb9ade9e5
ÏîÄ¿´úÂë/WCS/WCSServices/WIDESEAWCS_Server/Controllers/AGV/AGVController.cs
@@ -15,9 +15,13 @@
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Repository;
using WIDESEAWCS_Tasks;
using WIDESEAWCS_Tasks.ConveyorLineJob;
using WIDESEAWCS_Tasks.DBNames;
using WIDESEAWCS_Tasks.StackPlateJob;
using static Dm.net.buffer.ByteArrayBuffer;
namespace WIDESEAWCS_Server.Controllers
{
@@ -28,12 +32,14 @@
        private readonly IStationMangerRepository _stationMangerRepository;
        private readonly ITaskService _taskService;
        private readonly ITaskRepository _taskRepository;
        private readonly IRouterRepository _routerRepository;
        public AGVController(IStationMangerRepository stationMangerRepository, ITaskService taskService, ITaskRepository taskRepository)
        public AGVController(IStationMangerRepository stationMangerRepository, ITaskService taskService, ITaskRepository taskRepository,IRouterRepository routerRepository)
        {
            _stationMangerRepository = stationMangerRepository;
            _taskService = taskService;
            _taskRepository = taskRepository;
            _routerRepository = routerRepository;
        }
        
@@ -51,24 +57,44 @@
            {
                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)
                    if (task.TaskState==TaskStatusEnum.AGV_Executing.ObjToInt())//出库取货请求
                    {
                        throw new Exception(content.Message);
                        var content = TakeRequest(secureApplyModel.WbCode);
                        if (!content.Status)
                        {
                            throw new Exception(content.Message);
                        }
                    }
                    else//出库放货请求
                    {
                        var content = PutRequest(task.NextAddress, task.PalletType);
                        if (!content.Status)
                        {
                            throw new Exception(content.Message);
                        }
                    }
                }
                else
                {
                    var content = PutRequest(task.NextAddress, task.PalletType);
                    if (!content.Status)
                    if (task.TaskState == TaskStatusEnum.AGV_Executing.ObjToInt())//入库取货请求
                    {
                        throw new Exception(content.Message);
                        var content = TakeRequest(secureApplyModel.WbCode);
                        if (!content.Status)
                        {
                            throw new Exception(content.Message);
                        }
                    }
                    else//入库放货请求
                    {
                        var content = PutRequest(task.NextAddress, task.TaskNum);
                        if (!content.Status)
                        {
                            throw new Exception(content.Message);
                        }
                    }
                }
                task.TaskState = TaskStatusEnum.AGV_Puting.ObjToInt();
                var up = _taskRepository.UpdateData(task);
                agvResponse.OK("成功","0");
            }
            catch (Exception ex)
@@ -200,17 +226,31 @@
                if (task == null) throw new Exception($"未找到任务,任务号【{agvUpdateModel.ReceiveTaskID}】");
                switch (agvUpdateModel.GoodsState)
                {
                    //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://入库根据这个信号判断放货完成
                    case "1"://出库根据这个信号判断取货完成
                        //更新任务状态
                        _taskService.UpdateTask(task, TaskStatusEnum.AGV_TakeFinish);
                        if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
                        {
                            var content = TakeFinish(task.CurrentAddress);
                            if (!content.Status)
                            {
                                throw new Exception(content.Message);
                            };
                        }
                        else
                        {
                            if (task.TaskType == TaskTypeEnum.PrintYLInbound.ObjToInt() || task.TaskType == TaskTypeEnum.PrintYLBackInbound.ObjToInt())
                            {
                                var content = TakeFinish(task.CurrentAddress);
                                if (!content.Status)
                                {
                                    throw new Exception(content.Message);
                                };
                            }
                        }
                        return agvResponse.OK("成功", "0");
                    case "2"://入库根据这个信号判断放货完成
                        if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
                        {
                            Dt_StationManger dt_Station = _stationMangerRepository.QueryFirst(x => x.StationCode == task.NextAddress);
@@ -218,14 +258,41 @@
                            {
                                throw new Exception($"{task.NextAddress}AGV站台未定义");
                            }
                            task.CurrentAddress = dt_Station.StationCode;
                            task.NextAddress = "";
                            task.TaskState = TaskStatusEnum.AGV_Finish.ObjToInt();
                            task.DeviceCode = dt_Station.StationDeviceCode;
                            var up = _taskRepository.UpdateData(task);
                            if (task.TaskType == TaskTypeEnum.PrintYLInbound.ObjToInt() || task.TaskType == TaskTypeEnum.PrintYLBackInbound.ObjToInt())
                            {
                                List<Dt_Router> routers = _routerRepository.QueryData(x => x.InOutType == task.TaskType && task.NextAddress == x.StartPosi);
                                Dt_Router router = routers.FirstOrDefault();
                                if (router == null)
                                {
                                    throw new Exception($"任务号:{task.TaskNum}未找到路由配置信息");
                                }
                                string oldAddress = task.NextAddress;
                                //更新任务状态
                                task.CurrentAddress = router.NextPosi;
                                task.NextAddress = "";
                                task.DeviceCode = router.ChildPosiDeviceCode;
                                _taskService.UpdateTask(task, TaskStatusEnum.AGV_Finish);
                                PutFinish(oldAddress, task.TaskNum);
                            }
                            else
                            {
                                task.CurrentAddress = dt_Station.StationCode;
                                task.NextAddress = "";
                                task.TaskState = TaskStatusEnum.AGV_Finish.ObjToInt();
                                task.DeviceCode = dt_Station.StationDeviceCode;
                                _taskRepository.UpdateData(task);
                            }
                            return agvResponse.OK("成功","0");
                        }
                        break;
                        else
                        {
                            _taskService.TaskCompleted(task.TaskNum);
                            if (task.TaskType==TaskTypeEnum.PrintYLOutbound.ObjToInt())
                            {
                                PutFinish(task.NextAddress);
                            }
                            return agvResponse.OK("成功", "0");
                        }
                    default:
                        throw new Exception($"未定义方法名【{agvUpdateModel.TaskState}】");
                }
@@ -235,7 +302,6 @@
                agvResponse.Error(ex.Message);
            }
            return agvResponse;
            //return _taskService.AgvUpdateTask(agvUpdateModel);
        }
        /// <summary>
@@ -245,7 +311,7 @@
        /// <param name="palletType"></param>
        /// <returns></returns>
        [HttpPost, HttpGet, Route("PutRequest"), AllowAnonymous]
        public WebResponseContent PutRequest(string code, int palletType)
        public WebResponseContent PutRequest(string code, int taskNum)
        {
            WebResponseContent content = new WebResponseContent();
            try
@@ -260,17 +326,75 @@
                {
                    return content.Error($"未找到对应设备");
                }
                OtherDevice otherDevice = (OtherDevice)device;
                short Command = otherDevice.GetValue<R_ConveyorLineCPDB, short>(R_ConveyorLineCPDB.Command, stationManger.StationCode);
                if (Command == 3)
                if (device.DeviceCode.Contains("Plate"))
                {
                    content.OK("允许放料");
                    CommonConveyorLine commonConveyorLine = (CommonConveyorLine)device;
                    StackPlateTaskCommandCommand command = commonConveyorLine.ReadCustomer<StackPlateTaskCommandCommand>(device.DeviceCode);
                    if (command != null && command.State == 2 && command.InteractiveSignal == 1)
                    {
                        return content.OK("允许放料");
                    }
                    else
                    {
                        return content.Error("禁止放料");
                    }
                }
                else
                {
                    return content.Error("禁止放料");
                    OtherDevice otherDevice = (OtherDevice)device;
                    if (device.DeviceCode.Contains("CP"))//成品输送线
                    {
                        short Command = otherDevice.GetValue<R_ConveyorLineCPDB, short>(R_ConveyorLineCPDB.Command, stationManger.StationCode);
                        if (Command == 3)
                        {
                            content.OK("允许放料");
                        }
                        else
                        {
                            return content.Error("禁止放料");
                        }
                    }
                    else if (device.DeviceCode.Contains("Coveryor"))//接驳台
                    {
                        bool RequestPut = otherDevice.GetValue<CoveryorDB, bool>(CoveryorDB.C_RequestPut, stationManger.StationDeviceCode);
                        if (!RequestPut)
                        {
                            otherDevice.SetValue(CoveryorDB.C_InTaskNum, taskNum, stationManger.StationDeviceCode);
                            otherDevice.SetValue(CoveryorDB.C_RequestPut, true, stationManger.StationDeviceCode);
                            Thread.Sleep(1000);
                        }
                        bool AllowFinish = otherDevice.GetValue<CoveryorDB, bool>(CoveryorDB.C_AllowFinish, stationManger.StationDeviceCode);
                        if (AllowFinish)
                        {
                            content.OK("允许放料");
                        }
                        else
                        {
                            return content.Error("禁止放料");
                        }
                    }
                    else if (device.DeviceCode.Contains("Retract"))//伸缩货叉
                    {
                        bool RequestPut = otherDevice.GetValue<RetractDB, bool>(RetractDB.Ret_RequestPut, stationManger.StationDeviceCode);
                        if (!RequestPut)
                        {
                            otherDevice.SetValue(RetractDB.Ret_TargetAddress, Convert.ToInt16(stationManger.StationCode), stationManger.StationDeviceCode);
                            otherDevice.SetValue(RetractDB.Ret_RequestPut, true, stationManger.StationDeviceCode);
                            Thread.Sleep(1000);
                        }
                        bool AllowFinish = otherDevice.GetValue<RetractDB, bool>(RetractDB.Ret_AllowFinish, stationManger.StationDeviceCode);
                        if (AllowFinish)
                        {
                            content.OK("允许放料");
                        }
                        else
                        {
                            return content.Error("禁止放料");
                        }
                    }
                }
                return content;
            }
@@ -287,11 +411,11 @@
        /// <param name="code"></param>
        /// <returns></returns>
        [HttpPost, HttpGet, Route("PutFinish"), AllowAnonymous]
        public WebResponseContent PutFinish(string code)
        public WebResponseContent PutFinish(string code,int taskNum=0)
        {
            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($"未找到站台配置");
@@ -301,9 +425,24 @@
                {
                    return WebResponseContent.Instance.Error($"未找到对应设备");
                }
                OtherDevice otherDevice = (OtherDevice)device;
                otherDevice.SetValue(GroundStationDBName.W_PutFinish, true, stationManger.StationCode);
                if (device.DeviceCode.Contains("Plate"))
                {
                    CommonConveyorLine commonConveyorLine = (CommonConveyorLine)device;
                    commonConveyorLine.SetValue(StackPlateDBName.WriteInteractiveSignal, Convert.ToInt16(1), device.DeviceCode);
                    return WebResponseContent.Instance.OK();
                }
                else
                {
                    OtherDevice otherDevice = (OtherDevice)device;
                    if (device.DeviceCode.Contains("Coveryor"))//接驳台
                    {
                        otherDevice.SetValue(CoveryorDB.C_PutFinish, true, stationManger.StationDeviceCode);
                    }
                    else if (device.DeviceCode.Contains("Retract"))//伸缩货叉
                    {
                        otherDevice.SetValue(RetractDB.Ret_PutFinish, true, stationManger.StationDeviceCode);
                    }
                }
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
@@ -321,45 +460,79 @@
        [HttpPost, HttpGet, Route("TakeRequest"), AllowAnonymous]
        public WebResponseContent TakeRequest(string code)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.AGVStationCode == 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)
                if (device.DeviceCode.Contains("Plate"))
                {
                    otherDevice.SetValue(GroundStationDBName.W_TakeRequest, true, stationManger.StationCode);
                    return WebResponseContent.Instance.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)
                    CommonConveyorLine commonConveyorLine = (CommonConveyorLine)device;
                    StackPlateTaskCommandCommand command = commonConveyorLine.ReadCustomer<StackPlateTaskCommandCommand>(device.DeviceCode);
                    if (command != null&&command.State == 2 && command.InteractiveSignal == 2)
                    {
                        return WebResponseContent.Instance.OK();
                        return content.OK("允许取料");
                    }
                    else
                    {
                        return WebResponseContent.Instance.Error($"取货申请中");
                        return content.Error("禁止取料");
                    }
                }
                else
                {
                    OtherDevice otherDevice = (OtherDevice)device;
                    if (otherDevice.DeviceCode.Contains("CP"))//成品输送线
                    {
                        short Command = otherDevice.GetValue<R_ConveyorLineCPDB, short>(R_ConveyorLineCPDB.Command, stationManger.StationCode);
                        if (Command == 2)
                        {
                            content.OK("允许取料");
                        }
                        else
                        {
                            return content.Error("禁止取料");
                        }
                    }
                    else if (device.DeviceCode.Contains("Coveryor"))//接驳台
                    {
                        bool AllowTake = otherDevice.GetValue<CoveryorDB, bool>(CoveryorDB.C_AllowTake, stationManger.StationDeviceCode);
                        if (AllowTake)
                        {
                            content.OK("允许取料");
                        }
                        else
                        {
                            return content.Error("禁止取料");
                        }
                    }
                    else if (device.DeviceCode.Contains("Retract"))//伸缩货叉
                    {
                        bool AllowTake = otherDevice.GetValue<RetractDB, bool>(RetractDB.Ret_AllowTake, stationManger.StationDeviceCode);
                        if (AllowTake)
                        {
                            content.OK("允许取料");
                        }
                        else
                        {
                            return content.Error("禁止取料");
                        }
                    }
                }
                return content;
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
                return content.Error(ex.Message);
            }
        }
@@ -374,7 +547,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($"未找到站台配置");
@@ -384,11 +557,29 @@
                {
                    return WebResponseContent.Instance.Error($"未找到对应设备");
                }
                if (device.DeviceCode.Contains("Plate"))
                {
                    CommonConveyorLine commonConveyorLine = (CommonConveyorLine)device;
                    commonConveyorLine.SetValue(StackPlateDBName.WriteInteractiveSignal, Convert.ToInt16(2), device.DeviceCode);
                    return WebResponseContent.Instance.OK();
                }
                else
                {
                    OtherDevice otherDevice = (OtherDevice)device;
                    if (device.DeviceCode.Contains("CP"))
                    {
                        otherDevice.SetValue(W_ConveyorLineCPDB.W_Command, 2, stationManger.StationCode);
                    }
                    else if (device.DeviceCode.Contains("Coveryor"))
                    {
                        otherDevice.SetValue(CoveryorDB.C_TakeFinish, true, stationManger.StationDeviceCode);
                    }
                    else if (device.DeviceCode.Contains("Retract"))//伸缩货叉
                    {
                        otherDevice.SetValue(RetractDB.Ret_TakeFinish, true, stationManger.StationDeviceCode);
                    }
                }
                OtherDevice otherDevice = (OtherDevice)device;
                otherDevice.SetValue(GroundStationDBName.W_TakeFinish, true, stationManger.StationCode);
                Thread.Sleep(1000);
                otherDevice.SetValue(GroundStationDBName.W_TakeFinish, false, stationManger.StationCode);
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)