refactor: 代码优化
This commit is contained in:
parent
687d77d549
commit
70628b2024
@ -9,9 +9,6 @@ import java.util.List;
|
||||
|
||||
public interface IFileService extends IService<FileBean> {
|
||||
|
||||
// void increaseFilePointCount(Long fileId);
|
||||
//
|
||||
// void decreaseFilePointCount(Long fileId);
|
||||
Long getFilePointCount(Long fileId);
|
||||
void unzipFile(long userFileId, int unzipMode, String filePath);
|
||||
|
||||
|
@ -5,32 +5,20 @@ import com.qiwenshare.file.domain.StorageBean;
|
||||
import com.qiwenshare.file.dto.file.DownloadFileDTO;
|
||||
import com.qiwenshare.file.dto.file.UploadFileDTO;
|
||||
import com.qiwenshare.file.dto.file.PreviewDTO;
|
||||
import com.qiwenshare.file.vo.file.UploadFileVo;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public interface IFiletransferService {
|
||||
|
||||
UploadFileVo uploadFileSpeed(UploadFileDTO uploadFileDTO);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
* @param request 请求
|
||||
* @param UploadFileDto 文件信息
|
||||
*/
|
||||
void uploadFile(HttpServletRequest request, UploadFileDTO UploadFileDto, Long userId);
|
||||
|
||||
void downloadFile(HttpServletResponse httpServletResponse, DownloadFileDTO downloadFileDTO);
|
||||
void previewFile(HttpServletResponse httpServletResponse, PreviewDTO previewDTO);
|
||||
void deleteFile(FileBean fileBean);
|
||||
StorageBean selectStorageBean(StorageBean storageBean);
|
||||
|
||||
void insertStorageBean(StorageBean storageBean);
|
||||
|
||||
void updateStorageBean(StorageBean storageBean);
|
||||
|
||||
StorageBean selectStorageByUser(StorageBean storageBean);
|
||||
Long selectStorageSizeByUserId(Long userId);
|
||||
}
|
||||
|
@ -4,6 +4,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.qiwenshare.file.domain.StorageBean;
|
||||
|
||||
public interface IStorageService extends IService<StorageBean> {
|
||||
public Long getTotalStorageSize(Long userId);
|
||||
Long getTotalStorageSize(Long userId);
|
||||
boolean checkStorage(Long userId, Long fileSize);
|
||||
}
|
||||
|
@ -15,14 +15,12 @@ public interface IUserFileService extends IService<UserFile> {
|
||||
boolean isDirExist(String fileName, String filePath, long userId);
|
||||
List<UserFile> selectSameUserFile(String fileName, String filePath, String extendName, Long userId);
|
||||
void replaceUserFilePath(String filePath, String oldFilePath, Long userId);
|
||||
List<FileListVo> userFileList(UserFile userFile, Long beginCount, Long pageCount);
|
||||
IPage<FileListVo> userFileList(String filePath, Long beginCount, Long pageCount);
|
||||
void updateFilepathByFilepath(String oldfilePath, String newfilePath, String fileName, String extendName, long userId);
|
||||
void userFileCopy(String oldfilePath, String newfilePath, String fileName, String extendName, long userId);
|
||||
|
||||
IPage<FileListVo> getFileByFileType(Integer fileTypeId, Long currentPage, Long pageCount, long userId);
|
||||
Long selectCountByExtendName(List<String> fileNameList, Long beginCount, Long pageCount, long userId);
|
||||
List<FileListVo> selectFileNotInExtendNames(List<String> fileNameList, Long beginCount, Long pageCount, long userId);
|
||||
Long selectCountNotInExtendNames(List<String> fileNameList, Long beginCount, Long pageCount, long userId);
|
||||
|
||||
List<UserFile> selectFileListLikeRightFilePath(String filePath, long userId);
|
||||
List<UserFile> selectFilePathTreeByUserId(Long userId);
|
||||
void deleteUserFile(Long userFileId, Long sessionUserId);
|
||||
|
@ -2,19 +2,36 @@ package com.qiwenshare.file.component;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.qiwenshare.common.util.DateUtil;
|
||||
import com.qiwenshare.file.api.IFileService;
|
||||
import com.qiwenshare.file.api.IFiletransferService;
|
||||
import com.qiwenshare.file.api.IRecoveryFileService;
|
||||
import com.qiwenshare.file.api.IUserFileService;
|
||||
import com.qiwenshare.file.domain.FileBean;
|
||||
import com.qiwenshare.file.domain.UserFile;
|
||||
import com.qiwenshare.file.mapper.FileMapper;
|
||||
import com.qiwenshare.file.mapper.UserFileMapper;
|
||||
import com.qiwenshare.file.util.QiwenFileUtil;
|
||||
import com.qiwenshare.ufop.factory.UFOPFactory;
|
||||
import com.qiwenshare.ufop.operation.copy.domain.CopyFile;
|
||||
import com.qiwenshare.ufop.util.UFOPUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.AsyncResult;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
@ -26,17 +43,34 @@ import java.util.concurrent.Future;
|
||||
public class AsyncTaskComp {
|
||||
@Resource
|
||||
IUserFileService userFileService;
|
||||
@Resource
|
||||
IFileService fileService;
|
||||
|
||||
@Resource
|
||||
IRecoveryFileService recoveryFileService;
|
||||
@Resource
|
||||
IFiletransferService filetransferService;
|
||||
@Resource
|
||||
UFOPFactory ufopFactory;
|
||||
@Resource
|
||||
UserFileMapper userFileMapper;
|
||||
@Resource
|
||||
FileMapper fileMapper;
|
||||
@Resource
|
||||
FileDealComp fileDealComp;
|
||||
|
||||
@Value("${ufop.storage-type}")
|
||||
private Integer storageType;
|
||||
|
||||
public Long getFilePointCount(Long fileId) {
|
||||
LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(UserFile::getFileId, fileId);
|
||||
long count = userFileMapper.selectCount(lambdaQueryWrapper);
|
||||
return count;
|
||||
}
|
||||
|
||||
public Future<String> deleteUserFile(Long userFileId) {
|
||||
|
||||
long begin = System.currentTimeMillis();
|
||||
UserFile userFile =userFileService.getById(userFileId);
|
||||
UserFile userFile = userFileService.getById(userFileId);
|
||||
if (userFile.getIsDir() == 1) {
|
||||
LambdaQueryWrapper<UserFile> userFileLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
userFileLambdaQueryWrapper.eq(UserFile::getDeleteBatchNum, userFile.getDeleteBatchNum());
|
||||
@ -44,13 +78,13 @@ public class AsyncTaskComp {
|
||||
recoveryFileService.deleteUserFileByDeleteBatchNum(userFile.getDeleteBatchNum());
|
||||
for (UserFile userFileItem : list) {
|
||||
|
||||
Long filePointCount = fileService.getFilePointCount(userFileItem.getFileId());
|
||||
Long filePointCount = getFilePointCount(userFileItem.getFileId());
|
||||
|
||||
if (filePointCount != null && filePointCount == 0 && userFileItem.getIsDir() == 0) {
|
||||
FileBean fileBean = fileService.getById(userFileItem.getFileId());
|
||||
FileBean fileBean = fileMapper.selectById(userFileItem.getFileId());
|
||||
try {
|
||||
filetransferService.deleteFile(fileBean);
|
||||
fileService.removeById(fileBean.getFileId());
|
||||
fileMapper.deleteById(fileBean.getFileId());
|
||||
} catch (Exception e) {
|
||||
log.error("删除本地文件失败:" + JSON.toJSONString(fileBean));
|
||||
}
|
||||
@ -59,13 +93,13 @@ public class AsyncTaskComp {
|
||||
} else {
|
||||
|
||||
recoveryFileService.deleteUserFileByDeleteBatchNum(userFile.getDeleteBatchNum());
|
||||
Long filePointCount = fileService.getFilePointCount(userFile.getFileId());
|
||||
Long filePointCount = getFilePointCount(userFile.getFileId());
|
||||
|
||||
if (filePointCount != null && filePointCount == 0 && userFile.getIsDir() == 0) {
|
||||
FileBean fileBean = fileService.getById(userFile.getFileId());
|
||||
FileBean fileBean = fileMapper.selectById(userFile.getFileId());
|
||||
try {
|
||||
filetransferService.deleteFile(fileBean);
|
||||
fileService.removeById(fileBean.getFileId());
|
||||
fileMapper.deleteById(fileBean.getFileId());
|
||||
} catch (Exception e) {
|
||||
log.error("删除本地文件失败:" + JSON.toJSONString(fileBean));
|
||||
}
|
||||
@ -73,34 +107,126 @@ public class AsyncTaskComp {
|
||||
}
|
||||
|
||||
long end = System.currentTimeMillis();
|
||||
System.out.println("任务 deleteUserFile 耗时="+(end-begin));
|
||||
System.out.println("任务 deleteUserFile 耗时=" + (end - begin));
|
||||
return new AsyncResult<String>("deleteUserFile");
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Future<String> saveUnzipFile(UserFile userFile, FileBean fileBean, int unzipMode, String entryName, String filePath) {
|
||||
String unzipUrl = UFOPUtils.getTempFile(fileBean.getFileUrl()).getAbsolutePath().replace("." + userFile.getExtendName(), "");
|
||||
String totalFileUrl = unzipUrl + entryName;
|
||||
File currentFile = new File(totalFileUrl);
|
||||
|
||||
|
||||
UserFile saveUserFile = new UserFile();
|
||||
|
||||
saveUserFile.setUploadTime(DateUtil.getCurrentTime());
|
||||
saveUserFile.setUserId(userFile.getUserId());
|
||||
saveUserFile.setFilePath(UFOPUtils.pathSplitFormat(userFile.getFilePath() + entryName.replace(currentFile.getName(), "")).replace("\\", "/"));
|
||||
|
||||
if (currentFile.isDirectory()) {
|
||||
saveUserFile.setIsDir(1);
|
||||
saveUserFile.setFileName(currentFile.getName());
|
||||
} else {
|
||||
|
||||
FileInputStream fis = null;
|
||||
String md5Str = UUID.randomUUID().toString();
|
||||
try {
|
||||
fis = new FileInputStream(currentFile);
|
||||
md5Str = DigestUtils.md5Hex(fis);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
IOUtils.closeQuietly(fis);
|
||||
}
|
||||
|
||||
FileInputStream fileInputStream = null;
|
||||
try {
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("identifier", md5Str);
|
||||
List<FileBean> list = fileMapper.selectByMap(param);
|
||||
|
||||
if (list != null && !list.isEmpty()) { //文件已存在
|
||||
saveUserFile.setFileId(list.get(0).getFileId());
|
||||
} else { //文件不存在
|
||||
fileInputStream = new FileInputStream(currentFile);
|
||||
CopyFile createFile = new CopyFile();
|
||||
createFile.setExtendName(UFOPUtils.getFileExtendName(totalFileUrl));
|
||||
String saveFileUrl = ufopFactory.getCopier().copy(fileInputStream, createFile);
|
||||
|
||||
FileBean tempFileBean = new FileBean(saveFileUrl, currentFile.length(), storageType, md5Str, userFile.getUserId());
|
||||
;
|
||||
fileMapper.insert(tempFileBean);
|
||||
|
||||
saveUserFile.setFileId(tempFileBean.getFileId());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
IOUtils.closeQuietly(fileInputStream);
|
||||
System.gc();
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
currentFile.delete();
|
||||
}
|
||||
|
||||
saveUserFile.setIsDir(0);
|
||||
saveUserFile.setExtendName(UFOPUtils.getFileExtendName(totalFileUrl));
|
||||
saveUserFile.setFileName(UFOPUtils.getFileNameNotExtend(currentFile.getName()));
|
||||
|
||||
}
|
||||
|
||||
|
||||
saveUserFile.setDeleteFlag(0);
|
||||
|
||||
if (unzipMode == 1) {
|
||||
saveUserFile.setFilePath(UFOPUtils.pathSplitFormat(userFile.getFilePath() + userFile.getFileName() + "/" + entryName.replace(currentFile.getName(), "")).replace("\\", "/"));
|
||||
} else if (unzipMode == 2) {
|
||||
saveUserFile.setFilePath(UFOPUtils.pathSplitFormat(filePath + entryName.replace(currentFile.getName(), "")).replace("\\", "/"));
|
||||
}
|
||||
|
||||
String fileName = fileDealComp.getRepeatFileName(saveUserFile, saveUserFile.getFilePath());
|
||||
|
||||
if (saveUserFile.getIsDir() == 1 && !fileName.equals(saveUserFile.getFileName())) {
|
||||
//如果是目录,而且重复,什么也不做
|
||||
} else {
|
||||
saveUserFile.setFileName(fileName);
|
||||
userFileMapper.insert(saveUserFile);
|
||||
}
|
||||
|
||||
|
||||
return new AsyncResult<String>("saveUnzipFile");
|
||||
}
|
||||
|
||||
//获取异步结果
|
||||
public Future<String> task4() throws InterruptedException{
|
||||
public Future<String> task4() throws InterruptedException {
|
||||
long begin = System.currentTimeMillis();
|
||||
Thread.sleep(2000L);
|
||||
long end = System.currentTimeMillis();
|
||||
System.out.println("任务4耗时="+(end-begin));
|
||||
System.out.println("任务4耗时=" + (end - begin));
|
||||
return new AsyncResult<String>("任务4");
|
||||
}
|
||||
|
||||
|
||||
public Future<String> task5() throws InterruptedException{
|
||||
|
||||
|
||||
public Future<String> task5() throws InterruptedException {
|
||||
long begin = System.currentTimeMillis();
|
||||
Thread.sleep(3000L);
|
||||
long end = System.currentTimeMillis();
|
||||
System.out.println("任务5耗时="+(end-begin));
|
||||
System.out.println("任务5耗时=" + (end - begin));
|
||||
return new AsyncResult<String>("任务5");
|
||||
}
|
||||
|
||||
public Future<String> task6() throws InterruptedException{
|
||||
|
||||
public Future<String> task6() throws InterruptedException {
|
||||
long begin = System.currentTimeMillis();
|
||||
Thread.sleep(1000L);
|
||||
long end = System.currentTimeMillis();
|
||||
System.out.println("任务6耗时="+(end-begin));
|
||||
System.out.println("任务6耗时=" + (end - begin));
|
||||
return new AsyncResult<String>("任务6");
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -258,9 +258,10 @@ public class FileDealComp {
|
||||
public void uploadESByUserFileId(Long userFileId) {
|
||||
|
||||
try {
|
||||
UserFile userFile = new UserFile();
|
||||
userFile.setUserFileId(userFileId);
|
||||
List<FileListVo> userfileResult = userFileMapper.userFileList(userFile, null, null);
|
||||
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("userFileId", userFileId);
|
||||
List<UserFile> userfileResult = userFileMapper.selectByMap(param);
|
||||
if (userfileResult != null && userfileResult.size() > 0) {
|
||||
FileSearch fileSearch = new FileSearch();
|
||||
BeanUtil.copyProperties(userfileResult.get(0), fileSearch);
|
||||
|
@ -197,35 +197,13 @@ public class FileController {
|
||||
@Parameter(description = "当前页", required = true) long currentPage,
|
||||
@Parameter(description = "页面数量", required = true) long pageCount){
|
||||
|
||||
UserFile userFile = new UserFile();
|
||||
JwtUser sessionUserBean = SessionUtil.getSession();
|
||||
if (userFile == null) {
|
||||
return RestResult.fail();
|
||||
|
||||
}
|
||||
userFile.setUserId(sessionUserBean.getUserId());
|
||||
IPage<FileListVo> fileList = userFileService.userFileList(filePath, currentPage, pageCount);
|
||||
|
||||
|
||||
List<FileListVo> fileList = null;
|
||||
userFile.setFilePath(UFOPUtils.urlDecode(filePath));
|
||||
if (currentPage == 0 || pageCount == 0) {
|
||||
fileList = userFileService.userFileList(userFile, 0L, 10L);
|
||||
} else {
|
||||
long beginCount = (currentPage - 1) * pageCount;
|
||||
|
||||
fileList = userFileService.userFileList(userFile, beginCount, pageCount);
|
||||
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<UserFile> userFileLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
userFileLambdaQueryWrapper.eq(UserFile::getUserId, userFile.getUserId())
|
||||
.eq(UserFile::getFilePath, userFile.getFilePath())
|
||||
.eq(UserFile::getDeleteFlag, 0);
|
||||
long total = userFileService.count(userFileLambdaQueryWrapper);
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("total", total);
|
||||
map.put("list", fileList);
|
||||
map.put("total", fileList.getTotal());
|
||||
map.put("list", fileList.getRecords());
|
||||
|
||||
|
||||
return RestResult.success().data(map);
|
||||
@ -270,8 +248,6 @@ public class FileController {
|
||||
@ResponseBody
|
||||
public RestResult<String> unzipFile(@RequestBody UnzipFileDTO unzipFileDto) {
|
||||
|
||||
JwtUser sessionUserBean = SessionUtil.getSession();
|
||||
|
||||
try {
|
||||
fileService.unzipFile(unzipFileDto.getUserFileId(), unzipFileDto.getUnzipMode(), unzipFileDto.getFilePath());
|
||||
} catch (QiwenException e) {
|
||||
|
@ -41,7 +41,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Tag(name = "filetransfer", description = "该接口为文件传输接口,主要用来做文件的上传和下载")
|
||||
@Tag(name = "filetransfer", description = "该接口为文件传输接口,主要用来做文件的上传、下载和预览")
|
||||
@RestController
|
||||
@RequestMapping("/filetransfer")
|
||||
public class FiletransferController {
|
||||
@ -83,77 +83,7 @@ public class FiletransferController {
|
||||
if (!isCheckSuccess) {
|
||||
return RestResult.fail().message("存储空间不足");
|
||||
}
|
||||
|
||||
UploadFileVo uploadFileVo = new UploadFileVo();
|
||||
Map<String, Object> param = new HashMap<String, Object>();
|
||||
param.put("identifier", uploadFileDto.getIdentifier());
|
||||
|
||||
List<FileBean> list = fileService.listByMap(param);
|
||||
if (list != null && !list.isEmpty()) {
|
||||
FileBean file = list.get(0);
|
||||
|
||||
UserFile userFile = new UserFile();
|
||||
|
||||
userFile.setUserId(sessionUserBean.getUserId());
|
||||
String relativePath = uploadFileDto.getRelativePath();
|
||||
if (relativePath.contains("/")) {
|
||||
userFile.setFilePath(uploadFileDto.getFilePath() + UFOPUtils.getParentPath(relativePath) + "/");
|
||||
fileDealComp.restoreParentFilePath(uploadFileDto.getFilePath() + UFOPUtils.getParentPath(relativePath) + "/", sessionUserBean.getUserId());
|
||||
fileDealComp.deleteRepeatSubDirFile(uploadFileDto.getFilePath(), sessionUserBean.getUserId());
|
||||
} else {
|
||||
userFile.setFilePath(uploadFileDto.getFilePath());
|
||||
}
|
||||
|
||||
String fileName = uploadFileDto.getFilename();
|
||||
userFile.setFileName(UFOPUtils.getFileNameNotExtend(fileName));
|
||||
userFile.setExtendName(UFOPUtils.getFileExtendName(fileName));
|
||||
userFile.setDeleteFlag(0);
|
||||
List<FileListVo> userFileList = userFileService.userFileList(userFile, null, null);
|
||||
if (userFileList.size() <= 0) {
|
||||
|
||||
userFile.setIsDir(0);
|
||||
userFile.setUploadTime(DateUtil.getCurrentTime());
|
||||
userFile.setFileId(file.getFileId());
|
||||
//"fileName", "filePath", "extendName", "deleteFlag", "userId"
|
||||
|
||||
userFileService.save(userFile);
|
||||
// fileService.increaseFilePointCount(file.getFileId());
|
||||
fileDealComp.uploadESByUserFileId(userFile.getUserFileId());
|
||||
}
|
||||
|
||||
uploadFileVo.setSkipUpload(true);
|
||||
|
||||
} else {
|
||||
uploadFileVo.setSkipUpload(false);
|
||||
|
||||
List<Integer> uploaded = uploadTaskDetailService.getUploadedChunkNumList(uploadFileDto.getIdentifier());
|
||||
if (uploaded != null && !uploaded.isEmpty()) {
|
||||
uploadFileVo.setUploaded(uploaded);
|
||||
} else {
|
||||
|
||||
LambdaQueryWrapper<UploadTask> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(UploadTask::getIdentifier, uploadFileDto.getIdentifier());
|
||||
List<UploadTask> rslist = uploadTaskService.list(lambdaQueryWrapper);
|
||||
if (rslist == null || rslist.isEmpty()) {
|
||||
UploadTask uploadTask = new UploadTask();
|
||||
uploadTask.setIdentifier(uploadFileDto.getIdentifier());
|
||||
uploadTask.setUploadTime(DateUtil.getCurrentTime());
|
||||
uploadTask.setUploadStatus(UploadFileStatusEnum.UNCOMPLATE.getCode());
|
||||
uploadTask.setFileName(uploadFileDto.getFilename());
|
||||
String relativePath = uploadFileDto.getRelativePath();
|
||||
if (relativePath.contains("/")) {
|
||||
uploadTask.setFilePath(uploadFileDto.getFilePath() + UFOPUtils.getParentPath(relativePath) + "/");
|
||||
} else {
|
||||
uploadTask.setFilePath(uploadFileDto.getFilePath());
|
||||
}
|
||||
uploadTask.setExtendName(uploadTask.getExtendName());
|
||||
uploadTask.setUserId(sessionUserBean.getUserId());
|
||||
|
||||
uploadTaskService.save(uploadTask);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
UploadFileVo uploadFileVo = filetransferService.uploadFileSpeed(uploadFileDto);
|
||||
return RestResult.success().data(uploadFileVo);
|
||||
|
||||
}
|
||||
|
@ -106,7 +106,6 @@ public class OfficeController {
|
||||
fileBean.setFileSize(0L);
|
||||
fileBean.setFileUrl(fileUrl);
|
||||
fileBean.setStorageType(storageType);
|
||||
// fileBean.setPointCount(1);
|
||||
fileBean.setIdentifier(uuid);
|
||||
fileBean.setCreateTime(DateUtil.getCurrentTime());
|
||||
fileBean.setCreateUserId(loginUser.getUserId());
|
||||
|
@ -7,7 +7,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.qiwenshare.common.anno.MyLog;
|
||||
import com.qiwenshare.common.result.RestResult;
|
||||
import com.qiwenshare.common.util.DateUtil;
|
||||
import com.qiwenshare.file.api.*;
|
||||
import com.qiwenshare.file.api.IShareFileService;
|
||||
import com.qiwenshare.file.api.IShareService;
|
||||
import com.qiwenshare.file.api.IUserFileService;
|
||||
import com.qiwenshare.file.component.FileDealComp;
|
||||
import com.qiwenshare.file.config.security.user.JwtUser;
|
||||
import com.qiwenshare.file.domain.Share;
|
||||
@ -36,15 +38,12 @@ import java.util.*;
|
||||
public class ShareController {
|
||||
|
||||
public static final String CURRENT_MODULE = "文件分享";
|
||||
@Resource
|
||||
IUserService userService;
|
||||
|
||||
@Resource
|
||||
IShareFileService shareFileService;
|
||||
@Resource
|
||||
IShareService shareService;
|
||||
@Resource
|
||||
IFileService fileService;
|
||||
@Resource
|
||||
IUserFileService userFileService;
|
||||
@Resource
|
||||
FileDealComp fileDealComp;
|
||||
@ -129,12 +128,8 @@ public class ShareController {
|
||||
p.setFilePath(p.getFilePath().replaceFirst(filePath + fileName, savefilePath + savefileName));
|
||||
saveUserFileList.add(p);
|
||||
log.info("当前文件:" + JSON.toJSONString(p));
|
||||
if (p.getIsDir() == 0) {
|
||||
// fileService.increaseFilePointCount(p.getFileId());
|
||||
}
|
||||
|
||||
});
|
||||
} else {
|
||||
// fileService.increaseFilePointCount(userFile.getFileId());
|
||||
}
|
||||
userFile.setUserFileId(null);
|
||||
userFile.setUserId(userId);
|
||||
|
@ -1,42 +1,23 @@
|
||||
package com.qiwenshare.file.controller;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.qiwenshare.file.api.IElasticSearchService;
|
||||
import com.qiwenshare.file.component.FileDealComp;
|
||||
import com.qiwenshare.file.config.es.FileSearch;
|
||||
import com.qiwenshare.file.domain.FileBean;
|
||||
import com.qiwenshare.file.domain.UserFile;
|
||||
import com.qiwenshare.file.service.FileService;
|
||||
import com.qiwenshare.file.service.FiletransferService;
|
||||
import com.qiwenshare.file.service.UserFileService;
|
||||
import com.qiwenshare.file.service.UserService;
|
||||
import com.qiwenshare.file.vo.file.FileListVo;
|
||||
import com.qiwenshare.ufop.factory.UFOPFactory;
|
||||
import com.qiwenshare.ufop.operation.read.Reader;
|
||||
import com.qiwenshare.ufop.operation.read.domain.ReadFile;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.catalina.User;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Controller
|
||||
public class TaskController {
|
||||
|
||||
@Resource
|
||||
FileService fileService;
|
||||
@Resource
|
||||
UserFileService userFileService;
|
||||
@Resource
|
||||
FiletransferService filetransferService;
|
||||
@Autowired
|
||||
private IElasticSearchService elasticSearchService;
|
||||
@Resource
|
||||
|
@ -19,7 +19,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.lang3.StringUtils;
|
||||
import org.apache.shiro.crypto.hash.SimpleHash;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
@ -3,6 +3,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 com.qiwenshare.common.util.DateUtil;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
@ -51,4 +52,19 @@ public class FileBean {
|
||||
@Column(columnDefinition="bigint(20)")
|
||||
private Long modifyUserId;
|
||||
|
||||
public FileBean(){
|
||||
|
||||
}
|
||||
|
||||
public FileBean(String fileUrl, Long fileSize, Integer storageType, String identifier, Long userId) {
|
||||
this.fileUrl = fileUrl;
|
||||
this.fileSize = fileSize;
|
||||
this.fileStatus = 1;
|
||||
this.storageType = storageType;
|
||||
this.identifier = identifier;
|
||||
this.createTime = DateUtil.getCurrentTime();
|
||||
this.createUserId = userId;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ import java.util.Map;
|
||||
|
||||
public interface UserFileMapper extends BaseMapper<UserFile> {
|
||||
void replaceFilePath(@Param("filePath") String filePath, @Param("oldFilePath") String oldFilePath, @Param("userId") Long userId);
|
||||
List<FileListVo> userFileList(@Param("userFile") UserFile userFile, Long beginCount, Long pageCount);
|
||||
|
||||
void updateFilepathByPathAndName(String oldfilePath, String newfilePath, String fileName, String extendName, long userId);
|
||||
void updateFilepathByFilepath(String oldfilePath, String newfilePath, long userId);
|
||||
@ -29,9 +28,6 @@ public interface UserFileMapper extends BaseMapper<UserFile> {
|
||||
@Param("newFilePath") String newfilePath,
|
||||
@Param("userId") long userId);
|
||||
|
||||
IPage<FileListVo> selectFileByExtendName(Page<?> page, List<String> fileNameList, long userId);
|
||||
Long selectCountByExtendName(List<String> fileNameList, Long beginCount, Long pageCount, long userId);
|
||||
List<FileListVo> selectFileNotInExtendNames(List<String> fileNameList, Long beginCount, Long pageCount, long userId);
|
||||
Long selectCountNotInExtendNames(List<String> fileNameList, Long beginCount, Long pageCount, long userId);
|
||||
IPage<FileListVo> selectPageVo(Page<?> page, @Param("userFile") UserFile userFile, @Param("extendNameList") List<String> extendNameList);
|
||||
Long selectStorageSizeByUserId(@Param("userId") Long userId);
|
||||
}
|
||||
|
@ -3,22 +3,19 @@ package com.qiwenshare.file.service;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.qiwenshare.common.operation.FileOperation;
|
||||
import com.qiwenshare.common.util.DateUtil;
|
||||
import com.qiwenshare.file.advice.QiwenException;
|
||||
import com.qiwenshare.file.api.IFileService;
|
||||
import com.qiwenshare.file.component.FileDealComp;
|
||||
import com.qiwenshare.file.component.AsyncTaskComp;
|
||||
import com.qiwenshare.file.domain.FileBean;
|
||||
import com.qiwenshare.file.domain.UserFile;
|
||||
import com.qiwenshare.file.mapper.FileMapper;
|
||||
import com.qiwenshare.file.mapper.UserFileMapper;
|
||||
import com.qiwenshare.file.util.QiwenFileUtil;
|
||||
import com.qiwenshare.ufop.factory.UFOPFactory;
|
||||
import com.qiwenshare.ufop.operation.copy.domain.CopyFile;
|
||||
import com.qiwenshare.ufop.operation.download.Downloader;
|
||||
import com.qiwenshare.ufop.operation.download.domain.DownloadFile;
|
||||
import com.qiwenshare.ufop.util.UFOPUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -26,13 +23,10 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
@ -47,12 +41,12 @@ public class FileService extends ServiceImpl<FileMapper, FileBean> implements IF
|
||||
UserFileMapper userFileMapper;
|
||||
@Resource
|
||||
UFOPFactory ufopFactory;
|
||||
|
||||
@Value("${ufop.storage-type}")
|
||||
private Integer storageType;
|
||||
|
||||
@Resource
|
||||
FileDealComp fileDealComp;
|
||||
|
||||
AsyncTaskComp asyncTaskComp;
|
||||
|
||||
@Override
|
||||
public Long getFilePointCount(Long fileId) {
|
||||
@ -110,103 +104,7 @@ public class FileService extends ServiceImpl<FileMapper, FileBean> implements IF
|
||||
}
|
||||
for (int i = 0; i < fileEntryNameList.size(); i++){
|
||||
String entryName = fileEntryNameList.get(i);
|
||||
log.info("文件名:"+ entryName);
|
||||
executor.execute(() -> {
|
||||
String totalFileUrl = unzipUrl + entryName;
|
||||
File currentFile = new File(totalFileUrl);
|
||||
|
||||
FileBean tempFileBean = new FileBean();
|
||||
UserFile saveUserFile = new UserFile();
|
||||
|
||||
saveUserFile.setUploadTime(DateUtil.getCurrentTime());
|
||||
saveUserFile.setUserId(userFile.getUserId());
|
||||
saveUserFile.setFilePath(UFOPUtils.pathSplitFormat(userFile.getFilePath() + entryName.replace(currentFile.getName(), "")).replace("\\", "/"));
|
||||
|
||||
if (currentFile.isDirectory()){
|
||||
saveUserFile.setIsDir(1);
|
||||
saveUserFile.setFileName(currentFile.getName());
|
||||
}else{
|
||||
|
||||
FileInputStream fileInputStream = null;
|
||||
FileInputStream fileInputStream1 = null;
|
||||
try {
|
||||
fileInputStream = new FileInputStream(currentFile);
|
||||
String md5Str = DigestUtils.md5Hex(fileInputStream);
|
||||
Map<String, Object> param = new HashMap<String, Object>();
|
||||
param.put("identifier", md5Str);
|
||||
|
||||
List<FileBean> list = fileMapper.selectByMap(param);
|
||||
if (list != null && !list.isEmpty()) { //文件已存在
|
||||
saveUserFile.setFileId(list.get(0).getFileId());
|
||||
} else { //文件不存在
|
||||
fileInputStream1 = new FileInputStream(currentFile);
|
||||
CopyFile createFile = new CopyFile();
|
||||
createFile.setExtendName(UFOPUtils.getFileExtendName(totalFileUrl));
|
||||
String saveFileUrl = ufopFactory.getCopier().copy(fileInputStream1, createFile);
|
||||
tempFileBean.setFileSize(currentFile.length());
|
||||
tempFileBean.setFileUrl(saveFileUrl);
|
||||
tempFileBean.setStorageType(storageType);
|
||||
tempFileBean.setIdentifier(md5Str);
|
||||
fileMapper.insert(tempFileBean);
|
||||
|
||||
saveUserFile.setFileId(tempFileBean.getFileId());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (fileInputStream != null) {
|
||||
try {
|
||||
log.info("关闭流");
|
||||
fileInputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (fileInputStream1 != null) {
|
||||
try {
|
||||
log.info("关闭流");
|
||||
fileInputStream1.close();
|
||||
|
||||
System.gc();
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
currentFile.delete();
|
||||
}
|
||||
}
|
||||
|
||||
saveUserFile.setIsDir(0);
|
||||
saveUserFile.setExtendName(UFOPUtils.getFileExtendName(totalFileUrl));
|
||||
saveUserFile.setFileName(UFOPUtils.getFileNameNotExtend(currentFile.getName()));
|
||||
|
||||
}
|
||||
|
||||
|
||||
saveUserFile.setDeleteFlag(0);
|
||||
|
||||
if (unzipMode == 1) {
|
||||
saveUserFile.setFilePath(UFOPUtils.pathSplitFormat(userFile.getFilePath() + userFile.getFileName() + "/" + entryName.replace(currentFile.getName(), "")).replace("\\", "/"));
|
||||
} else if(unzipMode == 2) {
|
||||
saveUserFile.setFilePath(UFOPUtils.pathSplitFormat(filePath + entryName.replace(currentFile.getName(), "")).replace("\\", "/"));
|
||||
}
|
||||
|
||||
String fileName = fileDealComp.getRepeatFileName(saveUserFile, saveUserFile.getFilePath());
|
||||
|
||||
if (saveUserFile.getIsDir() == 1 && !fileName.equals(saveUserFile.getFileName())) {
|
||||
//如果是目录,而且重复,什么也不做
|
||||
} else {
|
||||
saveUserFile.setFileName(fileName);
|
||||
userFileMapper.insert(saveUserFile);
|
||||
}
|
||||
|
||||
});
|
||||
asyncTaskComp.saveUnzipFile(userFile, fileBean, unzipMode, entryName, filePath);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -2,16 +2,20 @@ package com.qiwenshare.file.service;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
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.qiwenshare.common.util.DateUtil;
|
||||
import com.qiwenshare.file.api.IFiletransferService;
|
||||
import com.qiwenshare.file.component.FileDealComp;
|
||||
import com.qiwenshare.file.config.security.user.JwtUser;
|
||||
import com.qiwenshare.file.domain.*;
|
||||
import com.qiwenshare.file.dto.file.DownloadFileDTO;
|
||||
import com.qiwenshare.file.dto.file.PreviewDTO;
|
||||
import com.qiwenshare.file.dto.file.UploadFileDTO;
|
||||
import com.qiwenshare.file.mapper.*;
|
||||
import com.qiwenshare.file.util.SessionUtil;
|
||||
import com.qiwenshare.file.vo.file.FileListVo;
|
||||
import com.qiwenshare.file.vo.file.UploadFileVo;
|
||||
import com.qiwenshare.ufop.constant.StorageTypeEnum;
|
||||
import com.qiwenshare.ufop.constant.UploadFileStatusEnum;
|
||||
import com.qiwenshare.ufop.exception.operation.DownloadException;
|
||||
@ -36,7 +40,9 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.zip.Adler32;
|
||||
import java.util.zip.CheckedOutputStream;
|
||||
import java.util.zip.ZipEntry;
|
||||
@ -47,8 +53,6 @@ import java.util.zip.ZipOutputStream;
|
||||
@Transactional(rollbackFor=Exception.class)
|
||||
public class FiletransferService implements IFiletransferService {
|
||||
|
||||
@Resource
|
||||
StorageMapper storageMapper;
|
||||
@Resource
|
||||
FileMapper fileMapper;
|
||||
|
||||
@ -60,12 +64,87 @@ public class FiletransferService implements IFiletransferService {
|
||||
@Resource
|
||||
FileDealComp fileDealComp;
|
||||
@Resource
|
||||
UploadTaskDetailMapper UploadTaskDetailMapper;
|
||||
UploadTaskDetailMapper uploadTaskDetailMapper;
|
||||
@Resource
|
||||
UploadTaskMapper uploadTaskMapper;
|
||||
@Resource
|
||||
ImageMapper imageMapper;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public UploadFileVo uploadFileSpeed(UploadFileDTO uploadFileDTO) {
|
||||
UploadFileVo uploadFileVo = new UploadFileVo();
|
||||
JwtUser sessionUserBean = SessionUtil.getSession();
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("identifier", uploadFileDTO.getIdentifier());
|
||||
List<FileBean> list = fileMapper.selectByMap(param);
|
||||
|
||||
if (list != null && !list.isEmpty()) {
|
||||
FileBean file = list.get(0);
|
||||
|
||||
UserFile userFile = new UserFile();
|
||||
|
||||
userFile.setUserId(sessionUserBean.getUserId());
|
||||
String relativePath = uploadFileDTO.getRelativePath();
|
||||
if (relativePath.contains("/")) {
|
||||
userFile.setFilePath(uploadFileDTO.getFilePath() + UFOPUtils.getParentPath(relativePath) + "/");
|
||||
fileDealComp.restoreParentFilePath(uploadFileDTO.getFilePath() + UFOPUtils.getParentPath(relativePath) + "/", sessionUserBean.getUserId());
|
||||
fileDealComp.deleteRepeatSubDirFile(uploadFileDTO.getFilePath(), sessionUserBean.getUserId());
|
||||
} else {
|
||||
userFile.setFilePath(uploadFileDTO.getFilePath());
|
||||
}
|
||||
|
||||
String fileName = uploadFileDTO.getFilename();
|
||||
userFile.setFileName(UFOPUtils.getFileNameNotExtend(fileName));
|
||||
userFile.setExtendName(UFOPUtils.getFileExtendName(fileName));
|
||||
userFile.setDeleteFlag(0);
|
||||
|
||||
List<UserFile> userFileList = userFileMapper.selectList(new QueryWrapper<>(userFile));
|
||||
if (userFileList.size() <= 0) {
|
||||
|
||||
userFile.setIsDir(0);
|
||||
userFile.setUploadTime(DateUtil.getCurrentTime());
|
||||
userFile.setFileId(file.getFileId());
|
||||
userFileMapper.insert(userFile);
|
||||
fileDealComp.uploadESByUserFileId(userFile.getUserFileId());
|
||||
}
|
||||
|
||||
uploadFileVo.setSkipUpload(true);
|
||||
|
||||
} else {
|
||||
uploadFileVo.setSkipUpload(false);
|
||||
|
||||
List<Integer> uploaded = uploadTaskDetailMapper.selectUploadedChunkNumList(uploadFileDTO.getIdentifier());
|
||||
if (uploaded != null && !uploaded.isEmpty()) {
|
||||
uploadFileVo.setUploaded(uploaded);
|
||||
} else {
|
||||
|
||||
LambdaQueryWrapper<UploadTask> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(UploadTask::getIdentifier, uploadFileDTO.getIdentifier());
|
||||
List<UploadTask> rslist = uploadTaskMapper.selectList(lambdaQueryWrapper);
|
||||
if (rslist == null || rslist.isEmpty()) {
|
||||
UploadTask uploadTask = new UploadTask();
|
||||
uploadTask.setIdentifier(uploadFileDTO.getIdentifier());
|
||||
uploadTask.setUploadTime(DateUtil.getCurrentTime());
|
||||
uploadTask.setUploadStatus(UploadFileStatusEnum.UNCOMPLATE.getCode());
|
||||
uploadTask.setFileName(uploadFileDTO.getFilename());
|
||||
String relativePath = uploadFileDTO.getRelativePath();
|
||||
if (relativePath.contains("/")) {
|
||||
uploadTask.setFilePath(uploadFileDTO.getFilePath() + UFOPUtils.getParentPath(relativePath) + "/");
|
||||
} else {
|
||||
uploadTask.setFilePath(uploadFileDTO.getFilePath());
|
||||
}
|
||||
uploadTask.setExtendName(uploadTask.getExtendName());
|
||||
uploadTask.setUserId(sessionUserBean.getUserId());
|
||||
uploadTaskMapper.insert(uploadTask);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return uploadFileVo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uploadFile(HttpServletRequest request, UploadFileDTO uploadFileDto, Long userId) {
|
||||
|
||||
@ -113,7 +192,7 @@ public class FiletransferService implements IFiletransferService {
|
||||
userFile.setExtendName(uploadFileResult.getExtendName());
|
||||
userFile.setDeleteFlag(0);
|
||||
userFile.setIsDir(0);
|
||||
List<FileListVo> userFileList = userFileMapper.userFileList(userFile, null, null);
|
||||
List<UserFile> userFileList = userFileMapper.selectList(new QueryWrapper<>(userFile));
|
||||
if (userFileList.size() > 0) {
|
||||
String fileName = fileDealComp.getRepeatFileName(userFile, uploadFileDto.getFilePath());
|
||||
userFile.setFileName(fileName);
|
||||
@ -127,7 +206,7 @@ public class FiletransferService implements IFiletransferService {
|
||||
|
||||
LambdaQueryWrapper<UploadTaskDetail> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(UploadTaskDetail::getIdentifier, uploadFileDto.getIdentifier());
|
||||
UploadTaskDetailMapper.delete(lambdaQueryWrapper);
|
||||
uploadTaskDetailMapper.delete(lambdaQueryWrapper);
|
||||
|
||||
LambdaUpdateWrapper<UploadTask> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||
lambdaUpdateWrapper.set(UploadTask::getUploadStatus, UploadFileStatusEnum.SUCCESS.getCode())
|
||||
@ -143,26 +222,26 @@ public class FiletransferService implements IFiletransferService {
|
||||
}
|
||||
|
||||
} else if (UploadFileStatusEnum.UNCOMPLATE.equals(uploadFileResult.getStatus())) {
|
||||
UploadTaskDetail UploadTaskDetail = new UploadTaskDetail();
|
||||
UploadTaskDetail.setFilePath(uploadFileDto.getFilePath());
|
||||
UploadTaskDetail uploadTaskDetail = new UploadTaskDetail();
|
||||
uploadTaskDetail.setFilePath(uploadFileDto.getFilePath());
|
||||
if (relativePath.contains("/")) {
|
||||
UploadTaskDetail.setFilePath(uploadFileDto.getFilePath() + UFOPUtils.getParentPath(relativePath) + "/");
|
||||
uploadTaskDetail.setFilePath(uploadFileDto.getFilePath() + UFOPUtils.getParentPath(relativePath) + "/");
|
||||
} else {
|
||||
UploadTaskDetail.setFilePath(uploadFileDto.getFilePath());
|
||||
uploadTaskDetail.setFilePath(uploadFileDto.getFilePath());
|
||||
}
|
||||
UploadTaskDetail.setFilename(uploadFileDto.getFilename());
|
||||
UploadTaskDetail.setChunkNumber(uploadFileDto.getChunkNumber());
|
||||
UploadTaskDetail.setChunkSize((int)uploadFileDto.getChunkSize());
|
||||
UploadTaskDetail.setRelativePath(uploadFileDto.getRelativePath());
|
||||
UploadTaskDetail.setTotalChunks(uploadFileDto.getTotalChunks());
|
||||
UploadTaskDetail.setTotalSize((int)uploadFileDto.getTotalSize());
|
||||
UploadTaskDetail.setIdentifier(uploadFileDto.getIdentifier());
|
||||
UploadTaskDetailMapper.insert(UploadTaskDetail);
|
||||
uploadTaskDetail.setFilename(uploadFileDto.getFilename());
|
||||
uploadTaskDetail.setChunkNumber(uploadFileDto.getChunkNumber());
|
||||
uploadTaskDetail.setChunkSize((int)uploadFileDto.getChunkSize());
|
||||
uploadTaskDetail.setRelativePath(uploadFileDto.getRelativePath());
|
||||
uploadTaskDetail.setTotalChunks(uploadFileDto.getTotalChunks());
|
||||
uploadTaskDetail.setTotalSize((int)uploadFileDto.getTotalSize());
|
||||
uploadTaskDetail.setIdentifier(uploadFileDto.getIdentifier());
|
||||
uploadTaskDetailMapper.insert(uploadTaskDetail);
|
||||
|
||||
} else if (UploadFileStatusEnum.FAIL.equals(uploadFileResult.getStatus())) {
|
||||
LambdaQueryWrapper<UploadTaskDetail> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(UploadTaskDetail::getIdentifier, uploadFileDto.getIdentifier());
|
||||
UploadTaskDetailMapper.delete(lambdaQueryWrapper);
|
||||
uploadTaskDetailMapper.delete(lambdaQueryWrapper);
|
||||
|
||||
LambdaUpdateWrapper<UploadTask> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||
lambdaUpdateWrapper.set(UploadTask::getUploadStatus, UploadFileStatusEnum.FAIL.getCode())
|
||||
@ -329,34 +408,7 @@ public class FiletransferService implements IFiletransferService {
|
||||
deleter.delete(deleteFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageBean selectStorageBean(StorageBean storageBean) {
|
||||
LambdaQueryWrapper<StorageBean> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(StorageBean::getUserId, storageBean.getUserId());
|
||||
return storageMapper.selectOne(lambdaQueryWrapper);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertStorageBean(StorageBean storageBean) {
|
||||
storageMapper.insert(storageBean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStorageBean(StorageBean storageBean) {
|
||||
LambdaUpdateWrapper<StorageBean> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||
lambdaUpdateWrapper.set(StorageBean::getStorageSize, storageBean.getStorageSize())
|
||||
.eq(StorageBean::getStorageId, storageBean.getStorageId())
|
||||
.eq(StorageBean::getUserId, storageBean.getUserId());
|
||||
storageMapper.update(null, lambdaUpdateWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageBean selectStorageByUser(StorageBean storageBean) {
|
||||
LambdaQueryWrapper<StorageBean> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(StorageBean::getUserId, storageBean.getUserId());
|
||||
return storageMapper.selectOne(lambdaQueryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long selectStorageSizeByUserId(Long userId){
|
||||
|
@ -11,10 +11,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @author: xxxg
|
||||
* @date: 2021/11/18 10:45
|
||||
*/
|
||||
|
||||
@Service
|
||||
public class NoticeService extends ServiceImpl<NoticeMapper, Notice> implements INoticeService {
|
||||
@Resource
|
||||
|
@ -9,13 +9,16 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.qiwenshare.common.constant.FileConstant;
|
||||
import com.qiwenshare.common.util.DateUtil;
|
||||
import com.qiwenshare.file.api.IUserFileService;
|
||||
import com.qiwenshare.file.config.security.user.JwtUser;
|
||||
import com.qiwenshare.file.domain.RecoveryFile;
|
||||
import com.qiwenshare.file.domain.UserFile;
|
||||
import com.qiwenshare.file.mapper.FileMapper;
|
||||
import com.qiwenshare.file.mapper.FileTypeMapper;
|
||||
import com.qiwenshare.file.mapper.RecoveryFileMapper;
|
||||
import com.qiwenshare.file.mapper.UserFileMapper;
|
||||
import com.qiwenshare.file.util.SessionUtil;
|
||||
import com.qiwenshare.file.vo.file.FileListVo;
|
||||
import com.qiwenshare.ufop.util.UFOPUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -85,8 +88,15 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileListVo> userFileList(UserFile userFile, Long beginCount, Long pageCount) {
|
||||
return userFileMapper.userFileList(userFile, beginCount, pageCount);
|
||||
public IPage<FileListVo> userFileList(String filePath, Long currentPage, Long pageCount) {
|
||||
Page<FileListVo> page = new Page<>(currentPage, pageCount);
|
||||
UserFile userFile = new UserFile();
|
||||
JwtUser sessionUserBean = SessionUtil.getSession();
|
||||
|
||||
userFile.setUserId(sessionUserBean.getUserId());
|
||||
userFile.setFilePath(UFOPUtils.urlDecode(filePath));
|
||||
|
||||
return userFileMapper.selectPageVo(page, userFile, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -140,7 +150,6 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IPage<FileListVo> getFileByFileType(Integer fileTypeId, Long currentPage, Long pageCount, long userId) {
|
||||
Page<FileListVo> page = new Page<>(currentPage, pageCount);
|
||||
@ -149,22 +158,9 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
||||
if (extendNameList != null && extendNameList.isEmpty()) {
|
||||
return page;
|
||||
}
|
||||
return userFileMapper.selectFileByExtendName(page, extendNameList, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long selectCountByExtendName(List<String> fileNameList, Long beginCount, Long pageCount, long userId) {
|
||||
return userFileMapper.selectCountByExtendName(fileNameList, beginCount, pageCount, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileListVo> selectFileNotInExtendNames(List<String> fileNameList, Long beginCount, Long pageCount, long userId) {
|
||||
return userFileMapper.selectFileNotInExtendNames(fileNameList, beginCount, pageCount, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long selectCountNotInExtendNames(List<String> fileNameList, Long beginCount, Long pageCount, long userId) {
|
||||
return userFileMapper.selectCountNotInExtendNames(fileNameList, beginCount, pageCount, userId);
|
||||
UserFile userFile = new UserFile();
|
||||
userFile.setUserId(userId);
|
||||
return userFileMapper.selectPageVo(page, userFile, extendNameList);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,7 +21,6 @@ public class OperationLogUtil {
|
||||
*/
|
||||
public static OperationLogBean getOperationLogObj(HttpServletRequest request, Long userId, String isSuccess, String source, String operation, String detail) {
|
||||
|
||||
// UserBean sessionUserBean = (UserBean) SecurityUtils.getSubject().getPrincipal();
|
||||
//用户需要登录才能进行的操作,需要记录操作日志
|
||||
OperationLogBean operationLogBean = new OperationLogBean();
|
||||
operationLogBean.setUserId(userId);
|
||||
|
@ -18,4 +18,5 @@ public class QiwenFileUtil {
|
||||
userFile.setDeleteBatchNum(null);
|
||||
return userFile;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,11 +11,18 @@
|
||||
WHERE filepath LIKE N'${oldFilePath}%' and userId = #{userId};
|
||||
</update>
|
||||
|
||||
<select id="userFileList" resultType="com.qiwenshare.file.vo.file.FileListVo">
|
||||
|
||||
<select id="selectPageVo" parameterType="com.qiwenshare.file.domain.UserFile" resultType="com.qiwenshare.file.vo.file.FileListVo">
|
||||
select * from userfile a
|
||||
left join file on file.fileId = a.fileId
|
||||
left join image on a.fileId = image.fileId
|
||||
left join file on file.fileId = a.fileId
|
||||
<where>
|
||||
<if test="extendNameList != null and extendNameList.size() > 0">
|
||||
extendName in
|
||||
<foreach collection="extendNameList" open="(" close=")" separator="," item="extendName" >
|
||||
#{extendName}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="userFile.userId != null">
|
||||
and a.userId = #{userFile.userId}
|
||||
</if>
|
||||
@ -33,56 +40,7 @@
|
||||
</if>
|
||||
and a.deleteFlag = 0
|
||||
</where>
|
||||
ORDER BY isDir desc
|
||||
<if test="beginCount != null and pageCount != null">
|
||||
limit #{beginCount}, #{pageCount}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<sql id="selectByExtendName" >
|
||||
left join file on file.fileId = userfile.fileId
|
||||
where extendName in
|
||||
<foreach collection="fileNameList" open="(" close=")" separator="," item="fileName" >
|
||||
#{fileName}
|
||||
</foreach>
|
||||
and userId = #{userId}
|
||||
and deleteFlag = 0
|
||||
</sql>
|
||||
<sql id="selectByNotExtendName">
|
||||
left join file on file.fileId = userfile.fileId
|
||||
where extendName not in
|
||||
<foreach collection="fileNameList" open="(" close=")" separator="," item="fileName" >
|
||||
#{fileName}
|
||||
</foreach>
|
||||
and userId = #{userId}
|
||||
and deleteFlag = 0
|
||||
</sql>
|
||||
<select id="selectFileByExtendName" parameterType="com.qiwenshare.file.domain.UserFile" resultType="com.qiwenshare.file.vo.file.FileListVo">
|
||||
select * from userfile
|
||||
left join image on userfile.fileId = image.fileId
|
||||
left join file on file.fileId = userfile.fileId
|
||||
where extendName in
|
||||
<foreach collection="fileNameList" open="(" close=")" separator="," item="fileName" >
|
||||
#{fileName}
|
||||
</foreach>
|
||||
and userId = #{userId}
|
||||
and deleteFlag = 0
|
||||
</select>
|
||||
|
||||
<select id="selectCountByExtendName" parameterType="com.qiwenshare.file.domain.UserFile" resultType="java.lang.Long">
|
||||
select count(*) from userfile
|
||||
<include refid="selectByExtendName"></include>
|
||||
</select>
|
||||
|
||||
<select id="selectFileNotInExtendNames" parameterType="com.qiwenshare.file.domain.UserFile" resultType="com.qiwenshare.file.vo.file.FileListVo">
|
||||
select * from userfile
|
||||
<include refid="selectByNotExtendName"></include>
|
||||
limit #{beginCount}, #{pageCount}
|
||||
</select>
|
||||
|
||||
<select id="selectCountNotInExtendNames" parameterType="com.qiwenshare.file.domain.UserFile" resultType="java.lang.Long">
|
||||
select count(*) from userfile
|
||||
<include refid="selectByNotExtendName"></include>
|
||||
ORDER BY isDir desc
|
||||
</select>
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user