|
|
@@ -6,8 +6,6 @@ import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
|
import co.elastic.clients.elasticsearch.core.SearchResponse;
|
|
|
import co.elastic.clients.elasticsearch.core.search.HighlighterEncoder;
|
|
|
import co.elastic.clients.elasticsearch.core.search.Hit;
|
|
|
-import com.alibaba.fastjson2.JSON;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
@@ -15,11 +13,10 @@ import com.qiwenshare.common.anno.MyLog;
|
|
|
import com.qiwenshare.common.exception.QiwenException;
|
|
|
import com.qiwenshare.common.result.RestResult;
|
|
|
import com.qiwenshare.common.util.DateUtil;
|
|
|
-import com.qiwenshare.common.util.security.JwtUser;
|
|
|
import com.qiwenshare.common.util.security.SessionUtil;
|
|
|
import vip.xiaonuo.auth.core.util.StpLoginUserUtil;
|
|
|
-import vip.xiaonuo.disk.api.IFileService;
|
|
|
-import vip.xiaonuo.disk.api.IUserFileService;
|
|
|
+import vip.xiaonuo.disk.service.IFileService;
|
|
|
+import vip.xiaonuo.disk.service.IUserFileService;
|
|
|
import vip.xiaonuo.disk.component.AsyncTaskComp;
|
|
|
import vip.xiaonuo.disk.component.FileDealComp;
|
|
|
import vip.xiaonuo.disk.config.es.FileSearch;
|
|
|
@@ -39,8 +36,6 @@ import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.codec.digest.DigestUtils;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
import org.eclipse.jetty.util.StringUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
@@ -57,8 +52,6 @@ import java.util.*;
|
|
|
import java.util.concurrent.Executor;
|
|
|
import java.util.concurrent.Executors;
|
|
|
import java.util.regex.Pattern;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-import java.util.stream.Stream;
|
|
|
|
|
|
@Tag(name = "file", description = "该接口为文件接口,主要用来做一些文件的基本操作,如创建目录,删除,移动,复制等。")
|
|
|
@RestController
|
|
|
@@ -81,6 +74,9 @@ public class FileController {
|
|
|
@Value("${ufop.storage-type}")
|
|
|
private Integer storageType;
|
|
|
|
|
|
+ @Value("${common.account}")
|
|
|
+ private String commonUserId;
|
|
|
+
|
|
|
public static Executor executor = Executors.newFixedThreadPool(20);
|
|
|
|
|
|
public static final String CURRENT_MODULE = "文件接口";
|
|
|
@@ -154,6 +150,85 @@ public class FileController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Operation(summary = "创建文件", description = "创建文件", tags = {"file"})
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping(value = "/createCommonFile", method = RequestMethod.POST)
|
|
|
+ public RestResult<Object> createCommonFile(@Valid @RequestBody CreateFileDTO createFileDTO) {
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ String userId = commonUserId;
|
|
|
+ String filePath = createFileDTO.getFilePath();
|
|
|
+ String fileName = createFileDTO.getFileName();
|
|
|
+ String extendName = createFileDTO.getExtendName();
|
|
|
+ List<UserFile> userFiles = userFileService.selectSameUserFile(fileName, filePath, extendName, userId);
|
|
|
+ if (userFiles != null && !userFiles.isEmpty()) {
|
|
|
+ return RestResult.fail().message("同名文件已存在");
|
|
|
+ }
|
|
|
+ String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
+
|
|
|
+ String templateFilePath = "";
|
|
|
+ if ("docx".equals(extendName)) {
|
|
|
+ templateFilePath = "template/Word.docx";
|
|
|
+ } else if ("xlsx".equals(extendName)) {
|
|
|
+ templateFilePath = "template/Excel.xlsx";
|
|
|
+ } else if ("pptx".equals(extendName)) {
|
|
|
+ templateFilePath = "template/PowerPoint.pptx";
|
|
|
+ } else if ("txt".equals(extendName)) {
|
|
|
+ templateFilePath = "template/Text.txt";
|
|
|
+ } else if ("drawio".equals(extendName)) {
|
|
|
+ templateFilePath = "template/Drawio.drawio";
|
|
|
+ }
|
|
|
+ String url2 = ClassUtils.getDefaultClassLoader().getResource("static/" + templateFilePath).getPath();
|
|
|
+ url2 = URLDecoder.decode(url2, "UTF-8");
|
|
|
+ FileInputStream fileInputStream = new FileInputStream(url2);
|
|
|
+ Copier copier = ufopFactory.getCopier();
|
|
|
+ CopyFile copyFile = new CopyFile();
|
|
|
+ copyFile.setExtendName(extendName);
|
|
|
+ String fileUrl = copier.copy(fileInputStream, copyFile);
|
|
|
+
|
|
|
+ FileBean fileBean = new FileBean();
|
|
|
+ fileBean.setFileId(IdUtil.getSnowflakeNextIdStr());
|
|
|
+ fileBean.setFileSize(0L);
|
|
|
+ fileBean.setFileUrl(fileUrl);
|
|
|
+ fileBean.setStorageType(storageType);
|
|
|
+ fileBean.setIdentifier(uuid);
|
|
|
+ fileBean.setCreateTime(DateUtil.getCurrentTime());
|
|
|
+ fileBean.setCreateUserId(StpLoginUserUtil.getLoginUser().getId());
|
|
|
+ fileBean.setFileStatus(1);
|
|
|
+ boolean saveFlag = fileService.save(fileBean);
|
|
|
+ UserFile userFile = new UserFile();
|
|
|
+ if (saveFlag) {
|
|
|
+ userFile.setUserFileId(IdUtil.getSnowflakeNextIdStr());
|
|
|
+ userFile.setUserId(userId);
|
|
|
+ userFile.setFileName(fileName);
|
|
|
+ userFile.setFilePath(filePath);
|
|
|
+ userFile.setDeleteFlag(0);
|
|
|
+ userFile.setIsDir(0);
|
|
|
+ userFile.setExtendName(extendName);
|
|
|
+ userFile.setUploadTime(DateUtil.getCurrentTime());
|
|
|
+ userFile.setFileId(fileBean.getFileId());
|
|
|
+ userFile.setCreateTime(DateUtil.getCurrentTime());
|
|
|
+ userFile.setCreateUserId(SessionUtil.getUserId());
|
|
|
+ userFileService.save(userFile);
|
|
|
+ }
|
|
|
+ return RestResult.success().message("文件创建成功");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ return RestResult.fail().message(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Operation(summary = "创建文件夹", description = "目录(文件夹)的创建", tags = {"file"})
|
|
|
@RequestMapping(value = "/createFold", method = RequestMethod.POST)
|
|
|
@MyLog(operation = "创建文件夹", module = CURRENT_MODULE)
|
|
|
@@ -178,6 +253,38 @@ public class FileController {
|
|
|
return RestResult.success();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ @Operation(summary = "创建文件夹", description = "目录(文件夹)的创建", tags = {"file"})
|
|
|
+ @RequestMapping(value = "/createCommonFold", method = RequestMethod.POST)
|
|
|
+ @MyLog(operation = "创建文件夹", module = CURRENT_MODULE)
|
|
|
+ @ResponseBody
|
|
|
+ public RestResult<String> createCommonFold(@Valid @RequestBody CreateFoldDTO createFoldDto) {
|
|
|
+
|
|
|
+// String userId = SessionUtil.getSession().getUserId();
|
|
|
+ String userId = commonUserId;
|
|
|
+ String filePath = createFoldDto.getFilePath();
|
|
|
+
|
|
|
+
|
|
|
+ boolean isDirExist = fileDealComp.isDirExist(createFoldDto.getFileName(), createFoldDto.getFilePath(), userId);
|
|
|
+
|
|
|
+ if (isDirExist) {
|
|
|
+ return RestResult.fail().message("同名文件夹已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ UserFile userFile = QiwenFileUtil.getQiwenDir(userId, filePath, createFoldDto.getFileName());
|
|
|
+
|
|
|
+ userFileService.save(userFile);
|
|
|
+ fileDealComp.uploadESByUserFileId(userFile.getUserFileId());
|
|
|
+ return RestResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Operation(summary = "文件搜索", description = "文件搜索", tags = {"file"})
|
|
|
@GetMapping(value = "/search")
|
|
|
@MyLog(operation = "文件搜索", module = CURRENT_MODULE)
|
|
|
@@ -243,6 +350,79 @@ public class FileController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Operation(summary = "文件搜索", description = "文件搜索", tags = {"file"})
|
|
|
+ @GetMapping(value = "/searchCommon")
|
|
|
+ @MyLog(operation = "文件搜索", module = CURRENT_MODULE)
|
|
|
+ @ResponseBody
|
|
|
+ public RestResult<SearchFileVO> searchCommon(SearchFileDTO searchFileDTO) {
|
|
|
+ String userId = commonUserId;
|
|
|
+
|
|
|
+ int currentPage = (int)searchFileDTO.getCurrentPage() - 1;
|
|
|
+ int pageCount = (int)(searchFileDTO.getPageCount() == 0 ? 10 : searchFileDTO.getPageCount());
|
|
|
+
|
|
|
+ SearchResponse<FileSearch> search = null;
|
|
|
+ try {
|
|
|
+ search = elasticsearchClient.search(s -> s
|
|
|
+ .index("filesearch")
|
|
|
+ .query(_1 -> _1
|
|
|
+ .bool(_2 -> _2
|
|
|
+ .must(_3 -> _3
|
|
|
+ .bool(_4 -> _4
|
|
|
+ .should(_5 -> _5
|
|
|
+ .match(_6 -> _6
|
|
|
+ .field("fileName")
|
|
|
+ .query(searchFileDTO.getFileName())))
|
|
|
+ .should(_5 -> _5
|
|
|
+ .wildcard(_6 -> _6
|
|
|
+ .field("fileName")
|
|
|
+ .wildcard("*" + searchFileDTO.getFileName() + "*")))
|
|
|
+ .should(_5 -> _5
|
|
|
+ .match(_6 -> _6
|
|
|
+ .field("content")
|
|
|
+ .query(searchFileDTO.getFileName())))
|
|
|
+ .should(_5 -> _5
|
|
|
+ .wildcard(_6 -> _6
|
|
|
+ .field("content")
|
|
|
+ .wildcard("*" + searchFileDTO.getFileName() + "*")))
|
|
|
+ ))
|
|
|
+ .must(_3 -> _3
|
|
|
+ .term(_4 -> _4
|
|
|
+ .field("userId")
|
|
|
+ .value(userId)))
|
|
|
+ ))
|
|
|
+ .from(currentPage)
|
|
|
+ .size(pageCount)
|
|
|
+ .highlight(h -> h
|
|
|
+ .fields("fileName", f -> f.type("plain")
|
|
|
+ .preTags("<span class='keyword'>").postTags("</span>"))
|
|
|
+ .encoder(HighlighterEncoder.Html))
|
|
|
+ ,
|
|
|
+ FileSearch.class);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<SearchFileVO> searchFileVOList = new ArrayList<>();
|
|
|
+ for (Hit<FileSearch> hit : search.hits().hits()) {
|
|
|
+ SearchFileVO searchFileVO = new SearchFileVO();
|
|
|
+ BeanUtil.copyProperties(hit.source(), searchFileVO);
|
|
|
+ searchFileVO.setHighLight(hit.highlight());
|
|
|
+ searchFileVOList.add(searchFileVO);
|
|
|
+ asyncTaskComp.checkESUserFileId(searchFileVO.getUserFileId());
|
|
|
+ }
|
|
|
+ return RestResult.success().dataList(searchFileVOList, searchFileVOList.size());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Operation(summary = "文件重命名", description = "文件重命名", tags = {"file"})
|
|
|
@RequestMapping(value = "/renamefile", method = RequestMethod.POST)
|
|
|
@MyLog(operation = "文件重命名", module = CURRENT_MODULE)
|
|
|
@@ -277,6 +457,51 @@ public class FileController {
|
|
|
return RestResult.success();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Operation(summary = "文件重命名", description = "文件重命名", tags = {"file"})
|
|
|
+ @RequestMapping(value = "/renameCommonfile", method = RequestMethod.POST)
|
|
|
+ @MyLog(operation = "文件重命名", module = CURRENT_MODULE)
|
|
|
+ @ResponseBody
|
|
|
+ public RestResult<String> renameCommonfile(@RequestBody RenameFileDTO renameFileDto) {
|
|
|
+
|
|
|
+ String userId =commonUserId;
|
|
|
+ UserFile userFile = userFileService.getById(renameFileDto.getUserFileId());
|
|
|
+
|
|
|
+ List<UserFile> userFiles = userFileService.selectUserFileByNameAndPath(renameFileDto.getFileName(), userFile.getFilePath(), userId);
|
|
|
+ if (userFiles != null && !userFiles.isEmpty()) {
|
|
|
+ return RestResult.fail().message("同名文件已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ LambdaUpdateWrapper<UserFile> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ lambdaUpdateWrapper.set(UserFile::getFileName, renameFileDto.getFileName())
|
|
|
+ .set(UserFile::getUploadTime, DateUtil.getCurrentTime())
|
|
|
+ .eq(UserFile::getUserFileId, renameFileDto.getUserFileId());
|
|
|
+ userFileService.update(lambdaUpdateWrapper);
|
|
|
+ if (1 == userFile.getIsDir()) {
|
|
|
+ List<UserFile> list = userFileService.selectUserFileByLikeRightFilePath(new QiwenFile(userFile.getFilePath(), userFile.getFileName(), true).getPath(), userId);
|
|
|
+
|
|
|
+ for (UserFile newUserFile : list) {
|
|
|
+ String escapedPattern = Pattern.quote(new QiwenFile(userFile.getFilePath(), userFile.getFileName(), userFile.getIsDir() == 1).getPath());
|
|
|
+ newUserFile.setFilePath(newUserFile.getFilePath().replaceFirst(escapedPattern,
|
|
|
+ new QiwenFile(userFile.getFilePath(), renameFileDto.getFileName(), userFile.getIsDir() == 1).getPath()));
|
|
|
+ userFileService.updateById(newUserFile);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fileDealComp.uploadESByUserFileId(renameFileDto.getUserFileId());
|
|
|
+ return RestResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Operation(summary = "获取文件列表", description = "用来做前台列表展示", tags = {"file"})
|
|
|
@RequestMapping(value = "/getfilelist", method = RequestMethod.GET)
|
|
|
@ResponseBody
|
|
|
@@ -287,7 +512,7 @@ public class FileController {
|
|
|
@Parameter(description = "页面数量", required = true) long pageCount){
|
|
|
String userId = StpLoginUserUtil.getLoginUser().getId();
|
|
|
if ("0".equals(fileType)) {
|
|
|
- IPage<FileListVO> fileList = userFileService.userFileList(null, filePath, currentPage, pageCount);
|
|
|
+ IPage<FileListVO> fileList = userFileService.userFileList(userId, filePath, currentPage, pageCount);
|
|
|
return RestResult.success().dataList(fileList.getRecords(), fileList.getTotal());
|
|
|
} else {
|
|
|
IPage<FileListVO> fileList = userFileService.getFileByFileType(Integer.valueOf(fileType), currentPage, pageCount, userId);
|
|
|
@@ -296,6 +521,28 @@ public class FileController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @Operation(summary = "获取公共资源库文件列表", description = "用来做前台列表展示", tags = {"file"})
|
|
|
+ @RequestMapping(value = "/getcommonfilelist", method = RequestMethod.GET)
|
|
|
+ @ResponseBody
|
|
|
+ public RestResult<FileListVO> getcommonfilelist(
|
|
|
+ @Parameter(description = "文件类型", required = true) String fileType,
|
|
|
+ @Parameter(description = "文件路径", required = true) String filePath,
|
|
|
+ @Parameter(description = "当前页", required = true) long currentPage,
|
|
|
+ @Parameter(description = "页面数量", required = true) long pageCount
|
|
|
+ ){
|
|
|
+ String userId = commonUserId;
|
|
|
+ if ("0".equals(fileType)) {
|
|
|
+ IPage<FileListVO> fileList = userFileService.userFileList(userId, filePath, currentPage, pageCount);
|
|
|
+ return RestResult.success().dataList(fileList.getRecords(), fileList.getTotal());
|
|
|
+ } else {
|
|
|
+ IPage<FileListVO> fileList = userFileService.getFileByFileType(Integer.valueOf(fileType), currentPage, pageCount, userId);
|
|
|
+ return RestResult.success().dataList(fileList.getRecords(), fileList.getTotal());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Operation(summary = "批量删除文件", description = "批量删除文件", tags = {"file"})
|
|
|
@RequestMapping(value = "/batchdeletefile", method = RequestMethod.POST)
|
|
|
@MyLog(operation = "批量删除文件", module = CURRENT_MODULE)
|
|
|
@@ -315,6 +562,33 @@ public class FileController {
|
|
|
return RestResult.success().message("批量删除文件成功");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ @Operation(summary = "批量删除文件", description = "批量删除文件", tags = {"file"})
|
|
|
+ @RequestMapping(value = "/batchdeleteCommonfile", method = RequestMethod.POST)
|
|
|
+ @MyLog(operation = "批量删除文件", module = CURRENT_MODULE)
|
|
|
+ @ResponseBody
|
|
|
+ public RestResult<String> batchdeleteCommonfile(@RequestBody BatchDeleteFileDTO batchDeleteFileDto) {
|
|
|
+ String userFileIds = commonUserId;
|
|
|
+ String[] userFileIdList = userFileIds.split(",");
|
|
|
+ userFileService.update(new UpdateWrapper<UserFile>().lambda().set(UserFile::getDeleteFlag, 1).in(UserFile::getUserFileId, Arrays.asList(userFileIdList)));
|
|
|
+ for (String userFileId : userFileIdList) {
|
|
|
+ executor.execute(()->{
|
|
|
+ userFileService.deleteUserFile(userFileId, SessionUtil.getUserId());
|
|
|
+ });
|
|
|
+
|
|
|
+ fileDealComp.deleteESByUserFileId(userFileId);
|
|
|
+ }
|
|
|
+
|
|
|
+ return RestResult.success().message("批量删除文件成功");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Operation(summary = "删除文件", description = "可以删除文件或者目录", tags = {"file"})
|
|
|
@RequestMapping(value = "/deletefile", method = RequestMethod.POST)
|
|
|
@MyLog(operation = "删除文件", module = CURRENT_MODULE)
|
|
|
@@ -330,6 +604,23 @@ public class FileController {
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @Operation(summary = "删除文件", description = "可以删除文件或者目录", tags = {"file"})
|
|
|
+ @RequestMapping(value = "/deleteCommonfile", method = RequestMethod.POST)
|
|
|
+ @MyLog(operation = "删除文件", module = CURRENT_MODULE)
|
|
|
+ @ResponseBody
|
|
|
+ public RestResult deleteCommonFile(@RequestBody DeleteFileDTO deleteFileDto) {
|
|
|
+ String userId =commonUserId;
|
|
|
+ userFileService.deleteUserFile(deleteFileDto.getUserFileId(), userId);
|
|
|
+ fileDealComp.deleteESByUserFileId(deleteFileDto.getUserFileId());
|
|
|
+
|
|
|
+ return RestResult.success();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Operation(summary = "解压文件", description = "解压文件。", tags = {"file"})
|
|
|
@RequestMapping(value = "/unzipfile", method = RequestMethod.POST)
|
|
|
@MyLog(operation = "解压文件", module = CURRENT_MODULE)
|
|
|
@@ -346,12 +637,30 @@ public class FileController {
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ @Operation(summary = "解压文件", description = "解压文件。", tags = {"file"})
|
|
|
+ @RequestMapping(value = "/unzipCommonFile", method = RequestMethod.POST)
|
|
|
+ @MyLog(operation = "解压文件", module = CURRENT_MODULE)
|
|
|
+ @ResponseBody
|
|
|
+ public RestResult<String> unzipCommonFile(@RequestBody UnzipFileDTO unzipFileDto) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ fileService.unzipFile(unzipFileDto.getUserFileId(), unzipFileDto.getUnzipMode(), unzipFileDto.getFilePath());
|
|
|
+ } catch (QiwenException e) {
|
|
|
+ return RestResult.fail().message(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return RestResult.success();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
@Operation(summary = "文件复制", description = "可以复制文件或者目录", tags = {"file"})
|
|
|
@RequestMapping(value = "/copyfile", method = RequestMethod.POST)
|
|
|
@MyLog(operation = "文件复制", module = CURRENT_MODULE)
|
|
|
@ResponseBody
|
|
|
public RestResult<String> copyFile(@RequestBody CopyFileDTO copyFileDTO) {
|
|
|
- String userId = SessionUtil.getUserId();
|
|
|
+ String userId = StpLoginUserUtil.getLoginUser().getId();
|
|
|
String filePath = copyFileDTO.getFilePath();
|
|
|
String userFileIds = copyFileDTO.getUserFileIds();
|
|
|
String[] userFileIdArr = userFileIds.split(",");
|
|
|
@@ -374,6 +683,40 @@ public class FileController {
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @Operation(summary = "文件复制", description = "可以复制文件或者目录", tags = {"file"})
|
|
|
+ @RequestMapping(value = "/copyCommonfile", method = RequestMethod.POST)
|
|
|
+ @MyLog(operation = "文件复制", module = CURRENT_MODULE)
|
|
|
+ @ResponseBody
|
|
|
+ public RestResult<String> copyCommonfile(@RequestBody CopyFileDTO copyFileDTO) {
|
|
|
+ String userId = commonUserId;
|
|
|
+ String filePath = copyFileDTO.getFilePath();
|
|
|
+ String userFileIds = copyFileDTO.getUserFileIds();
|
|
|
+ String[] userFileIdArr = userFileIds.split(",");
|
|
|
+ for (String userFileId : userFileIdArr) {
|
|
|
+ UserFile userFile = userFileService.getById(userFileId);
|
|
|
+ String oldfilePath = userFile.getFilePath();
|
|
|
+ String fileName = userFile.getFileName();
|
|
|
+ if (userFile.isDirectory()) {
|
|
|
+ QiwenFile qiwenFile = new QiwenFile(oldfilePath, fileName, true);
|
|
|
+ if (filePath.startsWith(qiwenFile.getPath() + QiwenFile.separator) || filePath.equals(qiwenFile.getPath())) {
|
|
|
+ return RestResult.fail().message("原路径与目标路径冲突,不能复制");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ userFileService.userFileCopy(userId, userFileId, filePath);
|
|
|
+ fileDealComp.deleteRepeatSubDirFile(filePath, userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ return RestResult.success();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Operation(summary = "文件移动", description = "可以移动文件或者目录", tags = {"file"})
|
|
|
@RequestMapping(value = "/movefile", method = RequestMethod.POST)
|
|
|
@MyLog(operation = "文件移动", module = CURRENT_MODULE)
|
|
|
@@ -401,6 +744,40 @@ public class FileController {
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ @Operation(summary = "文件移动", description = "可以移动文件或者目录", tags = {"file"})
|
|
|
+ @RequestMapping(value = "/moveCommonFile", method = RequestMethod.POST)
|
|
|
+ @MyLog(operation = "文件移动", module = CURRENT_MODULE)
|
|
|
+ @ResponseBody
|
|
|
+ public RestResult<String> moveCommonFile(@RequestBody MoveFileDTO moveFileDto) {
|
|
|
+
|
|
|
+// JwtUser sessionUserBean = SessionUtil.getSession();
|
|
|
+ String userId =commonUserId;
|
|
|
+ UserFile userFile = userFileService.getById(moveFileDto.getUserFileId());
|
|
|
+ String oldfilePath = userFile.getFilePath();
|
|
|
+ String newfilePath = moveFileDto.getFilePath();
|
|
|
+ String fileName = userFile.getFileName();
|
|
|
+ String extendName = userFile.getExtendName();
|
|
|
+ if (StringUtil.isEmpty(extendName)) {
|
|
|
+ QiwenFile qiwenFile = new QiwenFile(oldfilePath, fileName, true);
|
|
|
+ if (newfilePath.startsWith(qiwenFile.getPath() + QiwenFile.separator) || newfilePath.equals(qiwenFile.getPath())) {
|
|
|
+ return RestResult.fail().message("原路径与目标路径冲突,不能移动");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ userFileService.updateFilepathByUserFileId(moveFileDto.getUserFileId(), newfilePath, userId);
|
|
|
+
|
|
|
+ fileDealComp.deleteRepeatSubDirFile(newfilePath, userId);
|
|
|
+ return RestResult.success();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Operation(summary = "批量移动文件", description = "可以同时选择移动多个文件或者目录", tags = {"file"})
|
|
|
@RequestMapping(value = "/batchmovefile", method = RequestMethod.POST)
|
|
|
@MyLog(operation = "批量移动文件", module = CURRENT_MODULE)
|
|
|
@@ -430,6 +807,39 @@ public class FileController {
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Operation(summary = "批量移动文件", description = "可以同时选择移动多个文件或者目录", tags = {"file"})
|
|
|
+ @RequestMapping(value = "/batchmoveCommonFile", method = RequestMethod.POST)
|
|
|
+ @MyLog(operation = "批量移动文件", module = CURRENT_MODULE)
|
|
|
+ @ResponseBody
|
|
|
+ public RestResult<String> batchmoveCommonFile(@RequestBody BatchMoveFileDTO batchMoveFileDto) {
|
|
|
+
|
|
|
+ String userId =commonUserId;
|
|
|
+
|
|
|
+ String newfilePath = batchMoveFileDto.getFilePath();
|
|
|
+
|
|
|
+ String userFileIds = batchMoveFileDto.getUserFileIds();
|
|
|
+ String[] userFileIdArr = userFileIds.split(",");
|
|
|
+
|
|
|
+ for (String userFileId : userFileIdArr) {
|
|
|
+ UserFile userFile = userFileService.getById(userFileId);
|
|
|
+ if (StringUtil.isEmpty(userFile.getExtendName())) {
|
|
|
+ QiwenFile qiwenFile = new QiwenFile(userFile.getFilePath(), userFile.getFileName(), true);
|
|
|
+ if (newfilePath.startsWith(qiwenFile.getPath() + QiwenFile.separator) || newfilePath.equals(qiwenFile.getPath())) {
|
|
|
+ return RestResult.fail().message("原路径与目标路径冲突,不能移动");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ userFileService.updateFilepathByUserFileId(userFile.getUserFileId(), newfilePath, userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ return RestResult.success().data("批量移动文件成功");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Operation(summary = "获取文件树", description = "文件移动的时候需要用到该接口,用来展示目录树", tags = {"file"})
|
|
|
@RequestMapping(value = "/getfiletree", method = RequestMethod.GET)
|
|
|
@ResponseBody
|
|
|
@@ -476,6 +886,61 @@ public class FileController {
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Operation(summary = "获取文件树", description = "文件移动的时候需要用到该接口,用来展示目录树", tags = {"file"})
|
|
|
+ @RequestMapping(value = "/getCommonFileTree", method = RequestMethod.GET)
|
|
|
+ @ResponseBody
|
|
|
+ public RestResult<TreeNode> getCommonFileTree() {
|
|
|
+ RestResult<TreeNode> result = new RestResult<TreeNode>();
|
|
|
+
|
|
|
+ String userId = commonUserId;
|
|
|
+ List<UserFile> userFileList = userFileService.selectFilePathTreeByUserId(userId);
|
|
|
+ TreeNode resultTreeNode = new TreeNode();
|
|
|
+ resultTreeNode.setLabel(QiwenFile.separator);
|
|
|
+ resultTreeNode.setId(0L);
|
|
|
+ long id = 1;
|
|
|
+ for (int i = 0; i < userFileList.size(); i++){
|
|
|
+ UserFile userFile = userFileList.get(i);
|
|
|
+ QiwenFile qiwenFile = new QiwenFile(userFile.getFilePath(), userFile.getFileName(), false);
|
|
|
+ String filePath = qiwenFile.getPath();
|
|
|
+
|
|
|
+ Queue<String> queue = new LinkedList<>();
|
|
|
+
|
|
|
+ String[] strArr = filePath.split(QiwenFile.separator);
|
|
|
+ for (int j = 0; j < strArr.length; j++){
|
|
|
+ if (!"".equals(strArr[j]) && strArr[j] != null){
|
|
|
+ queue.add(strArr[j]);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if (queue.size() == 0){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ resultTreeNode = fileDealComp.insertTreeNode(resultTreeNode, id++, QiwenFile.separator, queue);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ List<TreeNode> treeNodeList = resultTreeNode.getChildren();
|
|
|
+ Collections.sort(treeNodeList, (o1, o2) -> {
|
|
|
+ long i = o1.getId() - o2.getId();
|
|
|
+ return (int) i;
|
|
|
+ });
|
|
|
+ result.setSuccess(true);
|
|
|
+ result.setData(resultTreeNode);
|
|
|
+ return result;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Operation(summary = "修改文件", description = "支持普通文本类文件的修改", tags = {"file"})
|
|
|
@RequestMapping(value = "/update", method = RequestMethod.POST)
|
|
|
@ResponseBody
|
|
|
@@ -512,6 +977,48 @@ public class FileController {
|
|
|
return RestResult.success().message("修改文件成功");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ @Operation(summary = "修改文件", description = "支持普通文本类文件的修改", tags = {"file"})
|
|
|
+ @RequestMapping(value = "/updateCommon", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public RestResult<String> updateCommon(@RequestBody UpdateFileDTO updateFileDTO) {
|
|
|
+// JwtUser sessionUserBean = SessionUtil.getSession();
|
|
|
+ String userId = commonUserId;
|
|
|
+ UserFile userFile = userFileService.getById(updateFileDTO.getUserFileId());
|
|
|
+ FileBean fileBean = fileService.getById(userFile.getFileId());
|
|
|
+ Long pointCount = fileService.getFilePointCount(userFile.getFileId());
|
|
|
+ String fileUrl = fileBean.getFileUrl();
|
|
|
+ if (pointCount > 1) {
|
|
|
+ fileUrl = fileDealComp.copyFile(fileBean, userFile);
|
|
|
+ }
|
|
|
+ String content = updateFileDTO.getFileContent();
|
|
|
+ ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(content.getBytes());
|
|
|
+ try {
|
|
|
+ int fileSize = byteArrayInputStream.available();
|
|
|
+ fileDealComp.saveFileInputStream(fileBean.getStorageType(), fileUrl, byteArrayInputStream);
|
|
|
+
|
|
|
+ String md5Str = fileDealComp.getIdentifierByFile(fileUrl, fileBean.getStorageType());
|
|
|
+
|
|
|
+ fileService.updateFileDetail(userFile.getUserFileId(), md5Str, fileSize);
|
|
|
+
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new QiwenException(999999, "修改文件异常");
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ byteArrayInputStream.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return RestResult.success().message("修改文件成功");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Operation(summary = "查询文件详情", description = "查询文件详情", tags = {"file"})
|
|
|
@RequestMapping(value = "/detail", method = RequestMethod.GET)
|
|
|
@ResponseBody
|
|
|
@@ -523,5 +1030,13 @@ public class FileController {
|
|
|
|
|
|
|
|
|
|
|
|
+ @Operation(summary = "查询文件详情", description = "查询文件详情", tags = {"file"})
|
|
|
+ @RequestMapping(value = "/detailCommon", method = RequestMethod.GET)
|
|
|
+ @ResponseBody
|
|
|
+ public RestResult<FileDetailVO> detailCommon(
|
|
|
+ @Parameter(description = "用户文件Id", required = true) String userFileId){
|
|
|
+ FileDetailVO vo = fileService.getFileDetail(userFileId);
|
|
|
+ return RestResult.success().data(vo);
|
|
|
+ }
|
|
|
|
|
|
}
|