wanshenmean
2025-03-27 0d9fb6555efa42e27de4d57d3fb7b8d82a78ef45
优化任务处理逻辑并清理代码

移除了多个不必要的 `using` 语句,简化了代码结构。
添加了对 `_taskService.QueryExecutingConveyorLineTask` 的调用,以获取当前执行的任务,并在任务为空时处理新任务。
修改了任务查询逻辑,确保在特定条件下能够正确处理新任务。
简化了设备位置处理中的任务数量判断逻辑,并注释掉与未执行的空托出库任务相关的代码。
在发送命令后,添加了 `ConveyorLineSendFinish` 方法的调用,以确保任务完成后的适当处理。
已修改1个文件
44 ■■■■ 文件已修改
CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs 44 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
@@ -1,14 +1,9 @@
using AutoMapper;
using HslCommunication;
using Microsoft.AspNetCore.Components.Routing;
using NetTaste;
using Newtonsoft.Json;
using Quartz;
using SqlSugar;
using System.Drawing;
using System.Reflection;
using System.Security.Policy;
using System.Threading.Tasks;
using WIDESEAWCS_BasicInfoRepository;
using WIDESEAWCS_BasicInfoService;
using WIDESEAWCS_Common;
@@ -31,7 +26,6 @@
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_SignalR;
using WIDESEAWCS_Tasks.ConveyorLineJob;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
using ICacheService = WIDESEAWCS_Core.Caches.ICacheService;
namespace WIDESEAWCS_Tasks
@@ -353,15 +347,23 @@
                }
                else
                {
                    // 如果任务为空且条码不为"NoRead"且条码不为空,则处理新任务
                    if (task == null && command.Barcode != "NoRead" && command.Barcode.IsNotEmptyOrNull())
                    task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
                    if (task != null)
                    {
                        // 查询条码对应的任务
                        task = _taskService.QueryBarcodeTask(command.Barcode, childDeviceCode);
                        if (task == null)
                        RequestInNextAddress(conveyorLine, command, childDeviceCode, ProtocalDetailValue);
                    }
                    else
                    {
                        // 如果任务为空且条码不为"NoRead"且条码不为空,则处理新任务
                        if (task == null && command.Barcode != "NoRead" && command.Barcode.IsNotEmptyOrNull())
                        {
                            // 异步处理新任务
                            await HandleNewTaskAsync(conveyorLine, command, childDeviceCode, ProtocalDetailValue);
                            // 查询条码对应的任务
                            task = _taskService.QueryBarcodeTask(command.Barcode, childDeviceCode);
                            if (task == null)
                            {
                                // 异步处理新任务
                                await HandleNewTaskAsync(conveyorLine, command, childDeviceCode, ProtocalDetailValue);
                            }
                        }
                    }
                }
@@ -385,28 +387,26 @@
                    IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == platform.PLCCode);
                    if (device != null)
                    {
                        int x = 3;
                        CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
                        foreach (var item in Location)
                        {
                            x--;
                            ConveyorLineTaskCommand command1 = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(item);
                            if (command1.InteractiveSignal != 2)
                            {
                                var tasks = _taskRepository.QueryData(x => (x.TaskType == (int)TaskInboundTypeEnum.InTray || x.TaskType == (int)TaskOutboundTypeEnum.OutTray) && x.TargetAddress == childDeviceCode);
                                // 如果已有任务数量小于指定索引
                                if (tasks.Count < Location.Count && tasks.Count < x)
                                if (tasks.Count < Location.Count)
                                {
                                    return childDeviceCode;
                                }
                                else
                                {
                                    var Hastask = _taskRepository.QueryData(x => x.TaskType == (int)TaskOutboundTypeEnum.OutTray && x.TargetAddress == childDeviceCode && x.Roadway.Contains("CH") && x.TaskState == (int)TaskOutStatusEnum.OutNew);
                                    if (Hastask != null && Hastask.Count > 0)
                                    {
                                        //doto处理陈化未执行的空托出库任务
                                    }
                                    //var Hastask = _taskRepository.QueryData(x => x.TaskType == (int)TaskOutboundTypeEnum.OutTray && x.TargetAddress == childDeviceCode && x.Roadway.Contains("CH") && x.TaskState == (int)TaskOutStatusEnum.OutNew);
                                    //if (Hastask != null && Hastask.Count > 0)
                                    //{
                                    //    //doto处理陈化未执行的空托出库任务
                                    //}
                                    return null;
                                }
                            }
@@ -470,6 +470,8 @@
                        WriteInfo(conveyorLine.DeviceName, logs);
                        conveyorLine.SendCommand(taskCommand, childDeviceCode);
                        ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
                    }
                }
            }