|
@@ -2,9 +2,6 @@ package com.ims.eval.controller;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import com.documents4j.api.DocumentType;
|
|
|
-import com.documents4j.api.IConverter;
|
|
|
-import com.documents4j.job.LocalConverter;
|
|
|
import com.ims.common.utils.StringUtils;
|
|
|
import com.ims.eval.config.CustomException;
|
|
|
import com.ims.eval.entity.DataDictionary;
|
|
@@ -15,20 +12,12 @@ import com.ims.eval.service.IDataDictionaryService;
|
|
|
import com.ims.eval.service.IEvaluationNoticeService;
|
|
|
import com.ims.eval.util.FileUploadUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.io.FileUtils;
|
|
|
-import org.apache.commons.io.FilenameUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.core.io.ByteArrayResource;
|
|
|
-import org.springframework.core.io.Resource;
|
|
|
-import org.springframework.http.HttpHeaders;
|
|
|
-import org.springframework.http.MediaType;
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.*;
|
|
|
-import java.net.URL;
|
|
|
-import java.nio.file.Files;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
@@ -262,23 +251,25 @@ public class NoticeManagementController {
|
|
|
* @throws IOException 异常
|
|
|
*/
|
|
|
@GetMapping(value = "/filePreview")
|
|
|
- public ResponseEntity<Resource> convertToHtml(@RequestParam("url") String url) throws IOException {
|
|
|
- url = Path.getNoticePath() + url;
|
|
|
- InputStream inputStream = new URL(url).openStream();
|
|
|
- File sourceFile = File.createTempFile("source", ".docx");
|
|
|
- FileUtils.copyInputStreamToFile(inputStream, sourceFile);
|
|
|
- File htmlFile = new File(sourceFile.getParent(), FilenameUtils.getBaseName(sourceFile.getName()) + ".html");
|
|
|
- try (InputStream fis = new FileInputStream(sourceFile); OutputStream fos = new FileOutputStream(htmlFile)) {
|
|
|
- IConverter converter = LocalConverter.builder().build();
|
|
|
- converter.convert(fis).as(DocumentType.MS_WORD).to(fos).as(DocumentType.MHTML).execute();
|
|
|
- } catch (IOException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
+ public void convertToHtml(@RequestParam("url") String url, HttpServletResponse response) throws IOException {
|
|
|
+ String prefix = url.substring(0, url.lastIndexOf(".") - 1);
|
|
|
+ String suffix = ".pdf";
|
|
|
+ String filePath = Path.getNoticePath() + prefix + suffix;
|
|
|
+ boolean b = false;
|
|
|
+ if (b) {
|
|
|
+ File file = new File(filePath);
|
|
|
+ BufferedInputStream br = new BufferedInputStream(new FileInputStream(file));
|
|
|
+ byte[] buf = new byte[1024];
|
|
|
+ int len = 0;
|
|
|
+ response.reset();
|
|
|
+ response.setContentType("application/pdf");
|
|
|
+ response.setHeader("Content-Disposition", "inline; filename=" + java.net.URLEncoder.encode(file.getName(), "UTF-8"));
|
|
|
+ OutputStream out = response.getOutputStream();
|
|
|
+ while ((len = br.read(buf)) > 0) {
|
|
|
+ out.write(buf, 0, len);
|
|
|
+ }
|
|
|
+ br.close();
|
|
|
+ out.close();
|
|
|
}
|
|
|
- ByteArrayResource resource = new ByteArrayResource(Files.readAllBytes(htmlFile.toPath()));
|
|
|
- return ResponseEntity.ok()
|
|
|
- .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + htmlFile.getName())
|
|
|
- .contentType(MediaType.TEXT_HTML)
|
|
|
- .contentLength(htmlFile.length())
|
|
|
- .body(resource);
|
|
|
}
|
|
|
}
|