|
@@ -1,29 +1,25 @@
|
|
|
package com.doc.biz.controller;
|
|
|
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
+import com.doc.biz.service.IDocRecentService;
|
|
|
import com.doc.biz.service.IMongoService;
|
|
|
import com.doc.biz.vo.DocumentVO;
|
|
|
import com.doc.common.core.controller.BaseController;
|
|
|
import com.doc.common.core.domain.AjaxResult;
|
|
|
+import com.doc.common.utils.SecurityUtils;
|
|
|
import com.doc.system.service.ISysConfigService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.http.HttpHeaders;
|
|
|
-import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
-import org.yaml.snakeyaml.util.UriEncoder;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
-import java.io.OutputStream;
|
|
|
import java.nio.file.Files;
|
|
|
import java.util.HashMap;
|
|
|
-import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* 文件上传
|
|
@@ -44,62 +40,22 @@ public class ApiController extends BaseController {
|
|
|
private IMongoService mongoService;
|
|
|
@Resource
|
|
|
private ISysConfigService configService;
|
|
|
+ @Resource
|
|
|
+ private IDocRecentService recentService;
|
|
|
+
|
|
|
|
|
|
-// /**
|
|
|
-// * 文件下载
|
|
|
-// *
|
|
|
-// * @param fileId fileId
|
|
|
-// * @return
|
|
|
-// */
|
|
|
-// @ApiOperation("文件预览")
|
|
|
-// @GetMapping("/access/{fileId}")
|
|
|
-// public ResponseEntity<Object> access(@PathVariable(name = "fileId") String fileId) {
|
|
|
-// return down(fileId, false);
|
|
|
-// }
|
|
|
-//
|
|
|
-// /**
|
|
|
-// * 文件下载
|
|
|
-// *
|
|
|
-// * @param fileId fileId
|
|
|
-// * @return
|
|
|
-// */
|
|
|
-// @ApiOperation("文件下载")
|
|
|
-// @GetMapping("/download/{fileId}")
|
|
|
-// public ResponseEntity<Object> download(@PathVariable(name = "fileId") String fileId) {
|
|
|
-// return down(fileId, true);
|
|
|
-// }
|
|
|
-//
|
|
|
-// private ResponseEntity<Object> down(String fileId, boolean down) {
|
|
|
-// DocumentVO vo = mongoService.downloadFile(fileId);
|
|
|
-// if (Objects.nonNull(vo)) {
|
|
|
-// String disposition = down ? "attachment" : "inline";
|
|
|
-// disposition += "; filename=\"" + UriEncoder.encode(vo.getFileName()) + "\"";
|
|
|
-// return ResponseEntity.ok()
|
|
|
-// .header(HttpHeaders.CONTENT_DISPOSITION, disposition)
|
|
|
-// .header(HttpHeaders.CONTENT_TYPE, vo.getContentType())
|
|
|
-// .header(HttpHeaders.CONTENT_LENGTH, vo.getFileSize() + "")
|
|
|
-// .header("Connection", "close")
|
|
|
-// .body(vo.getData());
|
|
|
-// } else {
|
|
|
-// return ResponseEntity.status(HttpStatus.NOT_FOUND).body("file does not exist");
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// @ApiOperation("文件下载")
|
|
|
-// @GetMapping("/down/{fileId}")
|
|
|
-// public void download(@PathVariable(name = "fileId") String fileId, HttpServletResponse response) {
|
|
|
-// DocumentVO vo = mongoService.downloadFile(fileId);
|
|
|
-// response.setContentType(vo.getContentType());
|
|
|
-// response.setHeader("Content-Disposition", "attachment; filename=\"" + UriEncoder.encode(vo.getFileName()) + "\"");
|
|
|
-// response.addHeader("Content-Length", "" + vo.getFileSize());
|
|
|
-//
|
|
|
-// try (OutputStream stream = response.getOutputStream()) {
|
|
|
-// stream.write(vo.getData());
|
|
|
-// stream.flush();
|
|
|
-// } catch (IOException e) {
|
|
|
-// throw new RuntimeException(e);
|
|
|
-// }
|
|
|
-// }
|
|
|
+ /**
|
|
|
+ * 文件下载
|
|
|
+ *
|
|
|
+ * @param fileId fileId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation("文件预览")
|
|
|
+ @GetMapping("/access/{fileId}")
|
|
|
+ public ResponseEntity<Object> access(@PathVariable(name = "fileId") String fileId, @RequestParam Long uid) {
|
|
|
+ recentService.insertDocRecent(uid, fileId);
|
|
|
+ return mongoService.download(fileId, false);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 文字识别
|