huangxiaoqiang
10 小时以前 16749e23b489ee24f993fe9e87346680b7bcf63a
ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs
@@ -37,12 +37,12 @@
        private readonly ICacheService _cacheService;
        private readonly INoticeService _noticeService;
        private readonly IDt_StationManagerRepository _stationManagerRepository;
        private readonly ITask_HtyRepository _htyRepository;
        private readonly ITask_HtyRepository _task_htyRepository;
        private readonly ISys_ConfigService _sys_ConfigService;
        private static List<string>? userTokenIds;
        private static List<int>? userIds;
        public CommonStackerCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, ICacheService cacheService, INoticeService noticeService, IDt_StationManagerRepository stationManagerRepository, ITask_HtyRepository htyRepository, ISys_ConfigService sys_ConfigService)
        public CommonStackerCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, ICacheService cacheService, INoticeService noticeService, IDt_StationManagerRepository stationManagerRepository, ITask_HtyRepository task_htyRepository, ISys_ConfigService sys_ConfigService)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
@@ -51,7 +51,7 @@
            _cacheService = cacheService;
            _noticeService = noticeService;
            _stationManagerRepository = stationManagerRepository;
            _htyRepository = htyRepository;
            _task_htyRepository = task_htyRepository;
            _sys_ConfigService = sys_ConfigService;
        }
@@ -233,29 +233,39 @@
                    var task = _taskRepository.QueryFirst(x => x.TaskNum == e.TaskNum);
                    if (task == null) commonStackerCrane.SetValue(StackerCraneDBName.FinishConfirm, 1);
                    string x = $"【{commonStackerCrane.StackerCraneWorkStatusValue}】";
                    //if(task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
                    //{
                    //    CommonConveyorLine? conveyorLine = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1001") as CommonConveyorLine;
                    //    if (conveyorLine != null)
                    //    {
                    //        short InteractiveSignal = conveyorLine.GetValue<ConveyorLineDBName, short>(ConveyorLineDBName.InteractiveSignal, "101");
                    //        var structs = BitConverter.GetBytes(InteractiveSignal).Reverse().ToArray().ToBoolArray();
                    //        if (structs[0])
                    //        {
                    //            conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTaskNum, "9999", "101");
                    //        }
                    //    }
                    //}
                    string WorkStatus = $"【{commonStackerCrane.StackerCraneWorkStatusValue}】";
                    var content = _taskService.StackCraneTaskCompleted(e.TaskNum);
                    if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
                    {
                        CommonConveyorLine? conveyorLine = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1001") as CommonConveyorLine;
                        if (conveyorLine != null)
                        {
                            short InteractiveSignal = conveyorLine.GetValue<ConveyorLineDBName, short>(ConveyorLineDBName.InteractiveSignal, "LK001");
                            var structs = BitConverter.GetBytes(InteractiveSignal).Reverse().ToArray().ToBoolArray();
                            if (structs[0])
                            {
                                bool x = conveyorLine.Communicator.WriteNoRead("DB100.0", 9999);
                                if (!x)
                                {
                                    return;
                                }
                            }
                        }
                        var station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.TargetAddress);
                        if (station != null)
                        {
                            _taskService.SendAgvTask(station.stationRemark, task.TaskNum);
                            _taskService.UpdateTaskStatusToNext(task.TaskNum);
                        }
                    }
                    var isWorkType = commonStackerCrane.SetValue(StackerCraneDBName.FinishConfirm, 1);
                    str = $"{commonStackerCrane.DeviceName}】WMS|WCS任务完成:【{content.Status}{content.Message}】,堆垛机完成信号写入:【{isWorkType}】,任务号:【{e.TaskNum}】时间【{DateTime.Now}】";
                    WriteInfo(commonStackerCrane.DeviceName, str+x);
                    WriteInfo(commonStackerCrane.DeviceName, str + WorkStatus);
                    ConsoleHelper.WriteColorLine(str, ConsoleColor.Blue);
                }
            }
@@ -298,30 +308,44 @@
            if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
            {
                //    // æ£€æŸ¥å½“前出库任务站台是否允许放货
                //    var occupiedStation = OutTaskStationIsOccupied(task);
                //    if (occupiedStation == null)
                //    {
                //        // å¦‚果当前出库任务站台不允许放货,排除当前任务,查找其他出库任务
                //        var log = $"任务号:【{task.TaskNum}】出库地址:【{task.NextAddress}】不允许放货";
                //        ConsoleHelper.WriteErrorLine(log);
                //        _noticeService.Logs(userTokenIds, new { commonStackerCrane.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
                //        WriteInfo(commonStackerCrane.DeviceName, log);
                //        task = FindAnotherOutboundTask(commonStackerCrane.DeviceCode, task.TaskId);
                //        if (task == null)
                //        {
                //            task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
                //        }
                //    }
                //    else
                //    {
                //        return task;
                //    }
                return task;
                var InTask = _taskRepository.QueryFirst(x => x.TaskState > (int)TaskInStatusEnum.InNew && x.TaskState< (int)TaskInStatusEnum.SC_InExecuting);
                var OutTask = _taskRepository.QueryFirst(x => x.TaskState > (int)TaskOutStatusEnum.OutNew && x.TaskState < (int)TaskOutStatusEnum.AGV_OutExecuting);
                if (InTask != null)
                {
                    return null;
                }
                else if (OutTask != null)
                {
                    return null;
                }
                else
                {
                    CommonConveyorLine? conveyorLine = Storage.Devices.FirstOrDefault(x=>x.DeviceCode =="1001") as CommonConveyorLine;
                    if (conveyorLine != null)
                    {
                        short InteractiveSignal = conveyorLine.GetValue<ConveyorLineDBName, short>(ConveyorLineDBName.InteractiveSignal, "LK001");
                        var structs = BitConverter.GetBytes(InteractiveSignal).Reverse().ToArray().ToBoolArray();
                        if (structs[0] && !structs[2] && !structs[1])
                        {
                            conveyorLine.Communicator.WriteNoRead("DB100.0", 9990);
                        }
                        if (structs[0] && structs[2])
                        {
                            conveyorLine.Communicator.WriteNoRead("DB100.0", 9990);
                            return task;
                        }
                        else
                        {
                            task.ExceptionMessage = "请检查输送线是否是自动模式或已经移动到出库口";
                            return null;
                        }
                    }
                    else
                    {
                        task.ExceptionMessage = "输送线设备断开连接";
                        return null;
                    }
                }
            }
            else if (task == null)
            {
@@ -412,7 +436,8 @@
            stackerCraneTaskCommand.StartCommand = Convert.ToInt16(1);
            if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//判断是否是入库任务
            {
                string[] sourceCodes = task.CurrentAddress.Split("-");
                var station = _stationManagerRepository.QueryFirst(x => x.stationType == 1 && x.stationChildCode == task.CurrentAddress);
                string[] sourceCodes = station.stationLocation.Split("-");
                if (sourceCodes.Length == 3)
                {
                    stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]) % 2 != 0 ? (short)1 : (short)2;
@@ -425,7 +450,6 @@
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"出库任务起点错误,起点:【{task.CurrentAddress}】");
                    return null;
                }
                string[] targetCodes = task.NextAddress.Split("-");
                if (targetCodes.Length == 3)
                {
@@ -455,8 +479,8 @@
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"出库任务起点错误,起点:【{task.CurrentAddress}】");
                    return null;
                }
                string[] targetCodes = task.NextAddress.Split("-");
                var station = _stationManagerRepository.QueryFirst(x => x.stationType == 1 && x.stationChildCode == task.NextAddress);
                string[] targetCodes = station.stationLocation.Split("-");
                if (targetCodes.Length == 3)
                {
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]) % 2 != 0 ? (short)1 : (short)2;