Commit 8f276b49 authored by xixinzhao's avatar xixinzhao

检查报告无法下载

parent 93c68329
......@@ -46,10 +46,7 @@ import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.rdbms.service.BaseService;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.io.*;
import java.net.URLEncoder;
import java.text.ParseException;
import java.util.Arrays;
......@@ -296,37 +293,42 @@ public class CheckReportServiceImpl extends BaseService<CheckReportDto, CheckRep
report.setReportDate(getCheckReportDateStr(report));
report.setNowDate(DateUtils.dateFormat(new Date(), DateUtils.CHN_DATE_PATTERN));
if (!ValidationUtil.isEmpty(report)) {
String checkReportTemplatePath = this.getClass().getClassLoader().getResource("templates/check-report-template" +
".docx").getFile();
// String checkReportTemplatePath = this.getClass().getClassLoader().getResource("templates/check-report-template.docx").getFile();
String fileName = report.getName() + ".docx";
InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream("templates/check-report-template.docx");
CheckDangerTablePolicy checkDangerTablePolicy = new CheckDangerTablePolicy();
ReviewDangerTablePolicy reviewDangerTablePolicy = new ReviewDangerTablePolicy();
Configure.ConfigureBuilder configureBuilder = Configure.newBuilder();
configureBuilder.setElMode(ELMode.SPEL_MODE).bind("checkDangerList", checkDangerTablePolicy).bind("reviewDangerList", reviewDangerTablePolicy).build();
XWPFTemplate template = XWPFTemplate.compile(checkReportTemplatePath, configureBuilder.build()).render(report);
response.setContentType("application/msword");
response.setHeader("Content-Disposition",
"attachment;filename=" + URLEncoder.encode(fileName, "utf-8"));
OutputStream out = null;
BufferedOutputStream bos = null;
try {
out = response.getOutputStream();
bos = new BufferedOutputStream(out);
template.write(bos);
bos.flush();
out.flush();
} catch (IOException e) {
log.error("生成文档失败---------->");
e.printStackTrace();
} finally {
// XWPFTemplate template = XWPFTemplate.compile(checkReportTemplatePath, configureBuilder.build()).render(report);
if (resourceAsStream != null) {
XWPFTemplate template = XWPFTemplate.compile(resourceAsStream, configureBuilder.build()).render(report);
response.setContentType("application/msword");
response.setHeader("Content-Disposition",
"attachment;filename=" + URLEncoder.encode(fileName, "utf-8"));
OutputStream out = null;
BufferedOutputStream bos = null;
try {
bos.close();
out.close();
template.close();
out = response.getOutputStream();
bos = new BufferedOutputStream(out);
template.write(bos);
bos.flush();
out.flush();
} catch (IOException e) {
log.error("生成文档失败---------->");
e.printStackTrace();
} finally {
try {
bos.close();
out.close();
template.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} else {
log.error("获取模板失败---------->");
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment