Search in sources :

Example 1 with FileModel

use of com.qiwenshare.file.util.FileModel 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;
}
Also used : FileModel(com.qiwenshare.file.util.FileModel) RestResult(com.qiwenshare.common.result.RestResult) JSONObject(com.alibaba.fastjson.JSONObject) UserFile(com.qiwenshare.file.domain.UserFile) JSONObject(com.alibaba.fastjson.JSONObject) JwtUser(com.qiwenshare.common.util.security.JwtUser) IOException(java.io.IOException) NotLoginException(com.qiwenshare.common.exception.NotLoginException) Operation(io.swagger.v3.oas.annotations.Operation)

Example 2 with FileModel

use of com.qiwenshare.file.util.FileModel 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;
}
Also used : FileModel(com.qiwenshare.file.util.FileModel) RestResult(com.qiwenshare.common.result.RestResult) JSONObject(com.alibaba.fastjson.JSONObject) UserFile(com.qiwenshare.file.domain.UserFile) JSONObject(com.alibaba.fastjson.JSONObject) JwtUser(com.qiwenshare.common.util.security.JwtUser) IOException(java.io.IOException) NotLoginException(com.qiwenshare.common.exception.NotLoginException) Operation(io.swagger.v3.oas.annotations.Operation)

Aggregations

JSONObject (com.alibaba.fastjson.JSONObject)2 NotLoginException (com.qiwenshare.common.exception.NotLoginException)2 RestResult (com.qiwenshare.common.result.RestResult)2 JwtUser (com.qiwenshare.common.util.security.JwtUser)2 UserFile (com.qiwenshare.file.domain.UserFile)2 FileModel (com.qiwenshare.file.util.FileModel)2 Operation (io.swagger.v3.oas.annotations.Operation)2 IOException (java.io.IOException)2