Browse Source

无法正常下载报告的问题

tags/v1.1.0
qiujinyang 2 years ago
parent
commit
fa0ae70764
1 changed files with 7 additions and 1 deletions
  1. +7
    -1
      tuoheng-admin/src/main/java/com/tuoheng/admin/service/impl/ReportServiceImpl.java

+ 7
- 1
tuoheng-admin/src/main/java/com/tuoheng/admin/service/impl/ReportServiceImpl.java View File

@@ -238,6 +238,7 @@ public class ReportServiceImpl extends BaseServiceImpl<ReportMapper, Report> imp
f.delete();
f.createNewFile();
}
log.info("开始编写word文件,文件为:{}",filePath);
wordUtils.openDocument(filePath);
wordUtils.getDocument().setPageSize(PageSize.A4);
wordUtils.getDocument().setMargins(71f, 71f, 72f, 72f);
@@ -281,6 +282,7 @@ public class ReportServiceImpl extends BaseServiceImpl<ReportMapper, Report> imp
table.addCell(cell);
}
wordUtils.getDocument().add(table);
log.info("林场信息写入完成");

wordUtils.insertTitlePatternThird("二:巡检信息", WordUtilsOld.rtfGsBt3);
Table table2 = new Table(2);//生成一表格
@@ -340,6 +342,7 @@ public class ReportServiceImpl extends BaseServiceImpl<ReportMapper, Report> imp
table2.addCell(cell);
}
wordUtils.getDocument().add(table2);
log.info("巡检信息写入完成");

List<QuestionTypeCountVO> questionTypeInfo = reportInfoVO.getQuestionTypeInfo();
Map<String, Integer> questionCount=new HashMap<>();
@@ -420,6 +423,7 @@ public class ReportServiceImpl extends BaseServiceImpl<ReportMapper, Report> imp
wordUtils.getDocument().add(table3);
}

log.info("巡检结果写入完成");
if (reportInfoVO.getQuestionReportList().size() > 0) {
wordUtils.insertTitlePatternThird("四:问题清单", WordUtilsOld.rtfGsBt3);
log.info("报告标题四成功");
@@ -491,11 +495,12 @@ public class ReportServiceImpl extends BaseServiceImpl<ReportMapper, Report> imp
}

wordUtils.closeDocument();
log.info("问题清单写入完成");

//清空缓存
response.reset();
// 定义浏览器响应表头,并定义下载名
String urlFileName = URLEncoder.encode("汤山林场无人机巡检报告【"+ reportInfoVO.getReportNo() + "】.doc", "UTF-8");
String urlFileName = URLEncoder.encode("汤山林场无人机巡检报告【"+ reportInfoVO.getReportNo() + "】.docx", "UTF-8");
response.setHeader("Content-Disposition", "attachment;filename=" + urlFileName);
response.setCharacterEncoding("utf-8");
//定义下载的类型
@@ -503,6 +508,7 @@ public class ReportServiceImpl extends BaseServiceImpl<ReportMapper, Report> imp
OutputStream out;
File files = new File(filePath);

log.info("读出的文件文件地址为:{}",filePath);
FileInputStream inputStream = new FileInputStream(files);
//3.通过response获取ServletOutputStream对象(out)
out = response.getOutputStream();

Loading…
Cancel
Save