From 5c272c606bdf2da3577dbaa5f48d0ee163f1e7d2 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期四, 26 三月 2026 10:35:24 +0800
Subject: [PATCH] 纸张淋膜半成品入库逻辑优化

---
 项目代码/WCS/WCSServices/WIDESEAWCS_Tasks/成品仓/ConveyorLineJob_CPB.cs |  245 +++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 197 insertions(+), 48 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Tasks/\346\210\220\345\223\201\344\273\223/ConveyorLineJob_CPB.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Tasks/\346\210\220\345\223\201\344\273\223/ConveyorLineJob_CPB.cs"
index 91ec5eb..a631447 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Tasks/\346\210\220\345\223\201\344\273\223/ConveyorLineJob_CPB.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Tasks/\346\210\220\345\223\201\344\273\223/ConveyorLineJob_CPB.cs"
@@ -1,7 +1,6 @@
 锘縰sing Microsoft.AspNetCore.Components.Routing;
 using Newtonsoft.Json;
 using Quartz;
-using SqlSugar.Extensions;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -11,6 +10,8 @@
 using WIDESEAWCS_Common.TaskEnum;
 using WIDESEAWCS_Communicator;
 using WIDESEAWCS_Core;
+using WIDESEAWCS_Core.Helper;
+using WIDESEAWCS_DTO.TaskInfo;
 using WIDESEAWCS_IBasicInfoRepository;
 using WIDESEAWCS_ITaskInfoRepository;
 using WIDESEAWCS_ITaskInfoService;
@@ -62,65 +63,213 @@
 
         public Task Execute(IJobExecutionContext context)
         {
-            bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
-            if (flag && value != null)
+            try
             {
-                OtherDevice device = (OtherDevice)value;
-                List<string> deviceStations = device.DeviceProDTOs.Select(x => x.DeviceChildCode).Distinct().ToList();
-                List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(x => x.StationDeviceCode == device.DeviceCode);
-                foreach (var item in stationMangers.Where(x => deviceStations.Contains(x.StationCode)))
+                bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
+                if (flag && value != null)
                 {
-                    DeviceProDTO? deviceProRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(R_ConveyorLineCPDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
-                    DeviceProDTO? deviceProWrite = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(W_ConveyorLineCPDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
-                    if (deviceProRead != null && deviceProWrite!=null)
+                    OtherDevice device = (OtherDevice)value;
+                    List<string> deviceStations = device.DeviceProDTOs.Select(x => x.DeviceChildCode).Distinct().ToList();
+                    List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(x => x.StationDeviceCode == device.DeviceCode);
+                    foreach (var item in stationMangers.Where(x => deviceStations.Contains(x.StationCode)))
                     {
-                        R_ConveyorLineCPInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_ConveyorLineCPInfo>(deviceProRead.DeviceProAddress);
-                        if (conveyorLineInfoRead.Command == 6 && conveyorLineInfoRead.TaskNo>0 && !string.IsNullOrEmpty(conveyorLineInfoRead.PalletCode))
+                        DeviceProDTO? deviceProRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(R_ConveyorLineCPDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
+                        DeviceProDTO? deviceProWrite = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(W_ConveyorLineCPDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
+                        if (item.StationType == StationTypeEnum.StationType_InStartAndOutEnd.ObjToInt() && deviceProRead != null && deviceProWrite != null)
                         {
-                            Dt_Task task = _taskRepository.QueryFirst(x =>x.TaskNum== conveyorLineInfoRead.TaskNo && x.CurrentAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && x.TaskState == TaskStatusEnum.Line_Execute.ObjToInt() && x.DeviceCode==device.DeviceCode);
-                            if (task != null)
+                            R_ConveyorLineCPInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_ConveyorLineCPInfo>(deviceProRead.DeviceProAddress);
+                            //浜屾ゼ鍏ュ簱鎵爜璇锋眰宸ヤ綅
+                            if (conveyorLineInfoRead != null && conveyorLineInfoRead.Command == 5 && conveyorLineInfoRead.TaskNo > 0 && !string.IsNullOrEmpty(conveyorLineInfoRead.PalletCode))
                             {
-                                //鍒嗛厤宸烽亾 瀛樺叆鎵樼洏鏁版嵁
-                                
-                                List<Dt_Router> routers = _routerService.QueryNextRoutes(item.StationCode, "SC01_CP", task.TaskType);
-                                Dt_Router? router = routers.FirstOrDefault();
-                                if (routers == null || routers.Count == 0 || router == null)
+                                //鏌ユ壘瀵瑰簲浠诲姟
+                                Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == conveyorLineInfoRead.TaskNo && x.NextAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && x.TaskState == TaskStatusEnum.Line_Executing.ObjToInt() && x.DeviceCode == device.DeviceCode);
+                                if (task != null)
                                 {
-                                    WriteError(item.StationName, $"鏈壘鍒板搴旇矾鐢变俊鎭�,璁惧缂栧彿:{item.StationCode},浠诲姟鍙�:{task.TaskNum}");
-                                    continue;
+                                    //鍒嗛厤宸烽亾 瀛樺叆鎵樼洏鏁版嵁
+                                    string roadWay = _taskService.AssignCPRoadwayNo().Data.ToString();
+                                    if (!string.IsNullOrEmpty(roadWay))
+                                    {
+                                        List<Dt_Router> routers = _routerService.QueryNextRoutes(item.StationCode, 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;
+                                        }
+                                        WebResponseContent responseContent = _taskService.RequestInBoundPalletCode(task.TaskNum, conveyorLineInfoRead.PalletCode.Trim());
+                                        if (responseContent.Status)
+                                        {
+                                            device.SetValue(W_ConveyorLineCPDB.W_TargetAddress, router.NextPosi, item.StationCode);
+                                            device.SetValue(W_ConveyorLineCPDB.W_TaskNo, task.TaskNum, item.StationCode);
+                                            device.SetValue(W_ConveyorLineCPDB.W_Command, 1, item.StationCode);
+                                            task.CurrentAddress = item.StationCode;
+                                            task.NextAddress = router.NextPosi;
+                                            task.PalletCode = conveyorLineInfoRead.PalletCode.Trim();
+                                            task.Roadway = roadWay;
+                                            task.DeviceCode = router.ChildPosiDeviceCode;
+                                            _taskService.UpdateTask(task, TaskStatusEnum.Line_Executing);
+                                            WriteInfo(item.StationName, $"浠诲姟鍙穥task.TaskNum}涓嬩竴姝ュ埌杈緖router.NextPosi}鍏ュ簱绔欏彴");
+                                        }
+                                        else
+                                        {
+                                            WriteError(item.StationName, $"浠诲姟鍙穥task.TaskNum}鎵爜璇锋眰閿欒{responseContent.Message}");
+                                        }
+                                    }
+                                    else
+                                    {
+                                        WriteError(item.StationName, $"浠诲姟鍙�:{task.TaskNum}鏈壘鍒板彲鍒嗛厤宸烽亾");
+                                    } 
+                                        
+                                            
                                 }
-                                if (routers.Count > 1)
-                                {
-                                    WriteError(item.StationName, $"璺敱淇℃伅閰嶇疆閿欒,璁惧缂栧彿:{item.StationCode},浠诲姟鍙�:{task.TaskNum}");
-                                    continue;
-                                }
-                                
-                                device.SetValue(W_ConveyorLineCPDB.TargetAddress, router.NextPosi, item.StationCode);
-                                device.SetValue(W_ConveyorLineCPDB.TaskNo, task.TaskNum, item.StationCode);
-                                device.SetValue(W_ConveyorLineCPDB.Command, 1, item.StationCode);
-                                task.NextAddress=router.NextPosi;
-                                task.PalletType = 1;
-                                task.PalletCode = conveyorLineInfoRead.PalletCode;
-                                task.Roadway = "SC01_CP";
-                                task.DeviceCode = router.ChildPosiDeviceCode;
-                                _taskService.UpdateTask(task, TaskStatusEnum.Line_Executing);
-                                WriteError(item.StationName, $"浠诲姟鍙穥conveyorLineInfoRead.TaskNo}涓嬩竴姝�");
-                                //string? locationCode = _taskService.RequestAssignLocation(task.TaskNum, "AGV_CP");
-                                //if (string.IsNullOrEmpty(locationCode) && task.TaskType != TaskTypeEnum.EmptyProductBack.ObjToInt())
-                                //{
-                                //    WriteError(item.StationName, $"璇锋眰鍒嗛厤璐т綅杩斿洖淇℃伅閿欒,璁惧缂栧彿:{item.StationCode},浠诲姟鍙�:{task.TaskNum}");
-                                //    continue;
-                                //}
-
                             }
                         }
-                    }
-                    else
-                    {
-                        WriteError(item.StationName, $"鏈壘鍒拌澶囧瓙缂栧彿{item.StationCode}鐨勫崗璁俊鎭�");
+                        else if (item.StationType == StationTypeEnum.StationType_InboundAndOutbound.ObjToInt() && deviceProRead != null)
+                        {//鍏ュ簱RGV鎺ラ┏浣嶄氦浜�
+                            R_ConveyorLineCPInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_ConveyorLineCPInfo>(deviceProRead.DeviceProAddress);
+                            if (conveyorLineInfoRead != null)
+                            {
+                                WriteInfo(item.StationName, $"鐘舵�亄conveyorLineInfoRead.Serialize()}");
+                            }
+                            if (conveyorLineInfoRead != null && conveyorLineInfoRead.Command == 4 && conveyorLineInfoRead.TaskNo > 0)
+                            {
+                                Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == conveyorLineInfoRead.TaskNo && x.CurrentAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && x.TaskState == TaskStatusEnum.Line_Execute.ObjToInt() && x.DeviceCode == device.DeviceCode);
+                                if (task != null)
+                                {
+                                    List<Dt_Router> routers = _routerRepository.QueryData(x => x.InOutType == task.TaskType && task.CurrentAddress == x.StartPosi);
+                                    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;
+                                    }
+                                    device.SetValue(W_ConveyorLineCPDB.W_Command, 2, item.StationCode);
+                                    task.NextAddress = router.NextPosi;
+                                    _taskService.UpdateTask(task, TaskStatusEnum.Line_Executing);
+                                    WriteInfo(item.StationName, $"浠诲姟鍙穥conveyorLineInfoRead.TaskNo}涓嬩竴姝�");
+                                }
+                            }
+                        }
+                        else if (item.StationType == StationTypeEnum.StationType_OnlyOutbound.ObjToInt() && deviceProRead != null)
+                        {//浜屾ゼ鍑哄簱鍙h浆AGV浠诲姟
+                            R_ConveyorLineCPInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_ConveyorLineCPInfo>(deviceProRead.DeviceProAddress);
+                            if (conveyorLineInfoRead != null && conveyorLineInfoRead.Command == 2 && conveyorLineInfoRead.TaskNo > 0)
+                            {
+                                Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == conveyorLineInfoRead.TaskNo && x.NextAddress == item.StationCode && _taskService.TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == TaskStatusEnum.Line_Executing.ObjToInt() && x.DeviceCode == device.DeviceCode);
+                                if (task != null)
+                                {
+                                    //鍒嗛厤宸烽亾 瀛樺叆鎵樼洏鏁版嵁
+                                    List<Dt_Router> routers = _routerRepository.QueryData(x => x.InOutType == task.TaskType && task.NextAddress == x.StartPosi);
+                                    Dt_Router router = routers.FirstOrDefault();
+                                    if (router == null)
+                                    {
+                                        WriteError(item.StationName, $"浠诲姟鍙�:{task.TaskNum}鏈壘鍒拌矾鐢遍厤缃俊鎭�");
+                                        return Task.CompletedTask;
+                                    }
+                                    //鏇存柊浠诲姟淇℃伅
+                                    task.CurrentAddress = router.StartPosi;
+                                    task.NextAddress = task.TargetAddress;
+                                    task.DeviceCode = router.NextPosi;
+                                    _taskService.UpdateTask(task, TaskStatusEnum.AGV_Execute);
+                                    WriteInfo(item.StationName, $"浠诲姟鍙穥conveyorLineInfoRead.TaskNo}涓嬩竴姝�");
+                                }
+                            }
+                        }
+                        else if (item.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt() && deviceProRead != null && deviceProWrite != null)
+                        {
+                            R_ConveyorLineCPInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_ConveyorLineCPInfo>(deviceProRead.DeviceProAddress);
+                            //鎴愬搧浜屾ゼ鍏ュ簱鍙e啓鍏ュ搴斿叆搴撶珯鍙板湴鍧�
+                            if (conveyorLineInfoRead != null && conveyorLineInfoRead.Command == 4 && !string.IsNullOrEmpty(conveyorLineInfoRead.PalletCode))
+                            {
+                                Dt_Task task = _taskRepository.QueryFirst(x => x.PalletCode == conveyorLineInfoRead.PalletCode && x.CurrentAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && x.TaskState == TaskStatusEnum.AGV_Finish.ObjToInt() && x.DeviceCode == device.DeviceCode);
+                                if (task != null)
+                                {
+                                    //鍒嗛厤宸烽亾 瀛樺叆鎵樼洏鏁版嵁
+                                    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;
+                                    }
+                                    //鍐欏叆鍏ュ簱绾夸綋鍦板潃
+                                    device.SetValue(W_ConveyorLineCPDB.W_TargetAddress, router.NextPosi, item.StationCode);
+                                    device.SetValue(W_ConveyorLineCPDB.W_TaskNo, task.TaskNum, item.StationCode);
+                                    device.SetValue(W_ConveyorLineCPDB.W_Command, 1, item.StationCode);
+                                    //鏇存柊浠诲姟淇℃伅
+                                    task.CurrentAddress = item.StationCode;
+                                    task.NextAddress = router.NextPosi;
+                                    task.DeviceCode = router.ChildPosiDeviceCode;
+                                    _taskService.UpdateTask(task, TaskStatusEnum.Line_Executing);
+                                    WriteInfo(item.StationName, $"浠诲姟鍙穥conveyorLineInfoRead.TaskNo}涓嬩竴姝�");
+                                }
+                                else
+                                {
+                                    WriteError(item.StationName, $"鏈壘鍒拌澶囧瓙缂栧彿{item.StationCode}鐨勫崗璁俊鎭�");
+                                }
+                            }
+                        }
+                        else if (item.StationType == StationTypeEnum.StationType_StackingPlates.ObjToInt() && item.IsOccupied==StationOccupiedEnum.None.ObjToInt() && deviceProRead != null && deviceProWrite != null)
+                        {
+                            //鍙犵洏鏈哄伐浣嶅彨鏂�
+                            R_ConveyorLineCPInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_ConveyorLineCPInfo>(deviceProRead.DeviceProAddress);
+
+                            if (conveyorLineInfoRead != null && conveyorLineInfoRead.Command == 7 && conveyorLineInfoRead.TaskNo <= 0)
+                            {
+                                Dt_Task task = _taskRepository.QueryFirst(x => x.TargetAddress == item.StationCode && _taskService.TaskOutboundTypes.Contains(x.TaskType));
+                                if (task == null)
+                                {
+                                    //璇锋眰浠诲姟
+                                    WebResponseContent content = _taskService.RequestPlateOutTask(item.StationCode);
+                                    if (content.Status)
+                                    {
+                                        WriteInfo(item.StationName, $"浜屾ゼ绌烘墭鍙犵洏鍑哄簱浠诲姟鐢熸垚");
+                                    }
+                                    else
+                                    {
+                                        WriteInfo(item.StationName, $"{content.Message}");
+                                    }
+                                }
+                            }
+                            //鍙犵洏浠诲姟瀹屾垚浜や簰
+                            else if (conveyorLineInfoRead != null && conveyorLineInfoRead.Command == 8 && conveyorLineInfoRead.TaskNo > 0)
+                            {
+                                Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == conveyorLineInfoRead.TaskNo && x.TaskState == TaskStatusEnum.Line_Executing.ObjToInt() && x.DeviceCode == device.DeviceCode);
+                                if (task != null)
+                                {
+                                    //浠诲姟瀹屾垚
+                                    device.SetValue(W_ConveyorLineCPDB.W_Command, 2, item.StationCode);
+                                    _taskService.TaskCompleted(task.TaskNum);
+                                    WriteInfo(item.StationName, $"浠诲姟鍙穥conveyorLineInfoRead.TaskNo}鍙犵洏鍑哄簱瀹屾垚");
+                                }
+                            }
+                        }
+                        else
+                        {
+                            WriteError(item.StationName, $"鏈壘鍒拌澶囧瓙缂栧彿{item.StationCode}鐨勫崗璁俊鎭�");
+                        }
                     }
                 }
             }
+            catch (Exception ex)
+            {
+                WriteError(nameof(ConveyorLineJob_CPB),ex.Message);
+            }
             return Task.CompletedTask;
         }
     }

--
Gitblit v1.9.3