using SQLLinter.Common; using SQLLinter.Infrastructure.Diagram; using System.Text; namespace SQLLinter.Infrastructure.Reporters; public class HtmlReportFormatter_v1 : IReportFormatter { public string Format(List violations) => Format(violations, null); public string Format(List violations, BpmnDiagram? diagram) { if (violations.Count == 0) { return "

Нет нарушений

"; } var groupedByFile = violations .GroupBy(v => v.FileName) .OrderBy(g => g.Key); var sb = new StringBuilder(); sb.AppendLine(""); sb.AppendLine(""); sb.AppendLine(""); sb.AppendLine(""); sb.AppendLine("Отчёт по SQL‑проверкам"); sb.AppendLine(""); sb.AppendLine(""); sb.AppendLine(""); //sb.AppendLine("

Отчёт по SQL‑проверкам

"); int fileIndex = 0; foreach (var fileGroup in groupedByFile) { string divId = $"file_{fileIndex}"; sb.AppendLine($"
"); sb.AppendLine($"

Файл: {fileGroup.Key}

"); var groupedBySeverity = fileGroup .GroupBy(v => v.Severity) .OrderByDescending(g => g.Key); foreach (var severityGroup in groupedBySeverity) { string severityClass = severityGroup.Key switch { RuleViolationSeverity.Critical => "critical", RuleViolationSeverity.Warning => "warning", RuleViolationSeverity.Info => "info", _ => "" }; sb.AppendLine($"
"); sb.AppendLine($"

{severityGroup.Key}

"); sb.AppendLine(""); sb.AppendLine(""); sb.AppendLine(""); sb.AppendLine(""); sb.AppendLine(""); int rowIndex = 1; foreach (var v in severityGroup .OrderBy(x => x.Line) .ThenBy(x => x.Column)) { sb.AppendLine($""); rowIndex++; } sb.AppendLine(""); sb.AppendLine("
#СтрокаКолонкаПравилоОписание
{rowIndex}{v.Line}{v.Column}{v.RuleName}{v.Text}
"); sb.AppendLine("
"); } sb.AppendLine("
"); fileIndex++; } // Табы снизу sb.AppendLine("
"); fileIndex = 0; foreach (var fileGroup in groupedByFile) { sb.AppendLine($"
{fileGroup.Key}
"); fileIndex++; } sb.AppendLine("
"); // JS для переключения sb.AppendLine(""); sb.AppendLine(""); sb.AppendLine(""); return HtmlMinifier.MinifyHtml(sb.ToString()); } }