hutongqing
2024-08-26 569e91c63636345391f741df049c9374a141a434
WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
@@ -15,6 +15,7 @@
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
using AutoMapper;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using Quartz;
using System;
@@ -22,6 +23,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_IBasicInfoService;
using WIDESEAWCS_ITaskInfoService;
@@ -38,12 +40,14 @@
        private readonly ITaskService _taskService;
        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
        private readonly IRouterService _routerService;
        private readonly IMapper _mapper;
        public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService)
        public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
            _routerService = routerService;
            _mapper = mapper;
        }
        public Task Execute(IJobExecutionContext context)
@@ -51,53 +55,113 @@
            try
            {
                CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
                //if (conveyorLine != null)
                //{
                //    List<string> childDeviceCodes = _routerService.QueryAllPositions(conveyorLine.DeviceCode);
                if (conveyorLine != null)
                {
                    List<string> childDeviceCodes = _routerService.QueryAllPositions(conveyorLine.DeviceCode);
                //    foreach (string childDeviceCode in childDeviceCodes)
                //    {
                //        ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(childDeviceCode);
                //        if (command != null)
                //        {
                //            DeviceProtocolDetailDTO? deviceProtocolDetail = conveyorLine.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.ProtocalDetailValue == command.InteractiveSignal.ToString());
                //            if (deviceProtocolDetail != null)
                //            {
                //                SignalType signalType = Enum.Parse<SignalType>(deviceProtocolDetail.ProtocolDetailType);
                //                switch (signalType)
                //                {
                //                    case SignalType.InEntranceRequest:
                    foreach (string childDeviceCode in childDeviceCodes)
                    {
                        ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(childDeviceCode);
                        if (command != null)
                        {
                            List<int> signalTypes = Enum.GetValues(typeof(PLCSignalType)).Cast<int>().ToList();
                            if (!signalTypes.Contains(command.InteractiveSignal))
                            {
                                continue;
                            }
                //                        break;
                //                    case SignalType.InEntranceRequestReset:
                            DeviceProtocolDetailDTO? deviceProtocolDetail = conveyorLine.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.ProtocalDetailValue == command.InteractiveSignal.ToString() && x.DeviceProParamName == nameof(ConveyorLineTaskCommand.InteractiveSignal));
                            if (deviceProtocolDetail != null)
                            {
                                PLCSignalType signalType = Enum.Parse<PLCSignalType>(deviceProtocolDetail.ProtocolDetailType);
                                switch (signalType)
                                {
                                    case PLCSignalType.RequestInbound:
                                        {
                                            if (_taskService.RequestWMsTask(command.Barcode, childDeviceCode).Status)
                                            {
                                                Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
                                                if (task != null)
                                                {
                                                    ConveyorLineTaskCommand taskCommand = _mapper.Map<ConveyorLineTaskCommand>(task);
                                                    taskCommand.InteractiveSignal = command.InteractiveSignal;
                                                    bool t = conveyorLine.SendCommand(taskCommand, childDeviceCode);
                //                        break;
                //                    case SignalType.OutEntranceRequest:
                                                    _taskService.UpdateTaskStatusToNext(task.TaskNum);
                                                }
                                            }
                                        }
                                        break;
                                    case PLCSignalType.RequestInNextAddress:
                                        {
                                            Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
                                            if (task != null)
                                            {
                                                Dt_Task? newTask = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress);
                                                if (newTask != null)
                                                {
                                                    ConveyorLineTaskCommand taskCommand = _mapper.Map<ConveyorLineTaskCommand>(newTask);
                                                    taskCommand.InteractiveSignal = command.InteractiveSignal;
                                                    bool t = conveyorLine.SendCommand(taskCommand, childDeviceCode);
                                                }
                                            }
                                        }
                                        break;
                                    case PLCSignalType.ConveyorLineInFinish:
                                        {
                                            Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
                                            if (task != null)
                                            {
                                                bool t = conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, 0, childDeviceCode);
                                                WebResponseContent content = _taskService.UpdateTaskStatusToNext(task.TaskNum);
                                                Console.Out.WriteLine(content.Serialize());
                                            }
                                        }
                                        break;
                                    case PLCSignalType.RequestOutbound:
                                        {
                                            Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
                                            if (task != null)
                                            {
                                                ConveyorLineTaskCommand taskCommand = _mapper.Map<ConveyorLineTaskCommand>(task);
                                                taskCommand.InteractiveSignal = command.InteractiveSignal;
                                                bool t = conveyorLine.SendCommand(taskCommand, childDeviceCode);
                //                        break;
                //                    case SignalType.OutEntranceRequestReset:
                //                        break;
                //                    case SignalType.InStationRequest:
                //                        break;
                //                    case SignalType.InStationRequestReset:
                //                        break;
                //                    case SignalType.OutStationRequest:
                //                        break;
                //                    case SignalType.OutStationRequestReset:
                //                        break;
                //                    default:
                //                        break;
                //                }
                //            }
                //        }
                //    }
                //}
                                                _taskService.UpdateTaskStatusToNext(task.TaskNum);
                                            }
                                        }
                                        break;
                                    case PLCSignalType.RequestOutNextAddress:
                                        {
                                            Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
                                            if (task != null)
                                            {
                                                Dt_Task? newTask = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress);
                                                if (newTask != null)
                                                {
                                                    ConveyorLineTaskCommand taskCommand = _mapper.Map<ConveyorLineTaskCommand>(newTask);
                                                    taskCommand.InteractiveSignal = command.InteractiveSignal;
                                                    bool t = conveyorLine.SendCommand(taskCommand, childDeviceCode);
                                                }
                                            }
                                        }
                                        break;
                                    case PLCSignalType.ConveyorLineOutFinish:
                                        {
                                            Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
                                            if (task != null)
                                            {
                                                bool t = conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, 0, childDeviceCode);
                                                WebResponseContent content = _taskService.UpdateTaskStatusToNext(task.TaskNum);
                                                Console.Out.WriteLine(content.Serialize());
                                            }
                                        }
                                        break;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)