feat: 在线编辑下载文件罗马页码接口
This commit is contained in:
+64
@@ -18,8 +18,14 @@ import com.jero.modules.onlyoffice.service.IBusProcessModelHisService;
|
||||
import com.jero.modules.onlyoffice.service.LawsUserInfoService;
|
||||
import com.jero.modules.oss.entity.OSSFile;
|
||||
import com.jero.modules.oss.service.IOSSFileService;
|
||||
import com.sini.com.spire.doc.Document;
|
||||
import com.sini.com.spire.doc.collections.SectionCollection;
|
||||
import com.sini.com.spire.doc.documents.PageNumberStyle;
|
||||
import com.sini.com.spire.doc.documents.PageOrientation;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -34,6 +40,9 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
@@ -45,6 +54,7 @@ import java.util.*;
|
||||
@Api(tags = "onlyOffice操作")
|
||||
@RestController
|
||||
@RequestMapping("/onlyOffice")
|
||||
@Slf4j
|
||||
public class OnlyOfficeController {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(OnlyOfficeController.class);
|
||||
@@ -72,6 +82,9 @@ public class OnlyOfficeController {
|
||||
@Value(value = "${jero.fileSuffixLimits}")
|
||||
private String[] fileSuffixLimits;
|
||||
|
||||
@Value("${file.path}")
|
||||
private String filePath;//文件存储路径
|
||||
|
||||
@ApiOperation(value = "分页查询")
|
||||
@GetMapping("/pageList")
|
||||
public Result<IPage<BusProcessModelHis>> pageList(HttpServletRequest req, BusProcessModelHis processModelHis,
|
||||
@@ -338,6 +351,57 @@ public class OnlyOfficeController {
|
||||
busProcessModelHisService.downLoadFile(path, response);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据路径下载文件(罗马数字页码)")
|
||||
@GetMapping("/downLoadFileRoma")
|
||||
public void downLoadFileRoma(@RequestParam(name = "path") String path, HttpServletResponse response) {
|
||||
InputStream is = null;
|
||||
OutputStream os = null;
|
||||
response.reset();
|
||||
try {
|
||||
// 编码文件名
|
||||
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
||||
response.setHeader("Content-Disposition", "attachment;filename=file.docx");
|
||||
response.setContentType("application/octet-stream");
|
||||
|
||||
// 加载文档
|
||||
Document doc = new Document(filePath + path);
|
||||
doc.getSections().get(0).getPageSetup().setPageNumberStyle(PageNumberStyle.Roman_Upper);
|
||||
doc.getSections().get(0).getPageSetup().setOrientation(PageOrientation.Portrait);//纵向
|
||||
doc.getSections().get(1).getPageSetup().setPageNumberStyle(PageNumberStyle.Roman_Upper);
|
||||
doc.getSections().get(1).getPageSetup().setOrientation(PageOrientation.Portrait);//纵向
|
||||
|
||||
String downloadDocxFileTempUrl = filePath + "/downloadDocxFileTemp";
|
||||
File downloadDocxFileTempUrlFile = new File(downloadDocxFileTempUrl);
|
||||
|
||||
if (!downloadDocxFileTempUrlFile.exists()) {
|
||||
downloadDocxFileTempUrlFile.mkdirs();
|
||||
}
|
||||
String newFileName = UUID.randomUUID().toString().replace("-", "") + ".docx";
|
||||
String newFileUrl = downloadDocxFileTempUrl + "/" + newFileName;
|
||||
|
||||
//保存文档
|
||||
doc.saveToFile(newFileUrl);
|
||||
|
||||
File newFile = new File(newFileUrl);
|
||||
is = Files.newInputStream(newFile.toPath());
|
||||
os = response.getOutputStream();
|
||||
IOUtils.copy(is, os);
|
||||
os.flush();
|
||||
|
||||
is.close();
|
||||
if (newFile.delete()) {
|
||||
logger.info("在线编辑下载-临时文件删除成功: " + newFileUrl);
|
||||
} else {
|
||||
logger.info("在线编辑下载-临时文件删除失败: " + newFileUrl);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(is);
|
||||
IOUtils.closeQuietly(os);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/processModelHisOneUpdStatus")
|
||||
public BusProcessModelHis modelHisOneUpdStatus(String pid, String taskId) {
|
||||
return busProcessModelHisService.modelHisOneUpdStatus(pid, taskId);
|
||||
|
||||
Reference in New Issue
Block a user