Browse Source

样式优化:调整页边距、表格行距、图片大小等。

main
Julin 11 months ago
parent
commit
e339c95a4d
  1. 2
      code/pep-stats-report/app/db_helper.py
  2. 22
      code/pep-stats-report/main.py

2
code/pep-stats-report/app/db_helper.py

@ -80,7 +80,7 @@ from workflow_process_achievements as wpa
inner join "user" as u on wpa.deal_user_id=u.id inner join "user" as u on wpa.deal_user_id=u.id
inner join department_user as du on u.id=du."user" inner join department_user as du on u.id=du."user"
inner join department as d on du.department=d.id inner join department as d on du.department=d.id
where wpa.end_time >='{start}' and wpa.end_time < '{end}' and u.delete=0 and u.state=1 and u.active_status=1 where wpa.end_time >='{start}' and wpa.end_time < '{end}' and d.delete=0 and u.delete=0 and u.state=1 and u.active_status=1
and d.name not in {IGNORE_DEPARTMENTS} and d.name not in {IGNORE_DEPARTMENTS}
{IGNORE_PERSONS_SUBQUERY} {IGNORE_PERSONS_SUBQUERY}
''' '''

22
code/pep-stats-report/main.py

@ -118,9 +118,15 @@ def set_global_normal_style(doc):
style.font.name = 'Times New Roman' # 英文、数字字体 style.font.name = 'Times New Roman' # 英文、数字字体
style._element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体') # 中文字体 style._element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体') # 中文字体
style.font.size = Pt(14) # 四号 style.font.size = Pt(14) # 四号
style.paragraph_format.space_before = Pt(6) # 段前0.5行 style.paragraph_format.space_before = 0 # 段前
style.paragraph_format.space_after = Pt(6) # 段后0.5行 style.paragraph_format.space_after = 0 # 段后
style.paragraph_format.line_spacing_rule = WD_LINE_SPACING.ONE_POINT_FIVE # 1.5倍行距 style.paragraph_format.line_spacing_rule = WD_LINE_SPACING.SINGLE # 单倍行距
# 设置页边距
section = doc.sections[0]
section.top_margin = Cm(1.27)
section.right_margin = Cm(0.5)
section.bottom_margin = Cm(1.27)
section.left_margin = Cm(0.5)
# 设置单元格底纹 # 设置单元格底纹
@ -159,7 +165,7 @@ def create_twinx_chart(department, title, filename):
bgcolor = '#d9d9d9' bgcolor = '#d9d9d9'
fig, ax1 = plt.subplots(figsize=(8, 5), layout='constrained', facecolor=bgcolor) fig, ax1 = plt.subplots(figsize=(10, 6), layout='constrained', facecolor=bgcolor)
ax1.set_ylabel('平均处理流程时间(小时)') ax1.set_ylabel('平均处理流程时间(小时)')
y1_bar = ax1.bar(x_range, y1, width=0.25, label='流程处理时间', color=(91 / 255, 155 / 255, 213 / 255)) y1_bar = ax1.bar(x_range, y1, width=0.25, label='流程处理时间', color=(91 / 255, 155 / 255, 213 / 255))
@ -272,7 +278,7 @@ def add_section(doc, department_data):
p = doc.add_paragraph() p = doc.add_paragraph()
p.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER p.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
r = p.add_run() r = p.add_run()
r.add_picture('{}/{}'.format(REPORT_DIR, pic_name), width=Inches(6)) r.add_picture('{}/{}'.format(REPORT_DIR, pic_name), width=Cm(20.27))
def add_chapter_2(doc): def add_chapter_2(doc):
@ -388,16 +394,16 @@ def add_chapter_1(doc):
set_paragraph_format(p) set_paragraph_format(p)
table_data = list(map(lambda d: (d[0], d[1], d[2]), procinst_by_department)) table_data = list(map(lambda d: (d[0], d[1], d[2]), procinst_by_department))
insert_table(doc, ['序号', '部门', '人均处理流程条数', '平均单条流程处理时间'], {0: 1.5, 1: 5.8, 2: 3.6, 3: 4.3}, table_data, 'style1') insert_table(doc, ['序号', '部门', '人均处理流程条数', '平均单条流程处理时间'], {0: 1.8, 1: 5.8, 2: 5.9, 3: 6.8}, table_data, 'style1')
add_heading(doc, 2, '(二)部门平均单一流程处理耗时排行') add_heading(doc, 2, '(二)部门平均单一流程处理耗时排行')
table_data = list(map(lambda d: (d[0], d[2]), procinst_by_department)) table_data = list(map(lambda d: (d[0], d[2]), procinst_by_department))
table_data.sort(key=lambda d: d[1], reverse=True) table_data.sort(key=lambda d: d[1], reverse=True)
insert_table(doc, ['排名', '部门', '平均单条流程处理时间'], {0: 1.5, 1: 5.8, 2: 4.3}, table_data, 'style2') insert_table(doc, ['排名', '部门', '平均单条流程处理时间'], {0: 1.5, 1: 5.8, 2: 6.2}, table_data, 'style2')
add_heading(doc, 2, '(三)部门人均处理流程平均条数排行') add_heading(doc, 2, '(三)部门人均处理流程平均条数排行')
table_data = list(map(lambda d: (d[0], d[1]), procinst_by_department)) table_data = list(map(lambda d: (d[0], d[1]), procinst_by_department))
insert_table(doc, ['排名', '部门', '人均处理流程条数'], {0: 1.5, 1: 5.8, 2: 4.3}, table_data, 'style3') insert_table(doc, ['排名', '部门', '人均处理流程条数'], {0: 1.5, 1: 5.8, 2: 6.2}, table_data, 'style3')
def upload_to_qiniu(filename): def upload_to_qiniu(filename):

Loading…
Cancel
Save