From a8756c3526832332db4ef5685348d9b188c2bf2b Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期六, 13 九月 2025 08:36:44 +0800
Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/MeiRuiAn/HuaiAn

---
 代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/干膜仓/ConveyorLineJob_GM.cs |  107 +++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 94 insertions(+), 13 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\345\271\262\350\206\234\344\273\223/ConveyorLineJob_GM.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\345\271\262\350\206\234\344\273\223/ConveyorLineJob_GM.cs"
index 94217b8..ec69ca0 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\345\271\262\350\206\234\344\273\223/ConveyorLineJob_GM.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\345\271\262\350\206\234\344\273\223/ConveyorLineJob_GM.cs"
@@ -1,4 +1,6 @@
-锘縰sing Quartz;
+锘縰sing Microsoft.IdentityModel.Tokens;
+using Newtonsoft.Json;
+using Quartz;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -8,12 +10,14 @@
 using WIDESEAWCS_Common.Helper;
 using WIDESEAWCS_Common.TaskEnum;
 using WIDESEAWCS_Core;
+using WIDESEAWCS_Core.Caches;
 using WIDESEAWCS_Core.Helper;
 using WIDESEAWCS_IBasicInfoRepository;
 using WIDESEAWCS_ITaskInfoRepository;
 using WIDESEAWCS_ITaskInfoService;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_QuartzJob;
+using WIDESEAWCS_QuartzJob.ConveyorLine.Enum;
 using WIDESEAWCS_QuartzJob.DTO;
 using WIDESEAWCS_QuartzJob.Models;
 using WIDESEAWCS_QuartzJob.Repository;
@@ -24,20 +28,33 @@
     [DisallowConcurrentExecution]
     public class ConveyorLineJob_GM : JobBase, IJob
     {
-
+        private readonly ICacheService _cacheService;
         private readonly ITaskService _taskService;
         private readonly ITaskExecuteDetailService _taskExecuteDetailService;
         private readonly ITaskRepository _taskRepository;
         private readonly IStationMangerRepository _stationMangerRepository;
         private readonly IRouterRepository _routerRepository;
+        private readonly List<Dt_WarehouseDevice> warehouseDevices;
 
-        public ConveyorLineJob_GM(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository)
+        public ConveyorLineJob_GM(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, ICacheService
+            cacheService)
         {
+            _cacheService = cacheService;
             _taskService = taskService;
             _taskExecuteDetailService = taskExecuteDetailService;
             _taskRepository = taskRepository;
             _stationMangerRepository = stationMangerRepository;
             _routerRepository = routerRepository;
+
+            string? warehouseDevicesStr = _cacheService.Get<string>(nameof(Dt_WarehouseDevice));
+            if (!string.IsNullOrEmpty(warehouseDevicesStr))
+            {
+                warehouseDevices = JsonConvert.DeserializeObject<List<Dt_WarehouseDevice>>(warehouseDevicesStr) ?? new List<Dt_WarehouseDevice>();
+            }
+            else
+            {
+                warehouseDevices = new List<Dt_WarehouseDevice>();
+            }
         }
 
         public Task Execute(IJobExecutionContext context)
@@ -46,6 +63,12 @@
             if (flag && value != null)
             {
                 OtherDevice device = (OtherDevice)value;
+                Dt_WarehouseDevice? warehouseDevice = warehouseDevices.FirstOrDefault(x => x.DeviceCode == device.DeviceCode);
+                if (warehouseDevice == null)
+                {
+                    WriteError(device.DeviceName, $"璇烽厤缃粨搴撹澶囦俊鎭�");
+                    return Task.CompletedTask;
+                }
                 List<string> deviceStations = device.DeviceProDTOs.Select(x => x.DeviceChildCode).ToList();
                 List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(x => x.StationDeviceCode == device.DeviceCode);
                 foreach (var item in stationMangers.Where(x => deviceStations.Contains(x.StationCode)))
@@ -71,11 +94,23 @@
                         ConveyorLineSignal conveyorLineSignalWrite = conveyorLineInfoWrite.Signal.ByteToBoolObject<ConveyorLineSignal>();
                         if (item.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt())
                         {
+                            //骞茶啘鍏ュ簱绔欏彴浜や簰
                             if (conveyorLineSignalRead.STB && conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && !conveyorLineSignalWrite.ACK)
                             {
-                                if (!string.IsNullOrEmpty(conveyorLineInfoRead.Barcode))
+                                string boxcode = device.GetValue<R_ConveyorLineDB, string>(R_ConveyorLineDB.Boxcode, item.StationCode);
+                                
+                                if (!string.IsNullOrEmpty(boxcode))
                                 {
-                                    WebResponseContent content = _taskService.RequestWMSTask(conveyorLineInfoRead.Barcode, item.StationCode);
+                                    string sc = device.Communicator.Read<string>("DB900.478.0");
+                                    WriteError(device.DeviceName, $"璇诲彇鍊硷細{boxcode},瀵规瘮{sc}");
+                                    string boxEndCode = "";
+                                    if (boxcode.LastIndexOf(",PO:") >=0)
+                                    {
+                                        boxEndCode = "M"+ boxcode.Substring(0,boxcode.LastIndexOf(",PO:")) + sc.Substring(sc.IndexOf(",PO:")).Replace("\0", "");
+                                    }
+
+                                    //鍏ュ簱鐢宠浠诲姟
+                                    WebResponseContent content = _taskService.RequestWMSTask(conveyorLineInfoRead.Barcode, item.StationCode, boxEndCode);
                                     if (content.Status)
                                     {
                                         device.SetValue(W_ConveyorLineDB.ACK, true, item.StationCode);
@@ -84,10 +119,11 @@
                             }
                             else if (!conveyorLineSignalRead.STB && conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && conveyorLineSignalWrite.ACK)
                             {
-                                Dt_Task task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && x.PalletCode == conveyorLineInfoRead.Barcode && x.DeviceCode == item.StationDeviceCode);
+                                string boxcode = device.GetValue<R_ConveyorLineDB, string>(R_ConveyorLineDB.Boxcode, item.StationCode);
+                                Dt_Task task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && boxcode.Contains(x.PalletCode) && x.TaskState == TaskStatusEnum.New.ObjToInt());
                                 if (task != null)
                                 {
-                                    _taskService.UpdateTask(task, TaskStatusEnum.SC_Execute, currentAddress: item.StackerCraneStationCode);
+                                    _taskService.UpdateTask(task, TaskStatusEnum.SC_Execute, currentAddress: item.StackerCraneStationCode, deviceCode: task.Roadway, nextAddress: task.TargetAddress);
                                 }
 
                                 device.SetValue(W_ConveyorLineDB.ACK, false, item.StationCode);
@@ -98,7 +134,7 @@
                         {
                             if (!conveyorLineSignalRead.STB && !conveyorLineSignalRead.ACK && conveyorLineStatus.Online && !conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && !conveyorLineSignalWrite.STB && !conveyorLineSignalWrite.ACK)
                             {
-                                Dt_Task task = _taskRepository.QueryFirst(x => _taskService.TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == TaskStatusEnum.New.ObjToInt() && string.IsNullOrEmpty(x.TargetAddress) && string.IsNullOrEmpty(x.NextAddress));
+                                Dt_Task task = _taskRepository.QueryFirst(x => x.WarehouseId== warehouseDevice.WarehouseId && _taskService.TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == TaskStatusEnum.New.ObjToInt() && string.IsNullOrEmpty(x.TargetAddress) && !string.IsNullOrEmpty(x.NextAddress));
                                 if (task != null)
                                 {
                                     _taskService.UpdateTask(task, TaskStatusEnum.SC_Execute, nextAddress: item.StationCode, deviceCode: item.StackerCraneCode, targetAddress: item.StationCode);
@@ -116,6 +152,7 @@
                                         WriteError(item.StationName, $"鏈壘鍒板搴旂珯鍙颁俊鎭�,璁惧缂栧彿:{item.StationCode},浠诲姟鍙�:{task.TaskNum}");
                                         continue;
                                     }
+                                    //鍏ュ簱鐢宠鍒嗛厤璐т綅
                                     string? locationCode = _taskService.RequestAssignLocation(task.TaskNum, stationManger.StackerCraneCode);
                                     if (string.IsNullOrEmpty(locationCode))
                                     {
@@ -134,6 +171,7 @@
                             }
                             else
                             {
+                                //骞茶啘鍑哄簱绔欏彴浜や簰
                                 if (!conveyorLineSignalWrite.STB && !conveyorLineSignalRead.ACK && conveyorLineStatus.Goods)
                                 {
                                     Dt_Task task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && x.TaskState == TaskStatusEnum.Line_Execute.ObjToInt() && x.DeviceCode == item.StationDeviceCode);
@@ -152,19 +190,18 @@
                                             WriteError(item.StationName, $"鏈壘鍒拌矾鐢遍厤缃俊鎭�,璁惧缂栧彿:{item.StationCode},浠诲姟鍙�:{task.TaskNum}");
                                             continue;
                                         }
-
-                                        _taskService.UpdateTask(task, TaskStatusEnum.Line_Executing, nextAddress: router.NextPosi, targetAddress: router.NextPosi);
-
                                         device.SetValue(W_ConveyorLineDB.TaskNum, task.TaskNum, item.StationCode);
-                                        device.SetValue(W_ConveyorLineDB.EndPos, task.NextAddress, item.StationCode);
+                                        device.SetValue(W_ConveyorLineDB.EndPos, router.NextPosi, item.StationCode);
                                         device.SetValue(W_ConveyorLineDB.StartPos, task.CurrentAddress, item.StationCode);
                                         device.SetValue(W_ConveyorLineDB.Spare1, ConveyorWorkTypeEnum.Outbound.ObjToInt(), item.StationCode);
                                         device.SetValue(W_ConveyorLineDB.STB, true, item.StationCode);
+                                        _taskService.UpdateTask(task, TaskStatusEnum.Line_Executing, nextAddress: router.NextPosi, targetAddress: router.NextPosi);
                                     }
                                 }
                                 else if (conveyorLineSignalWrite.STB && conveyorLineSignalRead.ACK && conveyorLineStatus.Goods)
                                 {
-                                    _taskService.TaskCompleted(conveyorLineInfoRead.TaskNum);
+                                    //瀹屾垚骞茶啘鍑哄簱浠诲姟
+                                    _taskService.TaskCompleted(conveyorLineInfoWrite.TaskNum);
                                     device.SetValue(W_ConveyorLineDB.STB, false, item.StationCode);
                                 }
                             }
@@ -203,6 +240,50 @@
                     {
                         WriteInfo(device.DeviceName, $"鏈壘鍒拌澶囧瓙缂栧彿{item.StationCode}鐨勫崗璁俊鎭�");
                     }
+                    R_ConveyorLineInfo conveyorLineInfoRead1 = device.Communicator.ReadCustomer<R_ConveyorLineInfo>(deviceProRead.DeviceProAddress);
+                    W_ConveyorLineInfo conveyorLineInfoWrite1 = device.Communicator.ReadCustomer<W_ConveyorLineInfo>(deviceProWrite.DeviceProAddress);
+                    R_ConveyorLineStatus conveyorLineStatus1 = conveyorLineInfoRead1.Status.ByteToBoolObject<R_ConveyorLineStatus>();
+                    ConveyorLineSignal conveyorLineSignalRead1 = conveyorLineInfoRead1.Signal.ByteToBoolObject<ConveyorLineSignal>();
+                    ConveyorLineSignal conveyorLineSignalWrite1 = conveyorLineInfoWrite1.Signal.ByteToBoolObject<ConveyorLineSignal>();
+                    if (item.StationCode == "7003") {
+                        if (conveyorLineSignalRead1.STB && conveyorLineStatus1.Online && conveyorLineStatus1.Goods && !conveyorLineStatus1.Alarm && !conveyorLineSignalWrite1.ACK)
+                        {
+                            StackerCraneJob_GM.gMReadData.R_GM_Boxcode = device.Communicator.Read<string>("DB900.478.0");
+                        }
+                        StackerCraneJob_GM.gMReadData.R_GM_HandShake3 = conveyorLineStatus1.HandShake;
+                        StackerCraneJob_GM.gMReadData.R_GM_Online3 = conveyorLineStatus1.Online;
+                        StackerCraneJob_GM.gMReadData.R_GM_Free3 = conveyorLineStatus1.Free;
+                        StackerCraneJob_GM.gMReadData.R_GM_Goods3 = conveyorLineStatus1.Goods;
+                        StackerCraneJob_GM.gMReadData.R_GM_Alarm3 = conveyorLineStatus1.Alarm;
+                        StackerCraneJob_GM.gMReadData.R_GM_STB3 = conveyorLineSignalRead1.STB;
+                        StackerCraneJob_GM.gMReadData.R_GM_ACK3 = conveyorLineSignalRead1.ACK;
+                        StackerCraneJob_GM.gMReadData.W_GM_STB3 = conveyorLineSignalWrite1.STB;
+                        StackerCraneJob_GM.gMReadData.W_GM_ACK3 = conveyorLineSignalWrite1.ACK;
+                    }
+                    else if(item.StationCode == "7004")
+                    {
+                        StackerCraneJob_GM.gMReadData.R_GM_HandShake4 = conveyorLineStatus1.HandShake;
+                        StackerCraneJob_GM.gMReadData.R_GM_Online4 = conveyorLineStatus1.Online;
+                        StackerCraneJob_GM.gMReadData.R_GM_Free4 = conveyorLineStatus1.Free;
+                        StackerCraneJob_GM.gMReadData.R_GM_Goods4 = conveyorLineStatus1.Goods;
+                        StackerCraneJob_GM.gMReadData.R_GM_Alarm4 = conveyorLineStatus1.Alarm;
+                        StackerCraneJob_GM.gMReadData.R_GM_STB4 = conveyorLineSignalRead1.STB;
+                        StackerCraneJob_GM.gMReadData.R_GM_ACK4 = conveyorLineSignalRead1.ACK;
+                        StackerCraneJob_GM.gMReadData.W_GM_STB4 = conveyorLineSignalWrite1.STB;
+                        StackerCraneJob_GM.gMReadData.W_GM_ACK4 = conveyorLineSignalWrite1.ACK;
+                    }
+                    else if (item.StationCode == "7005")
+                    {
+                        StackerCraneJob_GM.gMReadData.R_GM_HandShake5 = conveyorLineStatus1.HandShake;
+                        StackerCraneJob_GM.gMReadData.R_GM_Online5 = conveyorLineStatus1.Online;
+                        StackerCraneJob_GM.gMReadData.R_GM_Free5 = conveyorLineStatus1.Free;
+                        StackerCraneJob_GM.gMReadData.R_GM_Goods5 = conveyorLineStatus1.Goods;
+                        StackerCraneJob_GM.gMReadData.R_GM_Alarm5 = conveyorLineStatus1.Alarm;
+                        StackerCraneJob_GM.gMReadData.R_GM_STB5 = conveyorLineSignalRead1.STB;
+                        StackerCraneJob_GM.gMReadData.R_GM_ACK5 = conveyorLineSignalRead1.ACK;
+                        StackerCraneJob_GM.gMReadData.W_GM_STB5 = conveyorLineSignalWrite1.STB;
+                        StackerCraneJob_GM.gMReadData.W_GM_ACK5 = conveyorLineSignalWrite1.ACK;
+                    }
                 }
             }
 

--
Gitblit v1.9.3