wanshenmean
3 天以前 b690250002ee04f4309e6a90fd16fbfd9bd959e2
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs
@@ -81,7 +81,7 @@
        /// <summary>
        /// 日志记录器
        /// </summary>
        private readonly ILogger  _logger;
        private readonly ILogger _logger;
        /// <summary>
        /// 堆垛机设备编码
@@ -121,36 +121,6 @@
        }
        /// <summary>
        /// 加载配置文件(优先级:配置文件 > 默认配置)
        /// </summary>
        /// <remarks>
        /// 从应用程序目录下的 StackerCraneJob/stackercrane-command-config.json 读取配置。
        /// 如果文件不存在或解析失败,使用默认配置。
        /// </remarks>
        /// <returns>堆垛机命令配置</returns>
        private static StackerCraneCommandConfig LoadConfig()
        {
            try
            {
                // 构造配置文件路径
                string configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "StackerCraneJob", "stackercrane-command-config.json");
                if (File.Exists(configPath))
                {
                    // 读取并解析 JSON 配置
                    string json = File.ReadAllText(configPath);
                    return System.Text.Json.JsonSerializer.Deserialize<StackerCraneCommandConfig>(json) ?? new StackerCraneCommandConfig();
                }
            }
            catch (Exception ex)
            {
                // 配置加载失败,使用默认配置
                Console.WriteLine($"配置加载失败: {ex.Message},使用默认配置");
            }
            return new StackerCraneCommandConfig();
        }
        /// <summary>
        /// Quartz Job 的执行入口
        /// </summary>
        /// <remarks>
@@ -174,9 +144,8 @@
                bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
                if (!flag || value is not CommonStackerCrane commonStackerCrane)
                {
                    _logger.Information("Execute:参数无效,未找到 JobParams 或类型不匹配");
                    // 参数无效,直接返回
                    QuartzLogHelper.LogWarn(_logger, "Execute:参数无效", "Execute:参数无效", "CommonStackerCraneJob");
                    QuartzLogHelper.LogInfo(_logger, "Execute:参数无效", "CommonStackerCraneJob");
                    return Task.CompletedTask;
                }
@@ -216,7 +185,6 @@
                if (stackerCraneTaskCommand == null)
                {
                    // 命令构建失败
                    QuartzLogHelper.LogWarn(_logger, "Execute:命令构建失败,设备: {DeviceCode},任务号: {TaskNum}", $"命令构建失败,任务号: {task.TaskNum}", _deviceCode, _deviceCode, task.TaskNum);
                    return Task.CompletedTask;
                }
@@ -230,17 +198,17 @@
                    commonStackerCrane.LastTaskType = task.TaskType;
                    _taskService.UpdateTaskStatusToNext(task.TaskNum);
                    QuartzLogHelper.LogInfo(_logger, "Execute:命令发送成功,设备: {DeviceCode},任务号: {TaskNum}", $"命令发送成功,任务号: {task.TaskNum}", _deviceCode, _deviceCode, task.TaskNum);
                    QuartzLogHelper.LogInfo(_logger, $"Execute:命令发送成功,设备: {_deviceCode},任务号: {task.TaskNum}", _deviceCode);
                }
                else
                {
                    QuartzLogHelper.LogError(_logger, "Execute:命令发送失败,设备: {DeviceCode},任务号: {TaskNum}", $"命令发送失败", _deviceCode, _deviceCode, task.TaskNum);
                    QuartzLogHelper.LogInfo(_logger, $"Execute:命令发送失败,设备: {_deviceCode},任务号: {task.TaskNum}", _deviceCode);
                }
            }
            catch (Exception ex)
            {
                // 记录异常
                QuartzLogHelper.LogError(_logger, ex, "Execute:执行异常,设备: {DeviceCode}", $"执行异常: {ex.Message}", _deviceCode, _deviceCode);
                QuartzLogHelper.LogError(_logger, ex, $"Execute:执行异常,设备: {_deviceCode}", $"执行异常: {ex.Message}", _deviceCode, _deviceCode);
            }
            finally
            {
@@ -268,7 +236,7 @@
            if (stackerCrane != null)
            {
                // 记录日志
                QuartzLogHelper.LogInfo(_logger, "CommonStackerCrane_StackerCraneTaskCompletedEventHandler:任务完成,任务号: {TaskNum}", $"任务完成,任务号: {e.TaskNum}", stackerCrane.DeviceCode, e.TaskNum);
                QuartzLogHelper.LogInfo(_logger, $"CommonStackerCrane_StackerCraneTaskCompletedEventHandler:任务完成,任务号: {e.TaskNum}", stackerCrane.DeviceCode);
                // 更新任务状态为完成
                if (_taskService.StackCraneTaskCompleted(e.TaskNum).Status)