From 515866f63c9fbdb83de3f2016e4eaf2af99490d7 Mon Sep 17 00:00:00 2001
From: hutongqing <hutongqing@hnkhzn.com>
Date: 星期三, 15 一月 2025 11:32:52 +0800
Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/MeiRuiAn/HuaiAn

---
 代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/板材仓/ConveyorLineJob_BC.cs |  344 ++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 231 insertions(+), 113 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\346\235\277\346\235\220\344\273\223/ConveyorLineJob_BC.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\346\235\277\346\235\220\344\273\223/ConveyorLineJob_BC.cs"
index e36e1f4..f6d4ff9 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\346\235\277\346\235\220\344\273\223/ConveyorLineJob_BC.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\346\235\277\346\235\220\344\273\223/ConveyorLineJob_BC.cs"
@@ -1,13 +1,17 @@
-锘縰sing Quartz;
+锘縰sing Newtonsoft.Json;
+using Quartz;
+using SqlSugar;
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Security.Policy;
 using System.Text;
 using System.Threading.Tasks;
 using WIDESEAWCS_Common;
 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;
@@ -17,27 +21,46 @@
 using WIDESEAWCS_QuartzJob.DTO;
 using WIDESEAWCS_QuartzJob.Models;
 using WIDESEAWCS_QuartzJob.Repository;
+using WIDESEAWCS_QuartzJob.Service;
+using WIDESEAWCS_TaskInfoService;
 using WIDESEAWCS_Tasks.ConveyorLineJob;
+using ICacheService = WIDESEAWCS_Core.Caches.ICacheService;
 
 namespace WIDESEAWCS_Tasks
 {
     [DisallowConcurrentExecution]
     public class ConveyorLineJob_BC : 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 IRouterService _routerService;
+        private readonly IRouterExtension _routerExtension;
+        private readonly List<Dt_WarehouseDevice> warehouseDevices;
 
-        public ConveyorLineJob_BC(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository)
+        public ConveyorLineJob_BC(ICacheService cacheService, ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IRouterService routerService, IRouterExtension routerExtension)
         {
+            _cacheService = cacheService;
             _taskService = taskService;
             _taskExecuteDetailService = taskExecuteDetailService;
             _taskRepository = taskRepository;
             _stationMangerRepository = stationMangerRepository;
             _routerRepository = routerRepository;
+            _routerService = routerService;
+            _routerExtension = routerExtension;
+
+            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 +69,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)))
@@ -58,148 +87,237 @@
                     {
                         R_ConveyorLineInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_ConveyorLineInfo>(deviceProRead.DeviceProAddress);
 
+                        W_ConveyorLineInfo conveyorLineInfoWrite = device.Communicator.ReadCustomer<W_ConveyorLineInfo>(deviceProWrite.DeviceProAddress);
+                        if (conveyorLineInfoRead == null || conveyorLineInfoWrite == null)
+                        {
+                            continue;
+                        }
+
                         R_ConveyorLineStatus conveyorLineStatus = conveyorLineInfoRead.Status.ByteToBoolObject<R_ConveyorLineStatus>();
 
                         ConveyorLineSignal conveyorLineSignalRead = conveyorLineInfoRead.Signal.ByteToBoolObject<ConveyorLineSignal>();
 
-                        W_ConveyorLineInfo conveyorLineInfoWrite = device.Communicator.ReadCustomer<W_ConveyorLineInfo>(deviceProWrite.DeviceProAddress);
-
                         ConveyorLineSignal conveyorLineSignalWrite = conveyorLineInfoWrite.Signal.ByteToBoolObject<ConveyorLineSignal>();
-                        if (item.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt())
+
+                        if (item.StationType == StationTypeEnum.StationType_InboundAndOutbound.ObjToInt())
                         {
+                            {
+                                #region 鐢熸垚浠诲姟鍚庣粰杈撻�佺嚎鍚姩淇″彿
+                                Dt_Task task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) /*&& x.DeviceCode == item.StationDeviceCode*/ && (x.TaskState == TaskStatusEnum.New.ObjToInt()) && x.WarehouseId == warehouseDevice.WarehouseId);
+                                if (task != null && conveyorLineInfoWrite.Spare2 == 0 && conveyorLineStatus.Goods)
+                                {
+                                    List<string> stations = _routerExtension.GetEndPoint(item.StationCode, TaskTypeEnum.Inbound.ObjToInt()).Select(x => x.NextPosi).ToList();
+                                    WebResponseContent responseContent = _taskService.RequestWMSAssignRoadway(stations, task.TaskNum, conveyorLineInfoRead.Spare2);
+                                    if (responseContent.Status)
+                                    {
+                                        device.SetValue(W_ConveyorLineDB.Spare2, 1, item.StationCode);
+                                        _taskService.UpdateTask(task, TaskStatusEnum.Line_Execute, deviceCode: item.StationDeviceCode, roadwayNo: responseContent.Data.ToString() ?? "");
+                                    }
+                                }
+                                else
+                                {
+                                    if (conveyorLineInfoWrite.Spare2 != 0)
+                                    {
+                                        WriteDebug(device.DeviceName, $"鍚姩淇″彿宸插啓鍏�");
+                                    }
+                                }
+                                #endregion
+                            }
+
                             if (conveyorLineSignalRead.STB && conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && !conveyorLineSignalWrite.ACK)
                             {
-                                if (!string.IsNullOrEmpty(conveyorLineInfoRead.Barcode))
+                                if (conveyorLineInfoRead.TaskNum == 0 && !string.IsNullOrEmpty(conveyorLineInfoRead.Barcode))//閲囪喘鍏ュ簱
                                 {
-                                    WebResponseContent content = _taskService.RequestWMSTask(conveyorLineInfoRead.Barcode, item.StationCode);
-                                    if (content.Status)
+                                    #region 浠诲姟鍙蜂负0锛屼笖鏈夋墭鐩樺彿锛屽垯鏄噰璐叆搴�
+                                    Dt_Task task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && x.DeviceCode == item.StationDeviceCode && (x.TaskState == TaskStatusEnum.Line_Execute.ObjToInt()) && x.PalletCode == conveyorLineInfoRead.Barcode && x.WarehouseId == warehouseDevice.WarehouseId);
+                                    if (task != null)
                                     {
-                                        device.SetValue(W_ConveyorLineDB.ACK, true);
+                                        device.SetValue(W_ConveyorLineDB.Spare2, 0, item.StationCode);
+
+                                        string currentAddress = task.CurrentAddress;
+                                        string nextAddress = task.NextAddress;
+                                        string targetAddress = task.TargetAddress;
+                                        string deviceCode = task.DeviceCode;
+                                        TaskStatusEnum taskState = TaskStatusEnum.Line_Executing;
+                                        List<Dt_Router> routers = _routerService.QueryNextRoutes(item.StationCode, task.Roadway, task.TaskType);
+                                        Dt_Router? router = routers.FirstOrDefault();
+                                        if (routers == null || routers.Count == 0 || router == null)
+                                        {
+                                            WriteError(item.StationName, $"鏈壘鍒板搴旇矾鐢变俊鎭�,璁惧缂栧彿:{item.StationCode},浠诲姟鍙�:{task.TaskNum}");
+                                            continue;
+                                        }
+                                        if (routers.Count > 1)
+                                        {
+                                            WriteError(item.StationName, $"璺敱淇℃伅閰嶇疆閿欒,璁惧缂栧彿:{item.StationCode},浠诲姟鍙�:{task.TaskNum}");
+                                            continue;
+                                        }
+
+                                        if (router.IsEnd)
+                                        {
+                                            string? targetLoca = _taskService.RequestAssignLocationByHeight(task.TaskNum, task.Roadway, conveyorLineInfoRead.Spare2);
+                                            if (!string.IsNullOrEmpty(targetLoca))
+                                            {
+                                                currentAddress = item.StackerCraneStationCode;
+                                                targetAddress = targetLoca;
+                                                nextAddress = targetLoca;
+                                                taskState = TaskStatusEnum.SC_Execute;
+                                                deviceCode = item.StackerCraneCode;
+                                                device.SetValue(W_ConveyorLineDB.EndPos, task.CurrentAddress, item.StationCode);
+                                            }
+                                            else
+                                            {
+                                                WriteError(item.StationName, $"璇锋眰鍒嗛厤璐т綅澶辫触,璁惧缂栧彿:{item.StationCode},浠诲姟鍙�:{task.TaskNum}");
+                                                continue;
+                                            }
+                                        }
+                                        else
+                                        {
+                                            device.SetValue(W_ConveyorLineDB.EndPos, task.NextAddress, item.StationCode);
+                                        }
+                                        device.SetValue(W_ConveyorLineDB.TaskNum, task.TaskNum, 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.ACK, true, item.StationCode);
+                                        _taskService.UpdateTask(task, taskState, currentAddress: currentAddress, nextAddress: nextAddress, targetAddress: targetAddress, deviceCode: deviceCode);
+                                    }
+                                    else
+                                    {
+                                        WriteInfo(device.DeviceName, $"鏈壘鍒版墭鐩榹conveyorLineInfoRead.Barcode}瀵瑰簲鐨勪换鍔′俊鎭�");
+                                    }
+                                    #endregion
+                                }
+                                else//鐢熶骇閫�搴�
+                                {
+                                    #region 鐢熶骇閫�搴�,甯︿换鍔″彿鏌ヨ浠诲姟
+                                    Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == conveyorLineInfoRead.TaskNum && x.NextAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && x.WarehouseId == warehouseDevice.WarehouseId); // 甯︿换鍔″彿鏌ヨ浠诲姟
+                                    if (task != null)
+                                    {
+                                        List<string> stations = _routerExtension.GetEndPoint(item.StationCode, TaskTypeEnum.Inbound.ObjToInt()).Select(x => x.NextPosi).ToList();
+                                        WebResponseContent responseContent = _taskService.RequestWMSAssignRoadway(stations, task.TaskNum, conveyorLineInfoRead.Spare2);
+                                        if (responseContent.Status)
+                                        {
+                                            //string currentAddress = task.CurrentAddress;
+                                            //string nextAddress = task.NextAddress;
+                                            //string targetAddress = task.TargetAddress;
+                                            string roadwayNo = task.Roadway;
+
+                                            string currentAddress = task.CurrentAddress;
+                                            string nextAddress = task.NextAddress;
+                                            string targetAddress = task.TargetAddress;
+                                            string deviceCode = task.DeviceCode;
+                                            TaskStatusEnum taskState = TaskStatusEnum.Line_Executing;
+                                            List<Dt_Router> routers = _routerService.QueryNextRoutes(item.StationCode, responseContent.Data.ToString(), task.TaskType);
+                                            Dt_Router? router = routers.FirstOrDefault();
+                                            if (routers == null || routers.Count == 0 || router == null)
+                                            {
+                                                WriteError(item.StationName, $"鏈壘鍒板搴旇矾鐢变俊鎭�,璁惧缂栧彿:{item.StationCode},浠诲姟鍙�:{task.TaskNum}");
+                                                continue;
+                                            }
+                                            if (routers.Count > 1)
+                                            {
+                                                WriteError(item.StationName, $"璺敱淇℃伅閰嶇疆閿欒,璁惧缂栧彿:{item.StationCode},浠诲姟鍙�:{task.TaskNum}");
+                                                continue;
+                                            }
+
+                                            if (router.IsEnd)
+                                            {
+                                                string? targetLoca = _taskService.RequestAssignLocationByHeight(task.TaskNum, responseContent.Data.ToString(), conveyorLineInfoRead.Spare2);
+                                                if (!string.IsNullOrEmpty(targetLoca))
+                                                {
+                                                    currentAddress = item.StackerCraneStationCode;
+                                                    targetAddress = targetLoca;
+                                                    nextAddress = targetLoca;
+                                                    taskState = TaskStatusEnum.SC_Execute;
+                                                    deviceCode = item.StackerCraneCode;
+                                                    roadwayNo = responseContent.Data.ToString();
+                                                    device.SetValue(W_ConveyorLineDB.EndPos, task.CurrentAddress, item.StationCode);
+                                                }
+                                                else
+                                                {
+                                                    WriteError(item.StationName, $"璇锋眰鍒嗛厤璐т綅澶辫触,璁惧缂栧彿:{item.StationCode},浠诲姟鍙�:{task.TaskNum}");
+                                                    continue;
+                                                }
+                                            }
+                                            else
+                                            {
+                                                device.SetValue(W_ConveyorLineDB.EndPos, task.NextAddress, item.StationCode);
+                                            }
+                                            device.SetValue(W_ConveyorLineDB.TaskNum, task.TaskNum, 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.ACK, true, item.StationCode);
+                                            _taskService.UpdateTask(task, taskState, currentAddress: currentAddress, nextAddress: nextAddress, targetAddress: targetAddress, deviceCode: deviceCode, roadwayNo: roadwayNo);
+                                        }
+                                        #endregion
                                     }
                                 }
                             }
                             else if (!conveyorLineSignalRead.STB && conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && conveyorLineSignalWrite.ACK)
                             {
-                                device.SetValue(W_ConveyorLineDB.ACK, false);
+                                device.SetValue(W_ConveyorLineDB.ACK, false, item.StationCode);
                             }
-                        }
-                        else if (item.StationType == StationTypeEnum.StationType_InboundAndOutbound.ObjToInt())
-                        {
-                            if (conveyorLineSignalRead.STB && conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && !conveyorLineSignalWrite.ACK)//鍏ュ簱
+                            else if (!conveyorLineSignalRead.STB && !conveyorLineSignalRead.ACK && conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && !conveyorLineSignalWrite.STB && !conveyorLineSignalWrite.ACK && conveyorLineInfoRead.TaskNum == 0)//鍑哄簱
                             {
-                                Dt_Task task = _taskRepository.QueryFirst(x => x.NextAddress == item.StackerCraneCode);
-                                if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
-                                {
-                                    Dt_StationManger? stationManger = stationMangers.FirstOrDefault(x => x.StationCode == item.StationCode);
-                                    if (stationManger == null)
-                                    {
-                                        WriteInfo(item.StationName, $"鏈壘鍒板搴旂珯鍙颁俊鎭�,璁惧缂栧彿:{item.StationCode},浠诲姟鍙�:{task.TaskNum}");
-                                        continue;
-                                    }
-                                    string? locationCode = _taskService.RequestAssignLocation(task.TaskNum, stationManger.StackerCraneCode);
-                                    if (string.IsNullOrEmpty(locationCode))
-                                    {
-                                        WriteInfo(item.StationName, $"璇锋眰鍒嗛厤璐т綅杩斿洖淇℃伅閿欒,璁惧缂栧彿:{item.StationCode},浠诲姟鍙�:{task.TaskNum}");
-                                        continue;
-                                    }
-                                    string oldAddress = task.NextAddress;
-                                    int oldStatus = task.TaskState;
-                                    task.CurrentAddress = stationManger.StackerCraneStationCode;
-                                    task.TargetAddress = locationCode;
-                                    task.NextAddress = locationCode;
-                                    task.DeviceCode = stationManger.StackerCraneCode;
-                                    task.TaskState = TaskStatusEnum.SC_Execute.ObjToInt();
-                                    _taskRepository.UpdateData(task);
-
-                                    _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, $"绯荤粺鑷姩娴佺▼,鐩爣鍦板潃鐢眥oldAddress}鍙樻洿涓簕task.NextAddress},浠诲姟鐘舵�佺敱{oldStatus}鍙樻洿涓簕task.TaskState}");
-
-                                    device.SetValue(W_ConveyorLineDB.Spare1, ConveyorWorkTypeEnum.Inbound.ObjToInt());
-                                    device.SetValue(W_ConveyorLineDB.ACK, true);
-                                }
-                            }
-                            else if (!conveyorLineSignalRead.STB && conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && conveyorLineSignalWrite.ACK)
-                            {
-                                device.SetValue(W_ConveyorLineDB.ACK, false);
-                            }
-                            else
-                            {
-                                if (!conveyorLineSignalWrite.STB && !conveyorLineSignalRead.ACK && conveyorLineStatus.Goods)
-                                {
-                                    Dt_Task task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && x.TaskState == TaskStatusEnum.Line_Execute.ObjToInt());
-                                    if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
-                                    {
-                                        Dt_StationManger? stationManger = stationMangers.FirstOrDefault(x => x.StationCode == item.StationCode);
-                                        if (stationManger == null)
-                                        {
-                                            WriteInfo(item.StationName, $"鏈壘鍒板搴旂珯鍙颁俊鎭�,璁惧缂栧彿:{item.StationCode},浠诲姟鍙�:{task.TaskNum}");
-                                            continue;
-                                        }
-
-                                        Dt_Router router = _routerRepository.QueryFirst(x => x.InOutType == task.TaskType && (task.CurrentAddress == x.StartPosi));
-                                        if (router == null)
-                                        {
-                                            WriteInfo(item.StationName, $"鏈壘鍒拌矾鐢遍厤缃俊鎭�,璁惧缂栧彿:{item.StationCode},浠诲姟鍙�:{task.TaskNum}");
-                                            continue;
-                                        }
-
-                                        string oldAddress = task.NextAddress;
-                                        int oldStatus = task.TaskState;
-                                        task.NextAddress = router.NextPosi;
-                                        task.TargetAddress = router.NextPosi;
-                                        task.TaskState = TaskStatusEnum.Line_Executing.ObjToInt();
-                                        _taskRepository.UpdateData(task);
-
-                                        _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, $"绯荤粺鑷姩娴佺▼,鐩爣鍦板潃鐢眥oldAddress}鍙樻洿涓簕task.NextAddress},浠诲姟鐘舵�佺敱{oldStatus}鍙樻洿涓簕task.TaskState}");
-
-                                        device.SetValue(W_ConveyorLineDB.TaskNum, task.TaskNum);
-                                        device.SetValue(W_ConveyorLineDB.EndPos, task.NextAddress);
-                                        device.SetValue(W_ConveyorLineDB.StartPos, task.CurrentAddress);
-                                        device.SetValue(W_ConveyorLineDB.Spare1, ConveyorWorkTypeEnum.Outbound.ObjToInt());
-                                        device.SetValue(W_ConveyorLineDB.STB, true);
-                                    }
-                                }
-                                else if (conveyorLineSignalWrite.STB && conveyorLineSignalRead.ACK && conveyorLineStatus.Goods)
-                                {
-                                    _taskService.TaskCompleted(conveyorLineInfoRead.TaskNum);
-                                    device.SetValue(W_ConveyorLineDB.STB, false);
-                                }
-                            }
-                        }
-                        else if (item.StationType == StationTypeEnum.StationType_InStartAndOutEnd.ObjToInt())
-                        {
-                            if (!conveyorLineSignalWrite.STB && !conveyorLineSignalWrite.ACK && !conveyorLineSignalRead.STB && !conveyorLineSignalRead.ACK && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm)
-                            {
-                                Dt_Task task = _taskRepository.QueryFirst(x => x.TaskState == TaskStatusEnum.New.ObjToInt() && string.IsNullOrEmpty(x.TargetAddress) && x.SourceAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType));
+                                Dt_Task task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && _taskService.TaskOutboundTypes.Contains(x.TaskType) && x.DeviceCode == item.StationDeviceCode && x.TaskState == TaskStatusEnum.Line_Execute.ObjToInt() && x.WarehouseId == warehouseDevice.WarehouseId);
                                 if (task != null)
                                 {
-                                    //todo 杈撻�佺嚎宸ヤ綔妯″紡闇�瑕佸垽鏂�
-                                    device.SetValue(W_ConveyorLineDB.Spare1, ConveyorWorkTypeEnum.Inbound.ObjToInt());
-                                    device.SetValue(W_ConveyorLineDB.STB, true);
+                                    _taskService.UpdateTask(task, TaskStatusEnum.Line_Executing);
+
+                                    device.SetValue(W_ConveyorLineDB.TaskNum, task.TaskNum, item.StationCode);
+                                    device.SetValue(W_ConveyorLineDB.StartPos, task.CurrentAddress, item.StationCode);
+                                    device.SetValue(W_ConveyorLineDB.EndPos, task.NextAddress, item.StationCode);
+                                    device.SetValue(W_ConveyorLineDB.Spare1, ConveyorWorkTypeEnum.Outbound.ObjToInt(), item.StationCode);
+                                    device.SetValue(W_ConveyorLineDB.STB, true, item.StationCode);
                                 }
+                                //else
+                                //{
+                                //    task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && string.IsNullOrEmpty(x.DeviceCode) && x.TaskState == TaskStatusEnum.New.ObjToInt() && x.WarehouseId == warehouseDevice.WarehouseId);
+                                //    if (task != null)
+                                //    {
+                                //        Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == task.CurrentAddress);
+                                //        if (stationManger != null)
+                                //        {
+                                //            _taskService.UpdateTask(task, TaskStatusEnum.SC_Execute, deviceCode: stationManger.StackerCraneCode, currentAddress: stationManger.StackerCraneStationCode, nextAddress: task.TargetAddress);
+                                //        }
+                                //    }
+                                //}
                             }
-                            else if (conveyorLineSignalWrite.STB && conveyorLineSignalRead.ACK && !conveyorLineStatus.Alarm)
+                            else if (!conveyorLineSignalRead.STB && conveyorLineSignalRead.ACK && conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && conveyorLineSignalWrite.STB && !conveyorLineSignalWrite.ACK)
                             {
-                                device.SetValue(W_ConveyorLineDB.STB, false);
-                            }
-                            else if (!conveyorLineSignalRead.STB && conveyorLineSignalWrite.ACK && !conveyorLineStatus.Alarm)
-                            {
-                                device.SetValue(W_ConveyorLineDB.ACK, false);
+                                device.SetValue(W_ConveyorLineDB.STB, false, item.StationCode);
                             }
                         }
+                        //else if (item.StationType == StationTypeEnum.StationType_InStartAndOutEnd.ObjToInt())
+                        //{
+                        //    if (!conveyorLineSignalWrite.ACK && conveyorLineSignalRead.STB && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm)
+                        //    {
+                        //        if (conveyorLineInfoRead.TaskNum == 0 && !string.IsNullOrEmpty(conveyorLineInfoRead.Barcode))//閫�鏂欏叆搴�
+                        //        {
+
+                        //        }
+                        //        else//鍑哄簱瀹屾垚
+                        //        {
+
+                        //        }
+                        //    }
+                        //    else if (conveyorLineSignalWrite.STB && conveyorLineSignalRead.ACK && !conveyorLineStatus.Alarm)
+                        //    {
+                        //        device.SetValue(W_ConveyorLineDB.STB, false, item.StationCode);
+                        //    }
+                        //    else if (!conveyorLineSignalRead.STB && conveyorLineSignalWrite.ACK && !conveyorLineStatus.Alarm)
+                        //    {
+                        //        device.SetValue(W_ConveyorLineDB.ACK, false, item.StationCode);
+                        //    }
+                        //}
                     }
                     else
                     {
-                        WriteInfo(device.DeviceName, $"鏈壘鍒拌澶囧瓙缂栧彿{item.StationCode}鐨勫崗璁俊鎭�");
+                        WriteError(device.DeviceName, $"鏈壘鍒拌澶囧瓙缂栧彿{item.StationCode}鐨勫崗璁俊鎭�");
                     }
                 }
             }
 
             return Task.CompletedTask;
-        }
-
-        public void OnlyInboundStationFunc()
-        {
-
         }
     }
 }

--
Gitblit v1.9.3