肖洋
2025-01-19 d59b540dd78d49ddf1f2e1c6dfb7b19a7d3e3d7c
优化代码结构和错误处理

在.gitignore文件中添加忽略调试和Copilot相关文件路径规则。
注释掉CommonConveyorLineJob.cs中不必要的日志记录,减少控制台输出。
设备查询逻辑修改为直接查询状态为"1"的设备,更新相关HTTP请求。
RequestInbound.cs中注释未使用的配置查询部分,并优化任务逻辑以提高可读性。
Dt_TaskService.cs添加清晰的错误反馈处理,并增加条件以优化数据过滤。
在任务相关逻辑中增加了更稳健的异常处理和调试输出。
已修改4个文件
111 ■■■■■ 文件已修改
.gitignore 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_GW/GWTask/RequestInbound.cs 76 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.gitignore
@@ -1654,3 +1654,15 @@
/Code Management/WCS/WIDESEAWCS_Server/.vs/WIDESEAWCS_Server/copilot-chat/bef6627e/sessions/36708593-3f69-4656-815a-651b3ad17c7d
*.xml
/Code Management/WMS/WIDESEA_WMSClient/report_form_rollup-plugin-visualizer.html
/Code Management/WCS/WIDESEAWCS_Server/.vs/WIDESEAWCS_Server/CopilotIndices/17.12.53.23981/CodeChunks.db
/Code Management/WCS/WIDESEAWCS_Server/.vs/WIDESEAWCS_Server/CopilotIndices/17.12.53.23981/CodeChunks.db-shm
/Code Management/WCS/WIDESEAWCS_Server/.vs/WIDESEAWCS_Server/CopilotIndices/17.12.53.23981/CodeChunks.db-wal
/Code Management/WCS/WIDESEAWCS_Server/.vs/WIDESEAWCS_Server/CopilotIndices/17.12.53.23981/SemanticSymbols.db
/Code Management/WCS/WIDESEAWCS_Server/.vs/WIDESEAWCS_Server/CopilotIndices/17.12.53.23981/SemanticSymbols.db-shm
/Code Management/WCS/WIDESEAWCS_Server/.vs/WIDESEAWCS_Server/CopilotIndices/17.12.53.23981/SemanticSymbols.db-wal
/Code Management/WMS/WIDESEA_WMSServer/.vs/WIDESEA_WMSServer/CopilotIndices/17.12.53.23981/CodeChunks.db
/Code Management/WMS/WIDESEA_WMSServer/.vs/WIDESEA_WMSServer/CopilotIndices/17.12.53.23981/CodeChunks.db-shm
/Code Management/WMS/WIDESEA_WMSServer/.vs/WIDESEA_WMSServer/CopilotIndices/17.12.53.23981/CodeChunks.db-wal
/Code Management/WMS/WIDESEA_WMSServer/.vs/WIDESEA_WMSServer/CopilotIndices/17.12.53.23981/SemanticSymbols.db
/Code Management/WMS/WIDESEA_WMSServer/.vs/WIDESEA_WMSServer/CopilotIndices/17.12.53.23981/SemanticSymbols.db-shm
/Code Management/WMS/WIDESEA_WMSServer/.vs/WIDESEA_WMSServer/CopilotIndices/17.12.53.23981/SemanticSymbols.db-wal
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
@@ -77,7 +77,7 @@
                CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
                if (conveyorLine != null)
                {
                    ConsoleHelper.WriteColorLine("开始:" + DateTime.Now, ConsoleColor.Cyan);
                    //ConsoleHelper.WriteColorLine("开始:" + DateTime.Now, ConsoleColor.Cyan);
                    // 查询所有子设备的位置
                    List<string> childDeviceCodes = _routerService.QueryAllPositions(conveyorLine.DeviceCode);
                    // 获取所有站点管理器
@@ -185,7 +185,7 @@
                    await Task.WhenAll(tasks);
                    ConsoleHelper.WriteColorLine("结束:" + DateTime.Now, ConsoleColor.Cyan);
                    //ConsoleHelper.WriteColorLine("结束:" + DateTime.Now, ConsoleColor.Cyan);
                }
            }
            catch (Exception ex)
@@ -768,7 +768,7 @@
                }
                var wmsIpAddress = wmsBase + requestTrayOutTask;
                var device = _deviceInfoRepository.QueryData(x => x.DeviceStatus == "1" && x.DeviceRemark == platform.Id.ToString());
                var device = _deviceInfoRepository.QueryData(x => x.DeviceStatus == "1");
                var deviceCode = device.Select(x => x.DeviceCode).ToList();
                // 发送HTTP POST请求获取任务数据
@@ -798,7 +798,7 @@
            var content = _taskService.ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO });
            if (content.Status)
            {
                Console.WriteLine($"{taskDTO.TaskType}呼叫成功");
                Console.WriteLine($"{taskDTO.TargetAddress}呼叫成功");
            }
            return content;
        }
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_GW/GWTask/RequestInbound.cs
@@ -238,50 +238,50 @@
        {
            if (command.ConveyorLineBarcode != "NoRead")
            {
                var config = _sys_ConfigService.GetByConfigKey("SYS_BASE", "ISFRINTRAY");
                if (config.ConfigValue == "1")
                //var config = _sys_ConfigService.GetByConfigKey("SYS_BASE", "ISFRINTRAY");
                //if (config.ConfigValue == "1")
                //{
                //    Random random = new Random();
                //    var task = new Dt_Task()
                //    {
                //        CurrentAddress = childDeviceCode,
                //        Grade = 1,
                //        NextAddress = "2066",
                //        PalletCode = command.ConveyorLineBarcode,
                //        Roadway = "FR",
                //        SourceAddress = childDeviceCode,
                //        TargetAddress = "2066",
                //        TaskNum = random.Next(1,9999),
                //        TaskType = (int)TaskInboundTypeEnum.InTray,
                //        TaskState = (int)TaskInStatusEnum.Line_InExecuting,
                //        WMSId = 0
                //    };
                //    var taskCommand = MapTaskCommand(task, command);
                //    conveyorLine.SendCommand(taskCommand, childDeviceCode);
                //}
                //else
                //{
                var taskDTO = CreateEmptyTrayTaskDto(command.ConveyorLineBarcode, childDeviceCode);
                if (_taskRepository.QueryFirst(x => x.PalletCode == taskDTO.PalletCode) != null)
                {
                    Random random = new Random();
                    var task = new Dt_Task()
                    {
                        CurrentAddress = childDeviceCode,
                        Grade = 1,
                        NextAddress = "2066",
                        PalletCode = command.ConveyorLineBarcode,
                        Roadway = "FR",
                        SourceAddress = childDeviceCode,
                        TargetAddress = "2066",
                        TaskNum = random.Next(1,9999),
                        TaskType = (int)TaskInboundTypeEnum.InTray,
                        TaskState = (int)TaskInStatusEnum.Line_InExecuting,
                        WMSId = 0
                    };
                    var taskCommand = MapTaskCommand(task, command);
                    conveyorLine.SendCommand(taskCommand, childDeviceCode);
                    WriteInfo(conveyorLine.DeviceName, "当前托盘存在任务");
                    return;
                }
                else
                var content = CreateAndSendTask(taskDTO);
                if (content.Status)
                {
                    var taskDTO = CreateEmptyTrayTaskDto(command.ConveyorLineBarcode, childDeviceCode);
                    if (_taskRepository.QueryFirst(x => x.PalletCode == taskDTO.PalletCode) != null)
                    var task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
                    if (task != null)
                    {
                        WriteInfo(conveyorLine.DeviceName, "当前托盘存在任务");
                        return;
                    }
                    var content = CreateAndSendTask(taskDTO);
                    if (content.Status)
                    {
                        var task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
                        if (task != null)
                        {
                            var taskCommand = MapTaskCommand(task, command);
                            conveyorLine.SendCommand(taskCommand, childDeviceCode);
                            //ConveyorLineSendFinish(conveyorLine, childDeviceCode, true);
                            _taskService.UpdateTaskStatusToNext(task);
                        }
                        var taskCommand = MapTaskCommand(task, command);
                        conveyorLine.SendCommand(taskCommand, childDeviceCode);
                        //ConveyorLineSendFinish(conveyorLine, childDeviceCode, true);
                        _taskService.UpdateTaskStatusToNext(task);
                    }
                }
                //}
            }
        }
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs
@@ -168,7 +168,6 @@
                        if (content.Status)
                        {
                            var result = JsonConvert.DeserializeObject<BasicResult>(content.Data.ToString());
                            task.Remark = result.Success ? null : "NG";
                            if (!result.Success && result.MessageCode == "E10001")
                            {
@@ -178,9 +177,17 @@
                        else
                        {
                            task.Remark = "NG";
                            ConsoleHelper.WriteErrorLine("MOM通报点芯NG");
                            return content.Error("MOM通报点芯NG");
                        }
                    }
                }
            }
            if (task.Remark == "NG")
            {
                ConsoleHelper.WriteErrorLine("MOM通报点芯NG");
                return content.Error("MOM通报点芯NG");
            }
            // 更新库存状态和任务状态
@@ -738,7 +745,7 @@
                return content.Error(result.MOMMessage);
            // 获取异常电芯
            List<SerialNoDto>? serialNosError = result.SerialNos.Where(x => x.SerialNoStatus != 1).ToList();
            List<SerialNoDto>? serialNosError = result.SerialNos.Where(x => x.SerialNoStatus != 1 && x.SerialNoStatus != 4).ToList();
            if (serialNosError.Count > 0)
            {
                // TODO 创建任务送至NG排出口
@@ -1089,7 +1096,7 @@
                    throw new Exception("未找到空托盘入库站台和入库站台配置");
            }
            List<string> strings = stationManagers.Roadway.Split(',').ToList();
            Console.WriteLine(strings.ToJsonString() + "b-----------------------");
            //Console.WriteLine(strings.ToJsonString() + "b-----------------------");
            return await CreateNewTask(input, strings, 1);
        }
@@ -1265,7 +1272,7 @@
    /// <summary>
    /// 查询空盘库存信息
    /// </summary>
    private async Task<DtStockInfo> QueryStockInfoForEmptyTrayAsync(string areaCode,string position)
    private async Task<DtStockInfo> QueryStockInfoForEmptyTrayAsync(string areaCode, string position)
    {
        var area = await _areaInfoRepository.QueryFirstAsync(x => x.AreaCode == areaCode);