Search in sources :

Example 1 with RestResult

use of com.qiwenshare.common.result.RestResult in project qiwen-file by qiwenshare.

the class FileController method getFileTree.

@Operation(summary = "获取文件树", description = "文件移动的时候需要用到该接口,用来展示目录树", tags = { "file" })
@RequestMapping(value = "/getfiletree", method = RequestMethod.GET)
@ResponseBody
public RestResult<TreeNode> getFileTree() {
    RestResult<TreeNode> result = new RestResult<TreeNode>();
    JwtUser sessionUserBean = SessionUtil.getSession();
    List<UserFile> userFileList = userFileService.selectFilePathTreeByUserId(sessionUserBean.getUserId());
    TreeNode resultTreeNode = new TreeNode();
    resultTreeNode.setLabel("/");
    resultTreeNode.setId(0L);
    long id = 1;
    for (int i = 0; i < userFileList.size(); i++) {
        UserFile userFile = userFileList.get(i);
        String filePath = userFile.getFilePath() + userFile.getFileName() + "/";
        Queue<String> queue = new LinkedList<>();
        String[] strArr = filePath.split("/");
        for (int j = 0; j < strArr.length; j++) {
            if (!"".equals(strArr[j]) && strArr[j] != null) {
                queue.add(strArr[j]);
            }
        }
        if (queue.size() == 0) {
            continue;
        }
        resultTreeNode = fileDealComp.insertTreeNode(resultTreeNode, id++, "/", queue);
    }
    List<TreeNode> treeNodeList = resultTreeNode.getChildren();
    Collections.sort(treeNodeList, new Comparator<TreeNode>() {

        @Override
        public int compare(TreeNode o1, TreeNode o2) {
            long i = o1.getId() - o2.getId();
            return (int) i;
        }
    });
    result.setSuccess(true);
    result.setData(resultTreeNode);
    return result;
}
Also used : RestResult(com.qiwenshare.common.result.RestResult) TreeNode(com.qiwenshare.file.util.TreeNode) UserFile(com.qiwenshare.file.domain.UserFile) JwtUser(com.qiwenshare.common.util.security.JwtUser) Operation(io.swagger.v3.oas.annotations.Operation)

Example 2 with RestResult

use of com.qiwenshare.common.result.RestResult in project qiwen-file by qiwenshare.

the class NoticeController method getNoticeDetail.

@Operation(summary = "查询公告详情", tags = { "公告管理" })
@RequestMapping(value = "/detail", method = RequestMethod.GET)
@ResponseBody
public RestResult<Notice> getNoticeDetail(@Parameter(description = "公告id", required = true) long noticeId) {
    RestResult<Notice> result = new RestResult<Notice>();
    Notice notice = noticeService.getById(noticeId);
    return RestResult.success().data(notice);
}
Also used : RestResult(com.qiwenshare.common.result.RestResult) Notice(com.qiwenshare.file.domain.Notice) Operation(io.swagger.v3.oas.annotations.Operation)

Example 3 with RestResult

use of com.qiwenshare.common.result.RestResult 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 4 with RestResult

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

Example 5 with RestResult

use of com.qiwenshare.common.result.RestResult 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

RestResult (com.qiwenshare.common.result.RestResult)8 Operation (io.swagger.v3.oas.annotations.Operation)7 JwtUser (com.qiwenshare.common.util.security.JwtUser)6 UserFile (com.qiwenshare.file.domain.UserFile)4 JSONObject (com.alibaba.fastjson.JSONObject)3 NotLoginException (com.qiwenshare.common.exception.NotLoginException)3 IOException (java.io.IOException)3 FileModel (com.qiwenshare.file.util.FileModel)2 UserLoginVo (com.qiwenshare.file.vo.user.UserLoginVo)2 MyLog (com.qiwenshare.common.anno.MyLog)1 FileBean (com.qiwenshare.file.domain.FileBean)1 Notice (com.qiwenshare.file.domain.Notice)1 UserBean (com.qiwenshare.file.domain.user.UserBean)1 TreeNode (com.qiwenshare.file.util.TreeNode)1 RecoveryFileListVo (com.qiwenshare.file.vo.file.RecoveryFileListVo)1 Copier (com.qiwenshare.ufop.operation.copy.Copier)1 CopyFile (com.qiwenshare.ufop.operation.copy.domain.CopyFile)1 FileInputStream (java.io.FileInputStream)1 HashMap (java.util.HashMap)1 List (java.util.List)1