|
|
@@ -1,12 +1,8 @@
|
|
|
package com.doc.biz.controller;
|
|
|
|
|
|
-import com.doc.biz.domain.DocInfo;
|
|
|
-import com.doc.biz.domain.DocShare;
|
|
|
-import com.doc.biz.domain.EsDocInfo;
|
|
|
-import com.doc.biz.service.IDocInfoService;
|
|
|
-import com.doc.biz.service.IDocShareService;
|
|
|
-import com.doc.biz.service.IEsDocInfoService;
|
|
|
-import com.doc.biz.service.IMongoService;
|
|
|
+import com.doc.biz.domain.*;
|
|
|
+import com.doc.biz.service.*;
|
|
|
+import com.doc.biz.vo.DocInfoVO;
|
|
|
import com.doc.biz.vo.DocumentVO;
|
|
|
import com.doc.chat.domain.ChatMsg;
|
|
|
import com.doc.common.annotation.Log;
|
|
|
@@ -17,6 +13,7 @@ import com.doc.common.core.page.TableDataInfo;
|
|
|
import com.doc.common.enums.BusinessType;
|
|
|
import com.doc.common.utils.FileContentUtils;
|
|
|
import com.doc.common.utils.SecurityUtils;
|
|
|
+import com.doc.common.utils.bean.BeanUtils;
|
|
|
import com.doc.common.utils.poi.ExcelUtil;
|
|
|
import com.doc.system.service.ISysConfigService;
|
|
|
import io.swagger.annotations.*;
|
|
|
@@ -31,10 +28,7 @@ import org.yaml.snakeyaml.util.UriEncoder;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
|
|
|
/**
|
|
|
@@ -60,6 +54,8 @@ public class DocInfoController extends BaseController {
|
|
|
private IDocShareService shareService;
|
|
|
@Resource
|
|
|
private ISysConfigService configService;
|
|
|
+ @Resource
|
|
|
+ private IDocDirService dirService;
|
|
|
|
|
|
/**
|
|
|
* 文件上传
|
|
|
@@ -69,9 +65,7 @@ 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);
|
|
|
process(vo, spaceId, dirId);
|
|
|
@@ -90,9 +84,7 @@ public class DocInfoController extends BaseController {
|
|
|
*/
|
|
|
@ApiOperation("文件上传-多文件")
|
|
|
@PostMapping("/uploadFiles")
|
|
|
- public AjaxResult uploadFile(@ApiParam(value = "文件", required = true) @RequestPart(value = "files") List<MultipartFile> files,
|
|
|
- @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 = "files") List<MultipartFile> files, @ApiParam(value = "空间ID", required = true) @RequestParam Long spaceId, @ApiParam(value = "目录ID", required = true) @RequestParam Long dirId) {
|
|
|
try {
|
|
|
mongoService.uploadFiles(files).stream().forEach(vo -> {
|
|
|
process(vo, spaceId, dirId);
|
|
|
@@ -134,13 +126,14 @@ public class DocInfoController extends BaseController {
|
|
|
@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());
|
|
|
+ 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;" : "" + "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");
|
|
|
}
|
|
|
@@ -155,16 +148,7 @@ public class DocInfoController extends BaseController {
|
|
|
@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");
|
|
|
- }
|
|
|
+ return down(fileId, false);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -172,11 +156,7 @@ public class DocInfoController extends BaseController {
|
|
|
*/
|
|
|
@ApiOperation("文件移动")
|
|
|
@GetMapping("/move")
|
|
|
- @ApiImplicitParams({
|
|
|
- @ApiImplicitParam(name = "docId", value = "文件ID", required = true),
|
|
|
- @ApiImplicitParam(name = "spaceId", value = "空间ID"),
|
|
|
- @ApiImplicitParam(name = "dirId", value = "新目录ID", required = true)
|
|
|
- })
|
|
|
+ @ApiImplicitParams({@ApiImplicitParam(name = "docId", value = "文件ID", required = true), @ApiImplicitParam(name = "spaceId", value = "空间ID"), @ApiImplicitParam(name = "dirId", value = "新目录ID", required = true)})
|
|
|
public AjaxResult move(Long docId, Long dirId) {
|
|
|
DocInfo info = docInfoService.selectDocInfoByDocId(docId);
|
|
|
info.setDirId(dirId);
|
|
|
@@ -191,11 +171,7 @@ public class DocInfoController extends BaseController {
|
|
|
*/
|
|
|
@ApiOperation("文件复制")
|
|
|
@GetMapping("/copy")
|
|
|
- @ApiImplicitParams({
|
|
|
- @ApiImplicitParam(name = "docId", value = "文件ID", required = true),
|
|
|
- @ApiImplicitParam(name = "spaceId", value = "空间ID"),
|
|
|
- @ApiImplicitParam(name = "dirId", value = "新目录ID", required = true)
|
|
|
- })
|
|
|
+ @ApiImplicitParams({@ApiImplicitParam(name = "docId", value = "文件ID", required = true), @ApiImplicitParam(name = "spaceId", value = "空间ID"), @ApiImplicitParam(name = "dirId", value = "新目录ID", required = true)})
|
|
|
public AjaxResult copy(Long docId, Long spaceId, Long dirId) {
|
|
|
DocInfo info = docInfoService.selectDocInfoByDocId(docId);
|
|
|
info.setDocId(null);
|
|
|
@@ -221,16 +197,15 @@ public class DocInfoController extends BaseController {
|
|
|
@ApiOperation("文件分享添加人员")
|
|
|
@PostMapping("/share/{docId}")
|
|
|
public AjaxResult share(@ApiParam(value = "文件ID", required = true) @PathVariable(name = "docId") Long docId, @ApiParam(value = "分享人员", required = true) @RequestBody List<DocShare> shares) {
|
|
|
- DocInfo info = docInfoService.selectDocInfoByDocId(docId);
|
|
|
shareService.deleteDocShareByDocId(docId);
|
|
|
|
|
|
String content = configService.selectConfigByKey("msg.share.content");
|
|
|
- String finalContent = content.replace("{from}", SecurityUtils.getLoginUser().getUser().getNickName()).replace("{file}", info.getFileName());
|
|
|
shares.forEach(s -> {
|
|
|
s.setDocId(docId);
|
|
|
ChatMsg msg = new ChatMsg();
|
|
|
+ msg.setMsgType("1");
|
|
|
msg.setToId(s.getUserId());
|
|
|
- msg.setContent(finalContent);
|
|
|
+ msg.setContent(docId + "");
|
|
|
msg.setFromId(SecurityUtils.getUserId());
|
|
|
shareService.insertDocShare(s);
|
|
|
});
|
|
|
@@ -243,10 +218,7 @@ public class DocInfoController extends BaseController {
|
|
|
*/
|
|
|
@ApiOperation("文件重命名")
|
|
|
@GetMapping("/rename")
|
|
|
- @ApiImplicitParams({
|
|
|
- @ApiImplicitParam(name = "docId", value = "文件ID", required = true),
|
|
|
- @ApiImplicitParam(name = "name", value = "新文件名", required = true)
|
|
|
- })
|
|
|
+ @ApiImplicitParams({@ApiImplicitParam(name = "docId", value = "文件ID", required = true), @ApiImplicitParam(name = "name", value = "新文件名", required = true)})
|
|
|
public AjaxResult rename(Long docId, String name) {
|
|
|
DocInfo info = new DocInfo();
|
|
|
info.setDocId(docId);
|
|
|
@@ -272,6 +244,49 @@ public class DocInfoController extends BaseController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 文件搜索
|
|
|
+ */
|
|
|
+ @ApiOperation("文件搜索")
|
|
|
+ //@PreAuthorize("@ss.hasPermi('biz:info:list')")
|
|
|
+ @GetMapping("/search")
|
|
|
+ public TableDataInfo search(@ApiParam(value = "搜索关键字", required = true) @RequestParam String keyword) {
|
|
|
+ startPage();
|
|
|
+ Map<String, Object> temp = dirService.selectDirByUser(SecurityUtils.getUserId());
|
|
|
+ List<DocDir> dirList = (List<DocDir>) temp.get("dir");
|
|
|
+ List<DocSpace> spaceList = (List<DocSpace>) temp.get("space");
|
|
|
+ Map<Long, DocDir> dirMap = new HashMap<>(16);
|
|
|
+ Map<Long, DocSpace> spaceMap = new HashMap<>(16);
|
|
|
+ List<Long> dirIds = new ArrayList<>();
|
|
|
+ dirList.forEach(dir -> {
|
|
|
+ dirIds.add(dir.getDirId());
|
|
|
+ dirMap.put(dir.getDirId(), dir);
|
|
|
+ });
|
|
|
+
|
|
|
+ spaceList.forEach(space -> {
|
|
|
+ spaceMap.put(space.getSpaceId(), space);
|
|
|
+ });
|
|
|
+
|
|
|
+ Map<String, Object> map = new HashMap<>(4);
|
|
|
+ map.put("dirIds", dirIds);
|
|
|
+
|
|
|
+ DocInfo docInfo = new DocInfo();
|
|
|
+ docInfo.setFileName(keyword);
|
|
|
+ docInfo.setParams(map);
|
|
|
+ List<DocInfo> list = docInfoService.selectDocInfoList(docInfo);
|
|
|
+ List<DocInfoVO> result = new ArrayList<>();
|
|
|
+ list.forEach(info -> {
|
|
|
+ DocInfoVO vo = new DocInfoVO();
|
|
|
+ BeanUtils.copyProperties(info, vo);
|
|
|
+
|
|
|
+ vo.setDir(dirMap.get(vo.getDirId()));
|
|
|
+ vo.setSpace(spaceMap.get(vo.getSpaceId()));
|
|
|
+
|
|
|
+ result.add(vo);
|
|
|
+ });
|
|
|
+ return getDataTable(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 查询文件基本信息表列表
|
|
|
*/
|
|
|
@ApiOperation("根据目录ID查询文件列表")
|