From 75436cf57bd37dae73ee196356e49a3c5f4977b5 Mon Sep 17 00:00:00 2001 From: caihaohan Date: Wed, 9 Oct 2024 12:02:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9C=A8=E7=BA=BF=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OnlyOfficeController.java | 14 ++++----- .../service/impl/ProcessFileServiceImpl.java | 31 ++++++++----------- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/laws-modules/src/main/java/com/jero/modules/onlyoffice/controller/OnlyOfficeController.java b/laws-modules/src/main/java/com/jero/modules/onlyoffice/controller/OnlyOfficeController.java index 71744cef..be52b38e 100644 --- a/laws-modules/src/main/java/com/jero/modules/onlyoffice/controller/OnlyOfficeController.java +++ b/laws-modules/src/main/java/com/jero/modules/onlyoffice/controller/OnlyOfficeController.java @@ -3,6 +3,8 @@ package com.jero.modules.onlyoffice.controller; import cn.hutool.core.io.IoUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.jero.common.api.vo.Result; +import com.jero.common.api.vo.ResultCommon; +import com.jero.common.util.MessageUtils; import com.jero.common.util.obs.ObsBootUtil; import com.jero.modules.onlyoffice.entity.ProcessFile; import com.jero.modules.onlyoffice.service.IProcessFileService; @@ -75,19 +77,19 @@ public class OnlyOfficeController { return ProcessFileService.processEditFile(id); } - @ApiOperation(value = "|model| 传入 模板文档名称(不带后缀)默认 docx") + @ApiOperation(value = "模板文档名称(不带后缀)默认 docx") @GetMapping("/saveEditFile") public Result saveEditFile(String model) { - return Result.OK(ProcessFileService.saveEditFile(model)); + return Result.OK(MessageUtils.getMessage(ResultCommon.OK), ProcessFileService.saveEditFile(model)); } @ApiOperation(value = "根据传入的标准编号返回对应的在线编辑文件信息") @GetMapping("/findEditFileByStandardNo") public Result findEditFileByStandardNo(String standardNo) { - return Result.OK(ProcessFileService.findEditFileByStandardNo(standardNo)); + return Result.OK(MessageUtils.getMessage(ResultCommon.OK), ProcessFileService.findEditFileByStandardNo(standardNo)); } - @ApiOperation(value = "根据路径下载文件(罗马数字页码)") + @ApiOperation(value = "下载文件(罗马数字页码)") @GetMapping("/downLoadFileRoma") public void downLoadFileRoma(@RequestParam(name = "id") String fileId, HttpServletResponse response) { OSSFile file = ossFileService.getById(fileId); @@ -98,9 +100,7 @@ public class OnlyOfficeController { response.reset(); // 从文件服务器下载指定文件 - try (InputStream inputStream = ObsBootUtil.getOssFile(file.getUrl()); - OutputStream outputStream = response.getOutputStream() - ) { + try (InputStream inputStream = ObsBootUtil.getOssFile(file.getUrl())) { // 编码文件名 response.setCharacterEncoding(StandardCharsets.UTF_8.name()); response.setHeader("Content-Disposition", "attachment;filename=file.docx"); diff --git a/laws-modules/src/main/java/com/jero/modules/onlyoffice/service/impl/ProcessFileServiceImpl.java b/laws-modules/src/main/java/com/jero/modules/onlyoffice/service/impl/ProcessFileServiceImpl.java index 60c7d80a..a6f2c893 100644 --- a/laws-modules/src/main/java/com/jero/modules/onlyoffice/service/impl/ProcessFileServiceImpl.java +++ b/laws-modules/src/main/java/com/jero/modules/onlyoffice/service/impl/ProcessFileServiceImpl.java @@ -21,8 +21,11 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.io.File; import java.io.FileInputStream; -import java.io.IOException; -import java.util.*; +import java.net.URL; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; +import java.util.Map; import java.util.stream.Collectors; /** @@ -50,9 +53,10 @@ public class ProcessFileServiceImpl implements IProcessFileService { public String saveEditFile(String model) { OSSFile ossFile = new OSSFile(); try { - File file = new File("wordTemplate/DOCX.docx"); + URL fileUrl = getClass().getClassLoader().getResource("wordTemplate/DOCX.docx"); + File file = new File(fileUrl.getFile()); FileInputStream fileInputStream = new FileInputStream(file); - MultipartFile multipartFile = new MockMultipartFile("file", file.getName(), "application/octet-stream", fileInputStream); + MultipartFile multipartFile = new MockMultipartFile("file", model + ".docx", "application/octet-stream", fileInputStream); String savePath = CommonUtils.upload(multipartFile, "onlyoffice", uploadType); if (oConvertUtils.isNotEmpty(savePath)) { // 文件名 @@ -67,7 +71,7 @@ public class ProcessFileServiceImpl implements IProcessFileService { } catch (Exception e) { log.error(e.getMessage()); } - return ""; + return ossFile.getId(); } @Override @@ -118,18 +122,9 @@ public class ProcessFileServiceImpl implements IProcessFileService { Integer order2 = orderMap.get(file2.getStandardFileType()); return Integer.compare(order1, order2); }); - return fileList.get(0); - } - - public static MultipartFile convert(File file) { - try (FileInputStream input = new FileInputStream(file)) { - return new MockMultipartFile("file", - file.getName(), - "application/vnd.openxmlformats-officedocument.wordprocessingml.document", - input); - } catch (IOException e) { - // 处理异常 - } - return null; + OSSFile ossFile = fileList.get(0); + ossFile.setOnlId(UUIDUtils.randomUUID(10)); + ossFileService.updateById(ossFile); + return ossFile; } }