use of com.qiwenshare.common.util.security.JwtUser in project qiwen-file by qiwenshare.
the class OfficeController method editOfficeFile.
@Operation(summary = "编辑office文件", description = "编辑office文件", tags = { "office" })
@ResponseBody
@RequestMapping(value = "/editofficefile", method = RequestMethod.POST)
public RestResult<Object> editOfficeFile(HttpServletRequest request, @RequestBody EditOfficeFileDTO editOfficeFileDTO, @RequestHeader("token") String token) {
RestResult<Object> result = new RestResult<>();
log.info("editOfficeFile");
try {
JwtUser loginUser = SessionUtil.getSession();
UserFile userFile = userFileService.getById(editOfficeFileDTO.getUserFileId());
String baseUrl = request.getScheme() + "://" + deploymentHost + ":" + port + request.getContextPath();
log.info("回调地址baseUrl:" + baseUrl);
FileModel file = new FileModel(userFile.getFileName() + "." + userFile.getExtendName(), editOfficeFileDTO.getPreviewUrl(), userFile.getUploadTime(), String.valueOf(loginUser.getUserId()), loginUser.getUsername(), "edit");
file.changeType(request.getParameter("mode"), "edit");
String query = "?type=edit&userFileId=" + userFile.getUserFileId() + "&token=" + token;
file.editorConfig.callbackUrl = baseUrl + "/office/IndexServlet" + query;
JSONObject jsonObject = new JSONObject();
jsonObject.put("file", file);
jsonObject.put("docserviceApiUrl", ConfigManager.GetProperty("files.docservice.url.site") + ConfigManager.GetProperty("files.docservice.url.api"));
jsonObject.put("reportName", userFile.getFileName());
result.setData(jsonObject);
result.setCode(200);
result.setMessage("编辑报告成功!");
} catch (Exception e) {
log.error(e.getMessage());
result.setCode(500);
result.setMessage("服务器错误!");
}
return result;
}
use of com.qiwenshare.common.util.security.JwtUser in project qiwen-file by qiwenshare.
the class OfficeController method createOfficeFile.
@Operation(summary = "创建office文件", description = "创建office文件", tags = { "office" })
@ResponseBody
@RequestMapping(value = "/createofficefile", method = RequestMethod.POST)
public RestResult<Object> createOfficeFile(@RequestBody CreateOfficeFileDTO createOfficeFileDTO) {
RestResult<Object> result = new RestResult<>();
try {
JwtUser loginUser = SessionUtil.getSession();
String fileName = createOfficeFileDTO.getFileName();
String filePath = createOfficeFileDTO.getFilePath();
String extendName = createOfficeFileDTO.getExtendName();
List<UserFile> userFiles = userFileService.selectSameUserFile(fileName, filePath, extendName, loginUser.getUserId());
if (userFiles != null && !userFiles.isEmpty()) {
return RestResult.fail().message("同名文件已存在");
}
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
String templateFilePath = "";
if ("docx".equals(extendName)) {
templateFilePath = "template/Word.docx";
} else if ("xlsx".equals(extendName)) {
templateFilePath = "template/Excel.xlsx";
} else if ("pptx".equals(extendName)) {
templateFilePath = "template/PowerPoint.pptx";
}
String url2 = ClassUtils.getDefaultClassLoader().getResource("static/" + templateFilePath).getPath();
FileInputStream fileInputStream = new FileInputStream(url2);
Copier copier = ufopFactory.getCopier();
CopyFile copyFile = new CopyFile();
copyFile.setExtendName(extendName);
String fileUrl = copier.copy(fileInputStream, copyFile);
FileBean fileBean = new FileBean();
fileBean.setFileSize(0L);
fileBean.setFileUrl(fileUrl);
fileBean.setStorageType(storageType);
fileBean.setIdentifier(uuid);
fileBean.setCreateTime(DateUtil.getCurrentTime());
fileBean.setCreateUserId(loginUser.getUserId());
fileBean.setFileStatus(1);
boolean saveFlag = fileService.save(fileBean);
UserFile userFile = new UserFile();
if (saveFlag) {
userFile.setUserId(loginUser.getUserId());
userFile.setFileName(fileName);
userFile.setFilePath(filePath);
userFile.setDeleteFlag(0);
userFile.setIsDir(0);
userFile.setExtendName(extendName);
userFile.setUploadTime(DateUtil.getCurrentTime());
userFile.setFileId(fileBean.getFileId());
userFileService.save(userFile);
}
return RestResult.success().message("文件创建成功");
} catch (Exception e) {
log.error(e.getMessage());
return RestResult.fail().message(e.getMessage());
}
}
use of com.qiwenshare.common.util.security.JwtUser in project qiwen-file by qiwenshare.
the class OfficeController method previewOfficeFile.
@Operation(summary = "预览office文件", description = "预览office文件", tags = { "office" })
@RequestMapping(value = "/previewofficefile", method = RequestMethod.POST)
@ResponseBody
public RestResult<Object> previewOfficeFile(HttpServletRequest request, @RequestBody PreviewOfficeFileDTO previewOfficeFileDTO, @RequestHeader("token") String token) {
RestResult<Object> result = new RestResult<>();
try {
JwtUser loginUser = SessionUtil.getSession();
UserFile userFile = userFileService.getById(previewOfficeFileDTO.getUserFileId());
String baseUrl = request.getScheme() + "://" + deploymentHost + ":" + port + request.getContextPath();
FileModel file = new FileModel(userFile.getFileName() + "." + userFile.getExtendName(), previewOfficeFileDTO.getPreviewUrl(), userFile.getUploadTime(), String.valueOf(loginUser.getUserId()), loginUser.getUsername(), "view");
String query = "?type=show&token=" + token;
file.editorConfig.callbackUrl = baseUrl + "/office/IndexServlet" + query;
JSONObject jsonObject = new JSONObject();
jsonObject.put("file", file);
jsonObject.put("docserviceApiUrl", ConfigManager.GetProperty("files.docservice.url.site") + ConfigManager.GetProperty("files.docservice.url.api"));
jsonObject.put("reportName", userFile.getFileName());
result.setData(jsonObject);
result.setCode(200);
result.setMessage("获取报告成功!");
} catch (Exception e) {
log.error(e.getMessage());
result.setCode(500);
result.setMessage("服务器错误!");
}
return result;
}
use of com.qiwenshare.common.util.security.JwtUser in project qiwen-file by qiwenshare.
the class RecoveryFileController method deleteRecoveryFile.
@Operation(summary = "删除回收文件", description = "删除回收文件", tags = { "recoveryfile" })
@MyLog(operation = "删除回收文件", module = CURRENT_MODULE)
@RequestMapping(value = "/deleterecoveryfile", method = RequestMethod.POST)
@ResponseBody
public RestResult<String> deleteRecoveryFile(@RequestBody DeleteRecoveryFileDTO deleteRecoveryFileDTO) {
JwtUser sessionUserBean = SessionUtil.getSession();
RecoveryFile recoveryFile = recoveryFileService.getById(deleteRecoveryFileDTO.getRecoveryFileId());
asyncTaskComp.deleteUserFile(recoveryFile.getUserFileId());
recoveryFileService.removeById(deleteRecoveryFileDTO.getRecoveryFileId());
return RestResult.success().data("删除成功");
}
use of com.qiwenshare.common.util.security.JwtUser in project qiwen-file by qiwenshare.
the class RecoveryFileController method batchDeleteRecoveryFile.
@Operation(summary = "批量删除回收文件", description = "批量删除回收文件", tags = { "recoveryfile" })
@RequestMapping(value = "/batchdelete", method = RequestMethod.POST)
@MyLog(operation = "批量删除回收文件", module = CURRENT_MODULE)
@ResponseBody
public RestResult<String> batchDeleteRecoveryFile(@RequestBody BatchDeleteRecoveryFileDTO batchDeleteRecoveryFileDTO) {
JwtUser sessionUserBean = SessionUtil.getSession();
List<RecoveryFile> recoveryFileList = JSON.parseArray(batchDeleteRecoveryFileDTO.getRecoveryFileIds(), RecoveryFile.class);
for (RecoveryFile recoveryFile : recoveryFileList) {
RecoveryFile recoveryFile1 = recoveryFileService.getById(recoveryFile.getRecoveryFileId());
asyncTaskComp.deleteUserFile(recoveryFile1.getUserFileId());
recoveryFileService.removeById(recoveryFile1.getRecoveryFileId());
}
return RestResult.success().data("批量删除成功");
}
Aggregations