From 3e0a09e5381d080a0f82494386657bc8910abd29 Mon Sep 17 00:00:00 2001 From: Renpc-kilig <308442850@qq.com> Date: Tue, 12 Apr 2022 14:23:42 +0800 Subject: [PATCH] =?UTF-8?q?bug=E4=BF=AE=E6=94=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/fileupload/FileUploadController.java | 12 ++ .../pojo/dtos/fileupload/FileUploadDTO.java | 30 +++ .../pojo/vos/fileupload/FileUploadVO.java | 10 + .../fileupload/IFileUploadService.java | 3 + .../impl/FileUploadServiceImpl.java | 113 ++++++++--- .../systemoa/utils/OfficeToPDFUtils.java | 12 +- .../mapper/fileupload/file-upload-mapper.xml | 8 + .../templates/fileupload/update.html | 186 ++++++++++++++++-- 8 files changed, 332 insertions(+), 42 deletions(-) diff --git a/src/main/java/cn/com/tenlion/systemoa/controller/api/fileupload/FileUploadController.java b/src/main/java/cn/com/tenlion/systemoa/controller/api/fileupload/FileUploadController.java index 099b4e5..88228d4 100644 --- a/src/main/java/cn/com/tenlion/systemoa/controller/api/fileupload/FileUploadController.java +++ b/src/main/java/cn/com/tenlion/systemoa/controller/api/fileupload/FileUploadController.java @@ -15,6 +15,8 @@ import io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -108,4 +110,14 @@ public class FileUploadController extends DefaultBaseController { return new SuccessResultData<>(fileUploadService.count(params)); } + @ApiOperation(value = "文档上传详情", notes = "文档上传详情接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "fileUploadId", value = "文档上传ID", paramType = "path") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("get-pdf/{fileUploadId}") + public void getPdf(@PathVariable("fileUploadId") String fileUploadId, HttpServletRequest request, HttpServletResponse response) { + fileUploadService.getPdf(fileUploadId, request, response); + } + } \ No newline at end of file diff --git a/src/main/java/cn/com/tenlion/systemoa/pojo/dtos/fileupload/FileUploadDTO.java b/src/main/java/cn/com/tenlion/systemoa/pojo/dtos/fileupload/FileUploadDTO.java index f630bda..7284324 100644 --- a/src/main/java/cn/com/tenlion/systemoa/pojo/dtos/fileupload/FileUploadDTO.java +++ b/src/main/java/cn/com/tenlion/systemoa/pojo/dtos/fileupload/FileUploadDTO.java @@ -20,6 +20,8 @@ public class FileUploadDTO { private String catalogueId; @ApiModelProperty(name = "fileTypeId", value = "文档类型") private String fileTypeId; + @ApiModelProperty(name = "fileTypeName", value = "文档类型名称") + private String fileTypeName; @ApiModelProperty(name = "catalogueName", value = "所属目录名称") private String catalogueName; @ApiModelProperty(name = "catalogueType", value = "文档类型(个人、公共)") @@ -54,6 +56,10 @@ public class FileUploadDTO { private String shareRole; @ApiModelProperty(name = "pdfFilePath", value = "") private String pdfFilePath; + @ApiModelProperty(name = "oldFileType", value = "") + private String oldFileType; + @ApiModelProperty(name = "fileHz", value = "") + private String fileHz; public String getFileUploadId() { return fileUploadId == null ? "" : fileUploadId.trim(); @@ -79,6 +85,14 @@ public class FileUploadDTO { this.fileTypeId = fileTypeId; } + public String getFileTypeName() { + return fileTypeName; + } + + public void setFileTypeName(String fileTypeName) { + this.fileTypeName = fileTypeName; + } + public String getCatalogueName() { return catalogueName; } @@ -214,4 +228,20 @@ public class FileUploadDTO { public void setPdfFilePath(String pdfFilePath) { this.pdfFilePath = pdfFilePath; } + + public String getOldFileType() { + return oldFileType; + } + + public void setOldFileType(String oldFileType) { + this.oldFileType = oldFileType; + } + + public String getFileHz() { + return fileHz; + } + + public void setFileHz(String fileHz) { + this.fileHz = fileHz; + } } diff --git a/src/main/java/cn/com/tenlion/systemoa/pojo/vos/fileupload/FileUploadVO.java b/src/main/java/cn/com/tenlion/systemoa/pojo/vos/fileupload/FileUploadVO.java index 6f6066b..0824699 100644 --- a/src/main/java/cn/com/tenlion/systemoa/pojo/vos/fileupload/FileUploadVO.java +++ b/src/main/java/cn/com/tenlion/systemoa/pojo/vos/fileupload/FileUploadVO.java @@ -30,6 +30,8 @@ public class FileUploadVO { private String remake; @ApiModelProperty(name = "fileModular", value = "文件模块(单文件、多文件)") private String fileModular; + @ApiModelProperty(name = "pdfFilePath", value = "") + private String pdfFilePath; public String getCatalogueId() { return catalogueId == null ? "" : catalogueId.trim(); @@ -86,4 +88,12 @@ public class FileUploadVO { public void setFileModular(String fileModular) { this.fileModular = fileModular; } + + public String getPdfFilePath() { + return pdfFilePath; + } + + public void setPdfFilePath(String pdfFilePath) { + this.pdfFilePath = pdfFilePath; + } } diff --git a/src/main/java/cn/com/tenlion/systemoa/service/fileupload/IFileUploadService.java b/src/main/java/cn/com/tenlion/systemoa/service/fileupload/IFileUploadService.java index be47c45..2d73c10 100644 --- a/src/main/java/cn/com/tenlion/systemoa/service/fileupload/IFileUploadService.java +++ b/src/main/java/cn/com/tenlion/systemoa/service/fileupload/IFileUploadService.java @@ -7,6 +7,8 @@ import cn.com.tenlion.systemoa.pojo.vos.fileupload.FileUploadVO; import cn.com.tenlion.systemoa.pojo.bos.fileupload.FileUploadBO; import cn.com.tenlion.systemoa.pojo.pos.fileupload.FileUploadPO; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.util.List; import java.util.Map; @@ -185,4 +187,5 @@ public interface IFileUploadService { */ Integer count(Map params); + void getPdf(String fileUploadId, HttpServletRequest request, HttpServletResponse response); } \ No newline at end of file diff --git a/src/main/java/cn/com/tenlion/systemoa/service/fileupload/impl/FileUploadServiceImpl.java b/src/main/java/cn/com/tenlion/systemoa/service/fileupload/impl/FileUploadServiceImpl.java index 7e70828..adeb97f 100644 --- a/src/main/java/cn/com/tenlion/systemoa/service/fileupload/impl/FileUploadServiceImpl.java +++ b/src/main/java/cn/com/tenlion/systemoa/service/fileupload/impl/FileUploadServiceImpl.java @@ -14,26 +14,29 @@ import cn.com.tenlion.systemoa.utils.OfficeToPDFUtils; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import ink.wgink.common.base.DefaultBaseService; +import ink.wgink.exceptions.SearchException; import ink.wgink.module.file.dao.IFileDao; import ink.wgink.module.file.service.IFileService; import ink.wgink.pojo.ListPage; import ink.wgink.pojo.bos.UserInfoBO; import ink.wgink.pojo.pos.FilePO; import ink.wgink.pojo.result.SuccessResultList; +import ink.wgink.properties.FileProperties; import ink.wgink.util.UUIDUtil; +import ink.wgink.util.date.DateUtil; import ink.wgink.util.map.HashMapUtil; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; -import java.util.Base64; -import java.util.Iterator; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @ClassName: FileUploadServiceImpl @@ -57,6 +60,8 @@ public class FileUploadServiceImpl extends DefaultBaseService implements IFileUp private IFileDao fileDao; @Autowired private ConfigPro configPro; + @Autowired + private FileProperties fileProperties; @Override public void save(FileUploadVO fileUploadVO) { @@ -76,6 +81,7 @@ public class FileUploadServiceImpl extends DefaultBaseService implements IFileUp @Override public String saveReturnId(String token, FileUploadVO fileUploadVO) { String fileUploadId = UUIDUtil.getUUID(); + toPdf(fileUploadVO, fileUploadId); Map params = HashMapUtil.beanToMap(fileUploadVO); params.put("fileUploadId", fileUploadId); if (StringUtils.isBlank(token)) { @@ -118,6 +124,7 @@ public class FileUploadServiceImpl extends DefaultBaseService implements IFileUp @Override public void update(String token, String fileUploadId, FileUploadVO fileUploadVO) { + toPdf(fileUploadVO, fileUploadId); Map params = HashMapUtil.beanToMap(fileUploadVO); params.put("fileUploadId", fileUploadId); if (StringUtils.isBlank(token)) { @@ -126,11 +133,28 @@ public class FileUploadServiceImpl extends DefaultBaseService implements IFileUp setAppUpdateInfo(token, params); } fileUploadDao.update(params); + } @Override public FileUploadDTO get(Map params) { FileUploadDTO fileUploadDTO = fileUploadDao.get(params); + if(null != fileUploadDTO) { + if(!StringUtils.isEmpty(fileUploadDTO.getFileTypeId())) { + FileTypeDTO fileTypeDTO = fileTypeService.get(fileUploadDTO.getFileTypeId()); + if(null != fileTypeDTO) { + fileUploadDTO.setOldFileType(fileTypeDTO.getTypeName()); + fileUploadDTO.setFileTypeName(fileTypeDTO.getTypeName()); + } + } + if(!StringUtils.isEmpty(fileUploadDTO.getFileId())) { + params.put("fileId", fileUploadDTO.getFileId()); + FilePO filePO = fileDao.getPO(params); + if(null != filePO) { + fileUploadDTO.setFileHz(filePO.getFileName()); + } + } + } return fileUploadDTO; } @@ -191,7 +215,7 @@ public class FileUploadServiceImpl extends DefaultBaseService implements IFileUp FileUploadDTO fileUploadDTO = (FileUploadDTO) it.next(); params.put("fileTypeId", fileUploadDTO.getFileTypeId()); FileTypeDTO fileTypeDTO = fileTypeService.get(params); - if(null != params.get("typeBelong")) { + if(null != params.get("typeBelong") && null != fileTypeDTO) { if(!params.get("typeBelong").toString().equals(fileTypeDTO.getTypeBelong())) { it.remove(); continue; @@ -201,27 +225,6 @@ public class FileUploadServiceImpl extends DefaultBaseService implements IFileUp fileUploadDTO.setCatalogueType(fileTypeDTO.getTypeBelong()); fileUploadDTO.setCatalogueName(fileTypeDTO.getTypeName()); } - // 生成临时PDF文件 - if("文件".equals(fileUploadDTO.getFileType())) { - if("单文件".equals(fileUploadDTO.getFileModular())) { - String fileId = fileUploadDTO.getFileId(); - params.put("fileId", fileId); - FilePO filePO = fileDao.getPO(params); - if(null != filePO) { - String pdfPath = "src/main/resources/static/route/viewpdf/"+fileUploadDTO.getFileUploadId()+".pdf"; - if("pdf".equals(filePO.getFileType())) { - fileUploadDTO.setPdfFilePath(filePO.getFilePath()); - }else { - File file = new File(pdfPath); - if(file.exists()) { - file.delete(); - } - OfficeToPDFUtils.trans(filePO.getFilePath(), pdfPath, filePO.getFileType()); - fileUploadDTO.setPdfFilePath(pdfPath); - } - } - } - } } } /*if(null != fileUploadDTOList && fileUploadDTOList.size() > 0) { @@ -261,4 +264,62 @@ public class FileUploadServiceImpl extends DefaultBaseService implements IFileUp return count == null ? 0 : count; } + @Override + public void getPdf(String fileUploadId, HttpServletRequest request, HttpServletResponse response) { + FileUploadDTO fileUploadDTO = get(fileUploadId); + if(null != fileUploadDTO) { + if(!StringUtils.isEmpty(fileUploadDTO.getPdfFilePath())) { + File file = new File(fileUploadDTO.getPdfFilePath()); + if(file.exists()) { + byte[] data = null; + try{ + FileInputStream inputStream = new FileInputStream(file); + data = new byte[inputStream.available()]; + inputStream.read(data); + response.getOutputStream().write(data); + inputStream.close(); + }catch (Exception e) { + e.printStackTrace(); + } + }else { + throw new SearchException("文件不存在"); + } + } + } + } + + private void toPdf(FileUploadVO fileUploadVO, String fileUploadId) { + Map params = new HashMap<>(); + // 生成临时PDF文件 + if("文件".equals(fileUploadVO.getFileType())) { + if("单文件".equals(fileUploadVO.getFileModular())) { + String fileId = fileUploadVO.getFileId(); + params.put("fileId", fileId); + FilePO filePO = fileDao.getPO(params); + if(null != filePO) { + String baseUploadPath = fileProperties.getUploadPath(); + StringBuilder filePath = new StringBuilder(); + if (!baseUploadPath.endsWith(File.separator)) { + filePath.append(baseUploadPath).append(File.separator); + } else { + filePath.append(baseUploadPath); + } + filePath.append("viewPdfFile"); + filePath.append(File.separator).append(DateUtil.getDays()); + String pdfPath = filePath + "/" + fileUploadId + ".pdf"; + if("pdf".equals(filePO.getFileType())) { + fileUploadVO.setPdfFilePath(filePO.getFilePath()); + }else { + File file = new File(pdfPath); + if(file.exists()) { + file.delete(); + } + OfficeToPDFUtils.trans(filePO.getFilePath(), pdfPath, filePO.getFileType(), filePath.toString()); + fileUploadVO.setPdfFilePath(pdfPath); + } + } + } + } + } + } \ No newline at end of file diff --git a/src/main/java/cn/com/tenlion/systemoa/utils/OfficeToPDFUtils.java b/src/main/java/cn/com/tenlion/systemoa/utils/OfficeToPDFUtils.java index c2dd888..a273398 100644 --- a/src/main/java/cn/com/tenlion/systemoa/utils/OfficeToPDFUtils.java +++ b/src/main/java/cn/com/tenlion/systemoa/utils/OfficeToPDFUtils.java @@ -15,7 +15,7 @@ public class OfficeToPDFUtils { public static boolean judgeLicense() { boolean result = false; try { - license = OfficeToPDFUtils.class.getClassLoader().getResourceAsStream("license/license.xml"); //文件路径 + license = OfficeToPDFUtils.class.getClassLoader().getResourceAsStream("static/assets/js/pdf/license"); //文件路径 if (license != null) { License aposeLic = new License(); aposeLic.setLicense(license); @@ -28,13 +28,17 @@ public class OfficeToPDFUtils { } // 转换 - public static void trans(String filePath, String pdfPath, String type) { + public static void trans(String filePath, String pdfPath, String type, String folderPath) { if (!judgeLicense()) { System.out.println("license错误"); } try { System.out.println("as开始:" + filePath); long old = System.currentTimeMillis(); + File folder = new File(folderPath); + if(!folder.exists() && !folder.isDirectory()) { + folder.mkdirs(); + } File file = new File(pdfPath); toPdf(file, filePath, pdfPath, type); long now = System.currentTimeMillis(); @@ -181,10 +185,10 @@ public class OfficeToPDFUtils { } } - public static void main(String[] args) { + /*public static void main(String[] args) { String filePath = "C:\\Users\\29492\\Desktop\\test.pdf"; String PdfFilePath = "C:\\Users\\29492\\Desktop\\test111.pdf"; trans(filePath, PdfFilePath, "pdf"); - } + }*/ } diff --git a/src/main/resources/mybatis/mapper/fileupload/file-upload-mapper.xml b/src/main/resources/mybatis/mapper/fileupload/file-upload-mapper.xml index b2bf313..2c2cc96 100644 --- a/src/main/resources/mybatis/mapper/fileupload/file-upload-mapper.xml +++ b/src/main/resources/mybatis/mapper/fileupload/file-upload-mapper.xml @@ -20,6 +20,7 @@ + @@ -65,6 +66,7 @@ content, remake, file_modular, + pdf_file_path, creator, gmt_create, modifier, @@ -79,6 +81,7 @@ #{content}, #{remake}, #{fileModular}, + #{pdfFilePath}, #{creator}, #{gmtCreate}, #{modifier}, @@ -138,6 +141,9 @@ file_modular = #{fileModular}, + + + pdf_file_path = #{pdfFilePath}, gmt_modified = #{gmtModified}, modifier = #{modifier}, @@ -156,6 +162,7 @@ t1.content, t1.remake, t1.file_modular, + t1.pdf_file_path, t1.file_upload_id FROM data_file_upload t1 @@ -231,6 +238,7 @@ t1.content, t1.remake, t1.file_modular, + t1.pdf_file_path, t1.creator, t1.gmt_create, t1.modifier, diff --git a/src/main/resources/templates/fileupload/update.html b/src/main/resources/templates/fileupload/update.html index ba8ab22..b23bee1 100644 --- a/src/main/resources/templates/fileupload/update.html +++ b/src/main/resources/templates/fileupload/update.html @@ -45,9 +45,15 @@
+
+ +
+ +
+
- -
+ +
+