|
@@ -121,59 +121,4 @@ public class TestController {
|
|
|
}
|
|
|
return ResultData.ok();
|
|
|
}
|
|
|
- @Autowired
|
|
|
- ICaseInquestService caseInquestService;
|
|
|
- @GetMapping("/downDocx")
|
|
|
- public void downDocx(@RequestParam(required = false) Integer caseId,
|
|
|
- HttpServletResponse res, HttpServletRequest req) throws IOException {
|
|
|
-
|
|
|
- if(caseId == null){
|
|
|
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
- }
|
|
|
- CaseInquest caseInquest = caseInquestService.getByCaseId(caseId);
|
|
|
- if(caseInquest == null){
|
|
|
- throw new BusinessException(ResultCode.INQUEST_ERROR2);
|
|
|
- }
|
|
|
-
|
|
|
- InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("template/inquest-template.docx");
|
|
|
- // 渲染模板
|
|
|
-
|
|
|
- CaseInquestVo vo = new CaseInquestVo();
|
|
|
- BeanUtils.copyProperties(caseInquest,vo);
|
|
|
-
|
|
|
-
|
|
|
- String info = "证人或当事人(签名):%s %s年 %s月 %s日 身份证件号码:%s\n"
|
|
|
- +" 单位或住址:%s\n";
|
|
|
- StringBuilder msg = new StringBuilder();
|
|
|
- for (Object object : vo.getWitnessInfo()) {
|
|
|
- JSONObject obj = (JSONObject) object;
|
|
|
- WitnessVo witnessVo = JSONObject.toJavaObject(obj,WitnessVo.class);
|
|
|
- String format = String.format(info, witnessVo.getName(), witnessVo.getYear(), witnessVo.getMonth(), witnessVo.getDay(), witnessVo.getId(), witnessVo.getAddress());
|
|
|
- msg.append(format);
|
|
|
- }
|
|
|
- TextRenderData text = new TextRenderData("000000",msg.toString());
|
|
|
- Style style = text.getStyle();
|
|
|
- style.setUnderLine(true);
|
|
|
- vo.setText(text);
|
|
|
-
|
|
|
- XWPFTemplate template = XWPFTemplate.compile(inputStream).render(vo);
|
|
|
-
|
|
|
- // 设置响应头,指定文件类型和内容长度
|
|
|
- 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);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
}
|