feat(search): 实现文件搜索功能并调整文件列表检索
- 新增文件搜索接口,支持用户根据文件名或内容进行搜索。 - 调整文件列表检索逻辑,支持分页及文件名模糊查询。 - 重构文件控制器和用户文件服务,提取公共代码,提高可维护性。 - 修正多处代码格式,提升代码可读性与规范性。 fix(share): 修复分享功能中的过期时间检查问题 -现在分享文件时正确检查过期时间,-1表示不过期。 - 修复批量移动文件时的潜在路径问题。 feat(user): 增加修改密码功能及用户登录逻辑调整 -增加修改密码接口,用户可修改个人密码。 - 简化用户登录逻辑,若用户不存在
This commit is contained in:
parent
f15c0a3524
commit
f4fda113b9
@ -10,15 +10,21 @@ import java.util.List;
|
||||
|
||||
public interface IUserFileService extends IService<UserFile> {
|
||||
List<UserFile> selectUserFileByNameAndPath(String fileName, String filePath, String userId);
|
||||
|
||||
List<UserFile> selectSameUserFile(String fileName, String filePath, String extendName, String userId);
|
||||
|
||||
IPage<FileListVO> userFileList(String userId, String filePath, Long beginCount, Long pageCount);
|
||||
IPage<FileListVO> userFileList(Integer sysFlag, String userId, String filePath, Long beginCount, Long pageCount,String fileName);
|
||||
|
||||
void updateFilepathByUserFileId(String userFileId, String newfilePath, String userId);
|
||||
|
||||
void userFileCopy(String userId, String userFileId, String newfilePath);
|
||||
|
||||
IPage<FileListVO> getFileByFileType(Integer fileTypeId, Long currentPage, Long pageCount, String userId);
|
||||
IPage<FileListVO> getFileByFileType(Integer sysFlag, Integer fileTypeId, Long currentPage, Long pageCount, String userId,String fileName);
|
||||
|
||||
List<UserFile> selectUserFileListByPath(String filePath, String userId);
|
||||
|
||||
List<UserFile> selectFilePathTreeByUserId(String userId);
|
||||
|
||||
void deleteUserFile(String userFileId, String sessionUserId);
|
||||
|
||||
List<UserFile> selectUserFileByLikeRightFilePath(@Param("filePath") String filePath, @Param("userId") String userId);
|
||||
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.qiwenshare.common.result.RestResult;
|
||||
import com.qiwenshare.file.domain.user.Role;
|
||||
import com.qiwenshare.file.domain.user.UserBean;
|
||||
import com.qiwenshare.file.dto.user.EditPassWordDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -22,16 +23,20 @@ public interface IUserService extends IService<UserBean> {
|
||||
RestResult<String> registerUser(UserBean userBean);
|
||||
|
||||
|
||||
|
||||
UserBean findUserInfoByTelephone(String telephone);
|
||||
|
||||
List<Role> selectRoleListByUserId(String userId);
|
||||
|
||||
String getSaltByTelephone(String telephone);
|
||||
|
||||
UserBean selectUserByTelephoneAndPassword(String username, String password);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
*
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
RestResult<String> editPassword(EditPassWordDTO dto);
|
||||
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public class CommonFileController {
|
||||
@PostMapping(value = "/commonfile")
|
||||
@MyLog(operation = "共享文件", module = CURRENT_MODULE)
|
||||
@ResponseBody
|
||||
public RestResult<String> commonFile( @RequestBody CommonFileDTO commonFileDTO) {
|
||||
public RestResult<String> commonFile(@RequestBody CommonFileDTO commonFileDTO) {
|
||||
CommonFile commonFile = new CommonFile();
|
||||
commonFile.setUserFileId(commonFileDTO.getUserFileId());
|
||||
commonFile.setCommonFileId(IdUtil.getSnowflakeNextIdStr());
|
||||
@ -57,11 +57,11 @@ public class CommonFileController {
|
||||
List<FilePermission> list = JSON.parseArray(commonFileDTO.getCommonUserList(), FilePermission.class);
|
||||
|
||||
List<FilePermission> filePermissionList = new ArrayList<>();
|
||||
for (FilePermission filePermission : list) {
|
||||
filePermission.setFilePermissionId(IdUtil.getSnowflakeNextId());
|
||||
for (FilePermission filePermission : list) {
|
||||
filePermission.setFilePermissionId(IdUtil.getSnowflakeNextId());
|
||||
filePermission.setCommonFileId(commonFile.commonFileId);
|
||||
filePermissionList.add(filePermission);
|
||||
}
|
||||
}
|
||||
filePermissionService.saveBatch(filePermissionList);
|
||||
|
||||
return RestResult.success();
|
||||
@ -73,7 +73,7 @@ public class CommonFileController {
|
||||
@ResponseBody
|
||||
public RestResult<List<CommonFileUser>> commonFileUserList() {
|
||||
|
||||
JwtUser sessionUserBean = SessionUtil.getSession();
|
||||
JwtUser sessionUserBean = SessionUtil.getSession();
|
||||
List<CommonFileUser> list = commonFileService.selectCommonFileUser(sessionUserBean.getUserId());
|
||||
return RestResult.success().data(list);
|
||||
}
|
||||
@ -82,8 +82,8 @@ public class CommonFileController {
|
||||
@RequestMapping(value = "/getCommonFileByUser", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public RestResult<CommonFileListVo> getCommonFileByUser(
|
||||
@Parameter(description = "用户id", required = true) String userId){
|
||||
JwtUser sessionUserBean = SessionUtil.getSession();
|
||||
@Parameter(description = "用户id", required = true) String userId) {
|
||||
JwtUser sessionUserBean = SessionUtil.getSession();
|
||||
List<CommonFileListVo> commonFileVo = commonFileService.selectCommonFileByUser(userId, sessionUserBean.getUserId());
|
||||
|
||||
return RestResult.success().data(commonFileVo);
|
||||
@ -97,12 +97,13 @@ public class CommonFileController {
|
||||
@Parameter(description = "用户id", required = true) Long commonFileId,
|
||||
@Parameter(description = "文件路径", required = true) String filePath,
|
||||
@Parameter(description = "当前页", required = true) long currentPage,
|
||||
@Parameter(description = "页面数量", required = true) long pageCount){
|
||||
@Parameter(description = "页面数量", required = true) long pageCount,
|
||||
@Parameter(description = "是否文件管理员", required = false) Integer sysFlag) {
|
||||
|
||||
CommonFile commonFile = commonFileService.getById(commonFileId);
|
||||
UserFile userFile = userFileService.getById(commonFile.getUserFileId());
|
||||
QiwenFile qiwenFile = new QiwenFile(userFile.getFilePath(), filePath, true);
|
||||
IPage<FileListVO> fileList = userFileService.userFileList(userFile.getUserId(), qiwenFile.getPath(), currentPage, pageCount);
|
||||
IPage<FileListVO> fileList = userFileService.userFileList(sysFlag, userFile.getUserId(), qiwenFile.getPath(), currentPage, pageCount, null);
|
||||
|
||||
return RestResult.success().data(fileList);
|
||||
|
||||
|
@ -1,13 +1,7 @@
|
||||
package com.qiwenshare.file.controller;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
||||
import co.elastic.clients.elasticsearch.core.SearchResponse;
|
||||
import co.elastic.clients.elasticsearch.core.search.HighlighterEncoder;
|
||||
import co.elastic.clients.elasticsearch.core.search.Hit;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
@ -21,7 +15,6 @@ import com.qiwenshare.file.api.IFileService;
|
||||
import com.qiwenshare.file.api.IUserFileService;
|
||||
import com.qiwenshare.file.component.AsyncTaskComp;
|
||||
import com.qiwenshare.file.component.FileDealComp;
|
||||
import com.qiwenshare.file.config.es.FileSearch;
|
||||
import com.qiwenshare.file.domain.FileBean;
|
||||
import com.qiwenshare.file.domain.UserFile;
|
||||
import com.qiwenshare.file.dto.file.*;
|
||||
@ -38,8 +31,6 @@ import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@ -56,8 +47,6 @@ import java.util.*;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Tag(name = "file", description = "该接口为文件接口,主要用来做一些文件的基本操作,如创建目录,删除,移动,复制等。")
|
||||
@RestController
|
||||
@ -181,62 +170,62 @@ public class FileController {
|
||||
@MyLog(operation = "文件搜索", module = CURRENT_MODULE)
|
||||
@ResponseBody
|
||||
public RestResult<SearchFileVO> searchFile(SearchFileDTO searchFileDTO) {
|
||||
JwtUser sessionUserBean = SessionUtil.getSession();
|
||||
JwtUser sessionUserBean = SessionUtil.getSession();
|
||||
|
||||
int currentPage = (int)searchFileDTO.getCurrentPage() - 1;
|
||||
int pageCount = (int)(searchFileDTO.getPageCount() == 0 ? 10 : searchFileDTO.getPageCount());
|
||||
int currentPage = (int) searchFileDTO.getCurrentPage() - 1;
|
||||
int pageCount = (int) (searchFileDTO.getPageCount() == 0 ? 10 : searchFileDTO.getPageCount());
|
||||
|
||||
SearchResponse<FileSearch> search = null;
|
||||
try {
|
||||
search = elasticsearchClient.search(s -> s
|
||||
.index("filesearch")
|
||||
.query(_1 -> _1
|
||||
.bool(_2 -> _2
|
||||
.must(_3 -> _3
|
||||
.bool(_4 -> _4
|
||||
.should(_5 -> _5
|
||||
.match(_6 -> _6
|
||||
.field("fileName")
|
||||
.query(searchFileDTO.getFileName())))
|
||||
.should(_5 -> _5
|
||||
.wildcard(_6 -> _6
|
||||
.field("fileName")
|
||||
.wildcard("*" + searchFileDTO.getFileName() + "*")))
|
||||
.should(_5 -> _5
|
||||
.match(_6 -> _6
|
||||
.field("content")
|
||||
.query(searchFileDTO.getFileName())))
|
||||
.should(_5 -> _5
|
||||
.wildcard(_6 -> _6
|
||||
.field("content")
|
||||
.wildcard("*" + searchFileDTO.getFileName() + "*")))
|
||||
))
|
||||
.must(_3 -> _3
|
||||
.term(_4 -> _4
|
||||
.field("userId")
|
||||
.value(sessionUserBean.getUserId())))
|
||||
))
|
||||
.from(currentPage)
|
||||
.size(pageCount)
|
||||
.highlight(h -> h
|
||||
.fields("fileName", f -> f.type("plain")
|
||||
.preTags("<span class='keyword'>").postTags("</span>"))
|
||||
.encoder(HighlighterEncoder.Html))
|
||||
,
|
||||
FileSearch.class);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
List<SearchFileVO> searchFileVOList = new ArrayList<>();
|
||||
for (Hit<FileSearch> hit : search.hits().hits()) {
|
||||
SearchFileVO searchFileVO = new SearchFileVO();
|
||||
BeanUtil.copyProperties(hit.source(), searchFileVO);
|
||||
searchFileVO.setHighLight(hit.highlight());
|
||||
searchFileVOList.add(searchFileVO);
|
||||
asyncTaskComp.checkESUserFileId(searchFileVO.getUserFileId());
|
||||
}
|
||||
return RestResult.success().dataList(searchFileVOList, searchFileVOList.size());
|
||||
// SearchResponse<FileSearch> search = null;
|
||||
// try {
|
||||
// search = elasticsearchClient.search(s -> s
|
||||
// .index("filesearch")
|
||||
// .query(_1 -> _1
|
||||
// .bool(_2 -> _2
|
||||
// .must(_3 -> _3
|
||||
// .bool(_4 -> _4
|
||||
// .should(_5 -> _5
|
||||
// .match(_6 -> _6
|
||||
// .field("fileName")
|
||||
// .query(searchFileDTO.getFileName())))
|
||||
// .should(_5 -> _5
|
||||
// .wildcard(_6 -> _6
|
||||
// .field("fileName")
|
||||
// .wildcard("*" + searchFileDTO.getFileName() + "*")))
|
||||
// .should(_5 -> _5
|
||||
// .match(_6 -> _6
|
||||
// .field("content")
|
||||
// .query(searchFileDTO.getFileName())))
|
||||
// .should(_5 -> _5
|
||||
// .wildcard(_6 -> _6
|
||||
// .field("content")
|
||||
// .wildcard("*" + searchFileDTO.getFileName() + "*")))
|
||||
// ))
|
||||
// .must(_3 -> _3
|
||||
// .term(_4 -> _4
|
||||
// .field("userId")
|
||||
// .value(sessionUserBean.getUserId())))
|
||||
// ))
|
||||
// .from(currentPage)
|
||||
// .size(pageCount)
|
||||
// .highlight(h -> h
|
||||
// .fields("fileName", f -> f.type("plain")
|
||||
// .preTags("<span class='keyword'>").postTags("</span>"))
|
||||
// .encoder(HighlighterEncoder.Html))
|
||||
// ,
|
||||
// FileSearch.class);
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// List<SearchFileVO> searchFileVOList = new ArrayList<>();
|
||||
// for (Hit<FileSearch> hit : search.hits().hits()) {
|
||||
// SearchFileVO searchFileVO = new SearchFileVO();
|
||||
// BeanUtil.copyProperties(hit.source(), searchFileVO);
|
||||
// searchFileVO.setHighLight(hit.highlight());
|
||||
// searchFileVOList.add(searchFileVO);
|
||||
// asyncTaskComp.checkESUserFileId(searchFileVO.getUserFileId());
|
||||
// }
|
||||
return RestResult.success();
|
||||
}
|
||||
|
||||
|
||||
@ -246,7 +235,7 @@ public class FileController {
|
||||
@ResponseBody
|
||||
public RestResult<String> renameFile(@RequestBody RenameFileDTO renameFileDto) {
|
||||
|
||||
JwtUser sessionUserBean = SessionUtil.getSession();
|
||||
JwtUser sessionUserBean = SessionUtil.getSession();
|
||||
UserFile userFile = userFileService.getById(renameFileDto.getUserFileId());
|
||||
|
||||
List<UserFile> userFiles = userFileService.selectUserFileByNameAndPath(renameFileDto.getFileName(), userFile.getFilePath(), sessionUserBean.getUserId());
|
||||
@ -279,13 +268,15 @@ public class FileController {
|
||||
public RestResult<FileListVO> getFileList(
|
||||
@Parameter(description = "文件类型", required = true) String fileType,
|
||||
@Parameter(description = "文件路径", required = true) String filePath,
|
||||
@Parameter(description = "文件名称", required = false) String fileName,
|
||||
@Parameter(description = "当前页", required = true) long currentPage,
|
||||
@Parameter(description = "页面数量", required = true) long pageCount){
|
||||
@Parameter(description = "页面数量", required = true) long pageCount,
|
||||
@Parameter(description = "是否文件管理员", required = false) Integer sysFlag) {
|
||||
if ("0".equals(fileType)) {
|
||||
IPage<FileListVO> fileList = userFileService.userFileList(null, filePath, currentPage, pageCount);
|
||||
IPage<FileListVO> fileList = userFileService.userFileList(sysFlag, null, filePath, currentPage, pageCount, fileName);
|
||||
return RestResult.success().dataList(fileList.getRecords(), fileList.getTotal());
|
||||
} else {
|
||||
IPage<FileListVO> fileList = userFileService.getFileByFileType(Integer.valueOf(fileType), currentPage, pageCount, SessionUtil.getSession().getUserId());
|
||||
IPage<FileListVO> fileList = userFileService.getFileByFileType(sysFlag, Integer.valueOf(fileType), currentPage, pageCount, SessionUtil.getSession().getUserId(), fileName);
|
||||
return RestResult.success().dataList(fileList.getRecords(), fileList.getTotal());
|
||||
}
|
||||
}
|
||||
@ -300,8 +291,8 @@ public class FileController {
|
||||
String[] userFileIdList = userFileIds.split(",");
|
||||
userFileService.update(new UpdateWrapper<UserFile>().lambda().set(UserFile::getDeleteFlag, 1).in(UserFile::getUserFileId, Arrays.asList(userFileIdList)));
|
||||
for (String userFileId : userFileIdList) {
|
||||
executor.execute(()->{
|
||||
userFileService.deleteUserFile(userFileId, SessionUtil.getUserId());
|
||||
executor.execute(() -> {
|
||||
userFileService.deleteUserFile(userFileId, SessionUtil.getUserId());
|
||||
});
|
||||
|
||||
fileDealComp.deleteESByUserFileId(userFileId);
|
||||
@ -316,7 +307,7 @@ public class FileController {
|
||||
@ResponseBody
|
||||
public RestResult deleteFile(@RequestBody DeleteFileDTO deleteFileDto) {
|
||||
|
||||
JwtUser sessionUserBean = SessionUtil.getSession();
|
||||
JwtUser sessionUserBean = SessionUtil.getSession();
|
||||
userFileService.deleteUserFile(deleteFileDto.getUserFileId(), sessionUserBean.getUserId());
|
||||
fileDealComp.deleteESByUserFileId(deleteFileDto.getUserFileId());
|
||||
|
||||
@ -374,7 +365,7 @@ public class FileController {
|
||||
@ResponseBody
|
||||
public RestResult<String> moveFile(@RequestBody MoveFileDTO moveFileDto) {
|
||||
|
||||
JwtUser sessionUserBean = SessionUtil.getSession();
|
||||
JwtUser sessionUserBean = SessionUtil.getSession();
|
||||
UserFile userFile = userFileService.getById(moveFileDto.getUserFileId());
|
||||
String oldfilePath = userFile.getFilePath();
|
||||
String newfilePath = moveFileDto.getFilePath();
|
||||
@ -400,7 +391,7 @@ public class FileController {
|
||||
@ResponseBody
|
||||
public RestResult<String> batchMoveFile(@RequestBody BatchMoveFileDTO batchMoveFileDto) {
|
||||
|
||||
JwtUser sessionUserBean = SessionUtil.getSession();
|
||||
JwtUser sessionUserBean = SessionUtil.getSession();
|
||||
|
||||
|
||||
String newfilePath = batchMoveFileDto.getFilePath();
|
||||
@ -429,14 +420,14 @@ public class FileController {
|
||||
public RestResult<TreeNode> getFileTree() {
|
||||
RestResult<TreeNode> result = new RestResult<TreeNode>();
|
||||
|
||||
JwtUser sessionUserBean = SessionUtil.getSession();
|
||||
JwtUser sessionUserBean = SessionUtil.getSession();
|
||||
|
||||
List<UserFile> userFileList = userFileService.selectFilePathTreeByUserId(sessionUserBean.getUserId());
|
||||
TreeNode resultTreeNode = new TreeNode();
|
||||
resultTreeNode.setLabel(QiwenFile.separator);
|
||||
resultTreeNode.setId(0L);
|
||||
long id = 1;
|
||||
for (int i = 0; i < userFileList.size(); i++){
|
||||
for (int i = 0; i < userFileList.size(); i++) {
|
||||
UserFile userFile = userFileList.get(i);
|
||||
QiwenFile qiwenFile = new QiwenFile(userFile.getFilePath(), userFile.getFileName(), false);
|
||||
String filePath = qiwenFile.getPath();
|
||||
@ -444,13 +435,13 @@ public class FileController {
|
||||
Queue<String> queue = new LinkedList<>();
|
||||
|
||||
String[] strArr = filePath.split(QiwenFile.separator);
|
||||
for (int j = 0; j < strArr.length; j++){
|
||||
if (!"".equals(strArr[j]) && strArr[j] != null){
|
||||
for (int j = 0; j < strArr.length; j++) {
|
||||
if (!"".equals(strArr[j]) && strArr[j] != null) {
|
||||
queue.add(strArr[j]);
|
||||
}
|
||||
|
||||
}
|
||||
if (queue.size() == 0){
|
||||
if (queue.size() == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -473,7 +464,7 @@ public class FileController {
|
||||
@RequestMapping(value = "/update", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public RestResult<String> updateFile(@RequestBody UpdateFileDTO updateFileDTO) {
|
||||
JwtUser sessionUserBean = SessionUtil.getSession();
|
||||
JwtUser sessionUserBean = SessionUtil.getSession();
|
||||
UserFile userFile = userFileService.getById(updateFileDTO.getUserFileId());
|
||||
FileBean fileBean = fileService.getById(userFile.getFileId());
|
||||
Long pointCount = fileService.getFilePointCount(userFile.getFileId());
|
||||
@ -508,12 +499,10 @@ public class FileController {
|
||||
@RequestMapping(value = "/detail", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public RestResult<FileDetailVO> queryFileDetail(
|
||||
@Parameter(description = "用户文件Id", required = true) String userFileId){
|
||||
@Parameter(description = "用户文件Id", required = true) String userFileId) {
|
||||
FileDetailVO vo = fileService.getFileDetail(userFileId);
|
||||
return RestResult.success().data(vo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.qiwenshare.file.controller;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
@ -55,7 +56,7 @@ public class ShareController {
|
||||
@PostMapping(value = "/sharefile")
|
||||
@MyLog(operation = "分享文件", module = CURRENT_MODULE)
|
||||
@ResponseBody
|
||||
public RestResult<ShareFileVO> shareFile( @RequestBody ShareFileDTO shareFileDTO) {
|
||||
public RestResult<ShareFileVO> shareFile(@RequestBody ShareFileDTO shareFileDTO) {
|
||||
ShareFileVO shareSecretVO = new ShareFileVO();
|
||||
JwtUser sessionUserBean = SessionUtil.getSession();
|
||||
|
||||
@ -113,7 +114,7 @@ public class ShareController {
|
||||
@Operation(summary = "保存分享文件", description = "用来将别人分享的文件保存到自己的网盘中", tags = {"share"})
|
||||
@PostMapping(value = "/savesharefile")
|
||||
@MyLog(operation = "保存分享文件", module = CURRENT_MODULE)
|
||||
@Transactional(rollbackFor=Exception.class)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@ResponseBody
|
||||
public RestResult saveShareFile(@RequestBody SaveShareFileDTO saveShareFileDTO) {
|
||||
|
||||
@ -137,8 +138,7 @@ public class ShareController {
|
||||
|
||||
if (userFile.getIsDir() == 1) {
|
||||
ShareFile shareFile = shareFileService.getOne(new QueryWrapper<ShareFile>().lambda().eq(ShareFile::getUserFileId, userFileId).eq(ShareFile::getShareBatchNum, saveShareFileDTO.getShareBatchNum()));
|
||||
List<ShareFile> shareFileList = shareFileService.list(new QueryWrapper<ShareFile>().lambda().eq(ShareFile::getShareBatchNum, saveShareFileDTO.getShareBatchNum()).likeRight(ShareFile::getShareFilePath, QiwenFile.formatPath(shareFile.getShareFilePath() +"/"+ fileName)));
|
||||
|
||||
List<ShareFile> shareFileList = shareFileService.list(new QueryWrapper<ShareFile>().lambda().eq(ShareFile::getShareBatchNum, saveShareFileDTO.getShareBatchNum()).likeRight(ShareFile::getShareFilePath, QiwenFile.formatPath(shareFile.getShareFilePath() + "/" + fileName)));
|
||||
|
||||
|
||||
for (ShareFile shareFile1 : shareFileList) {
|
||||
@ -227,13 +227,17 @@ public class ShareController {
|
||||
return RestResult.fail().message("文件不存在!");
|
||||
}
|
||||
String endTime = share.getEndTime();
|
||||
// -- 如果过期时间为-1则不过期
|
||||
if ("999999".equals(endTime)) {
|
||||
return RestResult.success();
|
||||
}
|
||||
Date endTimeDate = null;
|
||||
try {
|
||||
endTimeDate = DateUtil.getDateByFormatString(endTime, "yyyy-MM-dd HH:mm:ss");
|
||||
} catch (ParseException e) {
|
||||
log.error("日期解析失败:{}" , e);
|
||||
log.error("日期解析失败:{}", e);
|
||||
}
|
||||
if (new Date().after(endTimeDate)) {
|
||||
if (new Date().after(endTimeDate)) {
|
||||
return RestResult.fail().message("分享已过期");
|
||||
} else {
|
||||
return RestResult.success();
|
||||
|
@ -13,6 +13,7 @@ import com.qiwenshare.file.api.IUserService;
|
||||
import com.qiwenshare.file.component.JwtComp;
|
||||
import com.qiwenshare.file.domain.UserLoginInfo;
|
||||
import com.qiwenshare.file.domain.user.UserBean;
|
||||
import com.qiwenshare.file.dto.user.EditPassWordDTO;
|
||||
import com.qiwenshare.file.dto.user.RegisterDTO;
|
||||
import com.qiwenshare.file.vo.user.UserLoginVo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@ -59,19 +60,35 @@ public class UserController {
|
||||
return restResult;
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "修改密码", description = "修改密码", tags = {"user"})
|
||||
@PostMapping(value = "/editPassword")
|
||||
@MyLog(operation = "修改密码", module = CURRENT_MODULE)
|
||||
@ResponseBody
|
||||
public RestResult<String> editPassword(@Valid @RequestBody EditPassWordDTO dto) {
|
||||
RestResult<String> restResult = null;
|
||||
restResult = userService.editPassword(dto);
|
||||
return restResult;
|
||||
}
|
||||
|
||||
@Operation(summary = "用户登录", description = "用户登录认证后才能进入系统", tags = {"user"})
|
||||
@GetMapping("/login")
|
||||
@MyLog(operation = "用户登录", module = CURRENT_MODULE)
|
||||
@ResponseBody
|
||||
public RestResult<UserLoginVo> userLogin(
|
||||
@Parameter(description = "登录手机号") String telephone,
|
||||
@Parameter(description = "登录密码") String password){
|
||||
@Parameter(description = "用户名") String userName) {
|
||||
String password = "123456";
|
||||
RestResult<UserLoginVo> restResult = new RestResult<UserLoginVo>();
|
||||
String salt = userService.getSaltByTelephone(telephone);
|
||||
String hashPassword = HashUtils.hashHex("MD5", password, salt, 1024);
|
||||
UserBean result = userService.selectUserByTelephoneAndPassword(telephone, hashPassword);
|
||||
if (result == null) {
|
||||
return RestResult.fail().message("手机号或密码错误!");
|
||||
result = new UserBean();
|
||||
result.setUsername(userName);
|
||||
result.setTelephone(telephone);
|
||||
result.setPassword(password);
|
||||
userService.registerUser(result);
|
||||
}
|
||||
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
|
@ -27,7 +27,7 @@ public class Share {
|
||||
private String extractionCode;
|
||||
@Column(columnDefinition="varchar(40) comment '分享批次号'")
|
||||
private String shareBatchNum;
|
||||
@Column(columnDefinition="int(2) comment '分享类型(0公共,1私密,2好友)'")
|
||||
@Column(columnDefinition="int(2) comment '分享类型(0公共,1私密,2好友,3共享)'")
|
||||
private Integer shareType;
|
||||
@Column(columnDefinition="int(2) comment '分享状态(0正常,1已失效,2已撤销)'")
|
||||
private Integer shareStatus;
|
||||
|
@ -13,7 +13,7 @@ public class ShareFileDTO {
|
||||
private String userFileIds;
|
||||
@Schema(description = "过期日期", example="2020-05-23 22:10:33")
|
||||
private String endTime;
|
||||
@Schema(description = "分享类型", example="0公共分享,1私密分享,2好友分享")
|
||||
@Schema(description = "分享类型", example="0公共分享,1私密分享,2好友分享,3文件共享(丢到共享里面)")
|
||||
private Integer shareType;
|
||||
@Schema(description = "备注", example="")
|
||||
private String remarks;
|
||||
@ -21,4 +21,4 @@ public class ShareFileDTO {
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
package com.qiwenshare.file.dto.user;
|
||||
|
||||
import com.qiwenshare.common.constant.RegexConstant;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
@Data
|
||||
@Schema(name = "用户注册DTO",required = true)
|
||||
public class EditPassWordDTO {
|
||||
|
||||
@Schema(description = "原密码", required = true, example = "password123")
|
||||
@NotBlank(message = "原密码")
|
||||
@Pattern(regexp = RegexConstant.PASSWORD_REGEX, message = "密码长度6-20位,不允许中文")
|
||||
private String oldPassword;
|
||||
|
||||
@Schema(description = "新密码", required = true, example = "password123")
|
||||
@NotBlank(message = "密码不能为空")
|
||||
@Pattern(regexp = RegexConstant.PASSWORD_REGEX, message = "密码长度6-20位,不允许中文")
|
||||
private String password;
|
||||
}
|
@ -70,7 +70,7 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> imple
|
||||
|
||||
|
||||
@Override
|
||||
public IPage<FileListVO> userFileList(String userId, String filePath, Long currentPage, Long pageCount) {
|
||||
public IPage<FileListVO> userFileList(Integer sysFlag, String userId, String filePath, Long currentPage, Long pageCount,String fileName) {
|
||||
Page<FileListVO> page = new Page<>(currentPage, pageCount);
|
||||
UserFile userFile = new UserFile();
|
||||
JwtUser sessionUserBean = SessionUtil.getSession();
|
||||
@ -79,7 +79,11 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> imple
|
||||
} else {
|
||||
userFile.setUserId(userId);
|
||||
}
|
||||
|
||||
//文件管理员不限制用户
|
||||
if (sysFlag != null && sysFlag == 1) {
|
||||
userFile.setUserId(null);
|
||||
}
|
||||
userFile.setFileName(fileName);
|
||||
userFile.setFilePath(URLDecoder.decodeForPath(filePath, StandardCharsets.UTF_8));
|
||||
|
||||
return userFileMapper.selectPageVo(page, userFile, null);
|
||||
@ -170,11 +174,16 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> imple
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<FileListVO> getFileByFileType(Integer fileTypeId, Long currentPage, Long pageCount, String userId) {
|
||||
public IPage<FileListVO> getFileByFileType(Integer sysFlag, Integer fileTypeId, Long currentPage, Long pageCount, String userId,String fileName) {
|
||||
Page<FileListVO> page = new Page<>(currentPage, pageCount);
|
||||
|
||||
UserFile userFile = new UserFile();
|
||||
userFile.setUserId(userId);
|
||||
userFile.setFileName(fileName);
|
||||
//文件管理员不限制用户
|
||||
if (sysFlag != null && sysFlag == 1) {
|
||||
userFile.setUserId(null);
|
||||
}
|
||||
return userFileMapper.selectPageVo(page, userFile, fileTypeId);
|
||||
}
|
||||
|
||||
@ -241,7 +250,7 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> imple
|
||||
List<UserFile> fileList = selectUserFileByLikeRightFilePath(filePath, userId);
|
||||
List<String> userFileIds = fileList.stream().map(UserFile::getUserFileId).collect(Collectors.toList());
|
||||
|
||||
//标记删除标志
|
||||
//标记删除标志
|
||||
if (CollectionUtils.isNotEmpty(userFileIds)) {
|
||||
LambdaUpdateWrapper<UserFile> userFileLambdaUpdateWrapper1 = new LambdaUpdateWrapper<>();
|
||||
userFileLambdaUpdateWrapper1.set(UserFile::getDeleteFlag, RandomUtil.randomInt(FileConstant.deleteFileRandomSize))
|
||||
|
@ -9,12 +9,14 @@ import com.qiwenshare.common.util.DateUtil;
|
||||
import com.qiwenshare.common.util.HashUtils;
|
||||
import com.qiwenshare.common.util.PasswordUtil;
|
||||
import com.qiwenshare.common.util.security.JwtUser;
|
||||
import com.qiwenshare.common.util.security.SessionUtil;
|
||||
import com.qiwenshare.file.api.IUserService;
|
||||
import com.qiwenshare.file.component.JwtComp;
|
||||
import com.qiwenshare.file.component.UserDealComp;
|
||||
import com.qiwenshare.file.controller.UserController;
|
||||
import com.qiwenshare.file.domain.user.Role;
|
||||
import com.qiwenshare.file.domain.user.UserBean;
|
||||
import com.qiwenshare.file.dto.user.EditPassWordDTO;
|
||||
import com.qiwenshare.file.mapper.UserMapper;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -32,7 +34,7 @@ import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@Transactional(rollbackFor=Exception.class)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class UserService extends ServiceImpl<UserMapper, UserBean> implements IUserService, UserDetailsService {
|
||||
|
||||
@Resource
|
||||
@ -83,7 +85,7 @@ public class UserService extends ServiceImpl<UserMapper, UserBean> implements IU
|
||||
if (userDealComp.isUserNameExit(userBean)) {
|
||||
return RestResult.fail().message("用户名已存在!");
|
||||
}
|
||||
if (!userDealComp.isPhoneFormatRight(userBean.getTelephone())){
|
||||
if (!userDealComp.isPhoneFormatRight(userBean.getTelephone())) {
|
||||
return RestResult.fail().message("手机号格式不正确!");
|
||||
}
|
||||
if (userDealComp.isPhoneExit(userBean)) {
|
||||
@ -143,9 +145,28 @@ public class UserService extends ServiceImpl<UserMapper, UserBean> implements IU
|
||||
|
||||
return userMapper.selectSaltByTelephone(telephone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserBean selectUserByTelephoneAndPassword(String username, String password) {
|
||||
return userMapper.selectUserByTelephoneAndPassword(username, password);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public RestResult<String> editPassword(EditPassWordDTO dto) {
|
||||
JwtUser sessionUserBean = SessionUtil.getSession();
|
||||
UserBean userBean = this.getById(sessionUserBean.getUserId());
|
||||
|
||||
String oldPassword = HashUtils.hashHex("MD5", dto.getOldPassword(), userBean.getSalt(), 1024);
|
||||
if (!oldPassword.equals(userBean.getPassword())) {
|
||||
return RestResult.fail().message("密码错误!");
|
||||
}
|
||||
String salt = PasswordUtil.getSaltValue();
|
||||
String newPassword = HashUtils.hashHex("MD5", dto.getPassword(), salt, 1024);
|
||||
userBean.setSalt(salt);
|
||||
userBean.setPassword(newPassword);
|
||||
userMapper.updateById(userBean);
|
||||
return RestResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,6 +6,6 @@ import lombok.Data;
|
||||
@Data
|
||||
@Schema(description="分享类型VO")
|
||||
public class ShareTypeVO {
|
||||
@Schema(description="0公共,1私密,2好友")
|
||||
@Schema(description="0公共,1私密,2好友,3共享")
|
||||
private Integer shareType;
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ logging.file.name=/qiwenshare/qiwen-file/log/web.log
|
||||
logging.level.root=info
|
||||
|
||||
#jpa配置 create/update
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.jpa.hibernate.ddl-a·uto=update
|
||||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
|
||||
spring.jpa.show-sql=true
|
||||
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
|
||||
@ -23,7 +23,7 @@ spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.Ph
|
||||
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
|
||||
spring.datasource.url = jdbc:mysql://localhost:3306/file?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=ma123456
|
||||
spring.datasource.password=root
|
||||
|
||||
#静态资源指定
|
||||
spring.mvc.static-path-pattern=/**
|
||||
|
@ -35,7 +35,7 @@
|
||||
and a.userFileId = #{userFile.userFileId}
|
||||
</if>
|
||||
<if test="userFile.fileName != null">
|
||||
and a.fileName = #{userFile.fileName}
|
||||
and a.fileName like concat('%', #{userFile.fileName}, '%')
|
||||
</if>
|
||||
and a.deleteFlag = 0
|
||||
</where>
|
||||
@ -53,4 +53,4 @@
|
||||
WHERE userfile.userId = #{userId}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
</mapper>
|
||||
|
Loading…
Reference in New Issue
Block a user