/**
* 返回申请单给前端
* // * @param args
* @throws Exception
*/
@GetMapping({"viewSupplyDetail/{id}"})
@ApiOperation("返回多个附件给前端")
@ResponseBody
public void viewDetail(@PathVariable String id, HttpServletResponse response) throws IOException {
InputStream is = null;
TechOrdDTO byPrimaryKey = this.baseService.getByPrimaryKey(id);
// byPrimaryKey.setProjectName(SecurityExtUtils.getCurrentLoginUser(getRequest()).getString("projectName"));
//获取模板文档
is = new ClassPathResource("/exportTemplate/technical_order.docx").getInputStream();
//填充数据
List<Map<String, Object>> resultList = new ArrayList<>();
if (CollectionUtils.isNotEmpty(byPrimaryKey.getTraList())) {
//节点状态类型翻译
AbstractDictUtils.dictFormatOfCollection(byPrimaryKey.getTraList(),
new String[]{CommunalConstants.DictType.NOD_STU},
new String[]{CommunalConstants.ClassFieldName.NODE_STATUS},
new String[]{CommunalConstants.ClassFieldName.NODE_STATUS});
for (TechTrackingDTO tracking : byPrimaryKey.getTraList()) {
Map<String, Object> resultListParams = new HashMap<>();
resultListParams.put("nodeName", tracking.getNodeName());
resultListParams.put("stu", tracking.getStu());
resultListParams.put("comment", tracking.getComment());
resultListParams.put("createTime", DateUtils.format(tracking.getCreateTime(), "yyyy年MM月dd日"));
resultListParams.put("createName", tracking.getCreateName());
resultList.add(resultListParams);
}
}
//准备数据
Map<String, Object> params = new HashMap<>();
params.put("data", resultList);
params.put("projectName", byPrimaryKey.getProjectName());
//维修类型翻译
AbstractDictUtils.singleDictFormat(byPrimaryKey, CommunalConstants.DictType.MAINTAIN_TYPE,
CommunalConstants.ClassFieldName.MAINTAIN, CommunalConstants.ClassFieldName.MAINTAIN);
params.put("type", byPrimaryKey.getType());
params.put("depName", byPrimaryKey.getDepName());
params.put("userName", byPrimaryKey.getUserName());
params.put("summarize", byPrimaryKey.getSummarize());
LoopRowTableRenderPolicy hackLoopTableRenderPolicy = new LoopRowTableRenderPolicy();
Configure config = Configure.builder().bind("data", hackLoopTableRenderPolicy).build();
XWPFTemplate template = XWPFTemplate.compile(is, config).render(params);
// 文件下载
response.setContentType("application/octet-stream");
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + System.currentTimeMillis() + ".docx");
ServletOutputStream outputStream = response.getOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(outputStream);
template.write(bos);
bos.flush();
outputStream.flush();
PoitlIOUtils.closeQuietlyMulti(template, bos, outputStream);
}
Java查出的数据生成word
最新推荐文章于 2023-07-11 10:25:43 发布