mirror of
https://gitee.com/bookshelfplus/bookshelfplus
synced 2025-09-01 22:53:29 +08:00
数据库 file_info, file_object_info 大调整;删除ScheduleTask代码及数据库
This commit is contained in:
@@ -85,11 +85,15 @@ public class QCloudCosUtils {
|
||||
}
|
||||
|
||||
public Boolean doesObjectExist(String folder, String objectKey) {
|
||||
return doesObjectExist(folder + objectKey);
|
||||
}
|
||||
|
||||
public Boolean doesObjectExist(String filePath) {
|
||||
COSClient cosClient = createCOSClient();
|
||||
// 存储桶的命名格式为 BucketName-APPID,此处填写的存储桶名称必须为此格式
|
||||
String bucketName = qCloudCosConfig.getBucketName();
|
||||
// 对象键(Key)是对象在存储桶中的唯一标识。详情请参见 [对象键](https://cloud.tencent.com/document/product/436/13324)
|
||||
String key = qCloudCosConfig.getKeyName() + folder + objectKey;
|
||||
String key = qCloudCosConfig.getKeyName() + filePath;
|
||||
return cosClient.doesObjectExist(bucketName, key);
|
||||
}
|
||||
|
||||
|
@@ -261,7 +261,7 @@ public class ExportController extends BaseController {
|
||||
return;
|
||||
}
|
||||
|
||||
String[] headers = {""/*编号*/, "书名", "格式", "总页数", "语言", "是否有水印/广告", "扫描版/电子版", "文件大小", "来源信息 & 备注", "下载地址"}; // "作者", "出版社", "出版日期", "ISBN"
|
||||
String[] headers = {""/*编号*/, "书名", "格式", "总页数", "语言", "是否有水印/广告", "扫描版/电子版", "文件大小", "来源", "下载地址"}; // "作者", "出版社", "出版日期", "ISBN"
|
||||
MarkdownTable markdownTable = MarkdownTable.create()
|
||||
.setHeader(headers)
|
||||
.setAlignment(MarkdownTable.Alignment.LEFT)
|
||||
@@ -298,17 +298,17 @@ public class ExportController extends BaseController {
|
||||
strings[5] = String.join(",", a);// 是否有水印/广告
|
||||
// strings[6] = fileDO.getScan() ? "扫描版" : "电子版";// 扫描版/电子版
|
||||
strings[7] = fileDO.getFileSize() + "";// 文件大小
|
||||
strings[8] = fileDO.getBookOrigin() + "";// 来源信息 & 备注
|
||||
strings[8] = fileDO.getSource() + "";// 来源信息 & 备注
|
||||
List<String> url = new ArrayList<>();
|
||||
StringBuilder download = new StringBuilder();
|
||||
for (FileObjectNode fileObjectNode : fileNode.children) {
|
||||
FileObjectDO fileObjectDO = fileObjectNode.current;
|
||||
// 打印出当前书籍的文件对象信息
|
||||
// System.out.println(getSpace(level - 1) + "\t\t\t[文件对象] " + fileObjectDO.getId() + "\t" + fileObjectDO.getFileName());
|
||||
if (Objects.equals(fileObjectDO.getStorageMediumType(), FileStorageMediumEnum.QCLOUD_COS.getStorageMediumName()))
|
||||
if (Objects.equals(fileObjectDO.getStorageMedium(), FileStorageMediumEnum.QCLOUD_COS.getStorageMediumName()))
|
||||
continue;
|
||||
download.append("[")
|
||||
.append(FileStorageMediumEnum.valueOf(fileObjectDO.getStorageMediumType()).getStorageMediumDisplayName())
|
||||
.append(FileStorageMediumEnum.valueOf(fileObjectDO.getStorageMedium()).getStorageMediumDisplayName())
|
||||
.append("](")
|
||||
.append(fileObjectDO.getFilePath())
|
||||
.append(")");
|
||||
|
@@ -20,7 +20,6 @@ import plus.bookshelf.Config.QCloudCosConfig;
|
||||
import plus.bookshelf.Controller.VO.FileObjectVO;
|
||||
import plus.bookshelf.Controller.VO.FileVO;
|
||||
import plus.bookshelf.Service.Impl.*;
|
||||
import plus.bookshelf.Service.Model.FailureFeedbackModel;
|
||||
import plus.bookshelf.Service.Model.FileModel;
|
||||
import plus.bookshelf.Service.Model.FileObjectModel;
|
||||
import plus.bookshelf.Service.Model.UserModel;
|
||||
@@ -70,7 +69,7 @@ public class FileController extends BaseController {
|
||||
List<FileObjectModel> fileObjectModels = fileObjectService.getFileObjectByBookId(bookId);
|
||||
List<FileObjectVO> fileObjectVOS = new ArrayList<>();
|
||||
for (FileObjectModel fileObjectModel : fileObjectModels) {
|
||||
FileObjectVO fileObjectVO = convertFileObjectVOFromModel(fileObjectModel);
|
||||
FileObjectVO fileObjectVO = FileObjectController.convertFileObjectVOFromModel(fileObjectModel);
|
||||
fileObjectVOS.add(fileObjectVO);
|
||||
}
|
||||
|
||||
@@ -120,114 +119,6 @@ public class FileController extends BaseController {
|
||||
return CommonReturnType.create(fileVOS);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "链接失效反馈", notes = "查询文件列表")
|
||||
@RequestMapping(value = "object/FailureFeedback", method = {RequestMethod.POST}, consumes = {CONTENT_TYPE_FORMED})
|
||||
@ResponseBody
|
||||
public CommonReturnType failureFeedback(@RequestParam(value = "token", required = false) String token,
|
||||
@RequestParam(value = "bookId", required = false) Integer bookId,
|
||||
@RequestParam(value = "fileId", required = false) Integer fileId,
|
||||
@RequestParam(value = "fileObjectId", required = false) Integer fileObjectId,
|
||||
@RequestParam(value = "visitorId", required = true) String visitorFingerprint) throws BusinessException {
|
||||
|
||||
Integer userId = null;
|
||||
if (token != null) {
|
||||
try {
|
||||
UserModel userModel = userService.getUserByToken(redisTemplate, token);
|
||||
userId = userModel.getId();
|
||||
} catch (BusinessException e) {
|
||||
// 用户未登录,不返回错误信息
|
||||
}
|
||||
}
|
||||
|
||||
if (!visitorFingerprintLogService.saveFingerprint("Failure Feedback", userId, visitorFingerprint)) {
|
||||
throw new BusinessException(BusinessErrorCode.OPERATION_NOT_ALLOWED, "参数错误,请联系管理员处理");
|
||||
}
|
||||
|
||||
FailureFeedbackModel failureFeedbackModel = new FailureFeedbackModel();
|
||||
failureFeedbackModel.setBookId(bookId);
|
||||
failureFeedbackModel.setFileId(fileId);
|
||||
failureFeedbackModel.setFileObjectId(fileObjectId);
|
||||
failureFeedbackModel.setUserId(userId);
|
||||
failureFeedbackModel.setCreateTime(Calendar.getInstance().getTime());
|
||||
|
||||
Boolean isSuccess = failureFeedbackService.addFailureFeedback(failureFeedbackModel);
|
||||
if (!isSuccess) {
|
||||
throw new BusinessException(BusinessErrorCode.UNKNOWN_ERROR, "反馈失败");
|
||||
}
|
||||
return CommonReturnType.create(isSuccess);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "【管理员】查询文件对象列表", notes = "查询文件列表")
|
||||
@RequestMapping(value = "object/list", method = {RequestMethod.POST}, consumes = {CONTENT_TYPE_FORMED})
|
||||
@ResponseBody
|
||||
public CommonReturnType objectList(@RequestParam(value = "token", required = false) String token) 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<FileObjectModel> fileObjectModels = fileObjectService.list(token);
|
||||
List<FileObjectVO> fileObjectVOS = new ArrayList<>();
|
||||
for (FileObjectModel fileObjectModel : fileObjectModels) {
|
||||
FileObjectVO fileObjectVO = convertFileObjectVOFromModel(fileObjectModel);
|
||||
fileObjectVOS.add(fileObjectVO);
|
||||
}
|
||||
return CommonReturnType.create(fileObjectVOS);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "【管理员】更新文件对象上传状态", notes = "重新从 COS 对象存储中获取文件对象上传状态")
|
||||
@RequestMapping(value = "object/refreshFileObjectStatus", method = {RequestMethod.POST}, consumes = {CONTENT_TYPE_FORMED})
|
||||
@ResponseBody
|
||||
public CommonReturnType refreshFileObjectStatus(@RequestParam(value = "token", required = false) String token,
|
||||
@RequestParam(value = "fileObjectId") Integer fileObjectId) 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, "非管理员用户无权进行此操作");
|
||||
}
|
||||
|
||||
// 获取旧文件权限
|
||||
FileObjectModel fileObjectModel = fileObjectService.getFileObjectById(fileObjectId);
|
||||
String fileSha1 = fileObjectModel.getFileSha1();
|
||||
String oldUploadStatus = fileObjectModel.getUploadStatus();
|
||||
|
||||
QCloudCosUtils qCloudCosUtils = new QCloudCosUtils(qCloudCosConfig, cosPresignedUrlGenerateLogService);
|
||||
|
||||
// 判断对象是否存在
|
||||
Boolean isExist = qCloudCosUtils.doesObjectExist(QCloudCosUtils.BOOK_SAVE_FOLDER, fileSha1);
|
||||
|
||||
Boolean isSuccess = false;
|
||||
|
||||
if (!isExist) {
|
||||
// 现在文件不存在
|
||||
switch (oldUploadStatus) {
|
||||
case "NOT_EXIST": // 文件不存在,不需要更新
|
||||
default:
|
||||
isSuccess = true;
|
||||
break;
|
||||
case "SUCCESS": // 上传成功,但是文件不存在了,更新为不存在
|
||||
case "UPLOADING": // 上传中,更新为不存在
|
||||
isSuccess = fileObjectService.updateFileStatus(fileObjectModel.getId(), "NOT_EXIST");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// 现在文件存在
|
||||
switch (oldUploadStatus) {
|
||||
case "SUCCESS": // 之前上传成功,现在存在,不做任何操作
|
||||
default:
|
||||
isSuccess = true;
|
||||
break;
|
||||
case "NOT_EXIST": // 之前不存在,现在存在,更新为上传成功
|
||||
case "UPLOADING": // 之前上传中,现在存在,更新为上传成功
|
||||
isSuccess = fileObjectService.updateFileStatus(fileObjectModel.getId(), "SUCCESS");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return CommonReturnType.create(isSuccess);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建文件操作预授权URL
|
||||
*
|
||||
@@ -294,7 +185,7 @@ public class FileController extends BaseController {
|
||||
if (isExist) throw new BusinessException(BusinessErrorCode.PARAMETER_VALIDATION_ERROR, "文件已存在");
|
||||
|
||||
Integer realFileId = fileObjectService.uploadFile(fileId, fileName, bookSaveFolder + fileSha1, fileSize,
|
||||
fileSha1, fileExt, fileName, FileStorageMediumEnum.QCLOUD_COS, "", lastModified);
|
||||
fileSha1, fileExt, FileStorageMediumEnum.QCLOUD_COS, "", lastModified);
|
||||
// fileId 可能为 0 (创建新文件)
|
||||
// realFileId 是从数据库中查询出来的,真实的文件id
|
||||
resultMap.put("fileId", realFileId);
|
||||
@@ -385,9 +276,10 @@ public class FileController extends BaseController {
|
||||
if (fileObject == null) {
|
||||
throw new BusinessException(BusinessErrorCode.PARAMETER_VALIDATION_ERROR, "文件不存在!");
|
||||
}
|
||||
// 更新文件状态
|
||||
Boolean isSuccess = fileObjectService.updateFileStatus(fileObject.getId(), "SUCCESS");
|
||||
if (!isSuccess) {
|
||||
// 更新文件对象状态
|
||||
Boolean isSuccess1 = fileObjectService.updateFileStatus(fileObject.getId(), "SUCCESS");
|
||||
|
||||
if (!isSuccess1) {
|
||||
throw new BusinessException(BusinessErrorCode.UNKNOWN_ERROR, "更新文件状态失败");
|
||||
}
|
||||
} else {
|
||||
@@ -407,20 +299,6 @@ public class FileController extends BaseController {
|
||||
fileVO.setFileModifiedAt(fileModel.getFileModifiedAt().getTime());
|
||||
return fileVO;
|
||||
}
|
||||
|
||||
private FileObjectVO convertFileObjectVOFromModel(FileObjectModel fileObjectModel) {
|
||||
if (fileObjectModel == null) {
|
||||
return null;
|
||||
}
|
||||
FileObjectVO fileObjectVO = new FileObjectVO();
|
||||
BeanUtils.copyProperties(fileObjectModel, fileObjectVO);
|
||||
try {
|
||||
// 尝试将 FileStorageMedium 转为中文,如果没有成功,那么就保留英文
|
||||
fileObjectVO.setStorageMediumType(FileStorageMediumEnum.valueOf(fileObjectModel.getStorageMediumType()).getStorageMediumDisplayName());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return fileObjectVO;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -0,0 +1,180 @@
|
||||
package plus.bookshelf.Controller.Controller;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import plus.bookshelf.Common.Enum.FileStorageMediumEnum;
|
||||
import plus.bookshelf.Common.Error.BusinessErrorCode;
|
||||
import plus.bookshelf.Common.Error.BusinessException;
|
||||
import plus.bookshelf.Common.FileManager.QCloudCosUtils;
|
||||
import plus.bookshelf.Common.Response.CommonReturnType;
|
||||
import plus.bookshelf.Config.QCloudCosConfig;
|
||||
import plus.bookshelf.Controller.VO.FileObjectVO;
|
||||
import plus.bookshelf.Service.Impl.*;
|
||||
import plus.bookshelf.Service.Model.FailureFeedbackModel;
|
||||
import plus.bookshelf.Service.Model.FileModel;
|
||||
import plus.bookshelf.Service.Model.FileObjectModel;
|
||||
import plus.bookshelf.Service.Model.UserModel;
|
||||
import plus.bookshelf.Service.Service.CosPresignedUrlGenerateLogService;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Api(tags = "文件对象管理")
|
||||
@Controller("file/object")
|
||||
@RequestMapping("/file/object")
|
||||
public class FileObjectController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
QCloudCosConfig qCloudCosConfig;
|
||||
|
||||
@Autowired
|
||||
UserServiceImpl userService;
|
||||
|
||||
@Autowired
|
||||
FileServiceImpl fileService;
|
||||
|
||||
@Autowired
|
||||
CosPresignedUrlGenerateLogService cosPresignedUrlGenerateLogService;
|
||||
|
||||
@Autowired
|
||||
FileObjectServiceImpl fileObjectService;
|
||||
|
||||
@Autowired
|
||||
FailureFeedbackServiceImpl failureFeedbackService;
|
||||
|
||||
@Autowired
|
||||
VisitorFingerprintLogServiceImpl visitorFingerprintLogService;
|
||||
|
||||
|
||||
@ApiOperation(value = "链接失效反馈", notes = "查询文件列表")
|
||||
@RequestMapping(value = "FailureFeedback", method = {RequestMethod.POST}, consumes = {CONTENT_TYPE_FORMED})
|
||||
@ResponseBody
|
||||
public CommonReturnType failureFeedback(@RequestParam(value = "token", required = false) String token,
|
||||
@RequestParam(value = "bookId", required = false) Integer bookId,
|
||||
@RequestParam(value = "fileId", required = false) Integer fileId,
|
||||
@RequestParam(value = "fileObjectId", required = false) Integer fileObjectId,
|
||||
@RequestParam(value = "visitorId", required = true) String visitorFingerprint) throws BusinessException {
|
||||
|
||||
Integer userId = null;
|
||||
if (token != null) {
|
||||
try {
|
||||
UserModel userModel = userService.getUserByToken(redisTemplate, token);
|
||||
userId = userModel.getId();
|
||||
} catch (BusinessException e) {
|
||||
// 用户未登录,不返回错误信息
|
||||
}
|
||||
}
|
||||
|
||||
if (!visitorFingerprintLogService.saveFingerprint("Failure Feedback", userId, visitorFingerprint)) {
|
||||
throw new BusinessException(BusinessErrorCode.OPERATION_NOT_ALLOWED, "参数错误,请联系管理员处理");
|
||||
}
|
||||
|
||||
FailureFeedbackModel failureFeedbackModel = new FailureFeedbackModel();
|
||||
failureFeedbackModel.setBookId(bookId);
|
||||
failureFeedbackModel.setFileId(fileId);
|
||||
failureFeedbackModel.setFileObjectId(fileObjectId);
|
||||
failureFeedbackModel.setUserId(userId);
|
||||
failureFeedbackModel.setCreateTime(Calendar.getInstance().getTime());
|
||||
|
||||
Boolean isSuccess = failureFeedbackService.addFailureFeedback(failureFeedbackModel);
|
||||
if (!isSuccess) {
|
||||
throw new BusinessException(BusinessErrorCode.UNKNOWN_ERROR, "反馈失败");
|
||||
}
|
||||
return CommonReturnType.create(isSuccess);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "【管理员】查询文件对象列表", notes = "查询文件列表")
|
||||
@RequestMapping(value = "list", method = {RequestMethod.POST}, consumes = {CONTENT_TYPE_FORMED})
|
||||
@ResponseBody
|
||||
public CommonReturnType objectList(@RequestParam(value = "token", required = false) String token) 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<FileObjectModel> fileObjectModels = fileObjectService.list();
|
||||
List<FileObjectVO> fileObjectVOS = new ArrayList<>();
|
||||
for (FileObjectModel fileObjectModel : fileObjectModels) {
|
||||
FileObjectVO fileObjectVO = convertFileObjectVOFromModel(fileObjectModel);
|
||||
fileObjectVOS.add(fileObjectVO);
|
||||
}
|
||||
return CommonReturnType.create(fileObjectVOS);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "【管理员】更新文件对象上传状态", notes = "重新从 COS 对象存储中获取文件对象上传状态")
|
||||
@RequestMapping(value = "refreshFileObjectStatus", method = {RequestMethod.POST}, consumes = {CONTENT_TYPE_FORMED})
|
||||
@ResponseBody
|
||||
public CommonReturnType refreshFileObjectStatus(@RequestParam(value = "token", required = false) String token,
|
||||
@RequestParam(value = "fileObjectId") Integer fileObjectId) 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, "非管理员用户无权进行此操作");
|
||||
}
|
||||
|
||||
// 获取旧文件权限
|
||||
FileObjectModel fileObjectModel = fileObjectService.getFileObjectById(fileObjectId);
|
||||
String filePath = fileObjectModel.getFilePath();
|
||||
String oldUploadStatus = fileObjectModel.getUploadStatus();
|
||||
|
||||
QCloudCosUtils qCloudCosUtils = new QCloudCosUtils(qCloudCosConfig, cosPresignedUrlGenerateLogService);
|
||||
|
||||
// 判断对象是否存在
|
||||
Boolean isExist = qCloudCosUtils.doesObjectExist(filePath);
|
||||
|
||||
Boolean isSuccess = false;
|
||||
|
||||
if (!isExist) {
|
||||
// 现在文件不存在
|
||||
switch (oldUploadStatus) {
|
||||
case "NOT_EXIST": // 文件不存在,不需要更新
|
||||
default:
|
||||
isSuccess = true;
|
||||
break;
|
||||
case "SUCCESS": // 上传成功,但是文件不存在了,更新为不存在
|
||||
case "UPLOADING": // 上传中,更新为不存在
|
||||
isSuccess = fileObjectService.updateFileStatus(fileObjectModel.getId(), "NOT_EXIST");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// 现在文件存在
|
||||
switch (oldUploadStatus) {
|
||||
case "SUCCESS": // 之前上传成功,现在存在,不做任何操作
|
||||
default:
|
||||
isSuccess = true;
|
||||
break;
|
||||
case "NOT_EXIST": // 之前不存在,现在存在,更新为上传成功
|
||||
case "UPLOADING": // 之前上传中,现在存在,更新为上传成功
|
||||
isSuccess = fileObjectService.updateFileStatus(fileObjectModel.getId(), "SUCCESS");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return CommonReturnType.create(isSuccess);
|
||||
}
|
||||
|
||||
public static FileObjectVO convertFileObjectVOFromModel(FileObjectModel fileObjectModel) {
|
||||
if (fileObjectModel == null) {
|
||||
return null;
|
||||
}
|
||||
FileObjectVO fileObjectVO = new FileObjectVO();
|
||||
BeanUtils.copyProperties(fileObjectModel, fileObjectVO);
|
||||
try {
|
||||
// 尝试将 FileStorageMedium 转为中文,如果没有成功,那么就保留英文
|
||||
fileObjectVO.setStorageMedium(FileStorageMediumEnum.valueOf(fileObjectModel.getStorageMedium()).getStorageMediumDisplayName());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return fileObjectVO;
|
||||
}
|
||||
}
|
@@ -11,17 +11,11 @@ public class FileObjectVO {
|
||||
// 存储的文件Id
|
||||
private Integer fileId;
|
||||
|
||||
// 文件名
|
||||
private String fileName;
|
||||
|
||||
// 文件大小
|
||||
private Long fileSize;
|
||||
|
||||
// 文件类型
|
||||
private String fileType;
|
||||
// 文件上传状态
|
||||
String uploadStatus;
|
||||
|
||||
// 文件存储介质类型
|
||||
String storageMediumType;
|
||||
String storageMedium;
|
||||
|
||||
// 文件地址
|
||||
// 如果是网盘就是分享链接,如果是本地存储就是文件路径
|
||||
@@ -35,13 +29,4 @@ public class FileObjectVO {
|
||||
|
||||
// 文件最后修改时间戳
|
||||
Long lastModified;
|
||||
|
||||
// 文件上传状态
|
||||
String uploadStatus;
|
||||
|
||||
// 文件哈希 - SHA1
|
||||
String fileSha1;
|
||||
|
||||
// 附加字段(JSON存储)
|
||||
String additionalFields;
|
||||
}
|
||||
|
@@ -11,14 +11,17 @@ public class FileVO {
|
||||
// 关联的书籍Id
|
||||
Integer bookId;
|
||||
|
||||
// 文件名 (用于展示给用户的文件名,不含扩展名)
|
||||
String fileDisplayName;
|
||||
|
||||
// 文件存储名称 (文件的实际文件名,含扩展名)
|
||||
// 文件名,不含扩展名
|
||||
String fileName;
|
||||
|
||||
// 文件格式
|
||||
String fileFormat;
|
||||
// 文件扩展名
|
||||
String fileExt;
|
||||
|
||||
// 文件大小
|
||||
long fileSize;
|
||||
|
||||
// 文件哈希 - SHA1
|
||||
String fileSha1;
|
||||
|
||||
// 总页数
|
||||
Integer numberOfPages;
|
||||
@@ -30,17 +33,11 @@ public class FileVO {
|
||||
Boolean advertising;
|
||||
|
||||
// 文件来源 电子版/扫描版
|
||||
String bookOrigin;
|
||||
String source;
|
||||
|
||||
// 文件创建时间
|
||||
long fileCreateAt;
|
||||
|
||||
// 文件修改时间
|
||||
long fileModifiedAt;
|
||||
|
||||
// 文件大小
|
||||
long fileSize;
|
||||
|
||||
// 文件哈希 - SHA1
|
||||
String fileSha1;
|
||||
}
|
||||
|
@@ -21,15 +21,6 @@ public class FileDO {
|
||||
*/
|
||||
private Integer bookId;
|
||||
|
||||
/**
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column file_info.file_display_name
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
private String fileDisplayName;
|
||||
|
||||
/**
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
@@ -42,11 +33,29 @@ public class FileDO {
|
||||
/**
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column file_info.file_format
|
||||
* This field corresponds to the database column file_info.file_ext
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
private String fileFormat;
|
||||
private String fileExt;
|
||||
|
||||
/**
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column file_info.file_size
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
private Long fileSize;
|
||||
|
||||
/**
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column file_info.file_sha1
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
private String fileSha1;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -78,11 +87,11 @@ public class FileDO {
|
||||
/**
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column file_info.book_origin
|
||||
* This field corresponds to the database column file_info.source
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
private String bookOrigin;
|
||||
private String source;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -102,24 +111,6 @@ public class FileDO {
|
||||
*/
|
||||
private Date fileModifiedAt;
|
||||
|
||||
/**
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column file_info.file_size
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
private Long fileSize;
|
||||
|
||||
/**
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column file_info.file_sha1
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
private String fileSha1;
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_info.id
|
||||
@@ -168,30 +159,6 @@ public class FileDO {
|
||||
this.bookId = bookId;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_info.file_display_name
|
||||
*
|
||||
* @return the value of file_info.file_display_name
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public String getFileDisplayName() {
|
||||
return fileDisplayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column file_info.file_display_name
|
||||
*
|
||||
* @param fileDisplayName the value for file_info.file_display_name
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setFileDisplayName(String fileDisplayName) {
|
||||
this.fileDisplayName = fileDisplayName == null ? null : fileDisplayName.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_info.file_name
|
||||
@@ -218,26 +185,74 @@ public class FileDO {
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_info.file_format
|
||||
* This method returns the value of the database column file_info.file_ext
|
||||
*
|
||||
* @return the value of file_info.file_format
|
||||
* @return the value of file_info.file_ext
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public String getFileFormat() {
|
||||
return fileFormat;
|
||||
public String getFileExt() {
|
||||
return fileExt;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column file_info.file_format
|
||||
* This method sets the value of the database column file_info.file_ext
|
||||
*
|
||||
* @param fileFormat the value for file_info.file_format
|
||||
* @param fileExt the value for file_info.file_ext
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setFileFormat(String fileFormat) {
|
||||
this.fileFormat = fileFormat == null ? null : fileFormat.trim();
|
||||
public void setFileExt(String fileExt) {
|
||||
this.fileExt = fileExt == null ? null : fileExt.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_info.file_size
|
||||
*
|
||||
* @return the value of file_info.file_size
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public Long getFileSize() {
|
||||
return fileSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column file_info.file_size
|
||||
*
|
||||
* @param fileSize the value for file_info.file_size
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setFileSize(Long fileSize) {
|
||||
this.fileSize = fileSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_info.file_sha1
|
||||
*
|
||||
* @return the value of file_info.file_sha1
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public String getFileSha1() {
|
||||
return fileSha1;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column file_info.file_sha1
|
||||
*
|
||||
* @param fileSha1 the value for file_info.file_sha1
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setFileSha1(String fileSha1) {
|
||||
this.fileSha1 = fileSha1 == null ? null : fileSha1.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -314,26 +329,26 @@ public class FileDO {
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_info.book_origin
|
||||
* This method returns the value of the database column file_info.source
|
||||
*
|
||||
* @return the value of file_info.book_origin
|
||||
* @return the value of file_info.source
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public String getBookOrigin() {
|
||||
return bookOrigin;
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column file_info.book_origin
|
||||
* This method sets the value of the database column file_info.source
|
||||
*
|
||||
* @param bookOrigin the value for file_info.book_origin
|
||||
* @param source the value for file_info.source
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setBookOrigin(String bookOrigin) {
|
||||
this.bookOrigin = bookOrigin == null ? null : bookOrigin.trim();
|
||||
public void setSource(String source) {
|
||||
this.source = source == null ? null : source.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -383,52 +398,4 @@ public class FileDO {
|
||||
public void setFileModifiedAt(Date fileModifiedAt) {
|
||||
this.fileModifiedAt = fileModifiedAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_info.file_size
|
||||
*
|
||||
* @return the value of file_info.file_size
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public Long getFileSize() {
|
||||
return fileSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column file_info.file_size
|
||||
*
|
||||
* @param fileSize the value for file_info.file_size
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setFileSize(Long fileSize) {
|
||||
this.fileSize = fileSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_info.file_sha1
|
||||
*
|
||||
* @return the value of file_info.file_sha1
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public String getFileSha1() {
|
||||
return fileSha1;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column file_info.file_sha1
|
||||
*
|
||||
* @param fileSha1 the value for file_info.file_sha1
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setFileSha1(String fileSha1) {
|
||||
this.fileSha1 = fileSha1 == null ? null : fileSha1.trim();
|
||||
}
|
||||
}
|
@@ -22,38 +22,20 @@ public class FileObjectDO {
|
||||
/**
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column file_object_info.file_name
|
||||
* This field corresponds to the database column file_object_info.upload_status
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
private String fileName;
|
||||
private String uploadStatus;
|
||||
|
||||
/**
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column file_object_info.file_size
|
||||
* This field corresponds to the database column file_object_info.storage_medium
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
private Long fileSize;
|
||||
|
||||
/**
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column file_object_info.file_type
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
private String fileType;
|
||||
|
||||
/**
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column file_object_info.storage_medium_type
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
private String storageMediumType;
|
||||
private String storageMedium;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -82,24 +64,6 @@ public class FileObjectDO {
|
||||
*/
|
||||
private String fileShareCode;
|
||||
|
||||
/**
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column file_object_info.upload_status
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
private String uploadStatus;
|
||||
|
||||
/**
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column file_object_info.file_sha1
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
private String fileSha1;
|
||||
|
||||
/**
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
@@ -109,15 +73,6 @@ public class FileObjectDO {
|
||||
*/
|
||||
private Long lastModified;
|
||||
|
||||
/**
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column file_object_info.additional_fields
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
private String additionalFields;
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_object_info.id
|
||||
@@ -168,98 +123,50 @@ public class FileObjectDO {
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_object_info.file_name
|
||||
* This method returns the value of the database column file_object_info.upload_status
|
||||
*
|
||||
* @return the value of file_object_info.file_name
|
||||
* @return the value of file_object_info.upload_status
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
public String getUploadStatus() {
|
||||
return uploadStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column file_object_info.file_name
|
||||
* This method sets the value of the database column file_object_info.upload_status
|
||||
*
|
||||
* @param fileName the value for file_object_info.file_name
|
||||
* @param uploadStatus the value for file_object_info.upload_status
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName == null ? null : fileName.trim();
|
||||
public void setUploadStatus(String uploadStatus) {
|
||||
this.uploadStatus = uploadStatus == null ? null : uploadStatus.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_object_info.file_size
|
||||
* This method returns the value of the database column file_object_info.storage_medium
|
||||
*
|
||||
* @return the value of file_object_info.file_size
|
||||
* @return the value of file_object_info.storage_medium
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public Long getFileSize() {
|
||||
return fileSize;
|
||||
public String getStorageMedium() {
|
||||
return storageMedium;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column file_object_info.file_size
|
||||
* This method sets the value of the database column file_object_info.storage_medium
|
||||
*
|
||||
* @param fileSize the value for file_object_info.file_size
|
||||
* @param storageMedium the value for file_object_info.storage_medium
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setFileSize(Long fileSize) {
|
||||
this.fileSize = fileSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_object_info.file_type
|
||||
*
|
||||
* @return the value of file_object_info.file_type
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public String getFileType() {
|
||||
return fileType;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column file_object_info.file_type
|
||||
*
|
||||
* @param fileType the value for file_object_info.file_type
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setFileType(String fileType) {
|
||||
this.fileType = fileType == null ? null : fileType.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_object_info.storage_medium_type
|
||||
*
|
||||
* @return the value of file_object_info.storage_medium_type
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public String getStorageMediumType() {
|
||||
return storageMediumType;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column file_object_info.storage_medium_type
|
||||
*
|
||||
* @param storageMediumType the value for file_object_info.storage_medium_type
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setStorageMediumType(String storageMediumType) {
|
||||
this.storageMediumType = storageMediumType == null ? null : storageMediumType.trim();
|
||||
public void setStorageMedium(String storageMedium) {
|
||||
this.storageMedium = storageMedium == null ? null : storageMedium.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -334,54 +241,6 @@ public class FileObjectDO {
|
||||
this.fileShareCode = fileShareCode == null ? null : fileShareCode.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_object_info.upload_status
|
||||
*
|
||||
* @return the value of file_object_info.upload_status
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public String getUploadStatus() {
|
||||
return uploadStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column file_object_info.upload_status
|
||||
*
|
||||
* @param uploadStatus the value for file_object_info.upload_status
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setUploadStatus(String uploadStatus) {
|
||||
this.uploadStatus = uploadStatus == null ? null : uploadStatus.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_object_info.file_sha1
|
||||
*
|
||||
* @return the value of file_object_info.file_sha1
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public String getFileSha1() {
|
||||
return fileSha1;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column file_object_info.file_sha1
|
||||
*
|
||||
* @param fileSha1 the value for file_object_info.file_sha1
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setFileSha1(String fileSha1) {
|
||||
this.fileSha1 = fileSha1 == null ? null : fileSha1.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_object_info.last_modified
|
||||
@@ -405,28 +264,4 @@ public class FileObjectDO {
|
||||
public void setLastModified(Long lastModified) {
|
||||
this.lastModified = lastModified;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_object_info.additional_fields
|
||||
*
|
||||
* @return the value of file_object_info.additional_fields
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public String getAdditionalFields() {
|
||||
return additionalFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column file_object_info.additional_fields
|
||||
*
|
||||
* @param additionalFields the value for file_object_info.additional_fields
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setAdditionalFields(String additionalFields) {
|
||||
this.additionalFields = additionalFields == null ? null : additionalFields.trim();
|
||||
}
|
||||
}
|
@@ -87,4 +87,13 @@ public interface FileDOMapper {
|
||||
* @return
|
||||
*/
|
||||
int getLastInsertId();
|
||||
|
||||
/**
|
||||
* 更新文件的SHA1值
|
||||
*
|
||||
* @param id 文件Id
|
||||
* @param fileSha1 文件的SHA1值
|
||||
* @return
|
||||
*/
|
||||
int updateFileSha1(Integer id, String fileSha1);
|
||||
}
|
@@ -12,7 +12,6 @@ import plus.bookshelf.Dao.DO.FileObjectDO;
|
||||
import plus.bookshelf.Dao.Mapper.FileObjectDOMapper;
|
||||
import plus.bookshelf.Service.Model.FileModel;
|
||||
import plus.bookshelf.Service.Model.FileObjectModel;
|
||||
import plus.bookshelf.Service.Model.UserModel;
|
||||
import plus.bookshelf.Service.Service.FileObjectService;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@@ -61,10 +60,7 @@ public class FileObjectServiceImpl implements FileObjectService {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<FileObjectModel> list(String token) throws InvocationTargetException, IllegalAccessException, BusinessException {
|
||||
|
||||
// 已经在 getUserByToken 方法中判断了 token 为空、不合法;用户不存在情况,此处无需再判断
|
||||
UserModel userModel = userService.getUserByToken(redisTemplate, token);
|
||||
public List<FileObjectModel> list() throws InvocationTargetException, IllegalAccessException, BusinessException {
|
||||
|
||||
FileObjectDO[] fileObjectDOS = fileObjectDOMapper.selectAll();
|
||||
|
||||
@@ -122,7 +118,7 @@ public class FileObjectServiceImpl implements FileObjectService {
|
||||
* @param fileExt 文件扩展名
|
||||
* @param fileNameWithoutExt 文件名(不包含扩展名)
|
||||
* @param fileStorageMediumEnum 文件存储介质
|
||||
* @param bookOrigin 文件来源
|
||||
* @param source 文件来源
|
||||
* @return 返回文件Id
|
||||
* @throws InvocationTargetException
|
||||
* @throws IllegalAccessException
|
||||
@@ -131,8 +127,8 @@ public class FileObjectServiceImpl implements FileObjectService {
|
||||
@Override
|
||||
@Transactional
|
||||
public Integer uploadFile(Integer fileId, String fileName, String filePath, Long fileSize, String fileSHA1,
|
||||
String fileExt, String fileNameWithoutExt, FileStorageMediumEnum fileStorageMediumEnum,
|
||||
String bookOrigin, Long lastModified
|
||||
String fileExt, FileStorageMediumEnum fileStorageMediumEnum,
|
||||
String source, Long lastModified
|
||||
) throws InvocationTargetException, IllegalAccessException, BusinessException {
|
||||
|
||||
if (fileId == 0) {
|
||||
@@ -142,9 +138,8 @@ public class FileObjectServiceImpl implements FileObjectService {
|
||||
fileModel.setFileName(fileName);
|
||||
fileModel.setFileSize(fileSize);
|
||||
fileModel.setFileSha1(fileSHA1);
|
||||
fileModel.setFileFormat(fileExt);
|
||||
fileModel.setFileDisplayName(fileNameWithoutExt);
|
||||
fileModel.setBookOrigin(bookOrigin);
|
||||
fileModel.setFileExt(fileExt);
|
||||
fileModel.setSource(source);
|
||||
|
||||
// 其余使用默认设置
|
||||
fileModel.setBookId(0);
|
||||
@@ -171,19 +166,14 @@ public class FileObjectServiceImpl implements FileObjectService {
|
||||
|
||||
fileObjectModel.setFileId(fileId);
|
||||
|
||||
fileObjectModel.setFileName(fileName);
|
||||
fileObjectModel.setFileSize(fileSize);
|
||||
fileObjectModel.setFileType(fileExt);
|
||||
fileObjectModel.setStorageMediumType(fileStorageMediumEnum.getStorageMediumName());
|
||||
fileObjectModel.setStorageMedium(fileStorageMediumEnum.getStorageMediumName());
|
||||
fileObjectModel.setFilePath(filePath);
|
||||
fileObjectModel.setFileSha1(fileSHA1);
|
||||
fileObjectModel.setUploadStatus("UPLOADING");
|
||||
fileObjectModel.setLastModified(lastModified);
|
||||
|
||||
// 其余使用默认设置
|
||||
fileObjectModel.setFilePwd("");
|
||||
fileObjectModel.setFileShareCode("");
|
||||
fileObjectModel.setAdditionalFields("");
|
||||
|
||||
Boolean isSuccess = addFileObject(fileObjectModel);
|
||||
if (!isSuccess) {
|
||||
@@ -199,7 +189,7 @@ public class FileObjectServiceImpl implements FileObjectService {
|
||||
* @param fileStatus
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateFileStatus(Integer fileObjectId, String fileStatus) throws InvocationTargetException, IllegalAccessException {
|
||||
public Boolean updateFileStatus(Integer fileObjectId, String fileStatus) {
|
||||
if (fileObjectId == null || fileObjectId == 0) {
|
||||
return false;
|
||||
}
|
||||
|
@@ -8,9 +8,11 @@ import plus.bookshelf.Common.Error.BusinessErrorCode;
|
||||
import plus.bookshelf.Common.Error.BusinessException;
|
||||
import plus.bookshelf.Config.QCloudCosConfig;
|
||||
import plus.bookshelf.Dao.DO.FileDO;
|
||||
import plus.bookshelf.Dao.DO.FileObjectDO;
|
||||
import plus.bookshelf.Dao.Mapper.FileDOMapper;
|
||||
import plus.bookshelf.Dao.Mapper.FileObjectDOMapper;
|
||||
import plus.bookshelf.Service.Model.FileModel;
|
||||
import plus.bookshelf.Service.Model.FileObjectModel;
|
||||
import plus.bookshelf.Service.Service.CosPresignedUrlGenerateLogService;
|
||||
import plus.bookshelf.Service.Service.FileService;
|
||||
|
||||
@@ -119,13 +121,13 @@ public class FileServiceImpl implements FileService {
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
@Override
|
||||
public Boolean addFile(FileModel fileModel) throws InvocationTargetException, IllegalAccessException {
|
||||
FileDO fileDO = copyFileToDataObject(fileModel);
|
||||
public Boolean addFile(FileModel fileModel) {
|
||||
FileDO fileDO = convertFromFileModel(fileModel);
|
||||
int affectRows = fileDOMapper.insertSelective(fileDO);
|
||||
return affectRows > 0;
|
||||
}
|
||||
|
||||
private FileDO copyFileToDataObject(FileModel fileModel) throws InvocationTargetException, IllegalAccessException {
|
||||
private FileDO convertFromFileModel(FileModel fileModel) {
|
||||
FileDO fileDO = new FileDO();
|
||||
BeanUtils.copyProperties(fileModel, fileDO);
|
||||
return fileDO;
|
||||
@@ -150,4 +152,31 @@ public class FileServiceImpl implements FileService {
|
||||
public Integer getLastInsertId() {
|
||||
return fileDOMapper.getLastInsertId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新文件的SHA1值
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateFileSha1(Integer fileId, String fileSha1) throws BusinessException {
|
||||
if (fileId == null || fileId == 0) {
|
||||
throw new BusinessException(BusinessErrorCode.PARAMETER_VALIDATION_ERROR, "fileId不能为空");
|
||||
}
|
||||
Integer affectRows = fileDOMapper.updateFileSha1(fileId, fileSha1);
|
||||
return affectRows > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过文件对象Id找到文件Id
|
||||
*
|
||||
* @param fileObjectId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public FileModel getFileByFileObjectId(Integer fileObjectId) {
|
||||
FileDO fileDO = fileDOMapper.selectByPrimaryKey(fileObjectId);
|
||||
FileModel fileModel = convertFromDataObject(fileDO);
|
||||
return fileModel;
|
||||
}
|
||||
}
|
||||
|
@@ -1,146 +0,0 @@
|
||||
package plus.bookshelf.Service.Impl;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import plus.bookshelf.Common.Enum.ScheduleTaskActionEnum;
|
||||
import plus.bookshelf.Common.Error.BusinessErrorCode;
|
||||
import plus.bookshelf.Common.Error.BusinessException;
|
||||
import plus.bookshelf.Common.FileManager.QCloudCosUtils;
|
||||
import plus.bookshelf.Config.QCloudCosConfig;
|
||||
import plus.bookshelf.Dao.DO.ScheduleTaskDO;
|
||||
import plus.bookshelf.Dao.Mapper.ScheduleTaskDOMapper;
|
||||
import plus.bookshelf.Service.Model.ScheduleTaskModel;
|
||||
import plus.bookshelf.Service.Service.CosPresignedUrlGenerateLogService;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static plus.bookshelf.Common.Enum.ScheduleTaskActionEnum.*;
|
||||
|
||||
@Service
|
||||
public class ScheduleTaskServiceImpl {
|
||||
|
||||
@Autowired
|
||||
QCloudCosConfig qCloudCosConfig;
|
||||
|
||||
@Autowired
|
||||
CosPresignedUrlGenerateLogService cosPresignedUrlGenerateLogService;
|
||||
|
||||
@Autowired
|
||||
ScheduleTaskDOMapper scheduleTaskDOMapper;
|
||||
|
||||
@Autowired
|
||||
FileServiceImpl fileService;
|
||||
|
||||
public void setExecutor() {
|
||||
// 创建定时任务 (主要是待用户将文件上传成功到COS后)
|
||||
java.util.concurrent.ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
|
||||
// 参数:1、任务体 2、首次执行的延时时间
|
||||
// 3、任务执行间隔 4、间隔时间单位
|
||||
service.scheduleAtFixedRate(() -> {
|
||||
try {
|
||||
thingsTodo();
|
||||
} catch (BusinessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, 0, 3, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void thingsTodo() throws BusinessException {
|
||||
|
||||
// 检查上传文件后未收到客户端发来的上传完成消息的情况。
|
||||
// 如果系统里面没有记录,那么删除COS存储桶中用户上传的这个文件。
|
||||
|
||||
System.out.println("检查定时任务");
|
||||
|
||||
ScheduleTaskDO[] scheduleTaskDO = scheduleTaskDOMapper.selectTodoTask();
|
||||
|
||||
for (ScheduleTaskDO task : scheduleTaskDO) {
|
||||
ScheduleTaskModel scheduleTaskModel = convertToModel(task);
|
||||
switch (scheduleTaskModel.getAction()) {
|
||||
case CHECK_FILE_IS_UPLOADED:
|
||||
// TODO 系统中没有这个文件,而对象存储中有这个文件,那么删除对象存储中的文件
|
||||
// fileService.doScheduleTask(scheduleTaskModel);
|
||||
// 检查文件是否被上传
|
||||
QCloudCosUtils qCloudCosUtils = new QCloudCosUtils(qCloudCosConfig, cosPresignedUrlGenerateLogService);
|
||||
Boolean isExists = qCloudCosUtils.doesObjectExist(QCloudCosUtils.BOOK_SAVE_FOLDER, task.getData());
|
||||
if (isExists) {
|
||||
// 如果文件存在,则更新数据库中的状态
|
||||
// TODO
|
||||
System.out.println("文件已经上传,更新数据库中的状态");
|
||||
}
|
||||
|
||||
// 在数据库中设置为完成
|
||||
Boolean isDoneSuccess = doneScheduleTask(task.getId());
|
||||
if (!isDoneSuccess) {
|
||||
throw new BusinessException(BusinessErrorCode.UNKNOWN_ERROR, "系统错误!更新数据库中的状态失败");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new BusinessException(BusinessErrorCode.UNKNOWN_ERROR, "未知的定时任务类型");
|
||||
}
|
||||
}
|
||||
|
||||
// 输出
|
||||
System.out.println("Task ScheduledExecutorService " + new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个新的定时任务(存入数据库)
|
||||
*
|
||||
* @param scheduleTaskModel
|
||||
* @return
|
||||
*/
|
||||
public Boolean insertScheduleTask(ScheduleTaskModel scheduleTaskModel) {
|
||||
ScheduleTaskDO scheduleTaskDO = convertToDataObject(scheduleTaskModel);
|
||||
int affectRows = scheduleTaskDOMapper.insertSelective(scheduleTaskDO);
|
||||
return affectRows > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 完成一个定时任务(从数据库中删除)
|
||||
* 注意先删除,删除成功后才进行处理,避免自动触发和手动触发同时进行
|
||||
*
|
||||
* @param scheduleTaskId
|
||||
* @return
|
||||
*/
|
||||
public Boolean doneScheduleTask(Integer scheduleTaskId) {
|
||||
int affectRows = scheduleTaskDOMapper.deleteByPrimaryKey(scheduleTaskId);
|
||||
return affectRows > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过 Guid 查询任务
|
||||
*
|
||||
* @param guid
|
||||
* @return
|
||||
*/
|
||||
public ScheduleTaskModel findTaskByGuid(String guid) {
|
||||
ScheduleTaskDO scheduleTaskDO = scheduleTaskDOMapper.selectByGuid(guid);
|
||||
return convertToModel(scheduleTaskDO);
|
||||
}
|
||||
|
||||
private static ScheduleTaskDO convertToDataObject(ScheduleTaskModel scheduleTaskModel) {
|
||||
if (scheduleTaskModel == null) {
|
||||
return null;
|
||||
}
|
||||
ScheduleTaskDO scheduleTaskDO = new ScheduleTaskDO();
|
||||
BeanUtils.copyProperties(scheduleTaskModel, scheduleTaskDO);
|
||||
scheduleTaskDO.setAction(String.valueOf(scheduleTaskModel.getAction()));
|
||||
return scheduleTaskDO;
|
||||
}
|
||||
|
||||
private static ScheduleTaskModel convertToModel(ScheduleTaskDO scheduleTaskDO) {
|
||||
if (scheduleTaskDO == null) {
|
||||
return null;
|
||||
}
|
||||
ScheduleTaskModel scheduleTaskModel = new ScheduleTaskModel();
|
||||
BeanUtils.copyProperties(scheduleTaskDO, scheduleTaskModel);
|
||||
scheduleTaskModel.setAction(ScheduleTaskActionEnum.valueOf(scheduleTaskDO.getAction()));
|
||||
return scheduleTaskModel;
|
||||
}
|
||||
}
|
@@ -13,14 +13,17 @@ public class FileModel {
|
||||
// 关联的书籍Id
|
||||
Integer bookId;
|
||||
|
||||
// 文件名 (用于展示给用户的文件名,不含扩展名)
|
||||
String fileDisplayName;
|
||||
|
||||
// 文件存储名称 (文件的实际文件名,含扩展名)
|
||||
// 文件名,不含扩展名
|
||||
String fileName;
|
||||
|
||||
// 文件格式 (文件扩展名)
|
||||
String fileFormat;
|
||||
// 文件扩展名
|
||||
String fileExt;
|
||||
|
||||
// 文件大小
|
||||
long fileSize;
|
||||
|
||||
// 文件哈希 - SHA1
|
||||
String fileSha1;
|
||||
|
||||
// 总页数
|
||||
Integer numberOfPages;
|
||||
@@ -32,17 +35,11 @@ public class FileModel {
|
||||
Boolean advertising;
|
||||
|
||||
// 文件来源 电子版/扫描版
|
||||
String bookOrigin;
|
||||
String source;
|
||||
|
||||
// 文件创建时间
|
||||
Date fileCreateAt;
|
||||
|
||||
// 文件修改时间
|
||||
Date fileModifiedAt;
|
||||
|
||||
// 文件大小
|
||||
long fileSize;
|
||||
|
||||
// 文件哈希 - SHA1
|
||||
String fileSha1;
|
||||
}
|
||||
|
@@ -11,17 +11,11 @@ public class FileObjectModel {
|
||||
// 存储的文件Id
|
||||
private Integer fileId;
|
||||
|
||||
// 文件名
|
||||
private String fileName;
|
||||
|
||||
// 文件大小
|
||||
private Long fileSize;
|
||||
|
||||
// 文件类型
|
||||
private String fileType;
|
||||
// 文件上传状态
|
||||
String uploadStatus;
|
||||
|
||||
// 文件存储介质类型
|
||||
String storageMediumType;
|
||||
String storageMedium;
|
||||
|
||||
// 文件地址
|
||||
// 如果是网盘就是分享链接,如果是本地存储就是文件路径
|
||||
@@ -35,13 +29,4 @@ public class FileObjectModel {
|
||||
|
||||
// 文件最后修改时间戳
|
||||
Long lastModified;
|
||||
|
||||
// 文件上传状态
|
||||
String uploadStatus;
|
||||
|
||||
// 文件哈希 - SHA1
|
||||
String fileSha1;
|
||||
|
||||
// 附加字段(JSON存储)
|
||||
String additionalFields;
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@ public interface FileObjectService {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<FileObjectModel> list(String token) throws InvocationTargetException, IllegalAccessException, BusinessException;
|
||||
List<FileObjectModel> list() throws InvocationTargetException, IllegalAccessException, BusinessException;
|
||||
|
||||
/**
|
||||
* 添加文件对象
|
||||
@@ -46,16 +46,16 @@ public interface FileObjectService {
|
||||
* @param fileSize 文件大小
|
||||
* @param fileSHA1 文件SHA1
|
||||
* @param fileExt 文件扩展名
|
||||
* @param fileNameWithoutExt 文件名(不包含扩展名)
|
||||
* @param fileName 文件名(不包含扩展名)
|
||||
* @param fileStorageMediumEnum 文件存储介质
|
||||
* @param bookOrigin 文件来源
|
||||
* @param source 文件来源
|
||||
* @return 是否插入成功
|
||||
* @throws InvocationTargetException
|
||||
* @throws IllegalAccessException
|
||||
* @throws BusinessException
|
||||
*/
|
||||
@Transactional
|
||||
Integer uploadFile(Integer fileId, String fileName, String filePath, Long fileSize, String fileSHA1, String fileExt, String fileNameWithoutExt, FileStorageMediumEnum fileStorageMediumEnum, String bookOrigin, Long lastModified) throws InvocationTargetException, IllegalAccessException, BusinessException;
|
||||
Integer uploadFile(Integer fileId, String fileName, String filePath, Long fileSize, String fileSHA1, String fileExt, FileStorageMediumEnum fileStorageMediumEnum, String source, Long lastModified) throws InvocationTargetException, IllegalAccessException, BusinessException;
|
||||
|
||||
/**
|
||||
* 修改文件对象上传状态信息
|
||||
|
@@ -56,4 +56,22 @@ public interface FileService {
|
||||
* @return
|
||||
*/
|
||||
Integer getLastInsertId();
|
||||
|
||||
/**
|
||||
* 更新文件的SHA1值
|
||||
*
|
||||
* @param fileId 文件Id
|
||||
* @param fileSha1 文件SHA1值
|
||||
* @return
|
||||
* @throws BusinessException
|
||||
*/
|
||||
Boolean updateFileSha1(Integer fileId, String fileSha1) throws BusinessException;
|
||||
|
||||
/**
|
||||
* 通过文件对象Id找到文件Id
|
||||
*
|
||||
* @param fileObjectId
|
||||
* @return
|
||||
*/
|
||||
FileModel getFileByFileObjectId(Integer fileObjectId);
|
||||
}
|
||||
|
Reference in New Issue
Block a user