增加回收站功能
This commit is contained in:
parent
dbe05ea599
commit
5939cffb57
@ -224,6 +224,7 @@ public class FileOperation {
|
||||
ZipEntry entry = (ZipEntry) entries.nextElement();
|
||||
|
||||
String[] nameStrArr = entry.getName().split("/");
|
||||
|
||||
String nameStr = "/";
|
||||
for (int i = 0; i < nameStrArr.length; i++) {
|
||||
if (!"".equals(nameStrArr[i])) {
|
||||
@ -235,6 +236,8 @@ public class FileOperation {
|
||||
|
||||
logger.info("解压" + entry.getName());
|
||||
String zipPath = "/" + entry.getName();
|
||||
|
||||
|
||||
fileEntryNameList.add(zipPath);
|
||||
//如果是文件夹,就创建个文件夹
|
||||
if (entry.isDirectory()) {
|
||||
@ -274,6 +277,17 @@ public class FileOperation {
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String zipPath : fileEntryNameList) {
|
||||
if (FileUtil.isImageFile(FileUtil.getFileType(zipPath))) {
|
||||
File file = new File(destDirPath + zipPath);
|
||||
File minFile = new File(destDirPath + FileUtil.getFileNameNotExtend(zipPath) + "_min." + FileUtil.getFileType(zipPath));
|
||||
try {
|
||||
ImageOperation.thumbnailsImage(file, minFile, 300);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
List<String> res = new ArrayList<>(set);
|
||||
return res;
|
||||
}
|
||||
|
@ -30,4 +30,5 @@ public interface IFiletransferService {
|
||||
void updateStorageBean(StorageBean storageBean);
|
||||
|
||||
StorageBean selectStorageByUser(StorageBean storageBean);
|
||||
Long selectStorageSizeByUserId(Long userId);
|
||||
}
|
||||
|
@ -27,6 +27,8 @@ import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import static com.qiwenshare.common.util.FileUtil.getFileExtendsByType;
|
||||
|
||||
@ -44,9 +46,13 @@ public class FileController {
|
||||
|
||||
@Resource
|
||||
QiwenFileConfig qiwenFileConfig;
|
||||
public static Executor executor = Executors.newFixedThreadPool(20);
|
||||
|
||||
public static int COMPLETE_COUNT = 0;
|
||||
|
||||
public static long treeid = 0;
|
||||
|
||||
|
||||
/**
|
||||
* 创建文件
|
||||
*
|
||||
@ -277,8 +283,12 @@ public class FileController {
|
||||
|
||||
List<FileBean> fileBeanList = new ArrayList<>();
|
||||
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||
log.info("解压缩文件数量:" + fileBeanList);
|
||||
|
||||
for (int i = 0; i < fileEntryNameList.size(); i++){
|
||||
String entryName = fileEntryNameList.get(i);
|
||||
log.info("文件名:"+ entryName);
|
||||
executor.execute(() -> {
|
||||
String totalFileUrl = unzipUrl + entryName;
|
||||
File currentFile = FileOperation.newFile(totalFileUrl);
|
||||
|
||||
@ -304,9 +314,14 @@ public class FileController {
|
||||
tempFileBean.setTimeStampName(FileUtil.getFileNameNotExtend(currentFile.getName()));
|
||||
tempFileBean.setFileUrl(File.separator + (currentFile.getPath()).replace(PathUtil.getStaticPath(), ""));
|
||||
}
|
||||
tempFileBean.setPointCount(1);
|
||||
|
||||
fileService.save(tempFileBean);
|
||||
userFile.setFileId(tempFileBean.getFileId());
|
||||
userFile.setDeleteFlag(0);
|
||||
userFileService.save(userFile);
|
||||
});
|
||||
|
||||
//fileBeanList.add(tempFileBean);
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,10 @@ public class FiletransferController {
|
||||
storageBean.setUserId(sessionUserBean.getUserId());
|
||||
}
|
||||
|
||||
StorageBean storage = filetransferService.selectStorageByUser(storageBean);
|
||||
Long storageSize = filetransferService.selectStorageSizeByUserId(sessionUserBean.getUserId());
|
||||
StorageBean storage = new StorageBean();
|
||||
storage.setUserId(sessionUserBean.getUserId());
|
||||
storage.setStorageSize(storageSize);
|
||||
restResult.setData(storage);
|
||||
restResult.setSuccess(true);
|
||||
return restResult;
|
||||
|
@ -24,7 +24,7 @@ public class FileBean {
|
||||
@Column(columnDefinition="bigint(20) comment '文件id'")
|
||||
private Long fileId;
|
||||
|
||||
@Column(columnDefinition="varchar(50) comment '时间戳名称'")
|
||||
@Column(columnDefinition="varchar(500) comment '时间戳名称'")
|
||||
private String timeStampName;
|
||||
|
||||
@Column(columnDefinition="varchar(500) comment '文件url'")
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.qiwenshare.file.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
@ -13,6 +15,7 @@ import javax.persistence.*;
|
||||
public class UserFile {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@TableId(type = IdType.AUTO)
|
||||
@Column(columnDefinition = "bigint(20) comment '用户文件id'")
|
||||
private Long userFileId;
|
||||
|
||||
@ -28,7 +31,7 @@ public class UserFile {
|
||||
@Column(columnDefinition="varchar(500) comment '文件路径'")
|
||||
private String filePath;
|
||||
|
||||
@Column(columnDefinition="varchar(10) comment '扩展名'")
|
||||
@Column(columnDefinition="varchar(100) comment '扩展名'")
|
||||
private String extendName;
|
||||
|
||||
@Column(columnDefinition="int(1) comment '是否是目录 0-否, 1-是'")
|
||||
|
@ -18,4 +18,6 @@ public interface UserFileMapper extends BaseMapper<UserFile> {
|
||||
|
||||
List<Map<String, Object>> selectFileByExtendName(List<String> fileNameList, long userId);
|
||||
List<Map<String, Object>> selectFileNotInExtendNames(List<String> fileNameList, long userId);
|
||||
|
||||
Long selectStorageSizeByUserId(Long userId);
|
||||
}
|
||||
|
@ -132,4 +132,9 @@ public class FiletransferService implements IFiletransferService {
|
||||
lambdaQueryWrapper.eq(StorageBean::getUserId, storageBean.getUserId());
|
||||
return storageMapper.selectOne(lambdaQueryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long selectStorageSizeByUserId(Long userId){
|
||||
return userFileMapper.selectStorageSizeByUserId(userId);
|
||||
}
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
||||
public void deleteUserFile(UserFile userFile, UserBean sessionUserBean) {
|
||||
StorageBean storageBean = filetransferService.selectStorageBean(new StorageBean(sessionUserBean.getUserId()));
|
||||
long deleteSize = 0;
|
||||
//String fileUrl = PathUtil.getStaticPath() + fileBean.getFileUrl();
|
||||
|
||||
if (userFile.getIsDir() == 1) {
|
||||
//1、先删除子目录
|
||||
String filePath = userFile.getFilePath() + userFile.getFileName() + "/";
|
||||
@ -130,29 +130,18 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
||||
|
||||
for (int i = 0; i < fileList.size(); i++){
|
||||
UserFile userFileTemp = fileList.get(i);
|
||||
//1.1、删除数据库文件
|
||||
//userFileMapper.deleteById(userFileTemp.getUserFileId());
|
||||
//1.2、如果是文件,需要记录文件大小
|
||||
|
||||
if (userFileTemp.getIsDir() != 1){
|
||||
FileBean fileBean = fileMapper.selectById(userFileTemp.getFileId());
|
||||
deleteSize += fileBean.getFileSize();
|
||||
//1.3、删除服务器文件,只删除文件,目录是虚拟的
|
||||
// if (file.getFileUrl() != null && file.getFileUrl().indexOf("upload") != -1){
|
||||
// if (file.getIsOSS() != null && file.getIsOSS() == 1) {
|
||||
// AliyunOSSDelete.deleteObject(qiwenFileConfig.getAliyun().getOss(), file.getFileUrl().substring(1));
|
||||
// } else {
|
||||
// FileOperation.deleteFile(PathUtil.getStaticPath() + file.getFileUrl());
|
||||
// if (FileUtil.isImageFile(file.getExtendName())) {
|
||||
// FileOperation.deleteFile(PathUtil.getStaticPath() + file.getFileUrl().replace(file.getTimeStampName(), file.getTimeStampName() + "_min"));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
if (fileBean.getPointCount() != null) {
|
||||
|
||||
LambdaUpdateWrapper<FileBean> fileBeanLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||
fileBeanLambdaUpdateWrapper.set(FileBean::getPointCount, fileBean.getPointCount() -1)
|
||||
.eq(FileBean::getFileId, fileBean.getFileId());
|
||||
// fileService.decreaseFilePointCount(fileBean.getFileId());
|
||||
fileMapper.update(null, fileBeanLambdaUpdateWrapper);
|
||||
|
||||
}
|
||||
}
|
||||
//标记删除标志
|
||||
LambdaUpdateWrapper<UserFile> userFileLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||
@ -162,8 +151,7 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
||||
userFileMapper.update(null, userFileLambdaUpdateWrapper);
|
||||
|
||||
}
|
||||
//2、根目录单独删除
|
||||
//userFileMapper.deleteById(userFile.getUserFileId());
|
||||
|
||||
LambdaUpdateWrapper<UserFile> userFileLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||
userFileLambdaUpdateWrapper.set(UserFile::getDeleteFlag, 1)
|
||||
.set(UserFile::getDeleteTime, DateUtil.getCurrentTime())
|
||||
|
@ -51,10 +51,10 @@ qiwen-file.share-mode=false
|
||||
#是否启用阿里云oss
|
||||
qiwen-file.aliyun.oss.enabled=false
|
||||
#阿里云oss基本配置
|
||||
qiwen-file.aliyun.oss.endpoint=
|
||||
qiwen-file.aliyun.oss.access-key-id=
|
||||
qiwen-file.aliyun.oss.access-key-secret=
|
||||
qiwen-file.aliyun.oss.bucket-name=
|
||||
qiwen-file.aliyun.oss.endpoint=oss-cn-beijing.aliyuncs.com
|
||||
qiwen-file.aliyun.oss.access-key-id=LTAI4Fi2E9hb17bXrmWxNJ5e
|
||||
qiwen-file.aliyun.oss.access-key-secret=ssIfJVGyQR9qZCXUzfdvdVxtlIHlAJ
|
||||
qiwen-file.aliyun.oss.bucket-name=qiwen-file
|
||||
#阿里云oss绑定域名
|
||||
qiwen-file.aliyun.oss.domain=
|
||||
qiwen-file.aliyun.oss.domain=oss.qiwenshare.com
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
<if test="extendName != null">
|
||||
and extendName = #{extendName}
|
||||
</if>
|
||||
and deleteFlag = 0
|
||||
</where>
|
||||
|
||||
</select>
|
||||
@ -36,6 +37,7 @@
|
||||
#{fileName}
|
||||
</foreach>
|
||||
and userId = #{userId}
|
||||
and deleteFlag = 0
|
||||
</select>
|
||||
|
||||
<select id="selectFileNotInExtendNames" parameterType="com.qiwenshare.file.domain.UserFile" resultType="java.util.Map">
|
||||
@ -46,11 +48,12 @@
|
||||
#{fileName}
|
||||
</foreach>
|
||||
and userId = #{userId}
|
||||
and deleteFlag = 0
|
||||
</select>
|
||||
|
||||
|
||||
<update id="updateFilepathByFilepath">
|
||||
UPDATE file SET filePath=REPLACE(filePath, #{param1}, #{param2})
|
||||
UPDATE userfile SET filePath=REPLACE(filePath, #{param1}, #{param2})
|
||||
WHERE filePath like N'${param1}%'
|
||||
</update>
|
||||
|
||||
@ -65,4 +68,10 @@
|
||||
</if>
|
||||
</update>
|
||||
|
||||
<select id="selectStorageSizeByUserId" resultType="java.lang.Long" parameterType="java.lang.Long">
|
||||
SELECT SUM(fileSize) FROM userfile
|
||||
LEFT JOIN file ON file.fileId = userfile.fileId
|
||||
WHERE userId = 2
|
||||
</select>
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue
Block a user