Class: Aio::Module::OutputStyle::SummaryReport

Inherits:
Aio::Module::OutputStyle show all
Includes:
Base::Toolkit::ExcelWps, Base::Toolkit::WordWps, Device, Aio::Module, Ui::Verbose
Defined in:
lib/modules/output/style/summary_report.rb

Constant Summary collapse

PlaceHolder =
"###"

Instance Attribute Summary

Attributes inherited from Aio::Module::OutputStyle

#device_manager, #module_manager, #output_file, #output_info

Instance Method Summary collapse

Methods included from Ui::Verbose

#clear_line, #print_error, #print_good, #progress_bar

Methods inherited from Aio::Module::OutputStyle

#author, #description, #each_devices_with_useful, #file_suffix, #license, #platform, #set_defaults, #type

Constructor Details

#initializeSummaryReport

Returns a new instance of SummaryReport.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/modules/output/style/summary_report.rb', line 14

def initialize
  super({
    :author				=> "Elin",
    :description	=> "输出巡检简要报告, 以WPS运行",
    :file_suffix	=> "doc",
    :platform     => ['windows']
  })

  # 附带信息
  @info = {
    :resource_file => File.join(::BaseFile, "aio", "resource"),
    :client		=> nil,
    :time 		=> ::Time.now.to_s.split(' ')[0],
  }
end

Instance Method Details

#add_device_table(dev_info) ⇒ Object

添加按照设备标明的表格



443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
# File 'lib/modules/output/style/summary_report.rb', line 443

def add_device_table(dev_info)
  tbl = [ ["序号",	"名称",	"型号",	"IP"] ]
  n = 1
  dev_info.each_pair do |name, klass_info|
    klass = klass_info[:klass]
    tbl << [n, name, 
            klass.device_info[:device_model],
            klass.get_manager_ip ]
    n += 1
  end
  @text.size = 10
  @text.add_table_by_value(tbl) do |table|
    table.center
    table.border_line
    table.set_columns_width(1, 44)
    table.set_columns_width(2, 143)
    table.set_columns_width(3, 143)
  end
end

#create_styleObject

创建风格



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/modules/output/style/summary_report.rb', line 80

def create_style

  # 用于目录的标题
  @doc.create_style_self("Contents") do |sty|
    sty.font.size = 20
    sty.font.NameFarEast = "黑体"
    sty.font.NameAscii = "Book Antiqua"
    sty.font.NameOther = "Book Antiqua"
    sty.font.bold = true
    # 段落间距
    sty.ParagraphFormat.Alignment = 2		# 文本右对齐
    sty.ParagraphFormat.LineUnitBefore = 3	# 
    sty.ParagraphFormat.LineUnitAfter = 2
    sty.NextParagraphStyle = "正文"
    # 段落控制
    sty.ParagraphFormat.WidowControl = true
    sty.ParagraphFormat.KeepWithNext = true
    sty.ParagraphFormat.PageBreakBefore = true
    # 边框
    sty.ParagraphFormat.Borders(-1).LineStyle = 0
    sty.ParagraphFormat.Borders(-2).LineStyle = 0
    sty.ParagraphFormat.Borders(-4).LineStyle = 0
    bottom = sty.ParagraphFormat.Borders(-3)
    bottom.LineStyle = 1
    bottom.LineWidth = 12
    bottom.Color = 0
  end

  # 一级标题
  @doc.create_style_self("font_chapter_name1") do |sty|
    sty.BaseStyle = "Contents"
    sty.ParagraphFormat.OutlineLevel = 1
    sty.NextParagraphStyle = "正文"
  end

  # 一级标题标号
  @doc.create_style_self("font_chapter_num1") do |sty|
    sty.BaseStyle = "Contents"
    sty.font.size = 72
    sty.ParagraphFormat.LineUnitBefore = 0.5
    sty.ParagraphFormat.LineUnitAfter = 0.5
    sty.ParagraphFormat.OutlineLevel = 1
    sty.NextParagraphStyle = "font_chapter_name1"
  end

  # 二级标题
  @doc.create_style_self("font_section_name1") do |sty|
    sty.BaseStyle = "正文"
    sty.font.bold = true
    sty.font.size = 18
    sty.ParagraphFormat.LineUnitBefore = 1
    sty.ParagraphFormat.LineUnitAfter = 1
    sty.ParagraphFormat.OutlineLevel = 2
    sty.NextParagraphStyle = "正文"
  end

  # 二级标题标号
  @doc.create_style_self("font_section_num1") do |sty|
    sty.BaseStyle = "font_section_name1"
    sty.NextParagraphStyle = "font_section_name1"
  end

  @doc.create_style_self("font_level3_name1") do |sty|
    sty.BaseStyle = "正文"
    sty.font.bold = true
    sty.font.size = 18
    sty.ParagraphFormat.LineUnitBefore = 1
    sty.ParagraphFormat.LineUnitAfter = 1
    sty.ParagraphFormat.OutlineLevel = 3
    sty.NextParagraphStyle = "正文"
  end

  @doc.create_style_self("font_level3_num1") do |sty|
    sty.BaseStyle = "font_level3_name1"
    sty.NextParagraphStyle = "font_level3_name1"
  end

  # 要点
  @doc.create_style_self("importance") do |sty|
    sty.BaseStyle = "正文"
    sty.font.bold = true
    sty.font.size = 18
    sty.ParagraphFormat.LineUnitBefore = 1
    sty.ParagraphFormat.LineUnitAfter = 1
    sty.NextParagraphStyle = "正文"
  end
end

#generateObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/modules/output/style/summary_report.rb', line 43

def generate

  word = Word.new
  #word.show
  word.display_alerts = false
  @doc = word.init_document
  @text = @doc.add_text

  # 创建风格
  create_style

  device_manager.devices.each_pair do |device_name, klass|
    #puts "summary_report"
    #pp device_name
    #pp klass.warning_klass
  end


  # 标号
  @mark	= [0, 0, 0]

  # 按流程算法运行
  process(info)

  # 保存
  word.display_alerts = true

  begin
    word.save(output_file.to_s)
  rescue Exception => e
    e.message
  ensure
    #word.close
  end
end

#generate_appraise(info) ⇒ Object

您对本次巡检情况的评价



502
503
504
505
506
507
508
# File 'lib/modules/output/style/summary_report.rb', line 502

def generate_appraise(info)
  add_title_2("您对本次巡检情况的评价")
  @text.add_table(1,1) do |tbl|
    tbl.height = 100
    tbl.border_line
  end
end

#generate_catalog(info) ⇒ Object

生成目录



212
213
214
215
216
# File 'lib/modules/output/style/summary_report.rb', line 212

def generate_catalog(info)
  @text.section("Contents") { "目  录" }
  @doc.create_catalog
  @text.page_break
end

#generate_cover(info) ⇒ Object

创建封面



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/modules/output/style/summary_report.rb', line 180

def generate_cover(info)
  @text.add_head_image(File.join(info[:resource_file], "cover_picture.png"))
  @text.style = "正文"
  @text.entry
  @text.entry
  @text.entry

  @text.font.size = 16
  @text.center
  @text.section { "数据通信网络高级巡检报告" }
  @text.entry
  @text.entry

  client = info[:client]
  time = info[:time]
  @text.font.Size = 15
  @text.section { "客户名称:#{client}" }
  @text.section { "巡检时间:#{time}" }

  @text.add_table(1,1) { |tbl| }
=begin
  @text.entry
  @text.entry
  @text.entry

  @text.left
  @text.font.bold = true
  @text.add_image(File.join(info[:resource_file], "logo.png"))
=end
end

#generate_inspection(info) ⇒ Object

巡检结论



484
485
486
487
488
489
490
# File 'lib/modules/output/style/summary_report.rb', line 484

def generate_inspection(info)
  add_title_2("巡检结论")
  @text.add_table(1,1) do |tbl|
    tbl.height = 100
    tbl.border_line
  end
end

#generate_introduction(info) ⇒ Object

生成前言



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/modules/output/style/summary_report.rb', line 219

def generate_introduction(info)
  @text.section("font_chapter_name1") { "前言" }
  @text.section("font_section_name1") { "概述" }
  @text.puts "根据#{info[:client]}的运行维护需要,公司对其网络设备进行了巡检。本文档提供了本次巡检所有设备的检查明细信息及汇总信息,针对检查中发现的设备在运行过程中存在的故障隐患和风险提出了相关建议,并对网络整体的健康程度进行了评估。"
  @text.entry
  @text.puts "通过本文档,您可以及时了解网络设备的健康状况,清除设备故障隐患,指导技术人员完成对网络的改造优化,提高网络的可用性,保障业务可靠运行。"

  @text.section("font_section_name1") { "读者对象" }
  @text.puts "本项目相关的网络运行维护主管、技术工程师、系统集成商工程师等。"

  @text.page_break
  @text.entry
  @text.section("importance") { "尊敬的_______________________ :" }
  @text.puts "感谢您选择我们的产品和服务!为了提高网络的可用性,保障网络的稳定运行,我们于#{info[:time]}对贵单位网络设备进行了巡检服务。现将本次服务的情况向您汇报如下,并请您对我们的工作给予评价。"
  @text.entry
  @text.puts "感谢您和您的团队在本次服务过程中给我们的配合和支持!"
  @text.entry
  @text.entry
  @text.entry
  @text.entry
  @text.entry
  @text.entry
  @text.entry
  @text.puts "本次巡检负责人:"
  @text.puts "联系电话:"
  @text.puts "联系邮箱:"
end

#generate_machine_room(info) ⇒ Object

机房环境检查结果



474
475
476
477
478
479
480
481
# File 'lib/modules/output/style/summary_report.rb', line 474

def generate_machine_room(info)
  add_title_2("机房环境检查结果")
  @text.add_table(1,1) do |tbl|
    tbl.height = 100
    tbl.border_line
  end

end

#generate_offer(info) ⇒ Object

运行维护建议



493
494
495
496
497
498
499
# File 'lib/modules/output/style/summary_report.rb', line 493

def generate_offer(info)
  add_title_2("运行维护建议")
  @text.add_table(1,1) do |tbl|
    tbl.height = 100
    tbl.border_line
  end
end

#generate_summarize(info) ⇒ Object

总结流程控制



465
466
467
468
469
470
471
# File 'lib/modules/output/style/summary_report.rb', line 465

def generate_summarize(info)
  @text.page_break
  generate_machine_room(info)
  generate_inspection(info)
  generate_offer(info)
  generate_appraise(info)
end

#generate_summary(info) ⇒ Object

巡检概要报告

流程控制



253
254
255
256
257
258
259
260
261
# File 'lib/modules/output/style/summary_report.rb', line 253

def generate_summary(info)
  add_title_1("巡检概要报告")
  generate_summary_overview(info)
  generate_summary_device_type(info)
  generate_summary_warning_device_top10(info)
  generate_summary_level(info)
  generate_summary_problem(info)
  generate_summary_major_problem(info)
end

#generate_summary_device_type(info) ⇒ Object

巡检设备类型



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/modules/output/style/summary_report.rb', line 274

def generate_summary_device_type(info)
  add_title_2("巡检设备类型")
  @text.puts "下图表示本次巡检各类型设备所占的比例: "

  # 生成table数据目录
  type_info = device_manager.device_type_classify.to_a
  tbl = []
  type_info.size.times do |i|
    # 将Hash 变成数组后,按照indent输出
    tbl << [ type_info[i][0], type_info[i][1].size.to_s ]
  end

  # 生成图表
  @text.chart(tbl) do |chart|
    chart.type = chart.class::Pie
    chart.style = 251
  end
end

#generate_summary_level(info) ⇒ Object

按问题级别展现



323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/modules/output/style/summary_report.rb', line 323

def generate_summary_level(info)

  # 当没有内容的时候,返回
  return if warning_summarize.total_number.zero?

  add_title_2("按问题级别展现")
  @text.puts "本次巡检发现的问题级别分布情况,如下图所示: "
  tbl = []
  if warning_summarize.has_serious?
    tbl << ["serious", warning_summarize.serious_number]
  end

  if warning_summarize.has_ordinary?
    tbl << ["ordinary", warning_summarize.ordinary_number]
  end

  if warning_summarize.has_compare?
    tbl << ["compare", warning_summarize.compare_number]
  end

  @text.chart(tbl) do |chart|
    chart.type = chart.class::Pie
    chart.style = 251
  end

  #------
  @text.entry
  @text.puts "1、本次巡检发现的严重问题数最多的5台设备,如下图所示:"
  tbl = warning_summarize.device_serious_sort
  # 只保留5个
  n = 0
  tbl.delete_if { |x| n += 1 ;n > 5 }
  tbl.insert(0, ["", "数量"])
  @text.chart(tbl) do |chart|
    chart.type = chart.class::ColumnClustered
    chart.style = 251
    chart.series_name = false
    chart.category_name = false
    chart.value = false
    chart.axes_unit(1)
  end

  #------
  @text.entry
  @text.puts "2、本次巡检发现的一般问题数最多的5台设备,如下图所示:"
  tbl = warning_summarize.device_ordinary_sort
  # 只保留5个
  n = 0
  tbl.delete_if { |x| n += 1 ;n > 5 }
  tbl.insert(0, ["", "数量"])
  @text.chart(tbl) do |chart|
    chart.type = chart.class::ColumnClustered
    chart.style = 251
    chart.series_name = false
    chart.category_name = false
    chart.value = false
    chart.axes_unit(1)
  end
end

#generate_summary_major_problem(info) ⇒ Object

主要问题分析及说明



402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
# File 'lib/modules/output/style/summary_report.rb', line 402

def generate_summary_major_problem(info)
  return if warning_summarize.total_number.zero?
  add_title_2("主要问题分析及说明")
  @text.puts "本章节将详细介绍巡检过程中发生的所有严重问题,及发生频率最高的3类一般和提示问题。"

  #------
  warning_summarize.summary[:serious].each_pair do |cs, dev_info|
    desc_klass = warning_summarize.get_desc(cs)
    add_title_3(desc_klass.title)
    level(:serious)
    @text.puts desc_klass.to_s + "不符合该规则的设备共#{dev_info.size}台,明细如下:"
    add_device_table(dev_info)
  end

  #------
  warning_summarize.summary[:ordinary].each_pair do |cs, dev_info|
    desc_klass = warning_summarize.get_desc(cs)
    add_title_3(desc_klass.title)
    level(:ordinary)
    @text.puts desc_klass.to_s + "不符合该规则的设备共#{dev_info.size}台,明细如下:"
    add_device_table(dev_info)
  end

end

#generate_summary_overview(info) ⇒ Object

概述



264
265
266
267
268
269
270
271
# File 'lib/modules/output/style/summary_report.rb', line 264

def generate_summary_overview(info)
  add_title_2("概述")
  tmp = "本次巡检共巡检设备#{device_manager.devices_number}台," +
    "发现问题#{warning_summarize.total_number}个。" +
    "其中严重问题#{warning_summarize.serious_number}个," + 
    "一般问题#{warning_summarize.ordinary_number}个。" 
  @text.puts tmp
end

#generate_summary_problem(info) ⇒ Object

按问题发生频率展现



384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
# File 'lib/modules/output/style/summary_report.rb', line 384

def generate_summary_problem(info)
  add_title_2("按问题发生频率展现")
  @text.puts "本次巡检发现的发生频率最多的5类问题,如下图所示:"
  tbl = warning_summarize.problem_frequency
  n = 0
  tbl.delete_if { |x| n += 1 ;n > 5 }
  tbl.insert(0, ["", "数量"])
  @text.chart(tbl) do |chart|
    chart.type = chart.class::BarClustered
    chart.style = 251
    chart.series_name = false
    chart.category_name = false
    chart.value = false
    chart.axes_unit(1)
  end
end

#generate_summary_warning_device_top10(info) ⇒ Object

发现问题数TOP20的设备



294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/modules/output/style/summary_report.rb', line 294

def generate_summary_warning_device_top10(info)
  add_title_2("发现问题数TOP10的设备")
  @text.puts "本次巡检发现问题数排名前10的设备,如下图所示: "

  tbl = [["", "serious", "ordinary", "compare"]]

  type_warning_info = warning_summarize.device_warning_sort
  n = 0
  type_warning_info.each do |dev|
    n += 1
    next unless dev[1].total_number > 0
    break if n > 10
    tbl << [	dev[0], 
             dev[1].serious_number,
             dev[1].ordinary_number,
             dev[1].compare_number ]
  end

  @text.chart(tbl) do |chart|
    chart.type = chart.class::ColumnStacked
    chart.style = 251
    chart.series_name = false
    chart.category_name = false
    chart.value = false
    chart.axes_unit(1)
  end
end

#infoObject



38
39
40
# File 'lib/modules/output/style/summary_report.rb', line 38

def info
  @info
end

#info_client=(e) ⇒ Object



30
31
32
# File 'lib/modules/output/style/summary_report.rb', line 30

def info_client=(e)
  @info[:client] = e
end

#info_time=(e) ⇒ Object



34
35
36
# File 'lib/modules/output/style/summary_report.rb', line 34

def info_time=(e)
  @info[:time] = e
end

#level(sym) ⇒ Object

打印级别



428
429
430
431
432
433
434
435
436
437
438
439
440
# File 'lib/modules/output/style/summary_report.rb', line 428

def level(sym)
  res = ""
  case sym
  when :serious
    res = "级别: 严重"
  when :ordinary
    res = "级别: 一般"
  end

  @text.style = "importance"
  @text.size = 12
  @text.puts res
end

#process(info) ⇒ Object

主体流程控制



169
170
171
172
173
174
175
176
177
# File 'lib/modules/output/style/summary_report.rb', line 169

def process(info)
  generate_cover(info)
  generate_catalog(info)
  generate_introduction(info)

  generate_summary(info)
  generate_summarize(info)
  update_catalog
end