From 569e91c63636345391f741df049c9374a141a434 Mon Sep 17 00:00:00 2001
From: hutongqing <hutongqing@hnkhzn.com>
Date: 星期一, 26 八月 2024 08:57:33 +0800
Subject: [PATCH] 添加路由新建配置,重新导出种子数据

---
 WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs |  177 +++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 107 insertions(+), 70 deletions(-)

diff --git a/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs b/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
index 2b099b1..8e5b535 100644
--- a/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
+++ b/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
@@ -15,13 +15,17 @@
  *----------------------------------------------------------------*/
 #endregion << 鐗� 鏈� 娉� 閲� >>
 
+using AutoMapper;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
 using Quartz;
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using WIDESEAWCS_Core;
 using WIDESEAWCS_Core.Helper;
+using WIDESEAWCS_IBasicInfoService;
 using WIDESEAWCS_ITaskInfoService;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_QuartzJob;
@@ -35,13 +39,15 @@
     {
         private readonly ITaskService _taskService;
         private readonly ITaskExecuteDetailService _taskExecuteDetailService;
-        private readonly IStationManagerService _stationManagerService;
+        private readonly IRouterService _routerService;
+        private readonly IMapper _mapper;
 
-        public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IStationManagerService stationManagerService)
+        public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper)
         {
             _taskService = taskService;
             _taskExecuteDetailService = taskExecuteDetailService;
-            _stationManagerService = stationManagerService;
+            _routerService = routerService;
+            _mapper = mapper;
         }
 
         public Task Execute(IJobExecutionContext context)
@@ -49,83 +55,114 @@
             try
             {
                 CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
-                List<Dt_StationManager> stationManagers = _stationManagerService.GetStationManagers();
-                foreach (var item in stationManagers)
+                if (conveyorLine != null)
                 {
-                    try
+                    List<string> childDeviceCodes = _routerService.QueryAllPositions(conveyorLine.DeviceCode);
+
+                    foreach (string childDeviceCode in childDeviceCodes)
                     {
-                        ushort value = conveyorLine.GetValue<ConveyorLineDBName, ushort>(ConveyorLineDBName.InteractiveSignal, item.StationCode);
-
-                        DeviceProtocolDetailDTO? deviceProtocolDetail = conveyorLine.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.ProtocalDetailValue == value.ToString());
-
-                        if (deviceProtocolDetail != null)
+                        ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(childDeviceCode);
+                        if (command != null)
                         {
-                            ConveyorLineTaskCommand? command = new ConveyorLineTaskCommand()
+                            List<int> signalTypes = Enum.GetValues(typeof(PLCSignalType)).Cast<int>().ToList();
+                            if (!signalTypes.Contains(command.InteractiveSignal))
                             {
-                                InteractiveSignal = 0,
-                                Barcode = "",
-                                TargetAddress = Convert.ToInt32(item.DeviceCode),
-                                TaskNum = 9988,
-                                TrayType = 3
-                            };
+                                continue;
+                            }
 
-                            SignalType signalType = Enum.Parse<SignalType>(deviceProtocolDetail.ProtocolDetailType);
-                            switch (signalType)
+                            DeviceProtocolDetailDTO? deviceProtocolDetail = conveyorLine.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.ProtocalDetailValue == command.InteractiveSignal.ToString() && x.DeviceProParamName == nameof(ConveyorLineTaskCommand.InteractiveSignal));
+                            if (deviceProtocolDetail != null)
                             {
-                                case SignalType.InEntranceRequest:
-                                    command.Barcode = "InEntranceRequest";
-                                    break;
-                                case SignalType.InEntranceResponse:
-                                    command.Barcode = "InEntranceResponse";
-                                    break;
-                                case SignalType.InEntranceRequestReset:
-                                    command.Barcode = "InEntranceRequestReset";
-                                    break;
-                                case SignalType.OutEntranceRequest:
-                                    command.Barcode = "OutEntranceRequest";
-                                    break;
-                                case SignalType.OutEntranceResponse:
-                                    command.Barcode = "OutEntranceResponse";
-                                    break;
-                                case SignalType.OutEntranceRequestReset:
-                                    command.Barcode = "OutEntranceRequestReset";
-                                    break;
-                                case SignalType.InStationRequest:
-                                    command.Barcode = "InStationRequest";
-                                    break;
-                                case SignalType.InStationResponse:
-                                    command.Barcode = "InStationResponse";
-                                    break;
-                                case SignalType.InStationRequestReset:
-                                    command.Barcode = "InStationRequestReset";
-                                    break;
-                                case SignalType.OutStationRequest:
-                                    command.Barcode = "OutStationRequest";
-                                    break;
-                                case SignalType.OutStationResponse:
-                                    command.Barcode = "OutStationResponse";
-                                    break;
-                                case SignalType.OutStationRequestReset:
-                                    command.Barcode = "OutStationRequestReset";
-                                    break;
-                                default:
-                                    command = null;
-                                    break;
+                                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);
+
+                                                    _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);
+
+                                                _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;
+                                }
                             }
-                            if (command != null)
-                            {
-                                conveyorLine.SendCommand(command, item.StationCode);
-                                Console.Out.WriteLine(command.Serialize());
-                            }
-                                
                         }
-
-                    }
-                    catch (Exception ex)
-                    {
-                        Console.Out.WriteLine(item.StationCode + ":" + ex.ToString());
                     }
                 }
+
             }
             catch (Exception ex)
             {

--
Gitblit v1.9.3