1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| import org.apache.commons.codec.binary.Base64; import org.apache.poi.xwpf.usermodel.XWPFDocument;
@PostMapping("submitReceipt") public R submitReceipt(@RequestBody Map<String, Object> params, HttpServletRequest request, HttpServletResponse response) throws Exception { if (!params.containsKey("id") || !params.containsKey("qm") || !params.containsKey("ps")) { throw new ValidationException("缺少必要参数"); } EpCheckEntity checkEntity = epCheckService.info(MapUtil.getLong(params, "id")); Map<String, Object> fillMap = new HashMap<>(); fillMap.put("year", LocalDate.now().getYear()); fillMap.put("unitName", checkEntity.getUnitName()); fillMap.put("currentIndex", params.get("currentIndex")); fillMap.put("leadPerson", checkEntity.getLeadPerson()); fillMap.put("submitTime", LocalDateTime.now().format(DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN))); fillMap.put("blockTime", checkEntity.getBlockingTime().toInstant().atZone(ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern(DatePattern.NORM_DATE_PATTERN))); fillMap.put("transferredPerson", checkEntity.getTransferredPerson()); fillMap.put("transferredPersonContact", checkEntity.getTransferredPersonContact()); fillMap.put("remark", checkEntity.getRemark()); fillMap.put("ps", params.get("ps")); if (CollUtil.isNotEmpty(checkEntity.getProblemEntityList())) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < checkEntity.getProblemEntityList().size(); i++) { sb.append((i + 1)); sb.append(StringPool.DOT); sb.append(checkEntity.getProblemEntityList().get(i).getProblemDescription()); sb.append(StringPool.SEMICOLON); } fillMap.put("problems", sb.toString()); } ImageEntity imageEntity = new ImageEntity(Base64.decodeBase64(MapUtil.getStr(params, "qm")), 100, 50); fillMap.put("qm", imageEntity);
XWPFDocument doc = WordExportUtil.exportWord07("./template/交办单.docx", fillMap); String headIndex = LocalDate.now().format(DateTimeFormatter.ofPattern(DatePattern.NORM_DATE_PATTERN)) + StringPool.DASH + String.format("%04d", checkEntity.getCurrentIndex()); File outFile = new File(headIndex + "交办单.docx"); doc.write(Files.newOutputStream(outFile.toPath())); String uuidFileName = UUID.randomUUID().toString(); try (FileInputStream inputStream = new FileInputStream(outFile)) { minioTemplate.putObject("receipt", uuidFileName + ".docx", inputStream); } catch (Exception e) { log.error("转换流错误"); } return R.ok("保存成功"); }
|