Search in sources :

Example 1 with JwtUser

use of com.qiwenshare.common.util.security.JwtUser in project qiwen-file by qiwenshare.

the class CommonFileController method commonFileUser.

@Operation(summary = "共享文件用户", description = "共享文件用户接口", tags = { "common" })
@GetMapping(value = "/commonfileuser")
@MyLog(operation = "共享文件用户", module = CURRENT_MODULE)
@ResponseBody
public RestResult<List<CommonFileUser>> commonFileUser() {
    JwtUser sessionUserBean = SessionUtil.getSession();
    List<CommonFileUser> list = commonFileService.selectCommonFileUser(sessionUserBean.getUserId());
    return RestResult.success().data(list);
}
Also used : CommonFileUser(com.qiwenshare.file.vo.commonfile.CommonFileUser) JwtUser(com.qiwenshare.common.util.security.JwtUser) Operation(io.swagger.v3.oas.annotations.Operation) MyLog(com.qiwenshare.common.anno.MyLog)

Example 2 with JwtUser

use of com.qiwenshare.common.util.security.JwtUser in project qiwen-file by qiwenshare.

the class FileController method searchFile.

@Operation(summary = "文件搜索", description = "文件搜索", tags = { "file" })
@GetMapping(value = "/search")
@MyLog(operation = "文件搜索", module = CURRENT_MODULE)
@ResponseBody
public RestResult<SearchHits<FileSearch>> searchFile(SearchFileDTO searchFileDTO) {
    JwtUser sessionUserBean = SessionUtil.getSession();
    NativeSearchQueryBuilder queryBuilder = new NativeSearchQueryBuilder();
    HighlightBuilder.Field allHighLight = new HighlightBuilder.Field("*").preTags("<span class='keyword'>").postTags("</span>");
    queryBuilder.withHighlightFields(allHighLight);
    // 设置分页
    int currentPage = (int) searchFileDTO.getCurrentPage() - 1;
    int pageCount = (int) (searchFileDTO.getPageCount() == 0 ? 10 : searchFileDTO.getPageCount());
    String order = searchFileDTO.getOrder();
    Sort.Direction direction = null;
    if (searchFileDTO.getDirection() == null) {
        direction = Sort.Direction.DESC;
    } else if ("asc".equals(searchFileDTO.getDirection())) {
        direction = Sort.Direction.ASC;
    } else if ("desc".equals(searchFileDTO.getDirection())) {
        direction = Sort.Direction.DESC;
    } else {
        direction = Sort.Direction.DESC;
    }
    if (order == null) {
        queryBuilder.withPageable(PageRequest.of(currentPage, pageCount));
    } else {
        queryBuilder.withPageable(PageRequest.of(currentPage, pageCount, Sort.by(direction, order)));
    }
    DisMaxQueryBuilder disMaxQueryBuilder = QueryBuilders.disMaxQuery();
    QueryBuilder q1 = QueryBuilders.boolQuery().must(QueryBuilders.multiMatchQuery(searchFileDTO.getFileName(), "fileName", "content")).must(QueryBuilders.termQuery("userId", sessionUserBean.getUserId())).boost(// 分词
    1f);
    QueryBuilder q2 = QueryBuilders.boolQuery().must(QueryBuilders.wildcardQuery("fileName", "*" + searchFileDTO.getFileName() + "*")).must(QueryBuilders.wildcardQuery("content", "*" + searchFileDTO.getFileName() + "*")).must(QueryBuilders.termQuery("userId", sessionUserBean.getUserId())).boost(// 模糊匹配
    2f);
    disMaxQueryBuilder.add(q1);
    disMaxQueryBuilder.add(q2);
    NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(disMaxQueryBuilder).withHighlightFields(allHighLight).build();
    // 
    // queryBuilder.withQuery(QueryBuilders.boolQuery()
    // //                .must(QueryBuilders.matchQuery("fileName", searchFileDTO.getFileName()))
    // .must(QueryBuilders.multiMatchQuery(searchFileDTO.getFileName(),"fileName", "content"))
    // .must(QueryBuilders.termQuery("userId", sessionUserBean.getUserId()))
    // ).withQuery(QueryBuilders.wildcardQuery("fileName", "*" + searchFileDTO.getFileName() + "*"));
    SearchHits<FileSearch> search = elasticsearchRestTemplate.search(searchQuery, FileSearch.class);
    return RestResult.success().data(search);
}
Also used : QueryBuilder(org.elasticsearch.index.query.QueryBuilder) DisMaxQueryBuilder(org.elasticsearch.index.query.DisMaxQueryBuilder) NativeSearchQueryBuilder(org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder) NativeSearchQuery(org.springframework.data.elasticsearch.core.query.NativeSearchQuery) DisMaxQueryBuilder(org.elasticsearch.index.query.DisMaxQueryBuilder) Sort(org.springframework.data.domain.Sort) JwtUser(com.qiwenshare.common.util.security.JwtUser) NativeSearchQueryBuilder(org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder) HighlightBuilder(org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder) FileSearch(com.qiwenshare.file.config.es.FileSearch) Operation(io.swagger.v3.oas.annotations.Operation) MyLog(com.qiwenshare.common.anno.MyLog)

Example 3 with JwtUser

use of com.qiwenshare.common.util.security.JwtUser in project qiwen-file by qiwenshare.

the class FileController method updateFile.

@Operation(summary = "修改文件", description = "支持普通文本类文件的修改", tags = { "file" })
@RequestMapping(value = "/update", method = RequestMethod.POST)
@ResponseBody
public RestResult<String> updateFile(@RequestBody UpdateFileDTO updateFileDTO) {
    JwtUser sessionUserBean = SessionUtil.getSession();
    UserFile userFile = userFileService.getById(updateFileDTO.getUserFileId());
    FileBean fileBean = fileService.getById(userFile.getFileId());
    Long pointCount = fileService.getFilePointCount(userFile.getFileId());
    if (pointCount > 1) {
        return RestResult.fail().message("暂不支持修改");
    }
    String content = updateFileDTO.getFileContent();
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(content.getBytes());
    try {
        Writer writer1 = ufopFactory.getWriter(fileBean.getStorageType());
        WriteFile writeFile = new WriteFile();
        writeFile.setFileUrl(fileBean.getFileUrl());
        int fileSize = byteArrayInputStream.available();
        writeFile.setFileSize(fileSize);
        writer1.write(byteArrayInputStream, writeFile);
        DownloadFile downloadFile = new DownloadFile();
        downloadFile.setFileUrl(fileBean.getFileUrl());
        InputStream inputStream = ufopFactory.getDownloader(fileBean.getStorageType()).getInputStream(downloadFile);
        String md5Str = DigestUtils.md5Hex(inputStream);
        fileBean.setIdentifier(md5Str);
        fileBean.setModifyTime(DateUtil.getCurrentTime());
        fileBean.setModifyUserId(sessionUserBean.getUserId());
        fileBean.setFileSize((long) fileSize);
        fileService.updateById(fileBean);
    } catch (Exception e) {
        throw new QiwenException(999999, "修改文件异常");
    } finally {
        try {
            byteArrayInputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return RestResult.success().message("修改文件成功");
}
Also used : WriteFile(com.qiwenshare.ufop.operation.write.domain.WriteFile) DownloadFile(com.qiwenshare.ufop.operation.download.domain.DownloadFile) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) QiwenException(com.qiwenshare.common.exception.QiwenException) IOException(java.io.IOException) QiwenException(com.qiwenshare.common.exception.QiwenException) ByteArrayInputStream(java.io.ByteArrayInputStream) UserFile(com.qiwenshare.file.domain.UserFile) FileBean(com.qiwenshare.file.domain.FileBean) JwtUser(com.qiwenshare.common.util.security.JwtUser) Writer(com.qiwenshare.ufop.operation.write.Writer) Operation(io.swagger.v3.oas.annotations.Operation)

Example 4 with JwtUser

use of com.qiwenshare.common.util.security.JwtUser 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 5 with JwtUser

use of com.qiwenshare.common.util.security.JwtUser in project qiwen-file by qiwenshare.

the class FileController method createFile.

@Operation(summary = "创建文件", description = "目录(文件夹)的创建", tags = { "file" })
@RequestMapping(value = "/createfile", method = RequestMethod.POST)
@MyLog(operation = "创建文件", module = CURRENT_MODULE)
@ResponseBody
public RestResult<String> createFile(@Valid @RequestBody CreateFileDTO createFileDto) {
    JwtUser sessionUserBean = SessionUtil.getSession();
    boolean isDirExist = userFileService.isDirExist(createFileDto.getFileName(), createFileDto.getFilePath(), sessionUserBean.getUserId());
    if (isDirExist) {
        return RestResult.fail().message("同名文件已存在");
    }
    UserFile userFile = new UserFile();
    userFile.setUserId(sessionUserBean.getUserId());
    userFile.setFileName(createFileDto.getFileName());
    userFile.setFilePath(createFileDto.getFilePath());
    userFile.setDeleteFlag(0);
    userFile.setIsDir(1);
    userFile.setUploadTime(DateUtil.getCurrentTime());
    userFileService.save(userFile);
    fileDealComp.uploadESByUserFileId(userFile.getUserFileId());
    return RestResult.success();
}
Also used : UserFile(com.qiwenshare.file.domain.UserFile) JwtUser(com.qiwenshare.common.util.security.JwtUser) Operation(io.swagger.v3.oas.annotations.Operation) MyLog(com.qiwenshare.common.anno.MyLog)

Aggregations

JwtUser (com.qiwenshare.common.util.security.JwtUser)30 Operation (io.swagger.v3.oas.annotations.Operation)26 MyLog (com.qiwenshare.common.anno.MyLog)16 UserFile (com.qiwenshare.file.domain.UserFile)13 RestResult (com.qiwenshare.common.result.RestResult)6 IOException (java.io.IOException)4 JSONObject (com.alibaba.fastjson.JSONObject)3 NotLoginException (com.qiwenshare.common.exception.NotLoginException)3 UploadFileVo (com.qiwenshare.file.vo.file.UploadFileVo)3 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)2 FileBean (com.qiwenshare.file.domain.FileBean)2 RecoveryFile (com.qiwenshare.file.domain.RecoveryFile)2 ShareFile (com.qiwenshare.file.domain.ShareFile)2 UserBean (com.qiwenshare.file.domain.user.UserBean)2 FileModel (com.qiwenshare.file.util.FileModel)2 FileListVo (com.qiwenshare.file.vo.file.FileListVo)2 UserLoginVo (com.qiwenshare.file.vo.user.UserLoginVo)2 LambdaUpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper)1 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1