mirror of
https://gitee.com/bookshelfplus/bookshelfplus
synced 2025-09-12 03:31:39 +08:00
关联文件仅可关联系统中未设置SHA1,或SHA1值相同的文件记录
This commit is contained in:
@@ -115,11 +115,9 @@
|
||||
<div id="processBar2" class="process-bar">
|
||||
<div id="processBar2Inner" class="process-bar-inner"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<p>关联文件</p>
|
||||
<p>关联文件<br><span style="font-size: 12px;">(仅可关联系统中未设置SHA1,或SHA1值相同的文件记录)</span></p>
|
||||
<select id="fileAssociator">
|
||||
<option value="0">新建文件</option>
|
||||
<!-- <option value="0">新建文件</option> -->
|
||||
</select>
|
||||
</div>
|
||||
<button id="beginUpload" disabled="true">开始上传</button>
|
||||
@@ -221,6 +219,9 @@
|
||||
fileInfo.fileSha1 = sha1;
|
||||
document.getElementById("file-sha1").innerHTML = fileInfo.fileSha1;
|
||||
|
||||
// 获取关联文件下拉框列表并渲染
|
||||
getFileAssociatorList(sha1);
|
||||
|
||||
// 完成
|
||||
console.log(fileInfo);
|
||||
}
|
||||
@@ -422,28 +423,32 @@
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
var fileAssociator = document.getElementById("fileAssociator");
|
||||
// 下拉框列表
|
||||
postRequest("/file/list", { token: localStorageUtils.getToken() })
|
||||
.then(function (responseData) {
|
||||
var axiosData = responseData.data;
|
||||
var status = axiosData.status;
|
||||
var data = axiosData.data;
|
||||
if (status === "success") {
|
||||
// console.log(data);
|
||||
// 数据进行转换
|
||||
var optionHTML = "";
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
const element = data[i];
|
||||
optionHTML += `<option value="${element.id}">[${element.id}] ${element.fileDisplayName}.${element.fileFormat}</option>`;
|
||||
// 关联文件下拉框列表
|
||||
function getFileAssociatorList(fileSha1) {
|
||||
var fileAssociator = document.getElementById("fileAssociator");
|
||||
// 下拉框列表
|
||||
postRequest("/file/list/MatchfileHash", { token: localStorageUtils.getToken(), fileSha1: fileSha1 })
|
||||
.then(function (responseData) {
|
||||
var axiosData = responseData.data;
|
||||
var status = axiosData.status;
|
||||
var data = axiosData.data;
|
||||
if (status === "success") {
|
||||
// console.log(data);
|
||||
// 数据进行转换
|
||||
var optionHTML = "";
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
const element = data[i];
|
||||
optionHTML += `<option value="${element.id}">[${element.id}] ${element.fileDisplayName}.${element.fileFormat}</option>`;
|
||||
}
|
||||
// 渲染到下拉框内
|
||||
// fileAssociator.innerHTML += optionHTML;
|
||||
fileAssociator.innerHTML = `<option value="0">新建文件</option>` + optionHTML;
|
||||
} else {
|
||||
alert(`出错啦!${data.errMsg} (错误码: ${data.errCode}) `);
|
||||
}
|
||||
// 渲染到下拉框内
|
||||
fileAssociator.innerHTML += optionHTML;
|
||||
} else {
|
||||
alert(`出错啦!${data.errMsg} (错误码: ${data.errCode}) `);
|
||||
}
|
||||
}).catch(function (error) {
|
||||
console.log(error);
|
||||
alert("无法连接到服务器,请检查网络连接!");
|
||||
});
|
||||
}).catch(function (error) {
|
||||
console.log(error);
|
||||
alert("无法连接到服务器,请检查网络连接!");
|
||||
});
|
||||
}
|
||||
</script>
|
@@ -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;
|
||||
|
||||
/**
|
||||
* 添加文件信息
|
||||
|
@@ -228,6 +228,12 @@
|
||||
<include refid="Base_Column_List" />
|
||||
from file_info
|
||||
</select>
|
||||
<select id="selectBySha1WithNullValue" parameterType="java.lang.String" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from file_info
|
||||
where file_sha1 = #{fileSha1,jdbcType=VARCHAR} or file_sha1 is null or file_sha1 = ''
|
||||
</select>
|
||||
<select id="getLastInsertId" resultType="java.lang.Integer">
|
||||
SELECT LAST_INSERT_ID();
|
||||
</select>
|
||||
|
Reference in New Issue
Block a user