From 5217cc32fa41bdd20fcf82e2d2caa105f0f6effd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E8=B6=85?= <1162714483@qq.com> Date: Sat, 17 Apr 2021 22:25:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=8C=E5=90=8D=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=88=A0=E9=99=A4=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/qiwenshare/common/util/DateUtil.java | 13 ++ .../com/qiwenshare/common/util/PathUtil.java | 2 +- .../qiwenshare/file/api/IUserFileService.java | 1 - .../file/component/FileDealComp.java | 176 ++++++++++++++++++ .../file/controller/FileController.java | 53 +++--- .../file/controller/ShareController.java | 6 +- .../com/qiwenshare/file/domain/TreeNode.java | 4 +- .../file/service/RecoveryFileService.java | 64 ++----- .../file/service/UserFileService.java | 48 +---- 9 files changed, 243 insertions(+), 124 deletions(-) create mode 100644 file-web/src/main/java/com/qiwenshare/file/component/FileDealComp.java diff --git a/file-common/src/main/java/com/qiwenshare/common/util/DateUtil.java b/file-common/src/main/java/com/qiwenshare/common/util/DateUtil.java index 6000bd4..2df5b2e 100644 --- a/file-common/src/main/java/com/qiwenshare/common/util/DateUtil.java +++ b/file-common/src/main/java/com/qiwenshare/common/util/DateUtil.java @@ -1,5 +1,9 @@ package com.qiwenshare.common.util; +import cn.hutool.captcha.generator.RandomGenerator; +import cn.hutool.core.util.RandomUtil; +import org.apache.commons.lang3.RandomUtils; + import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -111,4 +115,13 @@ public class DateUtil { return false; } + public static long getTime() { + long time = new Date().getTime(); + return time; + } + + public static void main(String[] args) { + System.out.println(RandomUtil.randomInt(6)); + } + } diff --git a/file-common/src/main/java/com/qiwenshare/common/util/PathUtil.java b/file-common/src/main/java/com/qiwenshare/common/util/PathUtil.java index 2476759..f870382 100644 --- a/file-common/src/main/java/com/qiwenshare/common/util/PathUtil.java +++ b/file-common/src/main/java/com/qiwenshare/common/util/PathUtil.java @@ -73,7 +73,7 @@ public class PathUtil { } public static void main(String[] args) { - String path = "aaa/bbb/ccc"; + String path = "aaa/bbb/ccc/"; System.out.println(getParentPath(path)); String fileName = path.substring(path.lastIndexOf("/")); System.out.println(fileName); diff --git a/file-web/src/main/java/com/qiwenshare/file/api/IUserFileService.java b/file-web/src/main/java/com/qiwenshare/file/api/IUserFileService.java index d5d6321..1f5d2ee 100644 --- a/file-web/src/main/java/com/qiwenshare/file/api/IUserFileService.java +++ b/file-web/src/main/java/com/qiwenshare/file/api/IUserFileService.java @@ -22,6 +22,5 @@ public interface IUserFileService extends IService { List selectFileListLikeRightFilePath(String filePath, long userId); List selectFilePathTreeByUserId(Long userId); void deleteUserFile(Long userFileId, Long sessionUserId); - String getRepeatFileName(UserFile userFile, String savefilePath); } diff --git a/file-web/src/main/java/com/qiwenshare/file/component/FileDealComp.java b/file-web/src/main/java/com/qiwenshare/file/component/FileDealComp.java new file mode 100644 index 0000000..691420e --- /dev/null +++ b/file-web/src/main/java/com/qiwenshare/file/component/FileDealComp.java @@ -0,0 +1,176 @@ +package com.qiwenshare.file.component; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.qiwenshare.common.constant.FileConstant; +import com.qiwenshare.common.util.DateUtil; +import com.qiwenshare.common.util.PathUtil; +import com.qiwenshare.file.domain.TreeNode; +import com.qiwenshare.file.domain.UserFile; +import com.qiwenshare.file.mapper.UserFileMapper; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Queue; + +@Component +public class FileDealComp { + @Resource + UserFileMapper userFileMapper; + + public String getRepeatFileName(UserFile userFile, String savefilePath) { + String fileName = userFile.getFileName(); + String extendName = userFile.getExtendName(); + Integer deleteFlag = userFile.getDeleteFlag(); + Long userId = userFile.getUserId(); + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(UserFile::getFilePath, savefilePath) + .eq(UserFile::getDeleteFlag, deleteFlag) + .eq(UserFile::getUserId, userId) + .eq(UserFile::getFileName, fileName); + if (userFile.getIsDir() == 0) { + lambdaQueryWrapper.eq(UserFile::getExtendName, extendName); + } + List list = userFileMapper.selectList(lambdaQueryWrapper); + if (list == null) { + return fileName; + } + if (list.isEmpty()) { + return fileName; + } + int i = 0; + + while (list != null && !list.isEmpty()) { + i++; + LambdaQueryWrapper lambdaQueryWrapper1 = new LambdaQueryWrapper<>(); + lambdaQueryWrapper1.eq(UserFile::getFilePath, savefilePath) + .eq(UserFile::getDeleteFlag, deleteFlag) + .eq(UserFile::getUserId, userId) + .eq(UserFile::getFileName, fileName + "(" + i + ")"); + if (userFile.getIsDir() == 0) { + lambdaQueryWrapper1.eq(UserFile::getExtendName, extendName); + } + list = userFileMapper.selectList(lambdaQueryWrapper1); + } + + return fileName + "(" + i + ")"; + + } + + public void restoreParentFilePath(String filePath, Long sessionUserId) { + String parentFilePath = PathUtil.getParentPath(filePath); + while(parentFilePath.contains("/")) { + String fileName = parentFilePath.substring(parentFilePath.lastIndexOf("/") + 1); + parentFilePath = PathUtil.getParentPath(parentFilePath); + + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(UserFile::getFilePath, parentFilePath + FileConstant.pathSeparator) + .eq(UserFile::getFileName, fileName) + .eq(UserFile::getDeleteFlag, 0) + .eq(UserFile::getUserId, sessionUserId); + List userFileList = userFileMapper.selectList(lambdaQueryWrapper); + if (userFileList.size() == 0) { + UserFile userFile = new UserFile(); + userFile.setUserId(sessionUserId); + userFile.setFileName(fileName); + userFile.setFilePath(parentFilePath + FileConstant.pathSeparator); + userFile.setDeleteFlag(0); + userFile.setIsDir(1); + userFile.setUploadTime(DateUtil.getCurrentTime()); + + userFileMapper.insert(userFile); + } + + } + } + + public void deleteRepeatSubDirFile(String filePath, Long sessionUserId) { + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + + lambdaQueryWrapper.select(UserFile::getFileName, UserFile::getFilePath) + .likeRight(UserFile::getFilePath, filePath) + .eq(UserFile::getIsDir, 1) + .eq(UserFile::getDeleteFlag, 0) + .eq(UserFile::getUserId, sessionUserId) + .groupBy(UserFile::getFilePath, UserFile::getFileName) + .having("count(fileName) >= 2"); + List repeatList = userFileMapper.selectList(lambdaQueryWrapper); + + for (UserFile userFile : repeatList) { + LambdaQueryWrapper lambdaQueryWrapper1 = new LambdaQueryWrapper<>(); + lambdaQueryWrapper1.eq(UserFile::getFilePath, userFile.getFilePath()) + .eq(UserFile::getFileName, userFile.getFileName()) + .eq(UserFile::getDeleteFlag, "0"); + List userFiles = userFileMapper.selectList(lambdaQueryWrapper1); + for (int i = 0; i < userFiles.size() - 1; i ++) { + userFileMapper.deleteById(userFiles.get(i).getUserFileId()); + } + } + } +// +// public TreeNode insertTreeNode(TreeNode treeNode, String filePath, Queue nodeNameQueue){ +// +// List childrenTreeNodes = treeNode.getChildren(); +// String currentNodeName = nodeNameQueue.peek(); +// if (currentNodeName == null){ +// return treeNode; +// } +// +// Map map = new HashMap<>(); +// filePath = filePath + currentNodeName + "/"; +// map.put("filePath", filePath); +// +// if (!isExistPath(childrenTreeNodes, currentNodeName)){ //1、判断有没有该子节点,如果没有则插入 +// //插入 +// TreeNode resultTreeNode = new TreeNode(); +// +// +// resultTreeNode.setAttributes(map); +// resultTreeNode.setLabel(nodeNameQueue.poll()); +// resultTreeNode.setId(treeid++); +// +// childrenTreeNodes.add(resultTreeNode); +// +// }else{ //2、如果有,则跳过 +// nodeNameQueue.poll(); +// } +// +// if (nodeNameQueue.size() != 0) { +// for (int i = 0; i < childrenTreeNodes.size(); i++) { +// +// TreeNode childrenTreeNode = childrenTreeNodes.get(i); +// if (currentNodeName.equals(childrenTreeNode.getLabel())){ +// childrenTreeNode = insertTreeNode(childrenTreeNode, filePath, nodeNameQueue); +// childrenTreeNodes.remove(i); +// childrenTreeNodes.add(childrenTreeNode); +// treeNode.setChildren(childrenTreeNodes); +// } +// +// } +// }else{ +// treeNode.setChildren(childrenTreeNodes); +// } +// +// return treeNode; +// +// } +// +// public boolean isExistPath(List childrenTreeNodes, String path){ +// boolean isExistPath = false; +// +// try { +// for (int i = 0; i < childrenTreeNodes.size(); i++){ +// if (path.equals(childrenTreeNodes.get(i).getLabel())){ +// isExistPath = true; +// } +// } +// }catch (Exception e){ +// e.printStackTrace(); +// } +// +// +// return isExistPath; +// } +} diff --git a/file-web/src/main/java/com/qiwenshare/file/controller/FileController.java b/file-web/src/main/java/com/qiwenshare/file/controller/FileController.java index dc2f432..3b1f54f 100644 --- a/file-web/src/main/java/com/qiwenshare/file/controller/FileController.java +++ b/file-web/src/main/java/com/qiwenshare/file/controller/FileController.java @@ -15,10 +15,7 @@ import com.qiwenshare.common.operation.FileOperation; import com.qiwenshare.common.util.FileUtil; import com.qiwenshare.common.util.PathUtil; import com.qiwenshare.file.anno.MyLog; -import com.qiwenshare.file.api.IFileService; -import com.qiwenshare.file.api.IRecoveryFileService; -import com.qiwenshare.file.api.IUserFileService; -import com.qiwenshare.file.api.IUserService; +import com.qiwenshare.file.api.*; import com.qiwenshare.common.config.QiwenFileConfig; import com.qiwenshare.file.config.es.FileSearch; import com.qiwenshare.file.domain.*; @@ -59,8 +56,9 @@ public class FileController { IUserService userService; @Resource IUserFileService userFileService; - @Resource - IRecoveryFileService recoveryFileService; + + @Autowired + private ElasticsearchRestTemplate elasticsearchRestTemplate; @Resource QiwenFileConfig qiwenFileConfig; @@ -68,10 +66,6 @@ public class FileController { public static final String CURRENT_MODULE = "文件接口"; - @Autowired - private ElasticsearchRestTemplate elasticsearchRestTemplate; - public static long treeid = 0; - @Operation(summary = "创建文件", description = "目录(文件夹)的创建", tags = {"file"}) @RequestMapping(value = "/createfile", method = RequestMethod.POST) @@ -518,23 +512,20 @@ public class FileController { @ResponseBody public RestResult getFileTree(@RequestHeader("token") String token) { RestResult result = new RestResult(); - UserFile userFile = new UserFile(); + UserBean sessionUserBean = userService.getUserBeanByToken(token); if (sessionUserBean == null) { throw new NotLoginException(); } - if (qiwenFileConfig.isShareMode()){ - userFile.setUserId(2L); - }else{ - userFile.setUserId(sessionUserBean.getUserId()); - } - List filePathList = userFileService.selectFilePathTreeByUserId(sessionUserBean.getUserId()); + List userFileList = userFileService.selectFilePathTreeByUserId(sessionUserBean.getUserId()); TreeNode resultTreeNode = new TreeNode(); resultTreeNode.setLabel("/"); - - for (int i = 0; i < filePathList.size(); i++){ - String filePath = filePathList.get(i).getFilePath() + filePathList.get(i).getFileName() + "/"; + resultTreeNode.setId(0L); + long id = 1; + for (int i = 0; i < userFileList.size(); i++){ + UserFile userFile = userFileList.get(i); + String filePath = userFile.getFilePath() + userFile.getFileName() + "/"; Queue queue = new LinkedList<>(); @@ -548,17 +539,26 @@ public class FileController { if (queue.size() == 0){ continue; } - resultTreeNode = insertTreeNode(resultTreeNode,"/", queue); + + resultTreeNode = insertTreeNode(resultTreeNode, id++, "/" , queue); } + List treeNodeList = resultTreeNode.getChildren(); + Collections.sort(treeNodeList, new Comparator() { + @Override + public int compare(TreeNode o1, TreeNode o2) { + long i = o1.getId() - o2.getId(); + return (int) i; + } + }); result.setSuccess(true); result.setData(resultTreeNode); return result; } - public TreeNode insertTreeNode(TreeNode treeNode, String filePath, Queue nodeNameQueue){ + public TreeNode insertTreeNode(TreeNode treeNode, long id, String filePath, Queue nodeNameQueue){ List childrenTreeNodes = treeNode.getChildren(); String currentNodeName = nodeNameQueue.peek(); @@ -566,18 +566,15 @@ public class FileController { return treeNode; } - Map map = new HashMap<>(); filePath = filePath + currentNodeName + "/"; - map.put("filePath", filePath); if (!isExistPath(childrenTreeNodes, currentNodeName)){ //1、判断有没有该子节点,如果没有则插入 //插入 TreeNode resultTreeNode = new TreeNode(); - - resultTreeNode.setAttributes(map); + resultTreeNode.setFilePath(filePath); resultTreeNode.setLabel(nodeNameQueue.poll()); - resultTreeNode.setId(treeid++); + resultTreeNode.setId(++id); childrenTreeNodes.add(resultTreeNode); @@ -590,7 +587,7 @@ public class FileController { TreeNode childrenTreeNode = childrenTreeNodes.get(i); if (currentNodeName.equals(childrenTreeNode.getLabel())){ - childrenTreeNode = insertTreeNode(childrenTreeNode, filePath, nodeNameQueue); + childrenTreeNode = insertTreeNode(childrenTreeNode, id * 10, filePath, nodeNameQueue); childrenTreeNodes.remove(i); childrenTreeNodes.add(childrenTreeNode); treeNode.setChildren(childrenTreeNodes); diff --git a/file-web/src/main/java/com/qiwenshare/file/controller/ShareController.java b/file-web/src/main/java/com/qiwenshare/file/controller/ShareController.java index 2d2d71e..6746e37 100644 --- a/file-web/src/main/java/com/qiwenshare/file/controller/ShareController.java +++ b/file-web/src/main/java/com/qiwenshare/file/controller/ShareController.java @@ -9,6 +9,7 @@ import com.qiwenshare.common.util.DateUtil; import com.qiwenshare.common.result.RestResult; import com.qiwenshare.file.anno.MyLog; import com.qiwenshare.file.api.*; +import com.qiwenshare.file.component.FileDealComp; import com.qiwenshare.file.domain.Share; import com.qiwenshare.file.domain.ShareFile; import com.qiwenshare.file.domain.UserBean; @@ -45,6 +46,8 @@ public class ShareController { IFileService fileService; @Resource IUserFileService userFileService; + @Resource + FileDealComp fileDealComp; @Operation(summary = "分享文件", description = "分享文件统一接口", tags = {"share"}) @PostMapping(value = "/sharefile") @@ -117,7 +120,7 @@ public class ShareController { for (ShareFile shareFile : fileList) { UserFile userFile = userFileService.getById(shareFile.getUserFileId()); String fileName = userFile.getFileName(); - String savefileName = userFileService.getRepeatFileName(userFile, savefilePath); + String savefileName = fileDealComp.getRepeatFileName(userFile, savefilePath); if (userFile.getIsDir() == 1) { List userfileList = userFileService.selectFileListLikeRightFilePath(userFile.getFilePath() + userFile.getFileName(), userFile.getUserId()); @@ -158,7 +161,6 @@ public class ShareController { throw new NotLoginException(); } List shareList = shareService.selectShareList(shareListDTO, sessionUserBean.getUserId()); - LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); int total = shareService.selectShareListTotalCount(shareListDTO, sessionUserBean.getUserId()); diff --git a/file-web/src/main/java/com/qiwenshare/file/domain/TreeNode.java b/file-web/src/main/java/com/qiwenshare/file/domain/TreeNode.java index 68f2537..60beaf7 100644 --- a/file-web/src/main/java/com/qiwenshare/file/domain/TreeNode.java +++ b/file-web/src/main/java/com/qiwenshare/file/domain/TreeNode.java @@ -29,10 +29,12 @@ public class TreeNode { */ private String state = "closed"; + private String filePath = "/"; + /** * 属性集合 */ - private Map attributes = new HashMap<>(); +// private Map attributes = new HashMap<>(); /** * 子节点列表 */ diff --git a/file-web/src/main/java/com/qiwenshare/file/service/RecoveryFileService.java b/file-web/src/main/java/com/qiwenshare/file/service/RecoveryFileService.java index 67c5e1a..12838df 100644 --- a/file-web/src/main/java/com/qiwenshare/file/service/RecoveryFileService.java +++ b/file-web/src/main/java/com/qiwenshare/file/service/RecoveryFileService.java @@ -4,9 +4,11 @@ import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.qiwenshare.common.constant.FileConstant; import com.qiwenshare.common.util.DateUtil; import com.qiwenshare.common.util.PathUtil; import com.qiwenshare.file.api.IRecoveryFileService; +import com.qiwenshare.file.component.FileDealComp; import com.qiwenshare.file.domain.FileBean; import com.qiwenshare.file.domain.RecoveryFile; import com.qiwenshare.file.domain.UserFile; @@ -33,11 +35,17 @@ public class RecoveryFileService extends ServiceImpl lambdaQueryWrapper = new LambdaQueryWrapper<>(); +// lambdaQueryWrapper.eq(RecoveryFile::getDeleteBatchNum, deleteBatchNum); +// List list = recoveryFileMapper.selectList(lambdaQueryWrapper); +// if () + LambdaUpdateWrapper userFileLambdaUpdateWrapper = new LambdaUpdateWrapper<>(); userFileLambdaUpdateWrapper.set(UserFile::getDeleteFlag, 0) .set(UserFile::getDeleteBatchNum, "") .eq(UserFile::getDeleteBatchNum, deleteBatchNum); userFileMapper.update(null, userFileLambdaUpdateWrapper); - String parentFilePath = PathUtil.getParentPath(filePath); - while(parentFilePath.indexOf("/") != -1) { - String fileName = parentFilePath.substring(parentFilePath.lastIndexOf("/") + 1); - parentFilePath = PathUtil.getParentPath(parentFilePath); - LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); - lambdaQueryWrapper.eq(UserFile::getFilePath, parentFilePath + "/") - .eq(UserFile::getFileName, fileName) - .eq(UserFile::getDeleteFlag, 0) - .eq(UserFile::getUserId, sessionUserId); - List userFileList = userFileMapper.selectList(lambdaQueryWrapper); - if (userFileList.size() == 0) { - UserFile userFile = new UserFile(); - userFile.setUserId(sessionUserId); - userFile.setFileName(fileName); - userFile.setFilePath(parentFilePath + "/"); - userFile.setDeleteFlag(0); - userFile.setIsDir(1); - userFile.setUploadTime(DateUtil.getCurrentTime()); + fileDealComp.restoreParentFilePath(filePath, sessionUserId); - userFileMapper.insert(userFile); - } - - } - - LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); - - lambdaQueryWrapper.select(UserFile::getFileName, UserFile::getFilePath) - .likeRight(UserFile::getFilePath, filePath) - .eq(UserFile::getIsDir, 1) - .eq(UserFile::getDeleteFlag, 0) - .groupBy(UserFile::getFilePath, UserFile::getFileName) - .having("count(fileName) >= 2"); - List repeatList = userFileMapper.selectList(lambdaQueryWrapper); - - for (UserFile userFile : repeatList) { - LambdaQueryWrapper lambdaQueryWrapper1 = new LambdaQueryWrapper<>(); - lambdaQueryWrapper1.eq(UserFile::getFilePath, userFile.getFilePath()) - .eq(UserFile::getFileName, userFile.getFileName()) - .eq(UserFile::getDeleteFlag, "0"); - List userFiles = userFileMapper.selectList(lambdaQueryWrapper1); - log.info("重复的文件:" + JSON.toJSONString(userFiles)); - for (int i = 0; i < userFiles.size() - 1; i ++) { - log.info("删除文件:" + JSON.toJSONString(userFiles.get(i))); - userFileMapper.deleteById(userFiles.get(i).getUserFileId()); - } - } - - log.info(JSON.toJSONString(repeatList)); + fileDealComp.deleteRepeatSubDirFile(filePath, sessionUserId); + // TODO 如果被还原的文件已存在,暂未实现 LambdaQueryWrapper recoveryFileServiceLambdaQueryWrapper = new LambdaQueryWrapper<>(); recoveryFileServiceLambdaQueryWrapper.eq(RecoveryFile::getDeleteBatchNum, deleteBatchNum); @@ -124,6 +93,7 @@ public class RecoveryFileService extends ServiceImpl lambdaQueryWrapper = new LambdaQueryWrapper<>(); lambdaQueryWrapper.eq(UserFile::getDeleteBatchNum, deleteBatchNum); diff --git a/file-web/src/main/java/com/qiwenshare/file/service/UserFileService.java b/file-web/src/main/java/com/qiwenshare/file/service/UserFileService.java index 96ad83b..393d661 100644 --- a/file-web/src/main/java/com/qiwenshare/file/service/UserFileService.java +++ b/file-web/src/main/java/com/qiwenshare/file/service/UserFileService.java @@ -1,5 +1,6 @@ package com.qiwenshare.file.service; +import cn.hutool.core.util.RandomUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -178,12 +179,11 @@ public class UserFileService extends ServiceImpl impl @Override public void deleteUserFile(Long userFileId, Long sessionUserId) { -// UserFile userFile UserFile userFile = userFileMapper.selectById(userFileId); String uuid = UUID.randomUUID().toString(); if (userFile.getIsDir() == 1) { LambdaUpdateWrapper userFileLambdaUpdateWrapper = new LambdaUpdateWrapper(); - userFileLambdaUpdateWrapper.set(UserFile::getDeleteFlag, 1) + userFileLambdaUpdateWrapper.set(UserFile::getDeleteFlag, RandomUtil.randomInt(10)) .set(UserFile::getDeleteBatchNum, uuid) .set(UserFile::getDeleteTime, DateUtil.getCurrentTime()) .eq(UserFile::getUserFileId, userFileId); @@ -198,7 +198,7 @@ public class UserFileService extends ServiceImpl impl FileBean fileBean = fileMapper.selectById(userFileTemp.getFileId()); LambdaUpdateWrapper userFileLambdaUpdateWrapper = new LambdaUpdateWrapper<>(); - userFileLambdaUpdateWrapper.set(UserFile::getDeleteFlag, 1) + userFileLambdaUpdateWrapper.set(UserFile::getDeleteFlag, RandomUtil.randomInt(10)) .set(UserFile::getDeleteTime, DateUtil.getCurrentTime()) .set(UserFile::getDeleteBatchNum, uuid) .eq(UserFile::getUserFileId, userFileTemp.getUserFileId()); @@ -216,46 +216,6 @@ public class UserFileService extends ServiceImpl impl } - @Override - public String getRepeatFileName(UserFile userFile, String savefilePath) { - String fileName = userFile.getFileName(); - String extendName = userFile.getExtendName(); - Integer deleteFlag = userFile.getDeleteFlag(); - Long userId = userFile.getUserId(); - LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); - lambdaQueryWrapper.eq(UserFile::getFilePath, savefilePath) - .eq(UserFile::getDeleteFlag, deleteFlag) - .eq(UserFile::getUserId, userId) - .eq(UserFile::getFileName, fileName); - if (userFile.getIsDir() == 0) { - lambdaQueryWrapper.eq(UserFile::getExtendName, extendName); - } - List list = userFileMapper.selectList(lambdaQueryWrapper); - if (list == null) { - return fileName; - } - if (list.isEmpty()) { - return fileName; - } - int i = 0; - - while (list != null && !list.isEmpty()) { - i++; - LambdaQueryWrapper lambdaQueryWrapper1 = new LambdaQueryWrapper<>(); - lambdaQueryWrapper1.eq(UserFile::getFilePath, savefilePath) - .eq(UserFile::getDeleteFlag, deleteFlag) - .eq(UserFile::getUserId, userId) - .eq(UserFile::getFileName, fileName + "(" + i + ")"); - if (userFile.getIsDir() == 0) { - lambdaQueryWrapper1.eq(UserFile::getExtendName, extendName); - } - list = userFileMapper.selectList(lambdaQueryWrapper1); - } - - return fileName + "(" + i + ")"; - - } - private void updateFileDeleteStateByFilePath(String filePath, String deleteBatchNum, Long userId) { new Thread(()->{ List fileList = selectFileListLikeRightFilePath(filePath, userId); @@ -266,7 +226,7 @@ public class UserFileService extends ServiceImpl impl public void run() { //标记删除标志 LambdaUpdateWrapper userFileLambdaUpdateWrapper1 = new LambdaUpdateWrapper<>(); - userFileLambdaUpdateWrapper1.set(UserFile::getDeleteFlag, 1) + userFileLambdaUpdateWrapper1.set(UserFile::getDeleteFlag, RandomUtil.randomInt(10)) .set(UserFile::getDeleteTime, DateUtil.getCurrentTime()) .set(UserFile::getDeleteBatchNum, deleteBatchNum) .eq(UserFile::getUserFileId, userFileTemp.getUserFileId())