Search in sources :

Example 21 with UserFile

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("批量移动文件成功");
}
Also used : UserFile(com.qiwenshare.file.domain.UserFile) JwtUser(com.qiwenshare.common.util.security.JwtUser) Operation(io.swagger.v3.oas.annotations.Operation) MyLog(com.qiwenshare.common.anno.MyLog)

Example 22 with UserFile

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();
}
Also used : UserFile(com.qiwenshare.file.domain.UserFile) JwtUser(com.qiwenshare.common.util.security.JwtUser) Operation(io.swagger.v3.oas.annotations.Operation) MyLog(com.qiwenshare.common.anno.MyLog)

Example 23 with UserFile

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("批量删除文件成功");
}
Also used : UserFile(com.qiwenshare.file.domain.UserFile) JwtUser(com.qiwenshare.common.util.security.JwtUser) Operation(io.swagger.v3.oas.annotations.Operation) MyLog(com.qiwenshare.common.anno.MyLog)

Example 24 with UserFile

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);
    }
}
Also used : DownloadFile(com.qiwenshare.ufop.operation.download.domain.DownloadFile) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Downloader(com.qiwenshare.ufop.operation.download.Downloader) IOException(java.io.IOException) QiwenException(com.qiwenshare.common.exception.QiwenException) IOException(java.io.IOException) QiwenException(com.qiwenshare.common.exception.QiwenException) UserFile(com.qiwenshare.file.domain.UserFile) FileBean(com.qiwenshare.file.domain.FileBean) UserFile(com.qiwenshare.file.domain.UserFile) DownloadFile(com.qiwenshare.ufop.operation.download.domain.DownloadFile) File(java.io.File)

Example 25 with UserFile

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);
}
Also used : LambdaUpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper) UserFile(com.qiwenshare.file.domain.UserFile) RecoveryFile(com.qiwenshare.file.domain.RecoveryFile)

Aggregations

UserFile (com.qiwenshare.file.domain.UserFile)26 Operation (io.swagger.v3.oas.annotations.Operation)15 JwtUser (com.qiwenshare.common.util.security.JwtUser)14 MyLog (com.qiwenshare.common.anno.MyLog)8 IOException (java.io.IOException)8 FileBean (com.qiwenshare.file.domain.FileBean)7 LambdaUpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper)5 RestResult (com.qiwenshare.common.result.RestResult)5 JSONObject (com.alibaba.fastjson.JSONObject)4 NotLoginException (com.qiwenshare.common.exception.NotLoginException)4 FileListVo (com.qiwenshare.file.vo.file.FileListVo)4 IPage (com.baomidou.mybatisplus.core.metadata.IPage)3 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)3 QiwenException (com.qiwenshare.common.exception.QiwenException)3 DownloadFile (com.qiwenshare.ufop.operation.download.domain.DownloadFile)3 FileInputStream (java.io.FileInputStream)3 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)2 RecoveryFile (com.qiwenshare.file.domain.RecoveryFile)2 ShareFile (com.qiwenshare.file.domain.ShareFile)2 FileModel (com.qiwenshare.file.util.FileModel)2