From d0f01f571918ae942349068776fa7fb70f3ab5cd Mon Sep 17 00:00:00 2001
From: hutongqing <hutongqing@hnkhzn.com>
Date: 星期三, 28 八月 2024 16:20:18 +0800
Subject: [PATCH] 更新设备信息表从表导入问题

---
 WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs |  191 ++++++++++++++++++++++++++++-------------------
 1 files changed, 115 insertions(+), 76 deletions(-)

diff --git a/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs b/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
index 1e28b0a..cf2f6af 100644
--- a/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
+++ b/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
@@ -15,13 +15,18 @@
  *----------------------------------------------------------------*/
 #endregion << 鐗� 鏈� 娉� 閲� >>
 
+using AutoMapper;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
 using Quartz;
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Reflection;
 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,11 +40,15 @@
     {
         private readonly ITaskService _taskService;
         private readonly ITaskExecuteDetailService _taskExecuteDetailService;
+        private readonly IRouterService _routerService;
+        private readonly IMapper _mapper;
 
-        public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService)
+        public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper)
         {
             _taskService = taskService;
             _taskExecuteDetailService = taskExecuteDetailService;
+            _routerService = routerService;
+            _mapper = mapper;
         }
 
         public Task Execute(IJobExecutionContext context)
@@ -47,83 +56,32 @@
             try
             {
                 CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
-                //    List<Dt_StationManager> stationManagers = _stationManagerService.GetStationManagers();
-                //    foreach (var item in stationManagers)
-                //    {
-                //        try
-                //        {
-                //            ushort value = conveyorLine.GetValue<ConveyorLineDBName, ushort>(ConveyorLineDBName.InteractiveSignal, item.StationCode);
+                if (conveyorLine != null)
+                {
+                    List<string> childDeviceCodes = _routerService.QueryAllPositions(conveyorLine.DeviceCode);
 
-                //            DeviceProtocolDetailDTO? deviceProtocolDetail = conveyorLine.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.ProtocalDetailValue == value.ToString());
+                    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() && x.DeviceProParamName == nameof(ConveyorLineTaskCommand.InteractiveSignal));
+                            if (deviceProtocolDetail != null)
+                            {
+                                MethodInfo? method = GetType().GetMethod(deviceProtocolDetail.ProtocolDetailType);
+                                if (method != null)
+                                {
+                                    method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode });
+                                }
+                                else
+                                {
+                                    //todo 鏈壘鍒板搴斿鐞嗘柟娉�
+                                }
+                            }
+                        }
+                    }
+                }
 
-                //            if (deviceProtocolDetail != null)
-                //            {
-                //                ConveyorLineTaskCommand? command = new ConveyorLineTaskCommand()
-                //                {
-                //                    InteractiveSignal = 0,
-                //                    Barcode = "",
-                //                    TargetAddress = Convert.ToInt32(item.DeviceCode),
-                //                    TaskNum = 9988,
-                //                    TrayType = 3
-                //                };
-
-                //                SignalType signalType = Enum.Parse<SignalType>(deviceProtocolDetail.ProtocolDetailType);
-                //                switch (signalType)
-                //                {
-                //                    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;
-                //                }
-                //                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)
             {
@@ -132,5 +90,86 @@
 
             return Task.CompletedTask;
         }
+
+        public void RequestInbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command,string childDeviceCode)
+        {
+            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);
+                }
+            }
+        }
+
+        public void RequestInNextAddress(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
+        {
+            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);
+                }
+            }
+        }
+
+        public void ConveyorLineInFinish(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
+        {
+            Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
+            if (task != null)
+            {
+                conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, 0, childDeviceCode);
+                WebResponseContent content = _taskService.UpdateTaskStatusToNext(task);
+                Console.Out.WriteLine(content.Serialize());
+            }
+        }
+
+        public void RequestOutbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
+        {
+            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);
+            }
+        }
+
+        public void RequestOutNextAddress(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
+        {
+            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);
+                }
+            }
+        }
+
+        public void ConveyorLineOutFinish(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
+        {
+            Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
+            if (task != null)
+            {
+                bool t = conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, 0, childDeviceCode);
+                WebResponseContent content = _taskService.UpdateTaskStatusToNext(task);
+                Console.Out.WriteLine(content.Serialize());
+            }
+        }
     }
 }

--
Gitblit v1.9.3