feat: 在线编辑文件相关
This commit is contained in:
+7
-7
@@ -3,6 +3,8 @@ package com.jero.modules.onlyoffice.controller;
|
|||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.jero.common.api.vo.Result;
|
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.common.util.obs.ObsBootUtil;
|
||||||
import com.jero.modules.onlyoffice.entity.ProcessFile;
|
import com.jero.modules.onlyoffice.entity.ProcessFile;
|
||||||
import com.jero.modules.onlyoffice.service.IProcessFileService;
|
import com.jero.modules.onlyoffice.service.IProcessFileService;
|
||||||
@@ -75,19 +77,19 @@ public class OnlyOfficeController {
|
|||||||
return ProcessFileService.processEditFile(id);
|
return ProcessFileService.processEditFile(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "|model| 传入 模板文档名称(不带后缀)默认 docx")
|
@ApiOperation(value = "模板文档名称(不带后缀)默认 docx")
|
||||||
@GetMapping("/saveEditFile")
|
@GetMapping("/saveEditFile")
|
||||||
public Result<String> saveEditFile(String model) {
|
public Result<String> saveEditFile(String model) {
|
||||||
return Result.OK(ProcessFileService.saveEditFile(model));
|
return Result.OK(MessageUtils.getMessage(ResultCommon.OK), ProcessFileService.saveEditFile(model));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "根据传入的标准编号返回对应的在线编辑文件信息")
|
@ApiOperation(value = "根据传入的标准编号返回对应的在线编辑文件信息")
|
||||||
@GetMapping("/findEditFileByStandardNo")
|
@GetMapping("/findEditFileByStandardNo")
|
||||||
public Result<String> findEditFileByStandardNo(String standardNo) {
|
public Result<String> 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")
|
@GetMapping("/downLoadFileRoma")
|
||||||
public void downLoadFileRoma(@RequestParam(name = "id") String fileId, HttpServletResponse response) {
|
public void downLoadFileRoma(@RequestParam(name = "id") String fileId, HttpServletResponse response) {
|
||||||
OSSFile file = ossFileService.getById(fileId);
|
OSSFile file = ossFileService.getById(fileId);
|
||||||
@@ -98,9 +100,7 @@ public class OnlyOfficeController {
|
|||||||
response.reset();
|
response.reset();
|
||||||
|
|
||||||
// 从文件服务器下载指定文件
|
// 从文件服务器下载指定文件
|
||||||
try (InputStream inputStream = ObsBootUtil.getOssFile(file.getUrl());
|
try (InputStream inputStream = ObsBootUtil.getOssFile(file.getUrl())) {
|
||||||
OutputStream outputStream = response.getOutputStream()
|
|
||||||
) {
|
|
||||||
// 编码文件名
|
// 编码文件名
|
||||||
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
||||||
response.setHeader("Content-Disposition", "attachment;filename=file.docx");
|
response.setHeader("Content-Disposition", "attachment;filename=file.docx");
|
||||||
|
|||||||
+13
-18
@@ -21,8 +21,11 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.net.URL;
|
||||||
import java.util.*;
|
import java.util.Arrays;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,9 +53,10 @@ public class ProcessFileServiceImpl implements IProcessFileService {
|
|||||||
public String saveEditFile(String model) {
|
public String saveEditFile(String model) {
|
||||||
OSSFile ossFile = new OSSFile();
|
OSSFile ossFile = new OSSFile();
|
||||||
try {
|
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);
|
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);
|
String savePath = CommonUtils.upload(multipartFile, "onlyoffice", uploadType);
|
||||||
if (oConvertUtils.isNotEmpty(savePath)) {
|
if (oConvertUtils.isNotEmpty(savePath)) {
|
||||||
// 文件名
|
// 文件名
|
||||||
@@ -67,7 +71,7 @@ public class ProcessFileServiceImpl implements IProcessFileService {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
}
|
}
|
||||||
return "";
|
return ossFile.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -118,18 +122,9 @@ public class ProcessFileServiceImpl implements IProcessFileService {
|
|||||||
Integer order2 = orderMap.get(file2.getStandardFileType());
|
Integer order2 = orderMap.get(file2.getStandardFileType());
|
||||||
return Integer.compare(order1, order2);
|
return Integer.compare(order1, order2);
|
||||||
});
|
});
|
||||||
return fileList.get(0);
|
OSSFile ossFile = fileList.get(0);
|
||||||
}
|
ossFile.setOnlId(UUIDUtils.randomUUID(10));
|
||||||
|
ossFileService.updateById(ossFile);
|
||||||
public static MultipartFile convert(File file) {
|
return ossFile;
|
||||||
try (FileInputStream input = new FileInputStream(file)) {
|
|
||||||
return new MockMultipartFile("file",
|
|
||||||
file.getName(),
|
|
||||||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
||||||
input);
|
|
||||||
} catch (IOException e) {
|
|
||||||
// 处理异常
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user