mirror of
https://gitee.com/bookshelfplus/bookshelfplus
synced 2025-09-21 01:10:39 +08:00
前端对象列表页面;文件对象管理页面后端Api;后端Api添加管理员身份验证
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package plus.bookshelf.Service.Impl;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import plus.bookshelf.Common.Error.BusinessException;
|
||||
import plus.bookshelf.Dao.DO.FileObjectDO;
|
||||
import plus.bookshelf.Dao.Mapper.FileObjectDOMapper;
|
||||
import plus.bookshelf.Service.Model.FileObjectModel;
|
||||
import plus.bookshelf.Service.Model.UserModel;
|
||||
import plus.bookshelf.Service.Service.FileObjectService;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class FileObjectServiceImpl implements FileObjectService {
|
||||
|
||||
@Autowired
|
||||
FileObjectDOMapper fileObjectDOMapper;
|
||||
|
||||
@Autowired
|
||||
RedisTemplate redisTemplate;
|
||||
|
||||
@Autowired
|
||||
UserServiceImpl userService;
|
||||
|
||||
/**
|
||||
* 列出所有文件对象
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<FileObjectModel> list(String token) throws InvocationTargetException, IllegalAccessException, BusinessException {
|
||||
|
||||
// 已经在 getUserByToken 方法中判断了 token 为空、不合法;用户不存在情况,此处无需再判断
|
||||
UserModel userModel = userService.getUserByToken(redisTemplate, token);
|
||||
|
||||
FileObjectDO[] fileObjectDOS = fileObjectDOMapper.selectAll();
|
||||
|
||||
List<FileObjectModel> fileObjectModels = new ArrayList<>();
|
||||
for (FileObjectDO fileObjectDO : fileObjectDOS) {
|
||||
FileObjectModel fileObjectModel = convertFromDataObject(fileObjectDO);
|
||||
fileObjectModels.add(fileObjectModel);
|
||||
}
|
||||
|
||||
return fileObjectModels;
|
||||
}
|
||||
|
||||
private FileObjectModel convertFromDataObject(FileObjectDO fileObjectDO) throws InvocationTargetException, IllegalAccessException {
|
||||
FileObjectModel fileObjectModel = new FileObjectModel();
|
||||
BeanUtils.copyProperties(fileObjectDO, fileObjectModel);
|
||||
return fileObjectModel;
|
||||
}
|
||||
}
|
@@ -1,11 +1,14 @@
|
||||
package plus.bookshelf.Service.Impl;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import plus.bookshelf.Dao.DO.FileDO;
|
||||
import plus.bookshelf.Dao.Mapper.FileDOMapper;
|
||||
import plus.bookshelf.Service.Model.FileModel;
|
||||
import plus.bookshelf.Service.Model.UserModel;
|
||||
import plus.bookshelf.Service.Service.FileService;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@@ -18,13 +21,24 @@ public class FileServiceImpl implements FileService {
|
||||
@Autowired
|
||||
FileDOMapper fileDOMapper;
|
||||
|
||||
@Autowired
|
||||
RedisTemplate redisTemplate;
|
||||
|
||||
@Autowired
|
||||
UserServiceImpl userService;
|
||||
|
||||
/**
|
||||
* 列出所有文件
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public List<FileModel> list() throws InvocationTargetException, IllegalAccessException {
|
||||
public List<FileModel> list(String token) throws InvocationTargetException, IllegalAccessException {
|
||||
|
||||
// 已经在 getUserByToken 方法中判断了 token 为空、不合法;用户不存在情况,此处无需再判断
|
||||
UserModel userModel = userService.getUserByToken(redisTemplate, token);
|
||||
|
||||
FileDO[] fileDOS = fileDOMapper.selectAll();
|
||||
|
||||
List<FileModel> fileModels = new ArrayList<>();
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package plus.bookshelf.Service.Model;
|
||||
|
||||
import lombok.Data;
|
||||
import plus.bookshelf.Common.Enum.FileStorageMediumEnum;
|
||||
|
||||
@Data
|
||||
public class FileObjectModel {
|
||||
@@ -13,7 +12,7 @@ public class FileObjectModel {
|
||||
private Integer fileId;
|
||||
|
||||
// 文件存储介质类型
|
||||
FileStorageMediumEnum storageMediumType;
|
||||
String storageMediumType;
|
||||
|
||||
// 文件地址
|
||||
// 如果是网盘就是分享链接,如果是本地存储就是文件路径
|
||||
@@ -26,5 +25,5 @@ public class FileObjectModel {
|
||||
String fileShareCode;
|
||||
|
||||
// 附加字段(JSON存储)
|
||||
Object additionalFields;
|
||||
String additionalFields;
|
||||
}
|
||||
|
@@ -0,0 +1,16 @@
|
||||
package plus.bookshelf.Service.Service;
|
||||
|
||||
import plus.bookshelf.Common.Error.BusinessException;
|
||||
import plus.bookshelf.Service.Model.FileObjectModel;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
|
||||
public interface FileObjectService {
|
||||
/**
|
||||
* 列出所有文件对象
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<FileObjectModel> list(String token) throws InvocationTargetException, IllegalAccessException, BusinessException;
|
||||
}
|
@@ -11,5 +11,5 @@ public interface FileService {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<FileModel> list() throws InvocationTargetException, IllegalAccessException;
|
||||
List<FileModel> list(String token) throws InvocationTargetException, IllegalAccessException;
|
||||
}
|
||||
|
Reference in New Issue
Block a user