Search in sources :

Example 21 with JwtUser

use of com.qiwenshare.common.util.security.JwtUser in project qiwen-file by qiwenshare.

the class FiletransferService method uploadFileSpeed.

@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;
}
Also used : LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) UploadFileVo(com.qiwenshare.file.vo.file.UploadFileVo) JwtUser(com.qiwenshare.common.util.security.JwtUser)

Example 22 with JwtUser

use of com.qiwenshare.common.util.security.JwtUser in project qiwen-file by qiwenshare.

the class ShareController method shareFile.

@Operation(summary = "分享文件", description = "分享文件统一接口", tags = { "share" })
@PostMapping(value = "/sharefile")
@MyLog(operation = "分享文件", module = CURRENT_MODULE)
@ResponseBody
public RestResult<ShareFileVO> shareFile(@RequestBody ShareFileDTO shareSecretDTO) {
    ShareFileVO shareSecretVO = new ShareFileVO();
    JwtUser sessionUserBean = SessionUtil.getSession();
    String uuid = UUID.randomUUID().toString().replace("-", "");
    Share share = new Share();
    BeanUtil.copyProperties(shareSecretDTO, share);
    share.setShareTime(DateUtil.getCurrentTime());
    share.setUserId(sessionUserBean.getUserId());
    share.setShareStatus(0);
    if (shareSecretDTO.getShareType() == 1) {
        String extractionCode = RandomUtil.randomNumbers(6);
        share.setExtractionCode(extractionCode);
        shareSecretVO.setExtractionCode(share.getExtractionCode());
    }
    share.setShareBatchNum(uuid);
    shareService.save(share);
    List<ShareFile> fileList = JSON.parseArray(shareSecretDTO.getFiles(), ShareFile.class);
    List<ShareFile> saveFileList = new ArrayList<>();
    for (ShareFile shareFile : fileList) {
        UserFile userFile = userFileService.getById(shareFile.getUserFileId());
        if (userFile.getUserId().compareTo(sessionUserBean.getUserId()) != 0) {
            return RestResult.fail().message("您只能分享自己的文件");
        }
        if (userFile.getIsDir() == 1) {
            List<UserFile> userfileList = userFileService.selectFileListLikeRightFilePath(userFile.getFilePath() + userFile.getFileName() + "/", sessionUserBean.getUserId());
            for (UserFile userFile1 : userfileList) {
                ShareFile shareFile1 = new ShareFile();
                shareFile1.setUserFileId(userFile1.getUserFileId());
                shareFile1.setShareBatchNum(uuid);
                shareFile1.setShareFilePath(userFile1.getFilePath().replaceFirst(userFile.getFilePath(), "/"));
                saveFileList.add(shareFile1);
            }
        }
        shareFile.setShareFilePath("/");
        shareFile.setShareBatchNum(uuid);
        saveFileList.add(shareFile);
    }
    shareFileService.batchInsertShareFile(saveFileList);
    shareSecretVO.setShareBatchNum(uuid);
    return RestResult.success().data(shareSecretVO);
}
Also used : ShareFile(com.qiwenshare.file.domain.ShareFile) ShareFileVO(com.qiwenshare.file.vo.share.ShareFileVO) UserFile(com.qiwenshare.file.domain.UserFile) JwtUser(com.qiwenshare.common.util.security.JwtUser) Share(com.qiwenshare.file.domain.Share) Operation(io.swagger.v3.oas.annotations.Operation) MyLog(com.qiwenshare.common.anno.MyLog)

Example 23 with JwtUser

use of com.qiwenshare.common.util.security.JwtUser in project qiwen-file by qiwenshare.

the class ShareController method shareList.

@Operation(summary = "查看已分享列表", description = "查看已分享列表", tags = { "share" })
@GetMapping(value = "/shareList")
@ResponseBody
public RestResult shareList(ShareListDTO shareListDTO) {
    JwtUser sessionUserBean = SessionUtil.getSession();
    List<ShareListVO> shareList = shareService.selectShareList(shareListDTO, sessionUserBean.getUserId());
    int total = shareService.selectShareListTotalCount(shareListDTO, sessionUserBean.getUserId());
    Map<String, Object> map = new HashMap<>();
    map.put("total", total);
    map.put("list", shareList);
    return RestResult.success().data(map);
}
Also used : ShareListVO(com.qiwenshare.file.vo.share.ShareListVO) JwtUser(com.qiwenshare.common.util.security.JwtUser) Operation(io.swagger.v3.oas.annotations.Operation)

Example 24 with JwtUser

use of com.qiwenshare.common.util.security.JwtUser in project qiwen-file by qiwenshare.

the class ShareController method saveShareFile.

@Operation(summary = "保存分享文件", description = "用来将别人分享的文件保存到自己的网盘中", tags = { "share" })
@PostMapping(value = "/savesharefile")
@MyLog(operation = "保存分享文件", module = CURRENT_MODULE)
@Transactional(rollbackFor = Exception.class)
@ResponseBody
public RestResult saveShareFile(@RequestBody SaveShareFileDTO saveShareFileDTO) {
    JwtUser sessionUserBean = SessionUtil.getSession();
    List<ShareFile> fileList = JSON.parseArray(saveShareFileDTO.getFiles(), ShareFile.class);
    String savefilePath = saveShareFileDTO.getFilePath();
    Long userId = sessionUserBean.getUserId();
    List<UserFile> saveUserFileList = new ArrayList<>();
    for (ShareFile shareFile : fileList) {
        UserFile userFile = userFileService.getById(shareFile.getUserFileId());
        String fileName = userFile.getFileName();
        String savefileName = fileDealComp.getRepeatFileName(userFile, savefilePath);
        if (userFile.getIsDir() == 1) {
            List<UserFile> userfileList = userFileService.selectFileListLikeRightFilePath(userFile.getFilePath() + userFile.getFileName(), userFile.getUserId());
            log.info("查询文件列表:" + JSON.toJSONString(userfileList));
            String filePath = userFile.getFilePath();
            userfileList.forEach(p -> {
                p.setUserFileId(null);
                p.setUserId(userId);
                p.setFilePath(p.getFilePath().replaceFirst(filePath + fileName, savefilePath + savefileName));
                saveUserFileList.add(p);
                log.info("当前文件:" + JSON.toJSONString(p));
            });
        }
        userFile.setUserFileId(null);
        userFile.setUserId(userId);
        userFile.setFilePath(savefilePath);
        userFile.setFileName(savefileName);
        saveUserFileList.add(userFile);
    }
    log.info("----------" + JSON.toJSONString(saveUserFileList));
    userFileService.saveBatch(saveUserFileList);
    return RestResult.success();
}
Also used : ShareFile(com.qiwenshare.file.domain.ShareFile) 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) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with JwtUser

use of com.qiwenshare.common.util.security.JwtUser 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)

Aggregations

JwtUser (com.qiwenshare.common.util.security.JwtUser)30 Operation (io.swagger.v3.oas.annotations.Operation)26 MyLog (com.qiwenshare.common.anno.MyLog)16 UserFile (com.qiwenshare.file.domain.UserFile)13 RestResult (com.qiwenshare.common.result.RestResult)6 IOException (java.io.IOException)4 JSONObject (com.alibaba.fastjson.JSONObject)3 NotLoginException (com.qiwenshare.common.exception.NotLoginException)3 UploadFileVo (com.qiwenshare.file.vo.file.UploadFileVo)3 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)2 FileBean (com.qiwenshare.file.domain.FileBean)2 RecoveryFile (com.qiwenshare.file.domain.RecoveryFile)2 ShareFile (com.qiwenshare.file.domain.ShareFile)2 UserBean (com.qiwenshare.file.domain.user.UserBean)2 FileModel (com.qiwenshare.file.util.FileModel)2 FileListVo (com.qiwenshare.file.vo.file.FileListVo)2 UserLoginVo (com.qiwenshare.file.vo.user.UserLoginVo)2 LambdaUpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper)1 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1