@@ -71,18 +71,28 @@ impl Stats {
71
71
72
72
impl fmt:: Display for Stats {
73
73
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
74
+ writeln ! ( f, "邮件发送统计报告" ) ?;
75
+ writeln ! ( f, "===================" ) ?;
76
+ writeln ! ( f, "1. 基本统计" ) ?;
74
77
writeln ! ( f, " 总计处理: {} 封邮件" , self . email_count) ?;
75
78
writeln ! ( f, " 成功发送: {} 封" , self . email_count - self . send_errors - self . parse_errors) ?;
76
- writeln ! ( f, " 解析失败: {} 封" , self . parse_errors) ?;
77
- writeln ! ( f, " 发送失败: {} 封" , self . send_errors) ?;
79
+ writeln ! ( f, " 总计失败: {} 封" , self . send_errors + self . parse_errors) ?;
78
80
79
81
if !self . error_details . is_empty ( ) {
80
- writeln ! ( f, " 发送失败详情:" ) ?;
81
- for ( error_type, count) in & self . error_details {
82
- writeln ! ( f, " {}: {} 封" , error_type, count) ?;
82
+ writeln ! ( f, "\n 2. 错误分类统计" ) ?;
83
+ let mut sorted_errors: Vec < _ > = self . error_details . iter ( ) . collect ( ) ;
84
+ sorted_errors. sort_by ( |a, b| b. 1 . cmp ( a. 1 ) ) ;
85
+
86
+ for ( error_type, count) in sorted_errors {
87
+ writeln ! ( f, " {} - {} 封 ({:.1}%)" ,
88
+ error_type,
89
+ count,
90
+ ( * count as f64 / self . email_count as f64 ) * 100.0
91
+ ) ?;
83
92
if let Some ( files) = self . failed_files . get ( error_type) {
93
+ writeln ! ( f, " 失败文件列表:" ) ?;
84
94
for file in files {
85
- writeln ! ( f, " - {}" , file) ?;
95
+ writeln ! ( f, " - {}" , file) ?;
86
96
}
87
97
}
88
98
}
0 commit comments