use of com.qiwenshare.file.domain.UserFile in project qiwen-file by qiwenshare.
the class QiwenFileUtil method getQiwenFile.
public static UserFile getQiwenFile(long userId, long fileId, String filePath, String fileName, String extendName) {
UserFile userFile = new UserFile();
userFile.setUserId(userId);
userFile.setFileId(fileId);
userFile.setFileName(fileName);
userFile.setFilePath(filePath);
userFile.setExtendName(extendName);
userFile.setIsDir(0);
userFile.setUploadTime(DateUtil.getCurrentTime());
userFile.setDeleteFlag(0);
userFile.setDeleteBatchNum(null);
return userFile;
}
use of com.qiwenshare.file.domain.UserFile in project qiwen-file by qiwenshare.
the class QiwenFileUtil method getQiwenDir.
public static UserFile getQiwenDir(long userId, String filePath, String fileName) {
UserFile userFile = new UserFile();
userFile.setUserId(userId);
userFile.setFileId(null);
userFile.setFileName(fileName);
userFile.setFilePath(filePath);
userFile.setExtendName(null);
userFile.setIsDir(1);
userFile.setUploadTime(DateUtil.getCurrentTime());
userFile.setDeleteFlag(0);
userFile.setDeleteBatchNum(null);
return userFile;
}
use of com.qiwenshare.file.domain.UserFile in project qiwen-file by qiwenshare.
the class OfficeController method IndexServlet.
@RequestMapping(value = "/IndexServlet", method = RequestMethod.POST)
@ResponseBody
public void IndexServlet(HttpServletResponse response, HttpServletRequest request) throws IOException {
String token = request.getParameter("token");
Long userId = userService.getUserIdByToken(token);
if (userId == null) {
throw new NotLoginException();
}
PrintWriter writer = response.getWriter();
Scanner scanner = new Scanner(request.getInputStream()).useDelimiter("\\A");
String body = scanner.hasNext() ? scanner.next() : "";
JSONObject jsonObj = JSON.parseObject(body);
log.info("===saveeditedfile:" + jsonObj.get("status"));
;
String status = jsonObj != null ? jsonObj.get("status").toString() : "";
if ("2".equals(status) || "6".equals(status)) {
String type = request.getParameter("type");
String downloadUri = (String) jsonObj.get("url");
if ("edit".equals(type)) {
// 修改报告
String userFileId = request.getParameter("userFileId");
UserFile userFile = userFileService.getById(userFileId);
FileBean fileBean = fileService.getById(userFile.getFileId());
Long pointCount = fileService.getFilePointCount(userFile.getFileId());
if (pointCount > 1) {
// 该场景,暂不支持编辑修改
writer.write("{\"error\":1}");
return;
}
URL url = new URL(downloadUri);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
int fileLength = 0;
try {
InputStream stream = connection.getInputStream();
Writer writer1 = ufopFactory.getWriter(fileBean.getStorageType());
WriteFile writeFile = new WriteFile();
writeFile.setFileUrl(fileBean.getFileUrl());
writeFile.setFileSize(connection.getContentLength());
writer1.write(stream, writeFile);
} catch (Exception e) {
log.error(e.getMessage());
} finally {
if ("2".equals(status)) {
LambdaUpdateWrapper<UserFile> userFileUpdateWrapper = new LambdaUpdateWrapper<>();
userFileUpdateWrapper.set(UserFile::getUploadTime, DateUtil.getCurrentTime()).eq(UserFile::getUserFileId, userFileId);
userFileService.update(userFileUpdateWrapper);
}
LambdaUpdateWrapper<FileBean> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
fileLength = connection.getContentLength();
log.info("当前修改文件大小为:" + Long.valueOf(fileLength));
DownloadFile downloadFile = new DownloadFile();
downloadFile.setFileUrl(fileBean.getFileUrl());
InputStream inputStream = ufopFactory.getDownloader(fileBean.getStorageType()).getInputStream(downloadFile);
String md5Str = DigestUtils.md5Hex(inputStream);
lambdaUpdateWrapper.set(FileBean::getIdentifier, md5Str).set(FileBean::getFileSize, Long.valueOf(fileLength)).set(FileBean::getModifyTime, DateUtil.getCurrentTime()).set(FileBean::getModifyUserId, userId).eq(FileBean::getFileId, fileBean.getFileId());
fileService.update(lambdaUpdateWrapper);
connection.disconnect();
}
}
}
if ("3".equals(status) || "7".equals(status)) {
// 不强制手动保存时为6,"6".equals(status)
log.debug("====保存失败:");
writer.write("{\"error\":1}");
} else {
log.debug("状态为:0");
writer.write("{\"error\":" + "0" + "}");
}
}
use of com.qiwenshare.file.domain.UserFile 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.UserFile 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