liulijun
2025-11-24 9086b238cd9fbb9fbeae7cab11d59576cd9d2853
ÏîÄ¿´úÂë/WCS/WCSServices/WIDESEAWCS_Server/Controllers/AGV/AGVController.cs
@@ -2,12 +2,15 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Text;
using System.Text.RegularExpressions;
using WIDESEA_DTO.Agv;
using WIDESEA_External.Model;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Enums;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_Core.LogHelper;
using WIDESEAWCS_DTO;
using WIDESEAWCS_DTO.Agv;
using WIDESEAWCS_IBasicInfoRepository;
using WIDESEAWCS_ITaskInfoRepository;
@@ -20,6 +23,7 @@
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
@@ -68,7 +72,7 @@
                    }
                    else//出库放货请求
                    {
                        var content = PutRequest(task.NextAddress, task.PalletType);
                        var content = PutRequest(task.NextAddress, task);
                        if (!content.Status)
                        {
                            throw new Exception(content.Message);
@@ -87,7 +91,7 @@
                    }
                    else//入库放货请求
                    {
                        var content = PutRequest(task.NextAddress, task.TaskNum);
                        var content = PutRequest(task.NextAddress, task);
                        if (!content.Status)
                        {
                            throw new Exception(content.Message);
@@ -239,7 +243,7 @@
                        }
                        else
                        {
                            if (task.TaskType == TaskTypeEnum.PrintInbound.ObjToInt() || task.TaskType == TaskTypeEnum.PrintBackInbound.ObjToInt())
                            if (task.TaskType == TaskTypeEnum.PrintYLInbound.ObjToInt() || task.TaskType == TaskTypeEnum.PrintYLBackInbound.ObjToInt())
                            {
                                var content = TakeFinish(task.CurrentAddress);
                                if (!content.Status)
@@ -257,7 +261,7 @@
                            {
                                throw new Exception($"{task.NextAddress}AGV站台未定义");
                            }
                            if (task.TaskType == TaskTypeEnum.PrintInbound.ObjToInt() || task.TaskType == TaskTypeEnum.PrintBackInbound.ObjToInt())
                            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();
@@ -286,7 +290,7 @@
                        else
                        {
                            _taskService.TaskCompleted(task.TaskNum);
                            if (task.TaskType==TaskTypeEnum.PrintOutbound.ObjToInt())
                            if (task.TaskType==TaskTypeEnum.PrintYLOutbound.ObjToInt() || task.TaskType == TaskTypeEnum.OutCarton.ObjToInt())
                            {
                                PutFinish(task.NextAddress);
                            }
@@ -310,7 +314,7 @@
        /// <param name="palletType"></param>
        /// <returns></returns>
        [HttpPost, HttpGet, Route("PutRequest"), AllowAnonymous]
        public WebResponseContent PutRequest(string code, int taskNum)
        public WebResponseContent PutRequest(string code, Dt_Task task)
        {
            WebResponseContent content = new WebResponseContent();
            try
@@ -320,65 +324,131 @@
                {
                    return content.Error($"未找到站台配置");
                }
                #region todo:临时逻辑
                if (stationManger.StationDeviceCode=="MES")
                {
                    RequestAGVArriveDTO requestAGVArriveDTO =new RequestAGVArriveDTO()
                    {
                        SD_WorkCentreAgvArriveNoticeInfo=new List<AgvArriveNotice> { new AgvArriveNotice()
                        {
                            DispatchPlanMaterialId=task.DispatchPlanId,
                            WorkCentreCode=task.WorkCentreCode,
                            LocationCode=code,
                            CallId=Guid.NewGuid().ToString().Replace("-","")
                        } }
                    };
                    MESResponse response = _taskService.MESAvgArriveNotice(requestAGVArriveDTO).DeserializeObject<MESResponse>() ?? throw new Exception("未获取到返回信息");
                    if (!response.Result)
                    {
                        throw new Exception($"调用MES小车允许放货报错,MES返回信息"+ Regex.Replace(response.Msg, @"\\u([0-9a-fA-F]{4})", match => {
                            return ((char)Convert.ToInt32(match.Groups[1].Value, 16)).ToString();
                        }));
                    }
                    if (response.Obj)
                    {
                        return content.Error($"允许取料");
                    }
                    else
                    {
                        return content.Error($"禁止放料");
                    }
                }
                #endregion
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode);
                if (device == null)
                {
                    return content.Error($"未找到对应设备");
                }
                if (device.DeviceCode.Contains("Plate"))
                {
                    CommonConveyorLine commonConveyorLine = (CommonConveyorLine)device;
                    StackPlateTaskCommandCommand command = commonConveyorLine.ReadCustomer<StackPlateTaskCommandCommand>(device.DeviceCode);
                OtherDevice otherDevice = (OtherDevice)device;
                    if (command != null && command.State == 2 && command.InteractiveSignal == 1)
                    {
                        return content.OK("允许放料");
                    }
                    else
                    {
                        return content.Error("禁止放料");
                    }
                }
                else
                {
                if (device.DeviceCode.Contains("CP"))//成品输送线
                {
                    short Command = otherDevice.GetValue<R_ConveyorLineCPDB, short>(R_ConveyorLineCPDB.Command, stationManger.StationCode);
                    if (Command == 3)
                    OtherDevice otherDevice = (OtherDevice)device;
                    if (device.DeviceCode.Contains("CP"))//成品输送线
                    {
                        content.OK("允许放料");
                        short Command = otherDevice.GetValue<R_ConveyorLineCPDB, short>(R_ConveyorLineCPDB.Command, stationManger.StationCode);
                        if (Command == 3)
                        {
                            content.OK("允许放料");
                        }
                        else
                        {
                            return content.Error("禁止放料");
                        }
                    }
                    else
                    else if (device.DeviceCode.Contains("Coveryor"))//接驳台
                    {
                        return content.Error("禁止放料");
                        bool RequestPut = otherDevice.GetValue<CoveryorDB, bool>(CoveryorDB.C_RequestPut, stationManger.StationDeviceCode);
                        if (!RequestPut)
                        {
                            otherDevice.SetValue(CoveryorDB.C_InTaskNum, task.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("禁止放料");
                        }
                    }
                    else if (device.DeviceCode.Contains("TrussCarton"))//桁架
                    {
                        bool RequestPut = otherDevice.GetValue<W_TrussCartonDB, bool>(GetCartonRequest(stationManger.StackerCraneStationCode), stationManger.StationDeviceCode);
                        if (!RequestPut)
                        {
                            otherDevice.SetValue(GetCartonRequest(stationManger.StackerCraneStationCode), true, stationManger.StationDeviceCode);
                            Thread.Sleep(1000);
                        }
                        bool AllowFinish = otherDevice.GetValue<R_TrussCartonDB, bool>(GetCarton(stationManger.StackerCraneStationCode), stationManger.StationDeviceCode);
                        if (AllowFinish)
                        {
                            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;
            }
            catch (Exception ex)
@@ -408,21 +478,103 @@
                {
                    return WebResponseContent.Instance.Error($"未找到对应设备");
                }
                OtherDevice otherDevice = (OtherDevice)device;
                if (device.DeviceCode.Contains("Coveryor"))//接驳台
                if (device.DeviceCode.Contains("Plate"))
                {
                    otherDevice.SetValue(CoveryorDB.C_PutFinish, true, stationManger.StationDeviceCode);
                    CommonConveyorLine commonConveyorLine = (CommonConveyorLine)device;
                    commonConveyorLine.SetValue(StackPlateDBName.WriteInteractiveSignal, Convert.ToInt16(1), device.DeviceCode);
                    return WebResponseContent.Instance.OK();
                }
                else if (device.DeviceCode.Contains("Retract"))//伸缩货叉
                else
                {
                    otherDevice.SetValue(RetractDB.Ret_PutFinish, true, stationManger.StationDeviceCode);
                    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);
                    }
                    else if (device.DeviceCode.Contains("TrussCarton"))//纸箱桁架
                    {
                        otherDevice.SetValue(GetCartonPut(stationManger.StackerCraneStationCode), true, stationManger.StationDeviceCode);
                    }
                }
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
        /// <summary>
        /// èŽ·å–æ¡æž¶æ”¾æ–™ä¿¡å·
        /// </summary>
        public W_TrussCartonDB GetCartonPut(string StationCode)
        {
            switch (StationCode)
            {
                case "1":
                    return W_TrussCartonDB.W_CartonPut1;
                case "2":
                    return W_TrussCartonDB.W_CartonPut2;
                case "3":
                    return W_TrussCartonDB.W_CartonPut3;
                case "4":
                    return W_TrussCartonDB.W_CartonPut4;
                case "5":
                    return W_TrussCartonDB.W_CartonPut5;
                case "6":
                    return W_TrussCartonDB.W_CartonPut6;
                default:
                    throw new Exception("未定义工位");
            }
        }
        /// <summary>
        /// èŽ·å–æ¡æž¶è¯·æ±‚ä¿¡å·
        /// </summary>
        public W_TrussCartonDB GetCartonRequest(string StationCode)
        {
            switch (StationCode)
            {
                case "1":
                    return W_TrussCartonDB.W_CartonRequest1;
                case "2":
                    return W_TrussCartonDB.W_CartonRequest2;
                case "3":
                    return W_TrussCartonDB.W_CartonRequest3;
                case "4":
                    return W_TrussCartonDB.W_CartonRequest4;
                case "5":
                    return W_TrussCartonDB.W_CartonRequest5;
                case "6":
                    return W_TrussCartonDB.W_CartonRequest6;
                default:
                    throw new Exception("未定义工位");
            }
        }
        /// <summary>
        /// èŽ·å–æ¡æž¶è¿›å…¥ä¿¡å·
        /// </summary>
        public R_TrussCartonDB GetCarton(string StationCode)
        {
            switch (StationCode)
            {
                case "1":
                    return R_TrussCartonDB.R_CartonAllow1;
                case "2":
                    return R_TrussCartonDB.R_CartonAllow2;
                case "3":
                    return R_TrussCartonDB.R_CartonAllow3;
                case "4":
                    return R_TrussCartonDB.R_CartonAllow4;
                case "5":
                    return R_TrussCartonDB.R_CartonAllow5;
                case "6":
                    return R_TrussCartonDB.R_CartonAllow6;
                default:
                    throw new Exception("未定义工位");
            }
        }
@@ -448,46 +600,61 @@
                {
                    return WebResponseContent.Instance.Error($"未找到对应设备{stationManger.StationDeviceCode}");
                }
                OtherDevice otherDevice = (OtherDevice)device;
                if (otherDevice.DeviceCode.Contains("CP"))//成品输送线
                if (device.DeviceCode.Contains("Plate"))
                {
                    short Command = otherDevice.GetValue<R_ConveyorLineCPDB, short>(R_ConveyorLineCPDB.Command, stationManger.StationCode);
                    if (Command == 2)
                    CommonConveyorLine commonConveyorLine = (CommonConveyorLine)device;
                    StackPlateTaskCommandCommand command = commonConveyorLine.ReadCustomer<StackPlateTaskCommandCommand>(device.DeviceCode);
                    if (command != null&&command.State == 2 && command.InteractiveSignal == 2)
                    {
                        content.OK("允许取料");
                        return content.OK("允许取料");
                    }
                    else
                    {
                        return content.Error("禁止取料");
                    }
                }
                else if (device.DeviceCode.Contains("Coveryor"))//接驳台
                else
                {
                    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("禁止取料");
                    }
                }
                    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)
@@ -496,7 +663,6 @@
            }
        }
        //[HttpPost, HttpGet, Route("TakeFinish"), AllowAnonymous]
        /// <summary>
        /// å–货完成
        /// </summary>
@@ -517,19 +683,27 @@
                {
                    return WebResponseContent.Instance.Error($"未找到对应设备");
                }
                OtherDevice otherDevice = (OtherDevice)device;
                if (device.DeviceCode.Contains("CP"))
                if (device.DeviceCode.Contains("Plate"))
                {
                    otherDevice.SetValue(W_ConveyorLineCPDB.W_Command, 2, stationManger.StationCode);
                    CommonConveyorLine commonConveyorLine = (CommonConveyorLine)device;
                    commonConveyorLine.SetValue(StackPlateDBName.WriteInteractiveSignal, Convert.ToInt16(2), device.DeviceCode);
                    return WebResponseContent.Instance.OK();
                }
                else if (device.DeviceCode.Contains("Coveryor"))
                else
                {
                    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;
                    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);
                    }
                }
                return WebResponseContent.Instance.OK();