huangxiaoqiang
2025-07-29 f23e0326aa05a1c5b47d4aec4c06e73d0d86b8e7
ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RGVJob/CommonRGVJob.cs
@@ -48,7 +48,7 @@
namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public class CommonRGVJob :JobBase, IJob
    public class CommonRGVJob : JobBase, IJob
    {
        private readonly ITaskService _taskService;
        private readonly ITaskRepository _taskRepository;
@@ -82,15 +82,8 @@
                CommonRGV commonRGV = (CommonRGV)context.JobDetail.JobDataMap.Get("JobParams");
                if (commonRGV != null)
                {
                    //if (!commonRGV.IsEventSubscribed)
                    //{
                    //    commonRGV.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;//订阅任务完成事件
                    //}
                    //commonRGV.CheckStackerCraneTaskCompleted();//防止任务完成事件监测超时,再手动触发一次
                    if (commonRGV.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.WorkCompleted))
                    {
                        var x = commonRGV.GetValue<RGVDBName, short>(RGVDBName.RGVTaskNum);
                        RGVTaskFinish(commonRGV, commonRGV.GetValue<RGVDBName, short>(RGVDBName.RGVTaskNum));
                    }
@@ -122,20 +115,32 @@
                    }
                    var userTokenIds = tokenInfos?.Select(x => x.Token_ID).ToList();
                    var userIds = tokenInfos?.Select(x => x.UserId).ToList();
                    string RGVAutoStatus(bool AutoStatus) => AutoStatus switch
                    {
                        true => "联机模式",
                        false => "单机模式",
                    };
                    string RGVWorkStatus(bool WorkStatus) => WorkStatus switch
                    {
                        true => "运行中",
                        false => "待机",
                    };
                    string RGVStatus(bool Status) => Status switch
                    {
                        true => "故障",
                        false => "正常",
                    };
                    object obj = new
                    {
                        Automatic = commonRGV.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.Automatic),
                        Fault = commonRGV.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.Fault),
                        Running = commonRGV.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.Running),
                        //commonRGV.StackerCraneAutoStatusDes,
                        //commonRGV.StackerCraneWorkStatusDes,
                        //commonRGV.DeviceCode,
                        //commonRGV.DeviceName,
                        //commonRGV.CurrentTaskNum,
                        //commonRGV.LastTaskNum,
                        Automatic = RGVAutoStatus(commonRGV.GetValue<RGVDBName, bool>(RGVDBName.Automatic)),
                        Fault = RGVStatus(commonRGV.GetValue<RGVDBName, bool>(RGVDBName.Fault)),
                        Running = RGVWorkStatus(commonRGV.GetValue<RGVDBName, bool>(RGVDBName.Running)),
                        LevelPoint = commonRGV.GetValue<RGVDBName, int>(RGVDBName.LevelPoint),
                        CurrentTaskNum = commonRGV.GetValue<RGVDBName, short>(RGVDBName.RGVTaskNum),
                        commonRGV.DeviceCode,
                        commonRGV.DeviceName,
                    };
                    _noticeService.StackerData(userIds?.FirstOrDefault(), userTokenIds, new { commonRGV.DeviceName, data = obj });
                    _noticeService.RGVData(userIds?.FirstOrDefault(), userTokenIds, new { commonRGV.DeviceName, data = obj });
                    #endregion è°ƒç”¨äº‹ä»¶æ€»çº¿é€šçŸ¥å‰ç«¯
                }
@@ -146,34 +151,16 @@
            }
            return Task.CompletedTask;
        }
        /// <summary>
        /// ä»»åŠ¡å®Œæˆäº‹ä»¶è®¢é˜…çš„æ–¹æ³•
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommonStackerCrane_StackerCraneTaskCompletedEventHandler(object? sender, WIDESEAWCS_QuartzJob.StackerCrane.StackerCraneTaskCompletedEventArgs e)
        {
            CommonRGV? commonRGV = sender as CommonRGV;
        }
        public void RGVTaskFinish(CommonRGV commonRGV, int TaskNum)
        {
            if (commonRGV != null)
            {
                #region æ—¥å¿—记录
                ConsoleHelper.WriteColorLine($"【{commonRGV.DeviceName}】堆垛机作业状态:【】时间【{DateTime.Now}】", ConsoleColor.Magenta);
                string str = $"【{commonRGV.DeviceName}】任务完成,任务号:【{TaskNum}】时间【{DateTime.Now}】";
                WriteInfo(commonRGV.DeviceName, str);
                ConsoleHelper.WriteColorLine(str, ConsoleColor.Blue);
                #endregion
                var task = _taskRepository.QueryFirst(x => x.TaskNum == TaskNum);
                if (task != null)
                {
                    if (task.TaskState == (int)TaskInStatusEnum.RGV_Indispatch)
                    if (task.TaskState == (int)TaskInStatusEnum.InRetuen)
                    {
                        Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.SourceAddress);
                        if (stationManager != null)
@@ -182,11 +169,41 @@
                            if (device != null)
                            {
                                CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
                                Thread.Sleep(100);
                                var Barcode = conveyorLine.GetValue<ConveyorLineDBName, string>(ConveyorLineDBName.ConveyorLineBarcode, stationManager.stationChildCode);
                                conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, Convert.ToSByte(3), stationManager.stationChildCode);
                                if (Barcode == null)
                                var content = _taskService.RGVTaskCompleted(TaskNum);
                            }
                        }
                    }
                    if (task.TaskState == (int)TaskInStatusEnum.RGV_Indispatch)
                    {
                        if (task.SourceAddress == "3002")
                        {
                            task.TaskState = (int)TaskInStatusEnum.RGV_IndispatchFinish;
                            _taskRepository.UpdateData(task);
                            return;
                        }
                        Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.SourceAddress);
                        if (stationManager != null)
                        {
                            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManager.stationPLC);
                            if (device != null)
                            {
                                CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
                                Thread.Sleep(100);
                                DeviceProDTO? devicePro = conveyorLine.DeviceProDTOs.Where(x => x.DeviceChildCode == stationManager.stationChildCode && x.DeviceProParamName == "ConveyorLineBarcode").FirstOrDefault();
                                var x = conveyorLine.Communicator.Read(devicePro.DeviceProAddress, 5);
                                string Barcode = Encoding.UTF8.GetString(x);
                                if (Barcode == null || Barcode == "")
                                {
                                    conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, Convert.ToSByte(3), stationManager.stationChildCode);
                                    commonRGV.SetValue(StackerCraneDBName.PutcargoLocation, Convert.ToSByte(stationManager.stationRemark));
                                    commonRGV.SetValue(StackerCraneDBName.TaskNum, Convert.ToInt16(task.TaskNum));
                                    //    commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(4));
                                    task.TaskState = (int)TaskInStatusEnum.InRetuen;
                                    _taskRepository.UpdateData(task);
                                    return;
                                }
                                var content = _taskService.RGVTaskCompleted(TaskNum, Barcode);
@@ -195,6 +212,24 @@
                    }
                    else
                    {
                        if (task.TaskState == (int)TaskOutStatusEnum.RGV_OutExecuting)
                        {
                            Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.TargetAddress && x.stationType == 7);
                            if (stationManager != null)
                            {
                                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManager.stationPLC);
                                if (device != null)
                                {
                                    CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
                                    Thread.Sleep(100);
                                    conveyorLine.SetValue(ConveyorLineDBName.ConveyorLineTargetAddress, Convert.ToInt16(stationManager.stationNextChildCode), stationManager.stationChildCode);
                                    Thread.Sleep(100);
                                    conveyorLine.SetValue(ConveyorLineDBName.ConveyorLineTaskNum, Convert.ToInt16(1000), stationManager.stationChildCode);
                                    Thread.Sleep(100);
                                    conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, Convert.ToSByte(2), stationManager.stationChildCode);
                                }
                            }
                        }
                        var content = _taskService.RGVTaskCompleted(TaskNum);
                    }
                }
@@ -211,7 +246,7 @@
            Dt_Task task;
            if (InStock)
            {
                task = _taskService.QueryRGVExecutingTask(commonRGV.DeviceCode);
                task = _taskService.QueryRGVExecutingTask(commonRGV.DeviceCode, commonRGV.GetValue<RGVDBName, short>(RGVDBName.RGVTaskNum));
                if (task != null)
                {
                    return task;
@@ -269,11 +304,9 @@
            rgvTaskCommand.TaskNum = Convert.ToInt16(task.TaskNum);
            if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//判断是否是入库任务
            {
                //rgvTaskCommand.TaskType = (byte)Convert.ToSByte(16);
                //rgvTaskCommand.TaskType = (byte)Convert.ToSByte(64);   é€€å›ž
                if (task.TaskState == (int)TaskInStatusEnum.InNew)
                {
                    Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.SourceAddress);
                    Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.CurrentAddress);
                    rgvTaskCommand.TaskType = (byte)Convert.ToSByte(3);
                    rgvTaskCommand.PickupLocation = (byte)Convert.ToSByte(stationManager.stationRemark);
                }
@@ -291,7 +324,6 @@
            }
            else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
            {
                if (task.TaskState == (int)TaskOutStatusEnum.Line_OutFinish)
                {
                    Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.CurrentAddress);