formatBatchReport 格式化批量报告
(report *types.BatchReport)
| 278 | |
| 279 | // formatBatchReport 格式化批量报告 |
| 280 | func (bm *Manager) formatBatchReport(report *types.BatchReport) string { |
| 281 | var result strings.Builder |
| 282 | |
| 283 | // 报告头部 |
| 284 | result.WriteString(fmt.Sprintf(` |
| 285 | 批量检测报告 |
| 286 | 总耗时: %s |
| 287 | 检测域名: %d 个 |
| 288 | 成功率: %.1f%% |
| 289 | 适合性率: %.1f%% |
| 290 | |
| 291 | `, |
| 292 | formatDuration(report.TotalDuration), |
| 293 | report.Statistics.TotalDomains, |
| 294 | report.Summary.SuccessRate*100, |
| 295 | report.Summary.SuitabilityRate*100, |
| 296 | )) |
| 297 | |
| 298 | // 分离适合和不适合的域名 |
| 299 | var suitableResults []*types.DetectionResult |
| 300 | var unsuitableResults []*types.DetectionResult |
| 301 | var excludedResults []*types.DetectionResult // 状态码不自然的域名 |
| 302 | |
| 303 | for _, domainResult := range report.Results { |
| 304 | if domainResult.Suitable && domainResult.Error == nil { |
| 305 | suitableResults = append(suitableResults, domainResult) |
| 306 | } else { |
| 307 | // 检查是否因为状态码不自然而被排除 |
| 308 | if domainResult.StatusCodeCategory == types.StatusCodeCategoryExcluded { |
| 309 | excludedResults = append(excludedResults, domainResult) |
| 310 | } else { |
| 311 | unsuitableResults = append(unsuitableResults, domainResult) |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | // 显示适合的域名表格 |
| 317 | if len(suitableResults) > 0 { |
| 318 | // 按星级排序:1星在最上面,5星在最下面 |
| 319 | bm.sortByRecommendationStars(suitableResults) |
| 320 | |
| 321 | result.WriteString("适合的域名:\n\n") |
| 322 | result.WriteString(bm.tableFormatter.FormatSuitableTable(suitableResults)) |
| 323 | result.WriteString("\n") |
| 324 | } |
| 325 | |
| 326 | // 显示不适合的域名统计 |
| 327 | if len(unsuitableResults) > 0 { |
| 328 | result.WriteString(bm.tableFormatter.FormatUnsuitableSummary(unsuitableResults)) |
| 329 | } |
| 330 | |
| 331 | // 显示被排除的域名(状态码不自然) |
| 332 | if len(excludedResults) > 0 { |
| 333 | result.WriteString("\n") |
| 334 | result.WriteString(bm.formatExcludedDomains(excludedResults)) |
| 335 | } |
| 336 | |
| 337 | return result.String() |
no test coverage detected