修复同名文件删除报错
This commit is contained in:
parent
37b1292ac1
commit
5217cc32fa
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -22,6 +22,5 @@ public interface IUserFileService extends IService<UserFile> {
|
||||
List<UserFile> selectFileListLikeRightFilePath(String filePath, long userId);
|
||||
List<UserFile> selectFilePathTreeByUserId(Long userId);
|
||||
void deleteUserFile(Long userFileId, Long sessionUserId);
|
||||
String getRepeatFileName(UserFile userFile, String savefilePath);
|
||||
|
||||
}
|
||||
|
@ -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<UserFile> 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<UserFile> list = userFileMapper.selectList(lambdaQueryWrapper);
|
||||
if (list == null) {
|
||||
return fileName;
|
||||
}
|
||||
if (list.isEmpty()) {
|
||||
return fileName;
|
||||
}
|
||||
int i = 0;
|
||||
|
||||
while (list != null && !list.isEmpty()) {
|
||||
i++;
|
||||
LambdaQueryWrapper<UserFile> 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<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(UserFile::getFilePath, parentFilePath + FileConstant.pathSeparator)
|
||||
.eq(UserFile::getFileName, fileName)
|
||||
.eq(UserFile::getDeleteFlag, 0)
|
||||
.eq(UserFile::getUserId, sessionUserId);
|
||||
List<UserFile> 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<UserFile> 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<UserFile> repeatList = userFileMapper.selectList(lambdaQueryWrapper);
|
||||
|
||||
for (UserFile userFile : repeatList) {
|
||||
LambdaQueryWrapper<UserFile> lambdaQueryWrapper1 = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper1.eq(UserFile::getFilePath, userFile.getFilePath())
|
||||
.eq(UserFile::getFileName, userFile.getFileName())
|
||||
.eq(UserFile::getDeleteFlag, "0");
|
||||
List<UserFile> 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<String> nodeNameQueue){
|
||||
//
|
||||
// List<TreeNode> childrenTreeNodes = treeNode.getChildren();
|
||||
// String currentNodeName = nodeNameQueue.peek();
|
||||
// if (currentNodeName == null){
|
||||
// return treeNode;
|
||||
// }
|
||||
//
|
||||
// Map<String, String> 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<TreeNode> 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;
|
||||
// }
|
||||
}
|
@ -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<TreeNode> getFileTree(@RequestHeader("token") String token) {
|
||||
RestResult<TreeNode> result = new RestResult<TreeNode>();
|
||||
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<UserFile> filePathList = userFileService.selectFilePathTreeByUserId(sessionUserBean.getUserId());
|
||||
List<UserFile> 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<String> 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<TreeNode> treeNodeList = resultTreeNode.getChildren();
|
||||
Collections.sort(treeNodeList, new Comparator<TreeNode>() {
|
||||
@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<String> nodeNameQueue){
|
||||
public TreeNode insertTreeNode(TreeNode treeNode, long id, String filePath, Queue<String> nodeNameQueue){
|
||||
|
||||
List<TreeNode> childrenTreeNodes = treeNode.getChildren();
|
||||
String currentNodeName = nodeNameQueue.peek();
|
||||
@ -566,18 +566,15 @@ public class FileController {
|
||||
return treeNode;
|
||||
}
|
||||
|
||||
Map<String, String> 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);
|
||||
|
@ -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<UserFile> userfileList = userFileService.selectFileListLikeRightFilePath(userFile.getFilePath() + userFile.getFileName(), userFile.getUserId());
|
||||
@ -158,7 +161,6 @@ public class ShareController {
|
||||
throw new NotLoginException();
|
||||
}
|
||||
List<ShareListVO> shareList = shareService.selectShareList(shareListDTO, sessionUserBean.getUserId());
|
||||
LambdaQueryWrapper<ShareFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
int total = shareService.selectShareListTotalCount(shareListDTO, sessionUserBean.getUserId());
|
||||
|
||||
|
@ -29,10 +29,12 @@ public class TreeNode {
|
||||
*/
|
||||
private String state = "closed";
|
||||
|
||||
private String filePath = "/";
|
||||
|
||||
/**
|
||||
* 属性集合
|
||||
*/
|
||||
private Map<String, String> attributes = new HashMap<>();
|
||||
// private Map<String, String> attributes = new HashMap<>();
|
||||
/**
|
||||
* 子节点列表
|
||||
*/
|
||||
|
@ -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<RecoveryFileMapper, Recove
|
||||
FileMapper fileMapper;
|
||||
@Resource
|
||||
RecoveryFileMapper recoveryFileMapper;
|
||||
@Resource
|
||||
FileDealComp fileDealComp;
|
||||
|
||||
public static Executor executor = Executors.newFixedThreadPool(20);
|
||||
|
||||
@Override
|
||||
public void deleteRecoveryFile(UserFile userFile) {
|
||||
if (userFile == null) {
|
||||
return ;
|
||||
|
||||
}
|
||||
if (userFile.getIsDir() == 1) {
|
||||
updateFilePointCountByBatchNum(userFile.getDeleteBatchNum());
|
||||
|
||||
@ -62,60 +70,21 @@ public class RecoveryFileService extends ServiceImpl<RecoveryFileMapper, Recove
|
||||
|
||||
@Override
|
||||
public void restorefile(String deleteBatchNum, String filePath, Long sessionUserId) {
|
||||
// LambdaQueryWrapper<RecoveryFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
// lambdaQueryWrapper.eq(RecoveryFile::getDeleteBatchNum, deleteBatchNum);
|
||||
// List<RecoveryFile> list = recoveryFileMapper.selectList(lambdaQueryWrapper);
|
||||
// if ()
|
||||
|
||||
LambdaUpdateWrapper<UserFile> 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<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(UserFile::getFilePath, parentFilePath + "/")
|
||||
.eq(UserFile::getFileName, fileName)
|
||||
.eq(UserFile::getDeleteFlag, 0)
|
||||
.eq(UserFile::getUserId, sessionUserId);
|
||||
List<UserFile> 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<UserFile> 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<UserFile> repeatList = userFileMapper.selectList(lambdaQueryWrapper);
|
||||
|
||||
for (UserFile userFile : repeatList) {
|
||||
LambdaQueryWrapper<UserFile> lambdaQueryWrapper1 = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper1.eq(UserFile::getFilePath, userFile.getFilePath())
|
||||
.eq(UserFile::getFileName, userFile.getFileName())
|
||||
.eq(UserFile::getDeleteFlag, "0");
|
||||
List<UserFile> 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<RecoveryFile> recoveryFileServiceLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
recoveryFileServiceLambdaQueryWrapper.eq(RecoveryFile::getDeleteBatchNum, deleteBatchNum);
|
||||
@ -124,6 +93,7 @@ public class RecoveryFileService extends ServiceImpl<RecoveryFileMapper, Recove
|
||||
|
||||
|
||||
|
||||
|
||||
private void updateFilePointCountByBatchNum(String deleteBatchNum) {
|
||||
LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(UserFile::getDeleteBatchNum, deleteBatchNum);
|
||||
|
@ -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<UserFileMapper, UserFile> 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<UserFile> userFileLambdaUpdateWrapper = new LambdaUpdateWrapper<UserFile>();
|
||||
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<UserFileMapper, UserFile> impl
|
||||
FileBean fileBean = fileMapper.selectById(userFileTemp.getFileId());
|
||||
|
||||
LambdaUpdateWrapper<UserFile> 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<UserFileMapper, UserFile> 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<UserFile> 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<UserFile> list = userFileMapper.selectList(lambdaQueryWrapper);
|
||||
if (list == null) {
|
||||
return fileName;
|
||||
}
|
||||
if (list.isEmpty()) {
|
||||
return fileName;
|
||||
}
|
||||
int i = 0;
|
||||
|
||||
while (list != null && !list.isEmpty()) {
|
||||
i++;
|
||||
LambdaQueryWrapper<UserFile> 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<UserFile> fileList = selectFileListLikeRightFilePath(filePath, userId);
|
||||
@ -266,7 +226,7 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
||||
public void run() {
|
||||
//标记删除标志
|
||||
LambdaUpdateWrapper<UserFile> 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())
|
||||
|
Loading…
Reference in New Issue
Block a user