namespace PLCSharp.Models; public sealed partial record ProjectBatch { public string Summary => Describe(); private string Describe() { bool undo = UndoOf.HasValue; var lines = new List(); var refs = new HashSet(); var manual = new HashSet(); foreach (var step in undo ? Steps.AsEnumerable().Reverse() : Steps) { if (step.Edit is { } edit) { string action = (edit.Action, undo) switch { ("create", false) or ("delete", true) => "新增", ("delete", false) or ("create", true) => "删除", _ => "修改" }; var fields = new List(); if (edit.Action == "update") foreach (var (key, value) in edit.After) { if (System.Text.Json.Nodes.JsonNode.DeepEquals(edit.Before[key], value)) continue; string from = (undo ? value : edit.Before[key])?.ToString() ?? "(空)"; string to = (undo ? edit.Before[key] : value)?.ToString() ?? "(空)"; string label = key switch { "Comment" => "备注", "Code" => "脚本", "ControlName" => "绑定控件", _ => key }; fields.Add(from.Length + to.Length <= 90 ? $"{label}由「{from}」改为「{to}」" : $"{label}有修改"); } lines.Add($"{action}{KindName(edit.Kind)}「{step.Name}」" + (fields.Count == 0 ? "" : $",{string.Join(",", fields)}")); foreach (var child in edit.OwnedRows) lines.Add($" 一并{(undo ? "恢复" : "删除")}{KindName(child.Kind)}「{child.Name}」"); foreach (var hit in edit.WorkflowReferences) refs.Add($"工作流「{hit["Name"]}」第 {hit["line"]} 行引用「{step.Name}」。"); foreach (var link in edit.ConfigReferences) refs.Add($"{KindName((string)link["table"])}的 {link["field"]} 引用「{step.Name}」。"); foreach (var hit in edit.ManualReferences) manual.Add($"「{hit["Name"]}」第 {hit["line"]} 行 · {hit["expression"]}"); } else if (step.Rename is { } rename) { lines.Add($"{KindName(rename.Kind)}「{(undo ? rename.NewName : rename.OldName)}」改名为「{(undo ? rename.OldName : rename.NewName)}」"); foreach (var flow in rename.Scripts) refs.Add($"工作流「{flow.Name}」同步更新。"); foreach (var hit in rename.ManualReferences) manual.Add($"「{hit["Name"]}」第 {hit["line"]} 行 · {hit["expression"]}"); foreach (var hit in rename.PointReferences.Concat(rename.MatrixReferences).Concat(rename.CylinderReferences)) refs.Add($"{KindName(hit.Table)}的 {hit.Field} 同步更新。"); foreach (var hit in rename.VisionReferences) refs.Add($"视觉功能的 {hit.Key} 同步更新。"); } } if (refs.Count > 0) { lines.Add("\n受影响的工作流和配置"); lines.AddRange(refs); } if (manual.Count > 0) { lines.Add("\n需要人工核对的引用"); lines.AddRange(manual); } lines.Add(Workflows.Count == 0 ? "没有需要编译的工作流。" : $"工作流编译结果(未运行):{string.Join("、", Workflows.Select(f => $"{f.Name}({(f.Compiled ? "通过" : "失败")})"))}"); return string.Join("\n", lines); } private static string KindName(string kind) => kind switch { "VisionLocalVariables" => "视觉局部变量", "ControlMeasurements" => "控件测量项", "InterpolationSegments" => "插补段", "InterpolationPoints" => "插补段内点", "Recipes" => "配方", "SystemVariables" => "系统变量", "CustomControls" => "主页控件", "Matrices" => "轴矩阵", "RobotMatrices" => "机器人矩阵", "InterpolationGroups" => "插补组", "Cameras" => "相机", "ImageDatas" => "视觉图像数据", "LocalImageDatas" => "本地图像数据", "Cylinders" => "气缸", "Robots" => "机器人", "Connects" => "通信连接", "DI" => "数字输入", "DQ" => "数字输出", "Axes" => "运动轴", "VisionFunctions" => "视觉功能", "Workflows" => "工作流", "AxisPoints" or "RobotPoints" => "点位", "Controllers" => "运动控制器", "CanvasConfigs" => "主页画布", "Variables" => "配方变量", _ => kind }; }