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);
}
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);
}
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("修改文件成功");
}
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;
}
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();
}
Aggregations