ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TContractController.java
@@ -331,7 +331,6 @@ } String url = wordUtil.generatePdf("/template", "1_yzj_租赁合同.xml", templateParam, "租赁合同", "E:\\"); System.out.println(url); res.add(url); } ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/PdfUtils.java
@@ -12,6 +12,7 @@ import java.io.*; import java.net.URL; import java.nio.file.Files; import java.util.concurrent.TimeUnit; @Slf4j @Component @@ -23,44 +24,85 @@ * * @param url */ public String wordToPdf(String url,String filePath, String fileName) { // public String wordToPdf(String url,String filePath, String fileName) { // try { // DocumentType documentType = DocumentType.DOC; // if(url.contains(".docx")){ // documentType = DocumentType.DOCX; // } // if(url.contains(".doc")){ // documentType = DocumentType.DOC; // } // if(url.contains(".xlsx")){ // documentType = DocumentType.XLSX; // }else { // if(url.contains(".xls")){ // documentType = DocumentType.XLS; // } // } // InputStream inputStream = new URL(url).openStream(); // ByteArrayOutputStream stream = new ByteArrayOutputStream(); // IConverter converter = LocalConverter.builder().build(); // converter.convert(inputStream) // .as(documentType) // .to(stream) // .as(DocumentType.PDF).execute(); // // //上传图片 // byte2File(stream.toByteArray(),filePath + "/pdf",fileName.substring(0,fileName.lastIndexOf(".")) + ".pdf"); // MultipartFile multipartFile = convertToMultipartFile(stream,fileName.substring(0,fileName.lastIndexOf(".")) ); // String s = tencentCosUtil.upLoadFile(multipartFile,"/wordToPdf"); // // stream.close(); // inputStream.close(); // return s; // } catch (Exception e) { // e.printStackTrace(); // } // return null; // } public String wordToPdf(String url, String filePath, String fileName) { try { DocumentType documentType = DocumentType.DOC; if(url.contains(".docx")){ if (url.contains(".docx")) { documentType = DocumentType.DOCX; } if(url.contains(".doc")){ } else if (url.contains(".doc")) { documentType = DocumentType.DOC; } if(url.contains(".xlsx")){ } else if (url.contains(".xlsx")) { documentType = DocumentType.XLSX; }else { if(url.contains(".xls")){ documentType = DocumentType.XLS; } } else if (url.contains(".xls")) { documentType = DocumentType.XLS; } InputStream inputStream = new URL(url).openStream(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); IConverter converter = LocalConverter.builder().build(); converter.convert(inputStream) .as(documentType) .to(stream) .as(DocumentType.PDF).execute(); //上传图片 byte2File(stream.toByteArray(),filePath + "/pdf",fileName.substring(0,fileName.lastIndexOf(".")) + ".pdf"); MultipartFile multipartFile = convertToMultipartFile(stream,fileName.substring(0,fileName.lastIndexOf(".")) ); String s = tencentCosUtil.upLoadFile(multipartFile,"/wordToPdf"); // Ensure the URL has a protocol part if (!url.startsWith("file://") && !url.startsWith("http://") && !url.startsWith("https://")) { url = "file://" + url; } stream.close(); inputStream.close(); return s; // 使用LibreOffice进行转换 ProcessBuilder pb = new ProcessBuilder( "soffice", "--headless", "--convert-to", "pdf", "--outdir", new File(filePath+ "/pdf"+fileName.substring(0, fileName.lastIndexOf(".")) + ".pdf").getParent(), filePath+fileName ); Process process = pb.start(); // 等待转换完成 int exitCode = process.waitFor(); if (exitCode == 0) { System.out.println("PDF转换成功!"); } else { System.out.println("PDF转换失败!"); } return ""; } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("Failed to generate PDF: " + e.getMessage(), e); } return null; } public static MultipartFile convertToMultipartFile(ByteArrayOutputStream baos, String fileName) throws IOException { @@ -209,10 +251,10 @@ } public String test(String fileName){ String url = "file:///E:\\"+fileName; String url = "file:///usr/local/project/file/"+fileName; // String filePath = "E:\\qiyeweixin\\WXWork\\1688855207501340\\Cache\\File\\2024-09"; // String fileName = "专业技术工作总结.docx";4 String filePath = "E:\\"; String filePath = "/usr/local/project/file/"; String s = wordToPdf(url, filePath, fileName); System.err.println(s); ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/WordPdfGenerator.java
New file @@ -0,0 +1,106 @@ //package com.ruoyi.web.controller.tool; // //import org.apache.poi.xwpf.usermodel.*; //import java.io.*; //import java.time.LocalDateTime; //import java.time.format.DateTimeFormatter; // //public class WordPdfGenerator { // // // 示例数据类 // public static class UserData { // private String name; // private String id; // private String department; // private LocalDateTime createTime; // // public UserData(String name, String id, String department) { // this.name = name; // this.id = id; // this.department = department; // this.createTime = LocalDateTime.now(); // } // // // getter方法省略 // } // // public static void generateDocument(UserData userData, String outputPath) { // try (XWPFDocument document = new XWPFDocument()) { // // 创建标题 // XWPFParagraph title = document.createParagraph(); // title.setAlignment(ParagraphAlignment.CENTER); // XWPFRun titleRun = title.createRun(); // titleRun.setText("用户信息表"); // titleRun.setBold(true); // titleRun.setFontSize(20); // titleRun.setFontFamily("宋体"); // // // 添加空行 // document.createParagraph(); // // // 创建表格 // XWPFTable table = document.createTable(5, 2); // table.setWidth("100%"); // // // 设置表格数据 // setCellText(table, 0, "姓名", userData.name); // setCellText(table, 1, "ID", userData.id); // setCellText(table, 2, "部门", userData.department); // setCellText(table, 3, "创建时间", // userData.createTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); // // // 保存Word文档 // String wordFile = outputPath + ".docx"; // try (FileOutputStream out = new FileOutputStream(wordFile)) { // document.write(out); // } // // // 转换为PDF // convertToPdf(wordFile, outputPath + ".pdf"); // // } catch (Exception e) { // e.printStackTrace(); // } // } // // private static void setCellText(XWPFTable table, int row, String label, String value) { // XWPFTableRow tableRow = table.getRow(row); // tableRow.getCell(0).setText(label); // tableRow.getCell(1).setText(value); // } // // private static void convertToPdf(String wordPath, String pdfPath) { // try { // // 使用LibreOffice进行转换 // ProcessBuilder pb = new ProcessBuilder( // "soffice", // "--headless", // "--convert-to", "pdf", // "--outdir", new File(pdfPath).getParent(), // wordPath // ); // Process process = pb.start(); // // // 等待转换完成 // int exitCode = process.waitFor(); // if (exitCode == 0) { // System.out.println("PDF转换成功!"); // } else { // System.out.println("PDF转换失败!"); // } // // // 删除临时Word文件 // new File(wordPath).delete(); // // } catch (Exception e) { // e.printStackTrace(); // } // } // // public static void main(String[] args) { // // 示例使用 // UserData userData = new UserData("张三", "EMP001", "技术部"); // String outputPath = "E:\\"; // generateDocument(userData, outputPath); // } //} ruoyi-system/src/main/java/com/ruoyi/system/service/impl/FlowListenerService.java
@@ -651,11 +651,10 @@ } case CATEGORY3: { // 合同提前终止审批 int submitStatus = status == 0 ? 4 : (status == 1 ? 6 : 5); int submitStatus = status == 0 ? 4 : (status == 1 ? 7 : 5); contractService.updateContractAuditStatus(processParameter.getString("projectId"), submitStatus); // 生成验收记录 TContract contract = contractService.getById(processParameter.getString("projectId")); contract.setStatus("7"); TCheckAcceptRecord tCheckAcceptRecord = new TCheckAcceptRecord(); tCheckAcceptRecord.setContractId(contract.getId()); tCheckAcceptRecord.setHouseId(contract.getHouseId()); @@ -667,7 +666,6 @@ int size = checkAcceptRecordMapper.selectList(new LambdaQueryWrapper<TCheckAcceptRecord>() .likeRight(TCheckAcceptRecord::getAcceptanceTime, LocalDate.now())).size(); tCheckAcceptRecord.setCode(replace.substring(2) + String.format("%03d", size + 1)); checkAcceptRecordMapper.insert(tCheckAcceptRecord); // 将所有未缴费账单设置未已失效 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/StateProcessTemplateServiceImpl.java
@@ -1365,6 +1365,7 @@ sysUserMap = new HashMap<>(); } for (ProcessTaskListVO processTaskListVO : processTaskListVOS) { processTaskListVO.setStatus(processTaskListVO.getTaskState() == 10 ? "2" : processTaskListVO.getTaskState().toString()); processTaskListVO.setTaskId(processTaskListVO.getId()); SysUser sysUser = sysUserMap.get(processTaskListVO.getCreateBy()); if (Objects.nonNull(sysUser)) { ruoyi-system/src/main/java/com/ruoyi/system/vo/ProcessTaskListVO.java
@@ -36,6 +36,7 @@ private Date createTime; private String status; private Integer taskState; private String taskId;