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);
}
Aggregations