The provided code is a method named 'doc2pdf' that converts a DOC or DOCX file to a PDF file. Here's a breakdown of what the code does:

  1. Query the file path of the specified file ID from the database using a mapper.
  2. Define the paths for the input DOC/DOCX file and the output PDF file.
  3. Download the file from the file system using 'fdfsFileUtils'.
  4. Convert the downloaded file from DOC/DOCX to PDF using 'AsposeUtils.Doc2PDF'.
  5. Print the file ID and matter ID to the console.
  6. Query for an existing attachment using the file ID and matter ID.
  7. Generate a new PDF file name based on the original file name.
  8. Upload the converted PDF file to the file system using 'fdfsFileUtils'.
  9. Delete any existing attachments with the same PDF file name.
  10. Create a new attachment record with the PDF file information.
  11. Insert the new attachment record and file upload information into the database.

If any exception occurs during the execution of the code, it will be caught and printed to the console.

public void doc2pdf(String fileId,String matterId) {
    try {
        AtFileupload atFileupload = atFileuploadMapper.queryFilePathByFileId(fileId);
        String docPath = filePathConfig.getXmlpath() + atFileupload.getFileName();
        String pdfPath = filePathConfig.getXmlpath() + atFileupload.getFileName().replace('docx', 'pdf').replace('doc', 'pdf');
        fdfsFileUtils.downFile(atFileupload.getFilePath(), docPath);
        AsposeUtils.Doc2PDF(filePathConfig.getXmlpath() + atFileupload.getFileName(), pdfPath);
        System.out.println(fileId);
        System.out.println(matterId);
        Attachment attachment1 = attachmentMapper.selectByFileIdAndMatterId(fileId, matterId);
        //添加记录
        String pdfName = atFileupload.getFileName().replace('docx', 'pdf').replace('doc', 'pdf');
        String fdfdPath = fdfsFileUtils.uploadFile(FDFSFileUtils.PUBLIC_OFFERING_REPORT_GROUP, new File(pdfPath));
        //先删除记录
        Map map = new HashMap<>();
        map.put('matterId',matterId);
        List<Attachment> attachments = attachmentMapper.selectByPrimaryMatterId(map);
        List<Attachment> delFiles = attachments.stream().filter(attachment -> StrUtil.equalsIgnoreCase(attachment.getAttachmentName(), pdfName)).collect(Collectors.toList());
        for (Attachment attachment : delFiles) {
            attachmentMapper.deleteByPrimaryKey(attachment.getAttachmentId());
            atFileuploadMapper.deleteFileInfo(attachment.getFileId());
        }
        //添加记录
        Attachment attachment_01 = new Attachment();
        String file_id = IdUtil.fastSimpleUUID();
        attachment_01.setAttachmentId(IdUtil.fastSimpleUUID());
        attachment_01.setAttachmentName(pdfName);
        attachment_01.setMatterId(matterId);
        attachment_01.setFileId(file_id);
        attachment_01.setParentId(attachment1.getAttachmentId());
        attachment_01.setIsDisclosureFile('Y');
        attachment_01.setIsWork('Y');
        attachmentMapper.insertSelective(attachment_01);
        AtFileupload fileupload = new AtFileupload();
        fileupload.setFileId(file_id);
        fileupload.setFileName(pdfName);
        fileupload.setFileNewName(fdfdPath.split('/')[fdfdPath.split('/').length - 1]);
        fileupload.setFilePath(fdfdPath);
        fileupload.setAbsolutePath(fdfdPath);
        fileupload.setGroupId(FDFSFileUtils.PUBLIC_OFFERING_REPORT_GROUP);
        atFileuploadMapper.insertAtFileupload(fileupload);
    } catch (Exception e) {
        e.printStackTrace();
    }

原文地址: https://www.cveoy.top/t/topic/pLTq 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录