| | |
| | | for (QualityInspectParam detail : paramList) { |
| | | detail.setIndex(index); |
| | | index++; |
| | | |
| | | if (detail.getParameterType() != null && detail.getParameterType() == 1) { |
| | | String min = detail.getMinValue() != null ? detail.getMinValue().stripTrailingZeros().toPlainString() : ""; |
| | | String max = detail.getMaxValue() != null ? detail.getMaxValue().stripTrailingZeros().toPlainString() : ""; |
| | | detail.setStandardValue(min + "~" + max); |
| | | } |
| | | } |
| | | InputStream inputStream = this.getClass().getResourceAsStream("/static/report-template.docx"); |
| | | Configure configure = Configure.builder() |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void downPdf(HttpServletResponse response, QualityInspect qualityInspect) { |
| | | QualityInspect inspect = qualityInspectMapper.selectById(qualityInspect.getId()); |
| | | String inspectType = ""; |
| | | switch (inspect.getInspectType()) { |
| | | case 0: |
| | | inspectType = "原材料检验"; |
| | | break; |
| | | case 1: |
| | | inspectType = "过程检验"; |
| | | break; |
| | | case 2: |
| | | inspectType = "出厂检验"; |
| | | break; |
| | | } |
| | | List<QualityInspectParam> paramList = qualityInspectParamService.list(Wrappers.<QualityInspectParam>lambdaQuery().eq(QualityInspectParam::getInspectId, inspect.getId())); |
| | | int index = 1; |
| | | for (QualityInspectParam detail : paramList) { |
| | | detail.setIndex(index); |
| | | index++; |
| | | |
| | | if (detail.getParameterType() != null && detail.getParameterType() == 1) { |
| | | String min = detail.getMinValue() != null ? detail.getMinValue().stripTrailingZeros().toPlainString() : ""; |
| | | String max = detail.getMaxValue() != null ? detail.getMaxValue().stripTrailingZeros().toPlainString() : ""; |
| | | detail.setStandardValue(min + "~" + max); |
| | | } |
| | | } |
| | | InputStream inputStream = this.getClass().getResourceAsStream("/static/report-template.docx"); |
| | | Configure configure = Configure.builder() |
| | | .bind("paramList", new HackLoopTableRenderPolicy()) |
| | | .build(); |
| | | String finalInspectType = inspectType; |
| | | XWPFTemplate template = XWPFTemplate.compile(inputStream, configure).render( |
| | | new HashMap<String, Object>() {{ |
| | | put("inspect", inspect); |
| | | put("inspectType", finalInspectType); |
| | | put("paramList", paramList); |
| | | }}); |
| | | |
| | | try { |
| | | // 先将模板写入到 ByteArrayOutputStream 中 |
| | | java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream(); |
| | | template.write(bos); |
| | | bos.flush(); |
| | | bos.close(); |
| | | inputStream.close(); |
| | | |
| | | // 使用 Spire.Doc 读取 docx 数据流并转为 PDF |
| | | java.io.ByteArrayInputStream bis = new java.io.ByteArrayInputStream(bos.toByteArray()); |
| | | com.spire.doc.Document document = new com.spire.doc.Document(bis); |
| | | |
| | | response.setContentType("application/pdf"); |
| | | String fileName = URLEncoder.encode("检验报告", "UTF-8"); |
| | | response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); |
| | | response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".pdf"); |
| | | |
| | | java.io.OutputStream os = response.getOutputStream(); |
| | | document.saveToStream(os, com.spire.doc.FileFormat.PDF); |
| | | os.flush(); |
| | | os.close(); |
| | | bis.close(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new RuntimeException("导出失败"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public int updateQualityInspect(QualityInspectDto qualityInspectDto) { |
| | | if (ObjectUtils.isNotNull(qualityInspectDto.getQualityInspectParams())) { |
| | | qualityInspectParamService.remove(Wrappers.<QualityInspectParam>lambdaQuery().eq(QualityInspectParam::getInspectId, qualityInspectDto.getId())); |