use of com.qiwenshare.file.domain.ShareFile 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);
}
use of com.qiwenshare.file.domain.ShareFile 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();
}
Aggregations