From f23e0326aa05a1c5b47d4aec4c06e73d0d86b8e7 Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com>
Date: 星期二, 29 七月 2025 17:43:15 +0800
Subject: [PATCH] 代码提交

---
 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/Task/RequestInbound.cs |  144 +++++++++++++++++++++++++++++++++++++----------
 1 files changed, 112 insertions(+), 32 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/Task/RequestInbound.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/Task/RequestInbound.cs"
index 227a2e1..d89caf3 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/Task/RequestInbound.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/Task/RequestInbound.cs"
@@ -1,6 +1,8 @@
 锘縰sing HslCommunication;
 using Mapster;
 using Newtonsoft.Json;
+using SqlSugar;
+using System.Text;
 using System.Text.RegularExpressions;
 using System.Threading.Tasks;
 using WIDESEAWCS_Common;
@@ -11,7 +13,11 @@
 using WIDESEAWCS_Model.BasicInfo;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_QuartzJob;
+using WIDESEAWCS_QuartzJob.DeviceBase;
+using WIDESEAWCS_QuartzJob.DTO;
+using WIDESEAWCS_QuartzJob.Models;
 using WIDESEAWCS_Tasks.ConveyorLineJob;
+using WIDESEAWCS_Tasks.StackerCraneJob;
 
 namespace WIDESEAWCS_Tasks
 {
@@ -26,28 +32,20 @@
                 case 1:
                     await RequestTask(conveyorLine, command, childDeviceCode, stationManager);
                     break;
-
+                case 9:
+                    RequestWMSTask(conveyorLine, stationManager);
+                    break;
                 case 2:
                 case 3:
-                    RequestInOrOutbound(command, conveyorLine, stationManager, task);
+                    RequestNextAddress(command, conveyorLine, stationManager, task);
                     break;
-                default:
-                    break;
-            }
-        }
-
-        public void HandleFinishTaskAsync(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, Dt_Task task=null)
-        {
-            var stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == childDeviceCode && x.stationPLC == conveyorLine.DeviceCode);
-
-            switch (stationManager.stationType)
-            {
                 case 4:
                 case 5:
-                    ConveyorLineInOrOutFinish(conveyorLine, command, stationManager, task);
-                    break;
-                case 7:
-                    ConveyorLineOutFinish(conveyorLine, command, stationManager, task);
+                    task = _taskService.QueryConveyorLineFinishTask(stationManager.stationChildCode, command.TaskNum);
+                    if (task != null)
+                    {
+                        _taskService.UpdateTaskStatusToNext(task);
+                    }
                     break;
                 default:
                     break;
@@ -56,31 +54,25 @@
 
         private async Task RequestTask(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, Dt_StationManager stationManager)
         {
-            var hasTask = await _taskRepository.QueryFirstAsync(x => x.SourceAddress == childDeviceCode);
+            var hasTask = await _taskRepository.QueryFirstAsync(x => x.SourceAddress == childDeviceCode && x.TaskState < (int)TaskInStatusEnum.RGV_InExecutingFinish && x.TaskState >= (int)TaskInStatusEnum.InNew);
             if (hasTask != null)
             {
                 var log = $"銆恵conveyorLine._deviceName}銆戜换鍔″彿锛氥�恵hasTask.TaskNum}銆�,鎵樼洏鏉$爜锛氥�恵hasTask.PalletCode}銆戝凡鍒拌揪銆恵childDeviceCode}銆戣緭閫佺嚎瀛樺湪浠诲姟";
                 ConsoleHelper.WriteWarningLine(log);
 
-               await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
+                await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
                 WriteInfo(conveyorLine.DeviceName, log);
                 return;
             }
             var RGVName = string.Empty;
             if (stationManager.stationFloor == "1F")
             {
-                var RGVOne = _taskRepository.QueryData(x => x.RGVName == "RGV01").ToList();
-                var RGVTwo = _taskRepository.QueryData(x => x.RGVName == "RGV02").ToList();
-                if (RGVOne.Count > RGVTwo.Count)
-                {
-                    RGVName = "RGV01";
-                }
-                else
-                {
-                    RGVName = "RGV02";
-                }
+                RGVName = stationManager.RGVName;
             }
-
+            else
+            {
+                RGVName = "RGV03";
+            }
             Dt_Task task = new Dt_Task()
             {
                 TaskNum = _taskRepository.GetTaskNo().Result,
@@ -88,12 +80,100 @@
                 TaskState = (int)TaskInStatusEnum.InNew,
                 SourceAddress = childDeviceCode,
                 Dispatchertime = DateTime.Now,
-                Grade = 1, // 璁剧疆榛樿浼樺厛绾т负1
+                Grade = 1,
                 Creater = "System",
                 Floor = stationManager.stationFloor,
-                RGVName = stationManager.RGVName != null ? stationManager.RGVName : RGVName,
+                RGVName = RGVName,
+                SourceStation= stationManager.remark,
             };
+
             _taskRepository.AddData(task);
         }
+        private void RequestWMSTask(CommonConveyorLine conveyorLine,  Dt_StationManager stationManager)
+        {
+            if (stationManager.stationChildCode == "3002")
+            {
+                DeviceProDTO? devicePro = conveyorLine.DeviceProDTOs.Where(x => x.DeviceChildCode == stationManager.stationChildCode && x.DeviceProParamName == "ConveyorLineBarcode").FirstOrDefault();
+                var x = conveyorLine.Communicator.Read(devicePro.DeviceProAddress, 5);
+
+                string Barcode = Encoding.UTF8.GetString(x);
+
+                if (Barcode == null)
+                {
+                    conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, Convert.ToSByte(3), stationManager.stationChildCode);
+                }
+                var task = _taskRepository.QueryFirst(x => x.PalletCode == Barcode && x.TaskState == (int)TaskInStatusEnum.HoistNew);
+
+                if (task != null)
+                {
+                    ConveyorLineTaskCommandWrite taskCommand = new ConveyorLineTaskCommandWrite()
+                    {
+                        TaskNum = Convert.ToInt16(task.TaskNum),
+                        TargetAddress = Convert.ToInt16(task.NextAddress),
+                        WriteInteractiveSignal = task.TaskType == (int)TaskOutboundTypeEnum.Outbound ? (byte)Convert.ToSByte(2) : (byte)Convert.ToSByte(1)
+                    };
+                    var result = SendCommand(taskCommand, conveyorLine, stationManager.stationChildCode);
+                    if (result)
+                    {
+                        task.TaskState = (int)TaskInStatusEnum.HoistInExecuting;
+                        _taskRepository.UpdateData(task);
+                    }
+                }
+                else
+                {
+                    var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
+                    var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue;
+                    var requestTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.RequestTask)?.ConfigValue;
+
+                    WMSTaskDTO taskDTO = new WMSTaskDTO()
+                    {
+                        TPbarcode = Barcode,
+                        WhCode = "1001",
+                        BeginPoint = stationManager.stationChildCode
+                    };
+                    if (wmsBase == null || requestTask == null)
+                    {
+                        throw new InvalidOperationException("WMS IP 鏈厤缃�");
+                    }
+                    var wmsIpAddress = wmsBase + requestTask;
+                    var result = WIDESEA_Comm.Http.HttpHelper.PostAsync(wmsIpAddress, taskDTO.ToJsonString()).Result;
+                }
+            }
+            else
+            {
+                DeviceProDTO? devicePro = conveyorLine.DeviceProDTOs.Where(x => x.DeviceChildCode == stationManager.stationChildCode && x.DeviceProParamName == "ConveyorLineBarcode").FirstOrDefault();
+                var x = conveyorLine.Communicator.Read(devicePro.DeviceProAddress, 5);
+
+                string Barcode = Encoding.UTF8.GetString(x);
+                if (Barcode == "")
+                {
+                    conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, Convert.ToSByte(3), stationManager.stationChildCode);
+                }
+                var task = _taskRepository.QueryFirst(x => x.PalletCode == Barcode);
+                if (task != null)
+                {
+
+                }
+                else
+                {
+                    var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
+                    var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue;
+                    var requestTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.RequestTask)?.ConfigValue;
+                    
+                    WMSTaskDTO taskDTO = new WMSTaskDTO()
+                    {
+                        TPbarcode = Barcode,
+                        WhCode = "1001",
+                        BeginPoint = stationManager.stationChildCode
+                    };
+                    if (wmsBase == null || requestTask == null)
+                    {
+                        throw new InvalidOperationException("WMS IP 鏈厤缃�");
+                    }
+                    var wmsIpAddress = wmsBase + requestTask;
+                    var result = WIDESEA_Comm.Http.HttpHelper.PostAsync(wmsIpAddress, taskDTO.ToJsonString()).Result;
+                }
+            } 
+        }
     }
 }

--
Gitblit v1.9.3