|
@@ -3,6 +3,7 @@ package com.fdkankan.fusion.controller;
|
|
import cn.hutool.http.HttpUtil;
|
|
import cn.hutool.http.HttpUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.deepoove.poi.XWPFTemplate;
|
|
import com.deepoove.poi.XWPFTemplate;
|
|
|
|
+import com.deepoove.poi.util.PoitlIOUtils;
|
|
import com.dtflys.forest.annotation.Post;
|
|
import com.dtflys.forest.annotation.Post;
|
|
import com.fdkankan.fusion.common.ResultCode;
|
|
import com.fdkankan.fusion.common.ResultCode;
|
|
import com.fdkankan.fusion.common.ResultData;
|
|
import com.fdkankan.fusion.common.ResultData;
|
|
@@ -20,9 +21,11 @@ import sun.java2d.pipe.SpanIterator;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.xml.transform.Result;
|
|
import javax.xml.transform.Result;
|
|
|
|
+import java.io.BufferedOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
import java.io.OutputStream;
|
|
import java.io.OutputStream;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
|
|
|
@@ -123,14 +126,29 @@ public class TestController {
|
|
}
|
|
}
|
|
CaseInquest caseInquest = caseInquestService.getByCaseId(caseId);
|
|
CaseInquest caseInquest = caseInquestService.getByCaseId(caseId);
|
|
if(caseInquest == null){
|
|
if(caseInquest == null){
|
|
- throw new BusinessException(ResultCode.INQUEST_ERROR);
|
|
|
|
|
|
+ throw new BusinessException(ResultCode.INQUEST_ERROR2);
|
|
}
|
|
}
|
|
- OutputStream os = res.getOutputStream();
|
|
|
|
|
|
|
|
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("template/inquest-template.docx");
|
|
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("template/inquest-template.docx");
|
|
// 渲染模板
|
|
// 渲染模板
|
|
- XWPFTemplate template = XWPFTemplate.compile(inputStream).render(caseInquest);
|
|
|
|
|
|
+ XWPFTemplate template = XWPFTemplate.compile(inputStream).render(new HashMap<>());
|
|
|
|
+
|
|
|
|
+ // 设置响应头,指定文件类型和内容长度
|
|
|
|
+ res.setContentType("application/octet-stream");
|
|
|
|
+ res.setHeader("Content-Disposition", "attachment; filename=output.docx");
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ // 返回网络流
|
|
|
|
+ OutputStream out = res.getOutputStream();
|
|
|
|
+ BufferedOutputStream bos = new BufferedOutputStream(out);
|
|
|
|
+ template.write(bos);
|
|
|
|
+ bos.flush();
|
|
|
|
+ out.flush();
|
|
|
|
+ // 关闭流
|
|
|
|
+ PoitlIOUtils.closeQuietlyMulti(template, bos, out);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+ }
|
|
|
|
|
|
- template.writeAndClose(os);
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|