mirror of
https://gitee.com/bookshelfplus/bookshelfplus
synced 2025-09-01 22:53:29 +08:00
关联文件仅可关联系统中未设置SHA1,或SHA1值相同的文件记录
This commit is contained in:
@@ -91,7 +91,27 @@ public class FileController extends BaseController {
|
||||
throw new BusinessException(BusinessErrorCode.OPERATION_NOT_ALLOWED, "非管理员用户无权进行此操作");
|
||||
}
|
||||
|
||||
List<FileModel> fileModels = fileService.list(token);
|
||||
List<FileModel> fileModels = fileService.list();
|
||||
List<FileVO> fileVOS = new ArrayList<>();
|
||||
for (FileModel fileModel : fileModels) {
|
||||
FileVO fileVO = convertFileVOFromModel(fileModel);
|
||||
fileVOS.add(fileVO);
|
||||
}
|
||||
return CommonReturnType.create(fileVOS);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "【管理员】查询文件列表(匹配文件哈希)", notes = "查询文件列表,返回文件哈希为空或者相同的文件")
|
||||
@RequestMapping(value = "list/MatchfileHash", method = {RequestMethod.POST}, consumes = {CONTENT_TYPE_FORMED})
|
||||
@ResponseBody
|
||||
public CommonReturnType matchfileHash(@RequestParam(value = "token", required = false) String token,
|
||||
@RequestParam(value = "fileSha1", required = true) String fileSha1) throws InvocationTargetException, IllegalAccessException, BusinessException {
|
||||
|
||||
UserModel userModel = userService.getUserByToken(redisTemplate, token);
|
||||
if (userModel == null || !Objects.equals(userModel.getGroup(), "ADMIN")) {
|
||||
throw new BusinessException(BusinessErrorCode.OPERATION_NOT_ALLOWED, "非管理员用户无权进行此操作");
|
||||
}
|
||||
|
||||
List<FileModel> fileModels = fileService.selectBySha1WithNullValue(fileSha1);
|
||||
List<FileVO> fileVOS = new ArrayList<>();
|
||||
for (FileModel fileModel : fileModels) {
|
||||
FileVO fileVO = convertFileVOFromModel(fileModel);
|
||||
|
@@ -60,6 +60,13 @@ public interface FileDOMapper {
|
||||
*/
|
||||
FileDO[] selectAll();
|
||||
|
||||
/**
|
||||
* 查询系统中的所有文件
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
FileDO[] selectBySha1WithNullValue(String fileSha1);
|
||||
|
||||
/**
|
||||
* 列出文件支持的下载方式
|
||||
*
|
||||
|
@@ -69,10 +69,7 @@ public class FileServiceImpl implements FileService {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<FileModel> list(String token) throws InvocationTargetException, IllegalAccessException, BusinessException {
|
||||
|
||||
// 已经在 getUserByToken 方法中判断了 token 为空、不合法;用户不存在情况,此处无需再判断
|
||||
UserModel userModel = userService.getUserByToken(redisTemplate, token);
|
||||
public List<FileModel> list() {
|
||||
|
||||
FileDO[] fileDOS = fileDOMapper.selectAll();
|
||||
|
||||
@@ -85,6 +82,25 @@ public class FileServiceImpl implements FileService {
|
||||
return fileModels;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列出所有 SHA1匹配 和 未设置SHA1 的文件
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<FileModel> selectBySha1WithNullValue(String fileSha1) {
|
||||
|
||||
FileDO[] fileDOS = fileDOMapper.selectBySha1WithNullValue(fileSha1);
|
||||
|
||||
List<FileModel> fileModels = new ArrayList<>();
|
||||
for (FileDO fileDO : fileDOS) {
|
||||
FileModel fileModel = convertFromDataObject(fileDO);
|
||||
fileModels.add(fileModel);
|
||||
}
|
||||
|
||||
return fileModels;
|
||||
}
|
||||
|
||||
private FileModel convertFromDataObject(FileDO fileDO) {
|
||||
if (fileDO == null) {
|
||||
return null;
|
||||
|
@@ -23,7 +23,14 @@ public interface FileService {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<FileModel> list(String token) throws InvocationTargetException, IllegalAccessException, BusinessException;
|
||||
List<FileModel> list();
|
||||
|
||||
/**
|
||||
* 列出所有SHA1匹配或者未设置SHA1的文件
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<FileModel> selectBySha1WithNullValue(String token) throws InvocationTargetException, IllegalAccessException, BusinessException;
|
||||
|
||||
/**
|
||||
* 添加文件信息
|
||||
|
Reference in New Issue
Block a user