huanghongfeng
7 天以前 8c8a68df710d568f5f2b358c1e8c4b4799547d0b
´úÂë¹ÜÀí/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/RgvOperationService.cs
@@ -48,15 +48,19 @@
using WIDESEAWCS_QuartzJob.Service;
using System.Net;
using WIDESEAWCS_ISystemServices;
using System.Security.Claims;
using WIDESEAWCS_Common.TaskEnum;
namespace WIDESEAWCS_TaskInfoService
{
    public class RgvOperationService : ServiceBase<Dt_Task_hty, ITask_HtyRepository>, IRgvOperationService
    {
        private readonly IAgvStationService _gvStationService;
        public RgvOperationService(ITask_HtyRepository BaseDal, IAgvStationService agvStationService) : base(BaseDal)
        private readonly ITaskRepository _taskRepository;
        public RgvOperationService(ITask_HtyRepository BaseDal, IAgvStationService agvStationService, ITaskRepository taskRepository) : base(BaseDal)
        {
            _gvStationService = agvStationService;
            _taskRepository = taskRepository;
        }
@@ -104,17 +108,17 @@
                case "1":  // å·¥ä½œæ¨¡å¼ï¼ˆ0手动、1自动)
                           //获取实例
                    DeviceProDTO? RGV_DWorkingmode = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_DWorkingmode", "DeviceCommand");        //任务类型
                      //第一步写入任务
                                                                                                                                                //第一步写入任务
                    RgvSetLine(Commonstacker, RGV_DWorkingmode.DeviceProAddress, WriteRGVvalue);
                    break;
                case "2":   //复位操作(0不复位、1复位)
                    DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Resetoperation", "DeviceCommand");        //任务类型
                                                                                                                                                //第一步写入任务
                                                                                                                                                    //第一步写入任务
                    RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, WriteRGVvalue);
                    break;
                case "3":   //任务确认完成(0不确定,1确定)
                    DeviceProDTO? RGV_taskcomplete = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_taskcomplete", "RGV_taskcomplete");        //任务类型
                                                                                                                                                //第一步写入任务
                                                                                                                                                   //第一步写入任务
                    RgvSetLine(Commonstacker, RGV_taskcomplete.DeviceProAddress, WriteRGVvalue);
                    break;
                case "4":   //任务类型(4清除)
@@ -163,7 +167,7 @@
        }
        /// <summary>
        /// å†™å…¥å¤ä½ï¼ˆå…¥åº“端)
        /// ä¸€é”®å¯åŠ¨å…¥åº“å­æ¯è½¦
        /// </summary>
        public WebResponseContent WriteInReset(SaveModel saveModel)
        {
@@ -172,7 +176,7 @@
            List<AGVStation> rgvdata = _gvStationService.GetInStroller();
            foreach (AGVStation rgvstation in rgvdata)
            {
                string DeviceName = saveModel.DelKeys[0].ToString();    //设备名称
                string DeviceName = rgvstation.ChildPosiDeviceCode;    //设备名称
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
                if (device == null) continue;
                SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
@@ -200,6 +204,70 @@
                //获取需要复位的设备
                DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Resetoperation", "DeviceCommand");        //复位报警信息
                RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)0);
            }
            return webResponse.OK();
        }
        /// <summary>
        /// ä¸€é”®æš‚停
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public WebResponseContent WriteOutbuttonpause(SaveModel saveModel)
        {
            WebResponseContent webResponse = new WebResponseContent();
            List<AGVStation> rgvdata = _gvStationService.GetOutStroller();
            foreach (AGVStation rgvstation in rgvdata)
            {
                string DeviceName = rgvstation.ChildPosiDeviceCode;    //设备名称
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
                if (device == null) continue;
                SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
                //获取需要复位的设备
                DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_DWorkingmode", "DeviceCommand");
                RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)0);
            }
            return webResponse.OK();
        }
        public WebResponseContent InWriteOutbuttonpause(SaveModel saveModel)
        {
            WebResponseContent webResponse = new WebResponseContent();
            List<AGVStation> rgvdata = _gvStationService.InGetOutStroller();
            foreach (AGVStation rgvstation in rgvdata)
            {
                string DeviceName = rgvstation.ChildPosiDeviceCode;    //设备名称
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
                if (device == null) continue;
                SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
                //获取需要复位的设备
                DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_DWorkingmode", "DeviceCommand");
                RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)0);
            }
            return webResponse.OK();
        }
        /// <summary>
        /// ä¸€é”®å¯åЍ
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public WebResponseContent WriteOuttouchstart(SaveModel saveModel)
        {
            WebResponseContent webResponse = new WebResponseContent();
            List<AGVStation> rgvdata = _gvStationService.GetOutStroller();
            foreach (AGVStation rgvstation in rgvdata)
            {
                string DeviceName = rgvstation.ChildPosiDeviceCode;    //设备名称
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
                if (device == null) continue;
                SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
                //获取需要复位的设备
                DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_DWorkingmode", "DeviceCommand");
                RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)1);
            }
            return webResponse.OK();
@@ -224,7 +292,7 @@
        /// <param name="conveyorLine"></param>
        /// <param name="DeviceProDataBlock"></param>
        /// <returns></returns>
        public static int GetLine(CommonConveyorLine Commonstacker, string DeviceProDataBlock)
        public static int GetLine(SpeStackerCrane Commonstacker, string DeviceProDataBlock)
        {
            return Commonstacker.Communicator.Read<short>(DeviceProDataBlock);
        }
@@ -240,7 +308,189 @@
            return Commonstacker.Communicator.Write<short>(DeviceProDataBlock, rgvvalues);
        }
        /// <summary>
        /// æ­£å¸¸å…¥åº“
        /// </summary>
        public WebResponseContent WriteInNormal(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            Dt_Task dt_Task = _taskRepository.QueryFirst(x => x.TaskState == (int)TaskInStatusEnum.InAbnormalFinish);
            if (dt_Task == null)
            {
               return WebResponseContent.Instance.Error("没有异常入库任务");
            }
            dt_Task.TaskState = (int)TaskInStatusEnum.RGV_InPickupFinish;
            dt_Task.RGVTaskType = (int)RGVTaskTypeEnum.Placing;
            dt_Task.NextAddress = "1021";
            _taskRepository.UpdateData(dt_Task);
            return content;
        }
        /// <summary>
        /// å…¥åº“异常排出
        /// </summary>
        public WebResponseContent WriteInAbnormal(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            Dt_Task dt_Task = _taskRepository.QueryFirst(x => x.TaskState == (int)TaskInStatusEnum.InAbnormalFinish);
            if (dt_Task == null)
            {
                return WebResponseContent.Instance.Error("没有异常入库任务");
            }
            dt_Task.TaskState = (int)TaskInStatusEnum.InexceptionalSelection;
            dt_Task.RGVTaskType = (int)RGVTaskTypeEnum.Placing;
            _taskRepository.UpdateData(dt_Task);
            return content;
        }
        public static List<string> OutStationareaList = new List<string>() { "RGV111", "RGV116", "RGV110", "RGV112", "RGV114", "RGV115", "RGV118" };
        public static List<string> InStationareaList = new List<string>() { "RGV111", "RGV116", "RGV110", "RGV112", "RGV114", "RGV115", "RGV118" };
        /// <summary>
        /// æŸ¥çœ‹æŠ¥è­¦
        /// </summary>
        public bool AQMReadAlarminform(int tasktype)
        {
            var deviceList = tasktype == 1 ? InStationareaList : OutStationareaList;
            foreach (string deviceName in deviceList)
            {
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == deviceName);
                if (device == null) return false;
                SpeStackerCrane stacker = (SpeStackerCrane)device;
                DeviceProDTO? faultInfo = GetRGVDeviceProDTO(stacker, deviceName, "RGV_Faultcode", "ReadDeviceCommand");
                int alarmCode = GetLine(stacker, faultInfo.DeviceProAddress);
                if (alarmCode != 0)
                {
                    return true;
                }
            }
            return false;
        }
        /// <summary>
        /// æŸ¥çœ‹æŠ¥è­¦
        /// </summary>
        public WebResponseContent ReadAlarminformation(SaveModel saveModel)
        {
            WebResponseContent webResponse = new WebResponseContent();
            string DeviceName = saveModel.DelKeys[0].ToString();    //设备名称
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
            if (device == null) return webResponse.Error();
            SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
            DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Faultcode", "ReadDeviceCommand");
            int baoj = GetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress);
            string alarmMessage = "";
            if (DeviceName == "RGV118")
            {
                 alarmMessage = GetAlarmMessage(baoj);
            }
            else if (DeviceName == "RGV111" || DeviceName == "RGV116")
            {
                 alarmMessage = GetAlarmMessage2(baoj);
            }
            else if (DeviceName == "RGV110" || DeviceName == "RGV112" || DeviceName == "RGV114" || DeviceName == "RGV115")
            {
                 alarmMessage = GetAlarmMessage3(baoj);
            }
            return webResponse.OK(data: alarmMessage);
        }
        // æŠ¥è­¦ä»£ç æ˜ å°„方法
        private string GetAlarmMessage(int alarmCode)
        {
            var alarmMessages = new Dictionary<int, string>
            {
        {0, "无报警"},
        {1, "RGV小车急停被按下"},
        {2, "正转雷达报警"},
        {3, "反转雷达报警"},
        {4, "前进限位报警"},
        {5, "后退限位报警"},
        {6, ""},
        {7, "PLC摸块故障"},
        {8, "PLC扩展模块故障"},
        {9, "称重模块故障"},
        {10, "扫码定位故障"},
        {11, "RGV长时间空转故障"},
        {12, "目的地不等于实际位置故障"},
        {13, "与总控通讯故障"},
        {14, "前雷达屏蔽警告"},
        {15, "后雷达屏蔽警告"},
        {16, "行走变频器故障"},
        {17, "伸缩叉变频器故障"},
        {18, "液压单元过载保护故障"},
        {19, "液压上升超时报警"},
        {20, "液压下降超时报警"},
        {21, "伸缩叉伸出超时报警"},
        {22, "伸缩叉缩回超时报警"},
        {23, "外形检测报警"},
        {24, "称重超重报警"},
        {25, "货叉伸出极限限位报警"},
        {26, "货叉缩回极限限位报警"},
        {27, "取货时自身有货物报警"},
        {28, "放货时自身无货物报警"},
        {29, "货叉未回到初始位报警"},
        {30, "触发仅移动命令时货叉不在初始位报警"},
                {31, "货叉到达初始位但中位传感器未检测到报警"}
            };
            return alarmMessages.ContainsKey(alarmCode) ? alarmMessages[alarmCode] : "未知报警代码";
        }
        private string GetAlarmMessage2(int alarmCode)
        {
            var alarmMessages = new Dictionary<int, string>
    {
        {0, "无报警"},
        {1, "RGV小车急停被按下"},
        {2, "前进限位报警"},
        {3, "后退限位报警"},
        {4, "PLC摸块故障"},
        {5, "PLC扩展模块故障"},
        {6, "扫码定位故障"},
        {7, "RGV长时间空转故障"},
        {8, "目的地不等于实际位置故障"},
        {9, "与总控通讯故障"},
        {10, "行走变频器故障"},
        {11, "液压单元过载保护故障"},
        {12, "液压上升超时报警"},
        {13, "液压下降超时报警"},
        {14, "取货时自身有货物报警"},
        {15, "放货时自身无货物报警"},
        {16, "取货检测不到货物报警"}
    };
            return alarmMessages.ContainsKey(alarmCode) ? alarmMessages[alarmCode] : "未知报警代码";
        }
        private string GetAlarmMessage3(int alarmCode)
        {
            var alarmMessages = new Dictionary<int, string>
    {
        {0, "无报警"},
        {1, "RGV小车急停被按下"},
        {2, "前进限位报警"},
        {3, "后退限位报警"},
        {4, "PLC摸块故障"},
        {5, "PLC扩展模块故障"},
        {6, "RGV长时间空转故障"},
        {7, "目的地不等于实际位置故障"},
        {8, "与总控通讯故障"},
        {9, "行走变频器故障"},
        {10, "取货时自身有货物报警"},
        {11, "放货时自身无货物报警"},
        {12, "停止时位置过冲报警"}
    };
            return alarmMessages.ContainsKey(alarmCode) ? alarmMessages[alarmCode] : "未知报警代码";
        }
    }
}