Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
MAC 2023-04-16 14:25:47 +08:00
commit d29e89f712
4 changed files with 55 additions and 50 deletions

View File

@ -25,7 +25,6 @@ import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -40,8 +39,6 @@ import java.util.concurrent.Future;
@Component @Component
@Async("asyncTaskExecutor") @Async("asyncTaskExecutor")
public class AsyncTaskComp { public class AsyncTaskComp {
@Resource
IUserFileService userFileService;
@Resource @Resource
IRecoveryFileService recoveryFileService; IRecoveryFileService recoveryFileService;
@ -62,16 +59,15 @@ public class AsyncTaskComp {
public Long getFilePointCount(String fileId) { public Long getFilePointCount(String fileId) {
LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(UserFile::getFileId, fileId); lambdaQueryWrapper.eq(UserFile::getFileId, fileId);
long count = userFileMapper.selectCount(lambdaQueryWrapper); return userFileMapper.selectCount(lambdaQueryWrapper);
return count;
} }
public Future<String> deleteUserFile(String userFileId) { public Future<String> deleteUserFile(String userFileId) {
UserFile userFile = userFileService.getById(userFileId); UserFile userFile = userFileMapper.selectById(userFileId);
if (userFile.getIsDir() == 1) { if (userFile.getIsDir() == 1) {
LambdaQueryWrapper<UserFile> userFileLambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<UserFile> userFileLambdaQueryWrapper = new LambdaQueryWrapper<>();
userFileLambdaQueryWrapper.eq(UserFile::getDeleteBatchNum, userFile.getDeleteBatchNum()); userFileLambdaQueryWrapper.eq(UserFile::getDeleteBatchNum, userFile.getDeleteBatchNum());
List<UserFile> list = userFileService.list(userFileLambdaQueryWrapper); List<UserFile> list = userFileMapper.selectList(userFileLambdaQueryWrapper);
recoveryFileService.deleteUserFileByDeleteBatchNum(userFile.getDeleteBatchNum()); recoveryFileService.deleteUserFileByDeleteBatchNum(userFile.getDeleteBatchNum());
for (UserFile userFileItem : list) { for (UserFile userFileItem : list) {
@ -103,7 +99,7 @@ public class AsyncTaskComp {
} }
} }
return new AsyncResult<String>("deleteUserFile"); return new AsyncResult<>("deleteUserFile");
} }
public Future<String> checkESUserFileId(String userFileId) { public Future<String> checkESUserFileId(String userFileId) {
@ -111,7 +107,7 @@ public class AsyncTaskComp {
if (userFile == null) { if (userFile == null) {
fileDealComp.deleteESByUserFileId(userFileId); fileDealComp.deleteESByUserFileId(userFileId);
} }
return new AsyncResult<String>("checkUserFileId"); return new AsyncResult<>("checkUserFileId");
} }
@ -128,8 +124,6 @@ public class AsyncTaskComp {
try { try {
fis = new FileInputStream(currentFile); fis = new FileInputStream(currentFile);
md5Str = DigestUtils.md5Hex(fis); md5Str = DigestUtils.md5Hex(fis);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
@ -192,7 +186,7 @@ public class AsyncTaskComp {
} }
fileDealComp.restoreParentFilePath(qiwenFile, userFile.getUserId()); fileDealComp.restoreParentFilePath(qiwenFile, userFile.getUserId());
return new AsyncResult<String>("saveUnzipFile"); return new AsyncResult<>("saveUnzipFile");
} }

View File

@ -28,6 +28,7 @@ import com.qiwenshare.ufop.operation.write.domain.WriteFile;
import com.qiwenshare.ufop.util.UFOPUtils; import com.qiwenshare.ufop.util.UFOPUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.jaudiotagger.audio.AudioFile; import org.jaudiotagger.audio.AudioFile;
@ -80,7 +81,7 @@ public class FileDealComp {
/** /**
* 获取重复文件名 * 获取重复文件名
* * <p>
* 场景1: 文件还原时 savefilePath 路径下保存 测试.txt 文件重名则会生成 测试(1).txt * 场景1: 文件还原时 savefilePath 路径下保存 测试.txt 文件重名则会生成 测试(1).txt
* 场景2 上传文件时 savefilePath 路径下保存 测试.txt 文件重名则会生成 测试(1).txt * 场景2 上传文件时 savefilePath 路径下保存 测试.txt 文件重名则会生成 测试(1).txt
* *
@ -91,39 +92,38 @@ public class FileDealComp {
public String getRepeatFileName(UserFile userFile, String savefilePath) { public String getRepeatFileName(UserFile userFile, String savefilePath) {
String fileName = userFile.getFileName(); String fileName = userFile.getFileName();
String extendName = userFile.getExtendName(); String extendName = userFile.getExtendName();
Integer deleteFlag = userFile.getDeleteFlag();
String userId = userFile.getUserId(); String userId = userFile.getUserId();
int isDir = userFile.getIsDir(); int isDir = userFile.getIsDir();
LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(UserFile::getFilePath, savefilePath) lambdaQueryWrapper.eq(UserFile::getFilePath, savefilePath)
.eq(UserFile::getDeleteFlag, deleteFlag) .eq(UserFile::getDeleteFlag, 0)
.eq(UserFile::getUserId, userId) .eq(UserFile::getUserId, userId)
.eq(UserFile::getFileName, fileName) .eq(UserFile::getFileName, fileName)
.eq(UserFile::getIsDir, isDir); .eq(UserFile::getIsDir, isDir);
if (userFile.getIsDir() == 0) { if (userFile.isFile()) {
lambdaQueryWrapper.eq(UserFile::getExtendName, extendName); lambdaQueryWrapper.eq(UserFile::getExtendName, extendName);
} }
List<UserFile> list = userFileMapper.selectList(lambdaQueryWrapper); List<UserFile> list = userFileMapper.selectList(lambdaQueryWrapper);
if (list == null) { if (CollectionUtils.isEmpty(list)) {
return fileName;
}
if (list.isEmpty()) {
return fileName; return fileName;
} }
int i = 0; int i = 0;
while (list != null && !list.isEmpty()) { while (!CollectionUtils.isEmpty(list)) {
i++; i++;
LambdaQueryWrapper<UserFile> lambdaQueryWrapper1 = new LambdaQueryWrapper<>(); LambdaQueryWrapper<UserFile> lambdaQueryWrapper1 = new LambdaQueryWrapper<>();
lambdaQueryWrapper1.eq(UserFile::getFilePath, savefilePath) lambdaQueryWrapper1.eq(UserFile::getFilePath, savefilePath)
.eq(UserFile::getDeleteFlag, deleteFlag) .eq(UserFile::getDeleteFlag, 0)
.eq(UserFile::getUserId, userId) .eq(UserFile::getUserId, userId)
.eq(UserFile::getFileName, fileName + "(" + i + ")") .eq(UserFile::getFileName, fileName + "(" + i + ")")
.eq(UserFile::getIsDir, isDir); .eq(UserFile::getIsDir, isDir);
if (userFile.getIsDir() == 0) { if (userFile.isFile()) {
lambdaQueryWrapper1.eq(UserFile::getExtendName, extendName); lambdaQueryWrapper1.eq(UserFile::getExtendName, extendName);
} }
list = userFileMapper.selectList(lambdaQueryWrapper1); list = userFileMapper.selectList(lambdaQueryWrapper1);
} }
return fileName + "(" + i + ")"; return fileName + "(" + i + ")";
@ -132,7 +132,7 @@ public class FileDealComp {
/** /**
* 还原父文件路径 * 还原父文件路径
* * <p>
* 1回收站文件还原操作会将文件恢复到原来的路径下,当还原文件的时候如果父目录已经不存在了则需要把父母录给还原 * 1回收站文件还原操作会将文件恢复到原来的路径下,当还原文件的时候如果父目录已经不存在了则需要把父母录给还原
* 2上传目录 * 2上传目录
* *
@ -143,7 +143,7 @@ public class FileDealComp {
if (qiwenFile.isFile()) { if (qiwenFile.isFile()) {
qiwenFile = qiwenFile.getParentFile(); qiwenFile = qiwenFile.getParentFile();
} }
while(qiwenFile.getParent() != null) { while (qiwenFile.getParent() != null) {
String fileName = qiwenFile.getName(); String fileName = qiwenFile.getName();
String parentFilePath = qiwenFile.getParent(); String parentFilePath = qiwenFile.getParent();
@ -173,13 +173,14 @@ public class FileDealComp {
/** /**
* 删除重复的子目录文件 * 删除重复的子目录文件
* * <p>
* 当还原目录的时候如果其子目录在文件系统中已存在则还原之后进行去重操作 * 当还原目录的时候如果其子目录在文件系统中已存在则还原之后进行去重操作
*
* @param filePath * @param filePath
* @param sessionUserId * @param sessionUserId
*/ */
public void deleteRepeatSubDirFile(String filePath, String sessionUserId) { public void deleteRepeatSubDirFile(String filePath, String sessionUserId) {
log.debug("删除子目录:"+filePath); log.debug("删除子目录:" + filePath);
LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.select(UserFile::getFileName, UserFile::getFilePath) lambdaQueryWrapper.select(UserFile::getFileName, UserFile::getFilePath)
@ -197,7 +198,7 @@ public class FileDealComp {
.eq(UserFile::getFileName, userFile.getFileName()) .eq(UserFile::getFileName, userFile.getFileName())
.eq(UserFile::getDeleteFlag, "0"); .eq(UserFile::getDeleteFlag, "0");
List<UserFile> userFiles = userFileMapper.selectList(lambdaQueryWrapper1); List<UserFile> userFiles = userFileMapper.selectList(lambdaQueryWrapper1);
for (int i = 0; i < userFiles.size() - 1; i ++) { for (int i = 0; i < userFiles.size() - 1; i++) {
userFileMapper.deleteById(userFiles.get(i).getUserFileId()); userFileMapper.deleteById(userFiles.get(i).getUserFileId());
} }
} }
@ -205,6 +206,7 @@ public class FileDealComp {
/** /**
* 组织一个树目录节点文件移动的时候使用 * 组织一个树目录节点文件移动的时候使用
*
* @param treeNode * @param treeNode
* @param id * @param id
* @param filePath * @param filePath
@ -258,20 +260,21 @@ public class FileDealComp {
/** /**
* 判断该路径在树节点中是否已经存在 * 判断该路径在树节点中是否已经存在
*
* @param childrenTreeNodes * @param childrenTreeNodes
* @param path * @param path
* @return * @return
*/ */
public boolean isExistPath(List<TreeNode> childrenTreeNodes, String path){ public boolean isExistPath(List<TreeNode> childrenTreeNodes, String path) {
boolean isExistPath = false; boolean isExistPath = false;
try { try {
for (int i = 0; i < childrenTreeNodes.size(); i++){ for (TreeNode childrenTreeNode : childrenTreeNodes) {
if (path.equals(childrenTreeNodes.get(i).getLabel())){ if (path.equals(childrenTreeNode.getLabel())) {
isExistPath = true; isExistPath = true;
} }
} }
}catch (Exception e){ } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -409,8 +412,7 @@ public class FileDealComp {
DownloadFile downloadFile = new DownloadFile(); DownloadFile downloadFile = new DownloadFile();
downloadFile.setFileUrl(fileUrl); downloadFile.setFileUrl(fileUrl);
InputStream inputStream = ufopFactory.getDownloader(storageType).getInputStream(downloadFile); InputStream inputStream = ufopFactory.getDownloader(storageType).getInputStream(downloadFile);
String md5Str = DigestUtils.md5Hex(inputStream); return DigestUtils.md5Hex(inputStream);
return md5Str;
} }
public void saveFileInputStream(int storageType, String fileUrl, InputStream inputStream) throws IOException { public void saveFileInputStream(int storageType, String fileUrl, InputStream inputStream) throws IOException {
@ -422,7 +424,7 @@ public class FileDealComp {
writer1.write(inputStream, writeFile); writer1.write(inputStream, writeFile);
} }
public boolean isDirExist(String fileName, String filePath, String userId){ public boolean isDirExist(String fileName, String filePath, String userId) {
LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(UserFile::getFileName, fileName) lambdaQueryWrapper.eq(UserFile::getFileName, fileName)
.eq(UserFile::getFilePath, QiwenFile.formatPath(filePath)) .eq(UserFile::getFilePath, QiwenFile.formatPath(filePath))

View File

@ -29,8 +29,7 @@ public class JwtComp {
// 本地的密码解码 // 本地的密码解码
byte[] encodedKey = Base64.decodeBase64(jwtProperties.getSecret()); byte[] encodedKey = Base64.decodeBase64(jwtProperties.getSecret());
// 根据给定的字节数组使用AES加密算法构造一个密钥 // 根据给定的字节数组使用AES加密算法构造一个密钥
SecretKey key = new SecretKeySpec(encodedKey, 0, encodedKey.length, "AES"); return new SecretKeySpec(encodedKey, 0, encodedKey.length, "AES");
return key;
} }
// 创建jwt // 创建jwt
@ -61,10 +60,9 @@ public class JwtComp {
// 解密jwt // 解密jwt
public Claims parseJWT(String jwt) throws Exception { public Claims parseJWT(String jwt) throws Exception {
SecretKey key = generalKey(); // 签名秘钥和生成的签名的秘钥一模一样 SecretKey key = generalKey(); // 签名秘钥和生成的签名的秘钥一模一样
Claims claims = Jwts.parser() // 得到DefaultJwtParser return Jwts.parser() // 得到DefaultJwtParser
.setSigningKey(key) // 设置签名的秘钥 .setSigningKey(key) // 设置签名的秘钥
.parseClaimsJws(jwt).getBody(); // 设置需要解析的jwt .parseClaimsJws(jwt).getBody();
return claims;
} }

View File

@ -1,6 +1,7 @@
package com.qiwenshare.file.service; package com.qiwenshare.file.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qiwenshare.file.api.IRecoveryFileService; import com.qiwenshare.file.api.IRecoveryFileService;
@ -12,6 +13,7 @@ import com.qiwenshare.file.mapper.RecoveryFileMapper;
import com.qiwenshare.file.mapper.UserFileMapper; import com.qiwenshare.file.mapper.UserFileMapper;
import com.qiwenshare.file.vo.file.RecoveryFileListVo; import com.qiwenshare.file.vo.file.RecoveryFileListVo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -45,17 +47,26 @@ public class RecoveryFileService extends ServiceImpl<RecoveryFileMapper, Recove
@Override @Override
public void restorefile(String deleteBatchNum, String filePath, String sessionUserId) { public void restorefile(String deleteBatchNum, String filePath, String sessionUserId) {
LambdaUpdateWrapper<UserFile> userFileLambdaUpdateWrapper = new LambdaUpdateWrapper<>(); List<UserFile> restoreUserFileList = userFileMapper.selectList(new QueryWrapper<UserFile>().lambda().eq(UserFile::getDeleteBatchNum, deleteBatchNum));
userFileLambdaUpdateWrapper.set(UserFile::getDeleteFlag, 0) for (UserFile restoreUserFile : restoreUserFileList) {
.set(UserFile::getDeleteBatchNum, "") restoreUserFile.setDeleteFlag(0);
.eq(UserFile::getDeleteBatchNum, deleteBatchNum); restoreUserFile.setDeleteBatchNum(deleteBatchNum);
userFileMapper.update(null, userFileLambdaUpdateWrapper); String fileName = fileDealComp.getRepeatFileName(restoreUserFile, restoreUserFile.getFilePath());
if (restoreUserFile.isDirectory()) {
if (!StringUtils.equals(fileName, restoreUserFile.getFileName())) {
userFileMapper.deleteById(restoreUserFile);
} else {
userFileMapper.updateById(restoreUserFile);
}
} else if (restoreUserFile.isFile()) {
restoreUserFile.setFileName(fileName);
userFileMapper.updateById(restoreUserFile);
}
}
QiwenFile qiwenFile = new QiwenFile(filePath, true); QiwenFile qiwenFile = new QiwenFile(filePath, true);
fileDealComp.restoreParentFilePath(qiwenFile, sessionUserId); fileDealComp.restoreParentFilePath(qiwenFile, sessionUserId);
fileDealComp.deleteRepeatSubDirFile(filePath, sessionUserId);
// TODO 如果被还原的文件已存在暂未实现
LambdaQueryWrapper<RecoveryFile> recoveryFileServiceLambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<RecoveryFile> recoveryFileServiceLambdaQueryWrapper = new LambdaQueryWrapper<>();
recoveryFileServiceLambdaQueryWrapper.eq(RecoveryFile::getDeleteBatchNum, deleteBatchNum); recoveryFileServiceLambdaQueryWrapper.eq(RecoveryFile::getDeleteBatchNum, deleteBatchNum);
recoveryFileMapper.delete(recoveryFileServiceLambdaQueryWrapper); recoveryFileMapper.delete(recoveryFileServiceLambdaQueryWrapper);