|
@@ -15,12 +15,17 @@ import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
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.util.List;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* 文件基本信息表Controller
|
|
@@ -46,9 +51,9 @@ public class DocInfoController extends BaseController {
|
|
|
*/
|
|
|
@ApiOperation("上传文件")
|
|
|
@PostMapping("/upload")
|
|
|
- public AjaxResult uploadFile(@ApiParam(value = "文件", required = true) @RequestPart(value = "file") MultipartFile file,
|
|
|
- @ApiParam(value = "空间ID", required = true) @RequestParam Long spaceId,
|
|
|
- @ApiParam(value = "目录ID", required = true) @RequestParam Long dirId) {
|
|
|
+ public AjaxResult uploadFile(@ApiParam(value = "文件" , required = true) @RequestPart(value = "file") MultipartFile file,
|
|
|
+ @ApiParam(value = "空间ID" , required = true) @RequestParam Long spaceId,
|
|
|
+ @ApiParam(value = "目录ID" , required = true) @RequestParam Long dirId) {
|
|
|
try {
|
|
|
DocumentVO vo = mongoService.uploadFile(file);
|
|
|
DocInfo docInfo = new DocInfo();
|
|
@@ -61,7 +66,7 @@ public class DocInfoController extends BaseController {
|
|
|
docInfo.setCreateBy(SecurityUtils.getUsername());
|
|
|
return toAjax(docInfoService.insertDocInfo(docInfo));
|
|
|
} catch (Exception e) {
|
|
|
- log.error("文件上传失败:", e);
|
|
|
+ log.error("文件上传失败:" , e);
|
|
|
return error(e.getMessage());
|
|
|
}
|
|
|
}
|
|
@@ -82,6 +87,48 @@ public class DocInfoController extends BaseController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 文件下载
|
|
|
+ *
|
|
|
+ * @param fileId fileId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation("文件下载")
|
|
|
+ @GetMapping("/download/{fileId}")
|
|
|
+ public ResponseEntity<Object> download(@PathVariable(name = "fileId") String fileId) {
|
|
|
+ DocumentVO mongoFileVo = mongoService.downloadFile(fileId);
|
|
|
+ if (Objects.nonNull(mongoFileVo)) {
|
|
|
+ return ResponseEntity.ok()
|
|
|
+ .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=\"" + UriEncoder.encode(mongoFileVo.getFileName()) + "\"")
|
|
|
+ .header(HttpHeaders.CONTENT_TYPE, mongoFileVo.getContentType())
|
|
|
+ .header(HttpHeaders.CONTENT_LENGTH, mongoFileVo.getFileSize() + "").header("Connection" , "close")
|
|
|
+ .body(mongoFileVo.getData());
|
|
|
+ } else {
|
|
|
+ return ResponseEntity.status(HttpStatus.NOT_FOUND).body("file does not exist");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 文件下载
|
|
|
+ *
|
|
|
+ * @param fileId fileId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation("文件预览")
|
|
|
+ @GetMapping("/preview/{fileId}")
|
|
|
+ public ResponseEntity<Object> preview(@PathVariable(name = "fileId") String fileId) {
|
|
|
+ DocumentVO mongoFileVo = mongoService.downloadFile(fileId);
|
|
|
+ if (Objects.nonNull(mongoFileVo)) {
|
|
|
+ return ResponseEntity.ok()
|
|
|
+ .header(HttpHeaders.CONTENT_DISPOSITION, "filename=\"" + UriEncoder.encode(mongoFileVo.getFileName()) + "\"")
|
|
|
+ .header(HttpHeaders.CONTENT_TYPE, mongoFileVo.getContentType())
|
|
|
+ .header(HttpHeaders.CONTENT_LENGTH, mongoFileVo.getFileSize() + "").header("Connection" , "close")
|
|
|
+ .body(mongoFileVo.getData());
|
|
|
+ } else {
|
|
|
+ return ResponseEntity.status(HttpStatus.NOT_FOUND).body("file does not exist");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 查询文件基本信息表列表
|
|
|
*/
|
|
|
@ApiOperation("查询文件基本信息表列表")
|
|
@@ -98,7 +145,7 @@ public class DocInfoController extends BaseController {
|
|
|
*/
|
|
|
@ApiOperation("导出文件基本信息表列表")
|
|
|
//@PreAuthorize("@ss.hasPermi('biz:info:export')")
|
|
|
- @Log(title = "文件基本信息表", businessType = BusinessType.EXPORT)
|
|
|
+ @Log(title = "文件基本信息表" , businessType = BusinessType.EXPORT)
|
|
|
@PostMapping("/export")
|
|
|
public void export(HttpServletResponse response, DocInfo docInfo) {
|
|
|
List<DocInfo> list = docInfoService.selectDocInfoList(docInfo);
|
|
@@ -121,7 +168,7 @@ public class DocInfoController extends BaseController {
|
|
|
*/
|
|
|
@ApiOperation("新增文件基本信息表")
|
|
|
//@PreAuthorize("@ss.hasPermi('biz:info:add')")
|
|
|
- @Log(title = "文件基本信息表", businessType = BusinessType.INSERT)
|
|
|
+ @Log(title = "文件基本信息表" , businessType = BusinessType.INSERT)
|
|
|
@PostMapping
|
|
|
public AjaxResult add(@RequestBody DocInfo docInfo) {
|
|
|
return toAjax(docInfoService.insertDocInfo(docInfo));
|
|
@@ -132,7 +179,7 @@ public class DocInfoController extends BaseController {
|
|
|
*/
|
|
|
@ApiOperation("修改文件基本信息表")
|
|
|
//@PreAuthorize("@ss.hasPermi('biz:info:edit')")
|
|
|
- @Log(title = "文件基本信息表", businessType = BusinessType.UPDATE)
|
|
|
+ @Log(title = "文件基本信息表" , businessType = BusinessType.UPDATE)
|
|
|
@PutMapping
|
|
|
public AjaxResult edit(@RequestBody DocInfo docInfo) {
|
|
|
docInfo.setUpdateBy(SecurityUtils.getUsername());
|
|
@@ -144,7 +191,7 @@ public class DocInfoController extends BaseController {
|
|
|
*/
|
|
|
@ApiOperation("删除文件基本信息表")
|
|
|
//@PreAuthorize("@ss.hasPermi('biz:info:remove')")
|
|
|
- @Log(title = "文件基本信息表", businessType = BusinessType.DELETE)
|
|
|
+ @Log(title = "文件基本信息表" , businessType = BusinessType.DELETE)
|
|
|
@DeleteMapping("/{docIds}")
|
|
|
public AjaxResult remove(@PathVariable Long[] docIds) {
|
|
|
for (Long docId : docIds) {
|