1
0
mirror of https://gitee.com/bookshelfplus/bookshelfplus synced 2025-09-21 01:10:39 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

完成文件对象管理刷新状态功能

This commit is contained in:
2022-04-16 23:47:22 +08:00
parent 3b6c6aa3e7
commit 5c895d0ef5
6 changed files with 134 additions and 39 deletions

View File

@@ -61,8 +61,8 @@
修改: ${new Date(element.fileModifiedAt).toLocaleString()}
</nobr></span>`,
管理: `<span class="overflow-omit" style="margin: 0 auto;">
<a href="<%= pageUrl %>detail?id=${element.id}">管理文件对象</a>
<a href="javascript:deleteBook(${element.id});">删除</a>
<a href="<%= pageUrl %>detail?id=${element.id}">管理文件对象(TODO)</a>
<a href="javascript:deleteBook(${element.id});">删除(TODO)</a>
</span>`,
})
});

View File

@@ -12,9 +12,7 @@
您现在在「文件管理 > 文件对象管理」,以下是系统所有文件对象信息
</p>
<script>
list({
tableElementId: "book-table"
});
list({ tableElementId: "book-table" });
function list({ tableElementId }) {
postRequest("/file/object/list", { token: localStorageUtils.getToken() })
@@ -53,11 +51,11 @@
状态: `${(element.uploadStatus ? element.uploadStatus : "<span style='color: grey; font-weight: bold;'>未知</span>")
.replace("SUCCESS", "<span style='color: green; font-weight: bold;'>成功</span>")
.replace("UPLOADING", "<span style='color: orange; font-weight: bold;'>正在上传</span>")
.replace("TERMINATED", "<span style='color: red; font-weight: bold;'>上传失败</span>")}`,
管理: `<span span class= "overflow-omit" style = "margin: 0 auto;" >
.replace("NOT_EXIST", "<span style='color: red; font-weight: bold;'>不存在</span>")}`,
管理: `<span span class="overflow-omit" style="margin: 0 auto;">
<a href="javascript:refreshFileObjectStatus(${element.id});">刷新状态</a>
<a href="<%= pageUrl %>../object-detail?id=${element.id}">修改</a>
<a href="javascript:deleteBook(${element.id});">删除</a>
<a href="<%= pageUrl %>../object-detail?id=${element.id}">修改(TODO)</a>
<a href="javascript:deleteBook(${element.id});">删除(TODO)</a>
</span > `,
})
});
@@ -81,4 +79,23 @@
alert("无法连接到服务器,请检查网络连接!");
});
}
function refreshFileObjectStatus(fileObjectId) {
postRequest("/file/object/refreshFileObjectStatus", { token: localStorageUtils.getToken(), fileObjectId: fileObjectId })
.then(function (responseData) {
var axiosData = responseData.data;
var status = axiosData.status;
var data = axiosData.data;
if (status === "success") {
console.log(data);
alert("刷新成功!");
list({ tableElementId: "book-table" });
} else {
alert(`出错啦!${data.errMsg} (错误码: ${data.errCode}) `);
}
}).catch(function (error) {
console.log(error);
alert("无法连接到服务器,请检查网络连接!");
});
}
</script>

View File

@@ -11,7 +11,7 @@
Target Server Version : 50726
File Encoding : 65001
Date: 15/04/2022 22:07:58
Date: 16/04/2022 23:29:53
*/
SET NAMES utf8mb4;
@@ -148,7 +148,7 @@ CREATE TABLE `file_info` (
`file_create_at` datetime NOT NULL,
`file_modified_at` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP,
`file_size` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
`hash_sha1` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
`file_sha1` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = DYNAMIC;
@@ -170,8 +170,9 @@ CREATE TABLE `file_object_info` (
`file_path` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '本地文件保存相对路径(本地维护用,非线上使用)',
`file_pwd` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
`file_share_code` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
`upload_status` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '上传状态(上传成功 SUCCESS正在上传 UPLOADING上传终止 TERMINATED',
`hash_sha1` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '文件SHA1哈希',
`upload_status` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '上传状态(上传成功 SUCCESS正在上传 UPLOADING上传终止 NOT_EXIST',
`file_sha1` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '文件SHA1哈希',
`last_modified` bigint(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT '文件最后修改时间戳',
`additional_fields` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = DYNAMIC;
@@ -196,7 +197,7 @@ CREATE TABLE `schedule_task` (
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `task_guid`(`task_guid`) USING BTREE,
INDEX `schedule_time`(`schedule_time`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of schedule_task

View File

@@ -95,17 +95,6 @@ public class FileController extends BaseController {
return CommonReturnType.create(fileVOS);
}
private FileVO convertFileVOFromModel(FileModel fileModel) {
if (fileModel == null) {
return null;
}
FileVO fileVO = new FileVO();
BeanUtils.copyProperties(fileModel, fileVO);
fileVO.setFileCreateAt(fileModel.getFileCreateAt().getTime());
fileVO.setFileModifiedAt(fileModel.getFileModifiedAt().getTime());
return fileVO;
}
@ApiOperation(value = "【管理员】查询文件对象列表", notes = "查询文件列表")
@RequestMapping(value = "object/list", method = {RequestMethod.POST}, consumes = {CONTENT_TYPE_FORMED})
@ResponseBody
@@ -125,18 +114,56 @@ public class FileController extends BaseController {
return CommonReturnType.create(fileObjectVOS);
}
private FileObjectVO convertFileObjectVOFromModel(FileObjectModel fileObjectModel) {
if (fileObjectModel == null) {
return null;
@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, "非管理员用户无权进行此操作");
}
FileObjectVO fileObjectVO = new FileObjectVO();
BeanUtils.copyProperties(fileObjectModel, fileObjectVO);
try {
// 尝试将 FileStorageMedium 转为中文,如果没有成功,那么就保留英文
fileObjectVO.setStorageMediumType(FileStorageMediumEnum.valueOf(fileObjectModel.getStorageMediumType()).getStorageMediumDisplayName());
} catch (Exception e) {
// 获取旧文件权限
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 fileObjectVO;
return CommonReturnType.create(isSuccess);
}
/**
@@ -196,7 +223,7 @@ public class FileController extends BaseController {
// 判断对象是否存在
Boolean isExist = qCloudCosUtils.doesObjectExist(bookSaveFolder, fileSha1);
String url = null;
switch (httpMethodName) {
switch (httpMethodName) {
case PUT:
// 上传文件
if (isExist) throw new BusinessException(BusinessErrorCode.PARAMETER_VALIDATION_ERROR, "文件已存在");
@@ -300,6 +327,31 @@ public class FileController extends BaseController {
}
return CommonReturnType.create("success");
}
private FileVO convertFileVOFromModel(FileModel fileModel) {
if (fileModel == null) {
return null;
}
FileVO fileVO = new FileVO();
BeanUtils.copyProperties(fileModel, fileVO);
fileVO.setFileCreateAt(fileModel.getFileCreateAt().getTime());
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;
}
}
/*

View File

@@ -78,7 +78,7 @@ public class FileObjectServiceImpl implements FileObjectService {
}
private FileObjectModel convertFromDataObject(FileObjectDO fileObjectDO) throws InvocationTargetException, IllegalAccessException {
if(fileObjectDO == null) {
if (fileObjectDO == null) {
return null;
}
FileObjectModel fileObjectModel = new FileObjectModel();
@@ -103,7 +103,7 @@ public class FileObjectServiceImpl implements FileObjectService {
}
private FileObjectDO convertFromFileObjectModel(FileObjectModel fileObjectModel) {
if(fileObjectModel == null) {
if (fileObjectModel == null) {
return null;
}
FileObjectDO fileObjectDO = new FileObjectDO();
@@ -213,7 +213,7 @@ public class FileObjectServiceImpl implements FileObjectService {
}
/**
* 通过文件路径获取文件
* 通过文件路径获取文件对象
*
* @param filePath 文件路径
* @return
@@ -224,4 +224,19 @@ public class FileObjectServiceImpl implements FileObjectService {
FileObjectModel fileObjectModel = convertFromDataObject(fileObjectDO);
return fileObjectModel;
}
/**
* 通过 Id 获取文件对象
*
* @param fileObjectId 文件对象 Id
* @return
* @throws InvocationTargetException
* @throws IllegalAccessException
*/
@Override
public FileObjectModel getFileObjectById(Integer fileObjectId) throws InvocationTargetException, IllegalAccessException {
FileObjectDO fileObjectDO = fileObjectDOMapper.selectByPrimaryKey(fileObjectId);
FileObjectModel fileObjectModel = convertFromDataObject(fileObjectDO);
return fileObjectModel;
}
}

View File

@@ -72,4 +72,14 @@ public interface FileObjectService {
* @return
*/
FileObjectModel getFileObjectByFilePath(String filePath) throws InvocationTargetException, IllegalAccessException;
/**
* 通过 Id 获取文件对象
*
* @param fileObjectId 文件对象 Id
* @return
* @throws InvocationTargetException
* @throws IllegalAccessException
*/
FileObjectModel getFileObjectById(Integer fileObjectId) throws InvocationTargetException, IllegalAccessException;
}