ÏîÄ¿´úÂë/WCS/WCSServices/WIDESEAWCS_Tasks/Ô­ÁÏ¿â/StackerCraneJob_YLSC3.cs
@@ -20,9 +20,11 @@
using WIDESEAWCS_Tasks.StackerCraneJob;
using WIDESEAWCS_Tasks;
using WIDESEAWCS_Core;
using SqlSugar.Extensions;
using WIDESEAWCS_Tasks.ConveyorLineJob;
using WIDESEAWCS_QuartzJob.Repository;
using WIDESEAWCS_Core.Helper;
using HslCommunication.WebSocket;
using WIDESEAWCS_DTO.Equipment;
namespace WIDESEAWCS_Tasks
{
@@ -36,8 +38,9 @@
        private readonly IRouterService _routerService;
        private readonly IRouterRepository _routerRepository;
        private readonly IStationMangerRepository _stationMangerRepository;
        private WebSocketServer _webSocketServer;
        public StackerCraneJob_YLSC3(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository)
        public StackerCraneJob_YLSC3(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository,WebSocketServer webSocketServer)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
@@ -45,6 +48,7 @@
            _routerService = routerService;
            _stationMangerRepository = stationMangerRepository;
            _routerRepository = routerRepository;
            _webSocketServer = webSocketServer;
        }
        public Task Execute(IJobExecutionContext context)
@@ -77,6 +81,7 @@
                                        task.Dispatchertime = DateTime.Now;
                                        task.ExceptionMessage = "";
                                        _taskService.UpdateTask(task, TaskStatusEnum.SC_Executing);
                                        //_taskService.UpdateTaskStatusToNext(task);
                                        commonStackerCrane.Communicator.Write("DB1000.20.0", true);
                                        //延时1s
                                        Thread.Sleep(1000);
@@ -85,6 +90,25 @@
                            }
                        }
                    }
                    #region è°ƒç”¨äº‹ä»¶æ€»çº¿é€šçŸ¥å‰ç«¯
                    EquipmentDTO equipmentDTO = new EquipmentDTO();
                    object obj = new
                    {
                        commonStackerCrane.DeviceName,
                        commonStackerCrane.DeviceCode,
                        StackerCraneAutoStatus.Automatic,
                        StackerCraneStatus.Normal,
                        StackerCraneWorkStatus.Standby,
                        TaskNum = commonStackerCrane.CurrentTaskNum,
                        WorkType = commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType),
                        StackerAlarm = commonStackerCrane.Communicator.Read<short>("DB1000.54.0"),
                    };
                    equipmentDTO.StackerDataJson = obj.Serialize();
                    _webSocketServer.PublishAllClientPayload(equipmentDTO.Serialize());
                    #endregion
                }
            }
            catch (Exception ex)
@@ -137,8 +161,33 @@
                            return WebResponseContent.Instance.Error($"未找到路由信息,{task.NextAddress}");
                        }
                        int oldStatus = task.TaskState;
                        // å †åž›æœºå®Œæˆ
                        _taskService.UpdateTask(task, TaskStatusEnum.Line_Execute, deviceCode: stationManger.StationDeviceCode, currentAddress: stationManger.StationCode, nextAddress: router.NextPosi);
                        //原料一楼出库下发线体逻辑
                        if (stationManger.StationDeviceCode == "CL1_YL")
                        {
                            // å †åž›æœºå®Œæˆ
                            _taskService.UpdateTask(task, TaskStatusEnum.Line_Execute, deviceCode: stationManger.StationDeviceCode, currentAddress: stationManger.StationCode, nextAddress: router.NextPosi);
                        }
                        else//原料二楼出库下发线体逻辑
                        {
                            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode);
                            if (device != null)
                            {
                                CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
                                conveyorLine.SetValue(ConveyorLineDBName.TaskNum, taskNum, stationManger.StationCode);
                                conveyorLine.SetValue(ConveyorLineDBName.TargetAddress, router.NextPosi, stationManger.StationCode);
                                conveyorLine.SetValue(ConveyorLineDBName.Width, task.TaskLength, stationManger.StationCode);
                                conveyorLine.SetValue(ConveyorLineDBName.Barcode, task.PalletCode, stationManger.StationCode);
                                conveyorLine.SetValue(ConveyorLineDBName.ResponState, 86, stationManger.StationCode);
                                _taskService.UpdateTaskStatusToNext(task);
                            }
                            else
                            {
                                WriteInfo(deviceCode, $"未找到出库站台【{stationManger.StationDeviceCode}】对应的通讯对象,无法发送输送线出库信号");
                                _taskService.UpdateTaskExceptionMessage(taskNum, $"未找到出库站台【{stationManger.StationDeviceCode}】对应的通讯对象,无法发送输送线出库信号");
                                return WebResponseContent.Instance.Error($"未找到出库站台【{stationManger.StationDeviceCode}】对应的通讯对象,无法发送输送线出库信号");
                            }
                        }
                        _taskExecuteDetailService.AddTaskExecuteDetail(taskNum, $"系统自动流程,任务状态从【{oldStatus}】转到【{task.TaskState}】");
                        WriteInfo(deviceCode, $"堆垛机出库任务完成,任务号:{taskNum}");
                    }
@@ -244,21 +293,43 @@
            Dt_StationManger? stationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == task.NextAddress && x.StackerCraneCode == task.DeviceCode);
            if (stationManger != null)
            {
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode);
                if (device != null)
                if (stationManger.StationDeviceCode == "CL1_YL")
                {
                    OtherDevice client = (OtherDevice)device;
                    if (client.GetValue<WR_CLineYLDB, short>(WR_CLineYLDB.WR_Request, stationManger.StationCode) != 99)//出库站台未被占用
                    IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode);
                    if (device != null)
                    {
                        task.NextAddress = stationManger.StackerCraneStationCode;
                        _taskRepository.UpdateData(task);
                        return task;
                        OtherDevice client = (OtherDevice)device;
                        if (client.GetValue<WR_CLineYLDB, short>(WR_CLineYLDB.WR_Request, stationManger.StationCode) != 99)//出库站台未被占用
                        {
                            task.NextAddress = stationManger.StackerCraneStationCode;
                            _taskRepository.UpdateData(task);
                            return task;
                        }
                    }
                    else
                    {
                        WriteInfo(task.DeviceCode, $"未找到出库站台【{stationManger.StationDeviceCode}】对应的通讯对象,无法判断出库站台是否被占用");
                        _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"未找到出库站台【{stationManger.StationDeviceCode}】对应的通讯对象,无法判断出库站台是否被占用");
                    }
                }
                else
                {
                    WriteInfo(task.DeviceCode, $"未找到出库站台【{stationManger.StationDeviceCode}】对应的通讯对象,无法判断出库站台是否被占用");
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"未找到出库站台【{stationManger.StationDeviceCode}】对应的通讯对象,无法判断出库站台是否被占用");
                    IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode);
                    if (device != null)
                    {
                        CommonConveyorLine client = (CommonConveyorLine)device;
                        if (client.GetValue<ConveyorLineDBName, short>(ConveyorLineDBName.InteractiveSignal, stationManger.StationCode) != 99)//出库站台未被占用
                        {
                            task.NextAddress = stationManger.StackerCraneStationCode;
                            _taskRepository.UpdateData(task);
                            return task;
                        }
                    }
                    else
                    {
                        WriteInfo(task.DeviceCode, $"未找到出库站台【{stationManger.StationDeviceCode}】对应的通讯对象,无法判断出库站台是否被占用");
                        _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"未找到出库站台【{stationManger.StationDeviceCode}】对应的通讯对象,无法判断出库站台是否被占用");
                    }
                }
            }
            else