Search in sources :

Example 1 with ShareFileVO

use of com.qiwenshare.file.vo.share.ShareFileVO 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)

Aggregations

MyLog (com.qiwenshare.common.anno.MyLog)1 JwtUser (com.qiwenshare.common.util.security.JwtUser)1 Share (com.qiwenshare.file.domain.Share)1 ShareFile (com.qiwenshare.file.domain.ShareFile)1 UserFile (com.qiwenshare.file.domain.UserFile)1 ShareFileVO (com.qiwenshare.file.vo.share.ShareFileVO)1 Operation (io.swagger.v3.oas.annotations.Operation)1