use of com.qiwenshare.file.domain.UserFile in project qiwen-file by qiwenshare.
the class FileController method batchMoveFile.
@Operation(summary = "批量移动文件", description = "可以同时选择移动多个文件或者目录", tags = { "file" })
@RequestMapping(value = "/batchmovefile", method = RequestMethod.POST)
@MyLog(operation = "批量移动文件", module = CURRENT_MODULE)
@ResponseBody
public RestResult<String> batchMoveFile(@RequestBody BatchMoveFileDTO batchMoveFileDto) {
JwtUser sessionUserBean = SessionUtil.getSession();
String files = batchMoveFileDto.getFiles();
String newfilePath = batchMoveFileDto.getFilePath();
List<UserFile> fileList = JSON.parseArray(files, UserFile.class);
for (UserFile userFile : fileList) {
if (StringUtil.isEmpty(userFile.getExtendName())) {
String testFilePath = userFile.getFilePath() + userFile.getFileName() + "/";
if (newfilePath.startsWith(testFilePath)) {
return RestResult.fail().message("原路径与目标路径冲突,不能移动");
}
}
userFileService.updateFilepathByFilepath(userFile.getFilePath(), newfilePath, userFile.getFileName(), userFile.getExtendName(), sessionUserBean.getUserId());
}
return RestResult.success().data("批量移动文件成功");
}
use of com.qiwenshare.file.domain.UserFile in project qiwen-file by qiwenshare.
the class FileController method copyFile.
@Operation(summary = "文件复制", description = "可以复制文件或者目录", tags = { "file" })
@RequestMapping(value = "/copyfile", method = RequestMethod.POST)
@MyLog(operation = "文件复制", module = CURRENT_MODULE)
@ResponseBody
public RestResult<String> copyFile(@RequestBody CopyFileDTO copyFileDTO) {
JwtUser sessionUserBean = SessionUtil.getSession();
long userFileId = copyFileDTO.getUserFileId();
UserFile userFile = userFileService.getById(userFileId);
String oldfilePath = userFile.getFilePath();
String newfilePath = copyFileDTO.getFilePath();
String fileName = userFile.getFileName();
String extendName = userFile.getExtendName();
if (userFile.getIsDir() == 1) {
String testFilePath = oldfilePath + fileName + "/";
if (newfilePath.startsWith(testFilePath)) {
return RestResult.fail().message("原路径与目标路径冲突,不能复制");
}
}
userFileService.userFileCopy(oldfilePath, newfilePath, fileName, extendName, sessionUserBean.getUserId());
return RestResult.success();
}
use of com.qiwenshare.file.domain.UserFile in project qiwen-file by qiwenshare.
the class FileController method deleteImageByIds.
@Operation(summary = "批量删除文件", description = "批量删除文件", tags = { "file" })
@RequestMapping(value = "/batchdeletefile", method = RequestMethod.POST)
@MyLog(operation = "批量删除文件", module = CURRENT_MODULE)
@ResponseBody
public RestResult<String> deleteImageByIds(@RequestBody BatchDeleteFileDTO batchDeleteFileDto) {
JwtUser sessionUserBean = SessionUtil.getSession();
List<UserFile> userFiles = JSON.parseArray(batchDeleteFileDto.getFiles(), UserFile.class);
DigestUtils.md5Hex("data");
for (UserFile userFile : userFiles) {
userFileService.deleteUserFile(userFile.getUserFileId(), sessionUserBean.getUserId());
fileDealComp.deleteESByUserFileId(userFile.getUserFileId());
}
return RestResult.success().message("批量删除文件成功");
}
use of com.qiwenshare.file.domain.UserFile in project qiwen-file by qiwenshare.
the class FileService method unzipFile.
@Override
public void unzipFile(long userFileId, int unzipMode, String filePath) {
UserFile userFile = userFileMapper.selectById(userFileId);
FileBean fileBean = fileMapper.selectById(userFile.getFileId());
File destFile = new File(UFOPUtils.getStaticPath() + "temp" + File.separator + fileBean.getFileUrl());
Downloader downloader = ufopFactory.getDownloader(fileBean.getStorageType());
DownloadFile downloadFile = new DownloadFile();
downloadFile.setFileUrl(fileBean.getFileUrl());
downloadFile.setFileSize(fileBean.getFileSize());
InputStream inputStream = downloader.getInputStream(downloadFile);
try {
FileUtils.copyInputStreamToFile(inputStream, destFile);
} catch (IOException e) {
e.printStackTrace();
}
String extendName = userFile.getExtendName();
String unzipUrl = UFOPUtils.getTempFile(fileBean.getFileUrl()).getAbsolutePath().replace("." + extendName, "");
List<String> fileEntryNameList = new ArrayList<>();
if ("zip".equals(extendName)) {
fileEntryNameList = FileOperation.unzip(destFile, unzipUrl);
} else if ("rar".equals(extendName)) {
try {
fileEntryNameList = FileOperation.unrar(destFile, unzipUrl);
} catch (Exception e) {
e.printStackTrace();
log.error("rar解压失败" + e);
throw new QiwenException(500001, "rar解压异常:" + e.getMessage());
}
} else {
throw new QiwenException(500002, "不支持的文件格式!");
}
if (destFile.exists()) {
destFile.delete();
}
if (!fileEntryNameList.isEmpty() && unzipMode == 1) {
UserFile qiwenDir = QiwenFileUtil.getQiwenDir(userFile.getUserId(), userFile.getFilePath(), userFile.getFileName());
userFileMapper.insert(qiwenDir);
}
for (int i = 0; i < fileEntryNameList.size(); i++) {
String entryName = fileEntryNameList.get(i);
asyncTaskComp.saveUnzipFile(userFile, fileBean, unzipMode, entryName, filePath);
}
}
use of com.qiwenshare.file.domain.UserFile in project qiwen-file by qiwenshare.
the class UserFileService method deleteUserFile.
@Override
public void deleteUserFile(Long userFileId, Long sessionUserId) {
UserFile userFile = userFileMapper.selectById(userFileId);
String uuid = UUID.randomUUID().toString();
if (userFile.getIsDir() == 1) {
LambdaUpdateWrapper<UserFile> userFileLambdaUpdateWrapper = new LambdaUpdateWrapper<UserFile>();
userFileLambdaUpdateWrapper.set(UserFile::getDeleteFlag, RandomUtil.randomInt(FileConstant.deleteFileRandomSize)).set(UserFile::getDeleteBatchNum, uuid).set(UserFile::getDeleteTime, DateUtil.getCurrentTime()).eq(UserFile::getUserFileId, userFileId);
userFileMapper.update(null, userFileLambdaUpdateWrapper);
String filePath = userFile.getFilePath() + userFile.getFileName() + "/";
updateFileDeleteStateByFilePath(filePath, uuid, sessionUserId);
} else {
UserFile userFileTemp = userFileMapper.selectById(userFileId);
LambdaUpdateWrapper<UserFile> userFileLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
userFileLambdaUpdateWrapper.set(UserFile::getDeleteFlag, RandomUtil.randomInt(1, FileConstant.deleteFileRandomSize)).set(UserFile::getDeleteTime, DateUtil.getCurrentTime()).set(UserFile::getDeleteBatchNum, uuid).eq(UserFile::getUserFileId, userFileTemp.getUserFileId());
userFileMapper.update(null, userFileLambdaUpdateWrapper);
}
RecoveryFile recoveryFile = new RecoveryFile();
recoveryFile.setUserFileId(userFileId);
recoveryFile.setDeleteTime(DateUtil.getCurrentTime());
recoveryFile.setDeleteBatchNum(uuid);
recoveryFileMapper.insert(recoveryFile);
}
Aggregations