aio_elin 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,562 +3,580 @@
3
3
  require "aio/core"
4
4
 
5
5
  class Aio::Module::OutputStyle::SummaryReport < Aio::Module::OutputStyle
6
- include Aio::Module
7
- include Aio::Device
8
- include Aio::Base::Toolkit::WordWps
9
- include Aio::Base::Toolkit::ExcelWps
10
- include Aio::Ui::Verbose
11
-
12
- PlaceHolder = "###"
13
-
14
- def initialize
15
- super({
16
- :author => "Elin",
17
- :description => "输出巡检简要报告, 以WPS运行",
18
- :file_suffix => "doc",
6
+ include Aio::Module
7
+ include Aio::Device
8
+ include Aio::Base::Toolkit::WordWps
9
+ include Aio::Base::Toolkit::ExcelWps
10
+ include Aio::Ui::Verbose
11
+
12
+ PlaceHolder = "###"
13
+
14
+ def initialize
15
+ super({
16
+ :author => "Elin",
17
+ :description => "输出巡检简要报告, 以WPS运行",
18
+ :file_suffix => "doc",
19
19
  :platform => ['windows']
20
20
  })
21
- end
22
-
23
- def generate
24
-
25
- word = Word.new
26
- #word.show
27
- word.display_alerts = false
28
- @doc = word.init_document
29
- @text = @doc.add_text
30
-
31
- # 创建风格
32
- create_style
33
-
34
- device_manager.devices.each_pair do |device_name, klass|
35
- #puts "summary_report"
36
- #pp device_name
37
- #pp klass.warning_klass
38
- end
39
-
40
- # 附带信息
41
- info = {
42
- :resource_file => File.join(::BaseFile, "aio", "resource"),
43
- :client => "中国银行湖北省分行",
44
- :time => ::Time.now.to_s.split(' ')[0],
45
-
46
- }
47
-
48
- # 标号
49
- @mark = [0, 0, 0]
50
-
51
- # 按流程算法运行
52
- process(info)
53
-
54
- # 保存
55
- word.display_alerts = true
56
-
57
- begin
58
- word.save(output_file.to_s)
59
- rescue Exception => e
60
- e.message
61
- ensure
62
- #word.close
63
- end
64
- end
65
-
66
- # 创建风格
67
- def create_style
68
-
69
- # 用于目录的标题
70
- @doc.create_style_self("Contents") do |sty|
71
- sty.font.size = 20
72
- sty.font.NameFarEast = "黑体"
73
- sty.font.NameAscii = "Book Antiqua"
74
- sty.font.NameOther = "Book Antiqua"
75
- sty.font.bold = true
76
- # 段落间距
77
- sty.ParagraphFormat.Alignment = 2 # 文本右对齐
78
- sty.ParagraphFormat.LineUnitBefore = 3 #
79
- sty.ParagraphFormat.LineUnitAfter = 2
80
- sty.NextParagraphStyle = "正文"
81
- # 段落控制
82
- sty.ParagraphFormat.WidowControl = true
83
- sty.ParagraphFormat.KeepWithNext = true
84
- sty.ParagraphFormat.PageBreakBefore = true
85
- # 边框
86
- sty.ParagraphFormat.Borders(-1).LineStyle = 0
87
- sty.ParagraphFormat.Borders(-2).LineStyle = 0
88
- sty.ParagraphFormat.Borders(-4).LineStyle = 0
89
- bottom = sty.ParagraphFormat.Borders(-3)
90
- bottom.LineStyle = 1
91
- bottom.LineWidth = 12
92
- bottom.Color = 0
93
- end
94
-
95
- # 一级标题
96
- @doc.create_style_self("font_chapter_name1") do |sty|
97
- sty.BaseStyle = "Contents"
98
- sty.ParagraphFormat.OutlineLevel = 1
99
- sty.NextParagraphStyle = "正文"
100
- end
101
-
102
- # 一级标题标号
103
- @doc.create_style_self("font_chapter_num1") do |sty|
104
- sty.BaseStyle = "Contents"
105
- sty.font.size = 72
106
- sty.ParagraphFormat.LineUnitBefore = 0.5
107
- sty.ParagraphFormat.LineUnitAfter = 0.5
108
- sty.ParagraphFormat.OutlineLevel = 1
109
- sty.NextParagraphStyle = "font_chapter_name1"
110
- end
111
-
112
- # 二级标题
113
- @doc.create_style_self("font_section_name1") do |sty|
114
- sty.BaseStyle = "正文"
115
- sty.font.bold = true
116
- sty.font.size = 18
117
- sty.ParagraphFormat.LineUnitBefore = 1
118
- sty.ParagraphFormat.LineUnitAfter = 1
119
- sty.ParagraphFormat.OutlineLevel = 2
120
- sty.NextParagraphStyle = "正文"
121
- end
122
-
123
- # 二级标题标号
124
- @doc.create_style_self("font_section_num1") do |sty|
125
- sty.BaseStyle = "font_section_name1"
126
- sty.NextParagraphStyle = "font_section_name1"
127
- end
128
-
129
- @doc.create_style_self("font_level3_name1") do |sty|
130
- sty.BaseStyle = "正文"
131
- sty.font.bold = true
132
- sty.font.size = 18
133
- sty.ParagraphFormat.LineUnitBefore = 1
134
- sty.ParagraphFormat.LineUnitAfter = 1
135
- sty.ParagraphFormat.OutlineLevel = 3
136
- sty.NextParagraphStyle = "正文"
137
- end
138
-
139
- @doc.create_style_self("font_level3_num1") do |sty|
140
- sty.BaseStyle = "font_level3_name1"
141
- sty.NextParagraphStyle = "font_level3_name1"
142
- end
143
-
144
- # 要点
145
- @doc.create_style_self("importance") do |sty|
146
- sty.BaseStyle = "正文"
147
- sty.font.bold = true
148
- sty.font.size = 18
149
- sty.ParagraphFormat.LineUnitBefore = 1
150
- sty.ParagraphFormat.LineUnitAfter = 1
151
- sty.NextParagraphStyle = "正文"
152
- end
153
- end
154
-
155
- # 主体流程控制
156
- def process(info)
157
- generate_cover(info)
158
- generate_catalog(info)
159
- generate_introduction(info)
160
-
161
- generate_summary(info)
162
- generate_summarize(info)
163
- update_catalog
164
- end
165
-
166
- # 创建封面
167
- def generate_cover(info)
168
- @text.add_head_image(File.join(info[:resource_file], "cover_picture.png"))
169
- @text.style = "正文"
170
- @text.entry
171
- @text.entry
172
- @text.entry
173
-
174
- @text.font.size = 16
175
- @text.center
176
- @text.section { "数据通信网络高级巡检报告" }
177
- @text.entry
178
- @text.entry
179
-
180
- client = info[:client]
181
- time = info[:time]
182
- @text.font.Size = 15
183
- @text.section { "客户名称:#{client}" }
184
- @text.section { "巡检时间:#{time}" }
185
-
186
- @text.add_table(1,1) { |tbl| }
21
+
22
+ # 附带信息
23
+ @info = {
24
+ :resource_file => File.join(::BaseFile, "aio", "resource"),
25
+ :client => nil,
26
+ :time => ::Time.now.to_s.split(' ')[0],
27
+ }
28
+ end
29
+
30
+ def info_client=(e)
31
+ @info[:client] = e
32
+ end
33
+
34
+ def info_time=(e)
35
+ @info[:time] = e
36
+ end
37
+
38
+ def info
39
+ @info
40
+ end
41
+
42
+
43
+ def generate
44
+
45
+ word = Word.new
46
+ #word.show
47
+ word.display_alerts = false
48
+ @doc = word.init_document
49
+ @text = @doc.add_text
50
+
51
+ # 创建风格
52
+ create_style
53
+
54
+ device_manager.devices.each_pair do |device_name, klass|
55
+ #puts "summary_report"
56
+ #pp device_name
57
+ #pp klass.warning_klass
58
+ end
59
+
60
+
61
+ # 标号
62
+ @mark = [0, 0, 0]
63
+
64
+ # 按流程算法运行
65
+ process(info)
66
+
67
+ # 保存
68
+ word.display_alerts = true
69
+
70
+ begin
71
+ word.save(output_file.to_s)
72
+ rescue Exception => e
73
+ e.message
74
+ ensure
75
+ #word.close
76
+ end
77
+ end
78
+
79
+ # 创建风格
80
+ def create_style
81
+
82
+ # 用于目录的标题
83
+ @doc.create_style_self("Contents") do |sty|
84
+ sty.font.size = 20
85
+ sty.font.NameFarEast = "黑体"
86
+ sty.font.NameAscii = "Book Antiqua"
87
+ sty.font.NameOther = "Book Antiqua"
88
+ sty.font.bold = true
89
+ # 段落间距
90
+ sty.ParagraphFormat.Alignment = 2 # 文本右对齐
91
+ sty.ParagraphFormat.LineUnitBefore = 3 #
92
+ sty.ParagraphFormat.LineUnitAfter = 2
93
+ sty.NextParagraphStyle = "正文"
94
+ # 段落控制
95
+ sty.ParagraphFormat.WidowControl = true
96
+ sty.ParagraphFormat.KeepWithNext = true
97
+ sty.ParagraphFormat.PageBreakBefore = true
98
+ # 边框
99
+ sty.ParagraphFormat.Borders(-1).LineStyle = 0
100
+ sty.ParagraphFormat.Borders(-2).LineStyle = 0
101
+ sty.ParagraphFormat.Borders(-4).LineStyle = 0
102
+ bottom = sty.ParagraphFormat.Borders(-3)
103
+ bottom.LineStyle = 1
104
+ bottom.LineWidth = 12
105
+ bottom.Color = 0
106
+ end
107
+
108
+ # 一级标题
109
+ @doc.create_style_self("font_chapter_name1") do |sty|
110
+ sty.BaseStyle = "Contents"
111
+ sty.ParagraphFormat.OutlineLevel = 1
112
+ sty.NextParagraphStyle = "正文"
113
+ end
114
+
115
+ # 一级标题标号
116
+ @doc.create_style_self("font_chapter_num1") do |sty|
117
+ sty.BaseStyle = "Contents"
118
+ sty.font.size = 72
119
+ sty.ParagraphFormat.LineUnitBefore = 0.5
120
+ sty.ParagraphFormat.LineUnitAfter = 0.5
121
+ sty.ParagraphFormat.OutlineLevel = 1
122
+ sty.NextParagraphStyle = "font_chapter_name1"
123
+ end
124
+
125
+ # 二级标题
126
+ @doc.create_style_self("font_section_name1") do |sty|
127
+ sty.BaseStyle = "正文"
128
+ sty.font.bold = true
129
+ sty.font.size = 18
130
+ sty.ParagraphFormat.LineUnitBefore = 1
131
+ sty.ParagraphFormat.LineUnitAfter = 1
132
+ sty.ParagraphFormat.OutlineLevel = 2
133
+ sty.NextParagraphStyle = "正文"
134
+ end
135
+
136
+ # 二级标题标号
137
+ @doc.create_style_self("font_section_num1") do |sty|
138
+ sty.BaseStyle = "font_section_name1"
139
+ sty.NextParagraphStyle = "font_section_name1"
140
+ end
141
+
142
+ @doc.create_style_self("font_level3_name1") do |sty|
143
+ sty.BaseStyle = "正文"
144
+ sty.font.bold = true
145
+ sty.font.size = 18
146
+ sty.ParagraphFormat.LineUnitBefore = 1
147
+ sty.ParagraphFormat.LineUnitAfter = 1
148
+ sty.ParagraphFormat.OutlineLevel = 3
149
+ sty.NextParagraphStyle = "正文"
150
+ end
151
+
152
+ @doc.create_style_self("font_level3_num1") do |sty|
153
+ sty.BaseStyle = "font_level3_name1"
154
+ sty.NextParagraphStyle = "font_level3_name1"
155
+ end
156
+
157
+ # 要点
158
+ @doc.create_style_self("importance") do |sty|
159
+ sty.BaseStyle = "正文"
160
+ sty.font.bold = true
161
+ sty.font.size = 18
162
+ sty.ParagraphFormat.LineUnitBefore = 1
163
+ sty.ParagraphFormat.LineUnitAfter = 1
164
+ sty.NextParagraphStyle = "正文"
165
+ end
166
+ end
167
+
168
+ # 主体流程控制
169
+ def process(info)
170
+ generate_cover(info)
171
+ generate_catalog(info)
172
+ generate_introduction(info)
173
+
174
+ generate_summary(info)
175
+ generate_summarize(info)
176
+ update_catalog
177
+ end
178
+
179
+ # 创建封面
180
+ def generate_cover(info)
181
+ @text.add_head_image(File.join(info[:resource_file], "cover_picture.png"))
182
+ @text.style = "正文"
183
+ @text.entry
184
+ @text.entry
185
+ @text.entry
186
+
187
+ @text.font.size = 16
188
+ @text.center
189
+ @text.section { "数据通信网络高级巡检报告" }
190
+ @text.entry
191
+ @text.entry
192
+
193
+ client = info[:client]
194
+ time = info[:time]
195
+ @text.font.Size = 15
196
+ @text.section { "客户名称:#{client}" }
197
+ @text.section { "巡检时间:#{time}" }
198
+
199
+ @text.add_table(1,1) { |tbl| }
187
200
  =begin
188
- @text.entry
189
- @text.entry
190
- @text.entry
201
+ @text.entry
202
+ @text.entry
203
+ @text.entry
191
204
 
192
- @text.left
193
- @text.font.bold = true
194
- @text.add_image(File.join(info[:resource_file], "logo.png"))
205
+ @text.left
206
+ @text.font.bold = true
207
+ @text.add_image(File.join(info[:resource_file], "logo.png"))
195
208
  =end
196
- end
197
-
198
- # 生成目录
199
- def generate_catalog(info)
200
- @text.section("Contents") { "目 录" }
201
- @doc.create_catalog
202
- @text.page_break
203
- end
204
-
205
- # 生成前言
206
- def generate_introduction(info)
207
- @text.section("font_chapter_name1") { "前言" }
208
- @text.section("font_section_name1") { "概述" }
209
- @text.puts "根据#{info[:client]}的运行维护需要,公司对其网络设备进行了巡检。本文档提供了本次巡检所有设备的检查明细信息及汇总信息,针对检查中发现的设备在运行过程中存在的故障隐患和风险提出了相关建议,并对网络整体的健康程度进行了评估。"
210
- @text.entry
211
- @text.puts "通过本文档,您可以及时了解网络设备的健康状况,清除设备故障隐患,指导技术人员完成对网络的改造优化,提高网络的可用性,保障业务可靠运行。"
212
-
213
- @text.section("font_section_name1") { "读者对象" }
214
- @text.puts "本项目相关的网络运行维护主管、技术工程师、系统集成商工程师等。"
215
-
216
- @text.page_break
217
- @text.entry
218
- @text.section("importance") { "尊敬的_______________________ :" }
219
- @text.puts "感谢您选择我们的产品和服务!为了提高网络的可用性,保障网络的稳定运行,我们于#{info[:time]}对贵单位网络设备进行了巡检服务。现将本次服务的情况向您汇报如下,并请您对我们的工作给予评价。"
220
- @text.entry
221
- @text.puts "感谢您和您的团队在本次服务过程中给我们的配合和支持!"
222
- @text.entry
223
- @text.entry
224
- @text.entry
225
- @text.entry
226
- @text.entry
227
- @text.entry
228
- @text.entry
229
- @text.puts "本次巡检负责人:"
230
- @text.puts "联系电话:"
231
- @text.puts "联系邮箱:"
232
- end
233
-
234
- ###
235
- #
236
- # 巡检概要报告
237
- #
238
- ###
239
- # 流程控制
240
- def generate_summary(info)
241
- add_title_1("巡检概要报告")
242
- generate_summary_overview(info)
243
- generate_summary_device_type(info)
244
- generate_summary_warning_device_top10(info)
245
- generate_summary_level(info)
246
- generate_summary_problem(info)
247
- generate_summary_major_problem(info)
248
- end
249
-
250
- # 概述
251
- def generate_summary_overview(info)
252
- add_title_2("概述")
253
- tmp = "本次巡检共巡检设备#{device_manager.devices_number}台," +
254
- "发现问题#{warning_summarize.total_number}个。" +
255
- "其中严重问题#{warning_summarize.serious_number}个," +
256
- "一般问题#{warning_summarize.ordinary_number}个。"
257
- @text.puts tmp
258
- end
259
-
260
- # 巡检设备类型
261
- def generate_summary_device_type(info)
262
- add_title_2("巡检设备类型")
263
- @text.puts "下图表示本次巡检各类型设备所占的比例: "
264
-
265
- # 生成table数据目录
266
- type_info = device_manager.device_type_classify.to_a
267
- tbl = []
268
- type_info.size.times do |i|
269
- # 将Hash 变成数组后,按照indent输出
270
- tbl << [ type_info[i][0], type_info[i][1].size.to_s ]
271
- end
272
-
273
- # 生成图表
274
- @text.chart(tbl) do |chart|
275
- chart.type = chart.class::Pie
276
- chart.style = 251
277
- end
278
- end
279
-
280
- # 发现问题数TOP20的设备
281
- def generate_summary_warning_device_top10(info)
282
- add_title_2("发现问题数TOP10的设备")
283
- @text.puts "本次巡检发现问题数排名前10的设备,如下图所示: "
284
-
285
- tbl = [["", "serious", "ordinary", "compare"]]
286
-
287
- type_warning_info = warning_summarize.device_warning_sort
288
- n = 0
289
- type_warning_info.each do |dev|
290
- n += 1
291
- next unless dev[1].total_number > 0
292
- break if n > 10
293
- tbl << [ dev[0],
294
- dev[1].serious_number,
295
- dev[1].ordinary_number,
296
- dev[1].compare_number ]
297
- end
298
-
299
- @text.chart(tbl) do |chart|
300
- chart.type = chart.class::ColumnStacked
301
- chart.style = 251
302
- chart.series_name = false
303
- chart.category_name = false
304
- chart.value = false
305
- chart.axes_unit(1)
306
- end
307
- end
308
-
309
- # 按问题级别展现
310
- def generate_summary_level(info)
311
- add_title_2("按问题级别展现")
312
- @text.puts "本次巡检发现的问题级别分布情况,如下图所示: "
313
- tbl = []
314
- if warning_summarize.has_serious?
315
- tbl << ["serious", warning_summarize.serious_number]
316
- end
317
-
318
- if warning_summarize.has_ordinary?
319
- tbl << ["ordinary", warning_summarize.ordinary_number]
320
- end
321
-
322
- if warning_summarize.has_compare?
323
- tbl << ["compare", warning_summarize.compare_number]
324
- end
325
-
326
- @text.chart(tbl) do |chart|
327
- chart.type = chart.class::Pie
328
- chart.style = 251
329
- end
330
-
331
- #------
332
- @text.entry
333
- @text.puts "1、本次巡检发现的严重问题数最多的5台设备,如下图所示:"
334
- tbl = warning_summarize.device_serious_sort
335
- # 只保留5个
336
- n = 0
337
- tbl.delete_if { |x| n += 1 ;n > 5 }
338
- tbl.insert(0, ["", "数量"])
339
- @text.chart(tbl) do |chart|
340
- chart.type = chart.class::ColumnClustered
341
- chart.style = 251
342
- chart.series_name = false
343
- chart.category_name = false
344
- chart.value = false
345
- chart.axes_unit(1)
346
- end
347
-
348
- #------
349
- @text.entry
350
- @text.puts "2、本次巡检发现的一般问题数最多的5台设备,如下图所示:"
351
- tbl = warning_summarize.device_ordinary_sort
352
- # 只保留5个
353
- n = 0
354
- tbl.delete_if { |x| n += 1 ;n > 5 }
355
- tbl.insert(0, ["", "数量"])
356
- @text.chart(tbl) do |chart|
357
- chart.type = chart.class::ColumnClustered
358
- chart.style = 251
359
- chart.series_name = false
360
- chart.category_name = false
361
- chart.value = false
362
- chart.axes_unit(1)
363
- end
364
- end
365
-
366
- # 按问题发生频率展现
367
- def generate_summary_problem(info)
368
- add_title_2("按问题发生频率展现")
369
- @text.puts "本次巡检发现的发生频率最多的5类问题,如下图所示:"
370
- tbl = warning_summarize.problem_frequency
371
- n = 0
372
- tbl.delete_if { |x| n += 1 ;n > 5 }
373
- tbl.insert(0, ["", "数量"])
374
- @text.chart(tbl) do |chart|
375
- chart.type = chart.class::BarClustered
376
- chart.style = 251
377
- chart.series_name = false
378
- chart.category_name = false
379
- chart.value = false
380
- chart.axes_unit(1)
381
- end
382
- end
383
-
384
- # 主要问题分析及说明
385
- def generate_summary_major_problem(info)
386
- add_title_2("主要问题分析及说明")
387
- @text.puts "本章节将详细介绍巡检过程中发生的所有严重问题,及发生频率最高的3类一般和提示问题。"
388
-
389
- #------
390
- warning_summarize.summary[:serious].each_pair do |cs, dev_info|
391
- desc_klass = warning_summarize.get_desc(cs)
392
- add_title_3(desc_klass.title)
393
- level(:serious)
394
- @text.puts desc_klass.to_s + "不符合该规则的设备共#{dev_info.size}台,明细如下:"
395
- add_device_table(dev_info)
396
- end
397
-
398
- #------
399
- warning_summarize.summary[:ordinary].each_pair do |cs, dev_info|
400
- desc_klass = warning_summarize.get_desc(cs)
401
- add_title_3(desc_klass.title)
402
- level(:ordinary)
403
- @text.puts desc_klass.to_s + "不符合该规则的设备共#{dev_info.size}台,明细如下:"
404
- add_device_table(dev_info)
405
- end
406
-
407
- end
408
-
409
- # 打印级别
410
- def level(sym)
411
- res = ""
412
- case sym
413
- when :serious
414
- res = "级别: 严重"
415
- when :ordinary
416
- res = "级别: 一般"
417
- end
418
-
419
- @text.style = "importance"
420
- @text.size = 12
421
- @text.puts res
422
- end
423
-
424
- # 添加按照设备标明的表格
425
- def add_device_table(dev_info)
426
- tbl = [ ["序号", "名称", "型号", "IP"] ]
427
- n = 1
428
- dev_info.each_pair do |name, klass_info|
429
- klass = klass_info[:klass]
430
- tbl << [n, name,
431
- klass.device_info[:device_model],
432
- klass.get_manager_ip ]
433
- n += 1
434
- end
435
- @text.size = 10
436
- @text.add_table_by_value(tbl) do |table|
437
- table.center
438
- table.border_line
439
- table.set_columns_width(1, 44)
440
- table.set_columns_width(2, 143)
441
- table.set_columns_width(3, 143)
442
- end
443
- end
444
-
445
-
446
- # 总结流程控制
447
- def generate_summarize(info)
448
- @text.page_break
449
- generate_machine_room(info)
450
- generate_inspection(info)
451
- generate_offer(info)
452
- generate_appraise(info)
453
- end
454
-
455
- # 机房环境检查结果
456
- def generate_machine_room(info)
457
- add_title_2("机房环境检查结果")
458
- @text.add_table(1,1) do |tbl|
459
- tbl.height = 100
460
- tbl.border_line
461
- end
462
-
463
- end
464
-
465
- # 巡检结论
466
- def generate_inspection(info)
467
- add_title_2("巡检结论")
468
- @text.add_table(1,1) do |tbl|
469
- tbl.height = 100
470
- tbl.border_line
471
- end
472
- end
473
-
474
- # 运行维护建议
475
- def generate_offer(info)
476
- add_title_2("运行维护建议")
477
- @text.add_table(1,1) do |tbl|
478
- tbl.height = 100
479
- tbl.border_line
480
- end
481
- end
482
-
483
- # 您对本次巡检情况的评价
484
- def generate_appraise(info)
485
- add_title_2("您对本次巡检情况的评价")
486
- @text.add_table(1,1) do |tbl|
487
- tbl.height = 100
488
- tbl.border_line
489
- end
490
- end
491
-
492
- private
493
- ###
494
- #
495
- # 本地方法
496
- #
497
- ###
498
- # 更新目录
499
- def update_catalog
500
- @doc.update_catalog
501
- end
502
-
503
- # 1级标题
504
- def add_title_1(str)
505
- @mark[0] += 1
506
- @mark[1] = 0
507
- @mark[2] = 0
508
- mk = @mark[0].to_s
509
- @text.style = "font_chapter_name1"
510
- @text.print join(mk, str)
511
- modify_num(mk, "font_chapter_num1")
512
- @text.entry
513
- end
514
-
515
- # 2级标题
516
- def add_title_2(str)
517
- @mark[1] += 1
518
- @mark[2] = 0
519
- mk = [@mark[0], @mark[1]].join(".")
520
- @text.style = "font_section_name1"
521
- @text.print join(mk, str)
522
- modify_num(mk, "font_section_num1")
523
- @text.entry
524
- end
525
-
526
- # 3级标题
527
- def add_title_3(str)
528
- @mark[2] += 1
529
- mk = [@mark[0], @mark[1], @mark[2]].join(".")
530
- @text.style = "font_level3_name1"
531
- @text.print join(mk, str)
532
- modify_num(mk, "font_level3_num1")
533
- @text.entry
534
- end
535
-
536
- # 合并,以空格分开
537
- def join(*arg)
538
- arg.join(" ")
539
- end
540
-
541
- # 修改标题数字
542
- def modify_num(num, sty)
543
- @doc.home_key
544
- @doc.move_right(num.size, 1)
545
- @text.now.Style = @doc.doc_work.Styles(sty)
546
- #@text.now.ParagraphFormat.LineUnitBefore = 0.1
547
- @doc.end_key
548
- end
549
-
550
- # 添加占位符
551
- def add_holder(str)
552
- PlaceHolder + " " + str
553
- end
554
-
555
- def replace_holder(str, style)
556
- @text.replace(PlaceHolder, str.to_s, style)
557
- end
558
-
559
- # 警告信息汇总类
560
- def warning_summarize
561
- device_manager.warning_summarize
562
- end
209
+ end
210
+
211
+ # 生成目录
212
+ def generate_catalog(info)
213
+ @text.section("Contents") { "目 录" }
214
+ @doc.create_catalog
215
+ @text.page_break
216
+ end
217
+
218
+ # 生成前言
219
+ def generate_introduction(info)
220
+ @text.section("font_chapter_name1") { "前言" }
221
+ @text.section("font_section_name1") { "概述" }
222
+ @text.puts "根据#{info[:client]}的运行维护需要,公司对其网络设备进行了巡检。本文档提供了本次巡检所有设备的检查明细信息及汇总信息,针对检查中发现的设备在运行过程中存在的故障隐患和风险提出了相关建议,并对网络整体的健康程度进行了评估。"
223
+ @text.entry
224
+ @text.puts "通过本文档,您可以及时了解网络设备的健康状况,清除设备故障隐患,指导技术人员完成对网络的改造优化,提高网络的可用性,保障业务可靠运行。"
225
+
226
+ @text.section("font_section_name1") { "读者对象" }
227
+ @text.puts "本项目相关的网络运行维护主管、技术工程师、系统集成商工程师等。"
228
+
229
+ @text.page_break
230
+ @text.entry
231
+ @text.section("importance") { "尊敬的_______________________ :" }
232
+ @text.puts "感谢您选择我们的产品和服务!为了提高网络的可用性,保障网络的稳定运行,我们于#{info[:time]}对贵单位网络设备进行了巡检服务。现将本次服务的情况向您汇报如下,并请您对我们的工作给予评价。"
233
+ @text.entry
234
+ @text.puts "感谢您和您的团队在本次服务过程中给我们的配合和支持!"
235
+ @text.entry
236
+ @text.entry
237
+ @text.entry
238
+ @text.entry
239
+ @text.entry
240
+ @text.entry
241
+ @text.entry
242
+ @text.puts "本次巡检负责人:"
243
+ @text.puts "联系电话:"
244
+ @text.puts "联系邮箱:"
245
+ end
246
+
247
+ ###
248
+ #
249
+ # 巡检概要报告
250
+ #
251
+ ###
252
+ # 流程控制
253
+ def generate_summary(info)
254
+ add_title_1("巡检概要报告")
255
+ generate_summary_overview(info)
256
+ generate_summary_device_type(info)
257
+ generate_summary_warning_device_top10(info)
258
+ generate_summary_level(info)
259
+ generate_summary_problem(info)
260
+ generate_summary_major_problem(info)
261
+ end
262
+
263
+ # 概述
264
+ def generate_summary_overview(info)
265
+ add_title_2("概述")
266
+ tmp = "本次巡检共巡检设备#{device_manager.devices_number}台," +
267
+ "发现问题#{warning_summarize.total_number}个。" +
268
+ "其中严重问题#{warning_summarize.serious_number}个," +
269
+ "一般问题#{warning_summarize.ordinary_number}个。"
270
+ @text.puts tmp
271
+ end
272
+
273
+ # 巡检设备类型
274
+ def generate_summary_device_type(info)
275
+ add_title_2("巡检设备类型")
276
+ @text.puts "下图表示本次巡检各类型设备所占的比例: "
277
+
278
+ # 生成table数据目录
279
+ type_info = device_manager.device_type_classify.to_a
280
+ tbl = []
281
+ type_info.size.times do |i|
282
+ # 将Hash 变成数组后,按照indent输出
283
+ tbl << [ type_info[i][0], type_info[i][1].size.to_s ]
284
+ end
285
+
286
+ # 生成图表
287
+ @text.chart(tbl) do |chart|
288
+ chart.type = chart.class::Pie
289
+ chart.style = 251
290
+ end
291
+ end
292
+
293
+ # 发现问题数TOP20的设备
294
+ def generate_summary_warning_device_top10(info)
295
+ add_title_2("发现问题数TOP10的设备")
296
+ @text.puts "本次巡检发现问题数排名前10的设备,如下图所示: "
297
+
298
+ tbl = [["", "serious", "ordinary", "compare"]]
299
+
300
+ type_warning_info = warning_summarize.device_warning_sort
301
+ n = 0
302
+ type_warning_info.each do |dev|
303
+ n += 1
304
+ next unless dev[1].total_number > 0
305
+ break if n > 10
306
+ tbl << [ dev[0],
307
+ dev[1].serious_number,
308
+ dev[1].ordinary_number,
309
+ dev[1].compare_number ]
310
+ end
311
+
312
+ @text.chart(tbl) do |chart|
313
+ chart.type = chart.class::ColumnStacked
314
+ chart.style = 251
315
+ chart.series_name = false
316
+ chart.category_name = false
317
+ chart.value = false
318
+ chart.axes_unit(1)
319
+ end
320
+ end
321
+
322
+ # 按问题级别展现
323
+ def generate_summary_level(info)
324
+
325
+ # 当没有内容的时候,返回
326
+ return if warning_summarize.total_number.zero?
327
+
328
+ add_title_2("按问题级别展现")
329
+ @text.puts "本次巡检发现的问题级别分布情况,如下图所示: "
330
+ tbl = []
331
+ if warning_summarize.has_serious?
332
+ tbl << ["serious", warning_summarize.serious_number]
333
+ end
334
+
335
+ if warning_summarize.has_ordinary?
336
+ tbl << ["ordinary", warning_summarize.ordinary_number]
337
+ end
338
+
339
+ if warning_summarize.has_compare?
340
+ tbl << ["compare", warning_summarize.compare_number]
341
+ end
342
+
343
+ @text.chart(tbl) do |chart|
344
+ chart.type = chart.class::Pie
345
+ chart.style = 251
346
+ end
347
+
348
+ #------
349
+ @text.entry
350
+ @text.puts "1、本次巡检发现的严重问题数最多的5台设备,如下图所示:"
351
+ tbl = warning_summarize.device_serious_sort
352
+ # 只保留5个
353
+ n = 0
354
+ tbl.delete_if { |x| n += 1 ;n > 5 }
355
+ tbl.insert(0, ["", "数量"])
356
+ @text.chart(tbl) do |chart|
357
+ chart.type = chart.class::ColumnClustered
358
+ chart.style = 251
359
+ chart.series_name = false
360
+ chart.category_name = false
361
+ chart.value = false
362
+ chart.axes_unit(1)
363
+ end
364
+
365
+ #------
366
+ @text.entry
367
+ @text.puts "2、本次巡检发现的一般问题数最多的5台设备,如下图所示:"
368
+ tbl = warning_summarize.device_ordinary_sort
369
+ # 只保留5个
370
+ n = 0
371
+ tbl.delete_if { |x| n += 1 ;n > 5 }
372
+ tbl.insert(0, ["", "数量"])
373
+ @text.chart(tbl) do |chart|
374
+ chart.type = chart.class::ColumnClustered
375
+ chart.style = 251
376
+ chart.series_name = false
377
+ chart.category_name = false
378
+ chart.value = false
379
+ chart.axes_unit(1)
380
+ end
381
+ end
382
+
383
+ # 按问题发生频率展现
384
+ def generate_summary_problem(info)
385
+ add_title_2("按问题发生频率展现")
386
+ @text.puts "本次巡检发现的发生频率最多的5类问题,如下图所示:"
387
+ tbl = warning_summarize.problem_frequency
388
+ n = 0
389
+ tbl.delete_if { |x| n += 1 ;n > 5 }
390
+ tbl.insert(0, ["", "数量"])
391
+ @text.chart(tbl) do |chart|
392
+ chart.type = chart.class::BarClustered
393
+ chart.style = 251
394
+ chart.series_name = false
395
+ chart.category_name = false
396
+ chart.value = false
397
+ chart.axes_unit(1)
398
+ end
399
+ end
400
+
401
+ # 主要问题分析及说明
402
+ def generate_summary_major_problem(info)
403
+ return if warning_summarize.total_number.zero?
404
+ add_title_2("主要问题分析及说明")
405
+ @text.puts "本章节将详细介绍巡检过程中发生的所有严重问题,及发生频率最高的3类一般和提示问题。"
406
+
407
+ #------
408
+ warning_summarize.summary[:serious].each_pair do |cs, dev_info|
409
+ desc_klass = warning_summarize.get_desc(cs)
410
+ add_title_3(desc_klass.title)
411
+ level(:serious)
412
+ @text.puts desc_klass.to_s + "不符合该规则的设备共#{dev_info.size}台,明细如下:"
413
+ add_device_table(dev_info)
414
+ end
415
+
416
+ #------
417
+ warning_summarize.summary[:ordinary].each_pair do |cs, dev_info|
418
+ desc_klass = warning_summarize.get_desc(cs)
419
+ add_title_3(desc_klass.title)
420
+ level(:ordinary)
421
+ @text.puts desc_klass.to_s + "不符合该规则的设备共#{dev_info.size}台,明细如下:"
422
+ add_device_table(dev_info)
423
+ end
424
+
425
+ end
426
+
427
+ # 打印级别
428
+ def level(sym)
429
+ res = ""
430
+ case sym
431
+ when :serious
432
+ res = "级别: 严重"
433
+ when :ordinary
434
+ res = "级别: 一般"
435
+ end
436
+
437
+ @text.style = "importance"
438
+ @text.size = 12
439
+ @text.puts res
440
+ end
441
+
442
+ # 添加按照设备标明的表格
443
+ def add_device_table(dev_info)
444
+ tbl = [ ["序号", "名称", "型号", "IP"] ]
445
+ n = 1
446
+ dev_info.each_pair do |name, klass_info|
447
+ klass = klass_info[:klass]
448
+ tbl << [n, name,
449
+ klass.device_info[:device_model],
450
+ klass.get_manager_ip ]
451
+ n += 1
452
+ end
453
+ @text.size = 10
454
+ @text.add_table_by_value(tbl) do |table|
455
+ table.center
456
+ table.border_line
457
+ table.set_columns_width(1, 44)
458
+ table.set_columns_width(2, 143)
459
+ table.set_columns_width(3, 143)
460
+ end
461
+ end
462
+
463
+
464
+ # 总结流程控制
465
+ def generate_summarize(info)
466
+ @text.page_break
467
+ generate_machine_room(info)
468
+ generate_inspection(info)
469
+ generate_offer(info)
470
+ generate_appraise(info)
471
+ end
472
+
473
+ # 机房环境检查结果
474
+ def generate_machine_room(info)
475
+ add_title_2("机房环境检查结果")
476
+ @text.add_table(1,1) do |tbl|
477
+ tbl.height = 100
478
+ tbl.border_line
479
+ end
480
+
481
+ end
482
+
483
+ # 巡检结论
484
+ def generate_inspection(info)
485
+ add_title_2("巡检结论")
486
+ @text.add_table(1,1) do |tbl|
487
+ tbl.height = 100
488
+ tbl.border_line
489
+ end
490
+ end
491
+
492
+ # 运行维护建议
493
+ def generate_offer(info)
494
+ add_title_2("运行维护建议")
495
+ @text.add_table(1,1) do |tbl|
496
+ tbl.height = 100
497
+ tbl.border_line
498
+ end
499
+ end
500
+
501
+ # 您对本次巡检情况的评价
502
+ def generate_appraise(info)
503
+ add_title_2("您对本次巡检情况的评价")
504
+ @text.add_table(1,1) do |tbl|
505
+ tbl.height = 100
506
+ tbl.border_line
507
+ end
508
+ end
509
+
510
+ private
511
+ ###
512
+ #
513
+ # 本地方法
514
+ #
515
+ ###
516
+ # 更新目录
517
+ def update_catalog
518
+ @doc.update_catalog
519
+ end
520
+
521
+ # 1级标题
522
+ def add_title_1(str)
523
+ @mark[0] += 1
524
+ @mark[1] = 0
525
+ @mark[2] = 0
526
+ mk = @mark[0].to_s
527
+ @text.style = "font_chapter_name1"
528
+ @text.print join(mk, str)
529
+ modify_num(mk, "font_chapter_num1")
530
+ @text.entry
531
+ end
532
+
533
+ # 2级标题
534
+ def add_title_2(str)
535
+ @mark[1] += 1
536
+ @mark[2] = 0
537
+ mk = [@mark[0], @mark[1]].join(".")
538
+ @text.style = "font_section_name1"
539
+ @text.print join(mk, str)
540
+ modify_num(mk, "font_section_num1")
541
+ @text.entry
542
+ end
543
+
544
+ # 3级标题
545
+ def add_title_3(str)
546
+ @mark[2] += 1
547
+ mk = [@mark[0], @mark[1], @mark[2]].join(".")
548
+ @text.style = "font_level3_name1"
549
+ @text.print join(mk, str)
550
+ modify_num(mk, "font_level3_num1")
551
+ @text.entry
552
+ end
553
+
554
+ # 合并,以空格分开
555
+ def join(*arg)
556
+ arg.join(" ")
557
+ end
558
+
559
+ # 修改标题数字
560
+ def modify_num(num, sty)
561
+ @doc.home_key
562
+ @doc.move_right(num.size, 1)
563
+ @text.now.Style = @doc.doc_work.Styles(sty)
564
+ #@text.now.ParagraphFormat.LineUnitBefore = 0.1
565
+ @doc.end_key
566
+ end
567
+
568
+ # 添加占位符
569
+ def add_holder(str)
570
+ PlaceHolder + " " + str
571
+ end
572
+
573
+ def replace_holder(str, style)
574
+ @text.replace(PlaceHolder, str.to_s, style)
575
+ end
576
+
577
+ # 警告信息汇总类
578
+ def warning_summarize
579
+ device_manager.warning_summarize
580
+ end
563
581
 
564
582
  end