feat(file): 新增文件哈希去重与文本提取功能- 在多个模块中引入 FileHashUtil 并用于文件上传前的哈希计算
- 优化文件上传逻辑,实现基于哈希的秒传机制 - 新增音频服务中的文本提取方法,支持 txt 和 docx 格式 - 使用流式解析技术处理大文件内容,避免内存溢出 -为 AppVideoController 添加 /extract 接口用于文本内容提取 - 完善文件哈希工具类,增强线程安全性与异常处理 - 调整 SysOssService 的 updateHash 方法以支持复用逻辑- 统一构建 SysOssVo 实体时的哈希字段设置逻辑
This commit is contained in:
@ -39,6 +39,7 @@ public class DeviceDebugService {
|
||||
private final IAppBusinessFileService appBusinessFileService;
|
||||
private final IAppOperationVideoService appOperationVideoService;
|
||||
private final DeviceService deviceService;
|
||||
private final FileHashUtil fileHashUtil;
|
||||
|
||||
/**
|
||||
* 文件上传并添加文件信息哈希去重
|
||||
@ -62,26 +63,12 @@ public class DeviceDebugService {
|
||||
Map<String, Long> hash2OssId = new LinkedHashMap<>(files.length);
|
||||
for (MultipartFile file : files) {
|
||||
// 1. 计算文件哈希
|
||||
String hash = FileHashUtil.hash(file);
|
||||
String hash = fileHashUtil.hash(file);
|
||||
|
||||
// 2. 先根据 hash 查库(秒传)
|
||||
SysOssVo exist = sysOssService.selectByHash(hash);
|
||||
Long ossId;
|
||||
if (exist != null) {
|
||||
// 2.1 已存在,直接复用
|
||||
ossId = exist.getOssId();
|
||||
hash2OssId.putIfAbsent(hash, ossId);
|
||||
} else {
|
||||
// 2.2 不存在,真正上传
|
||||
SysOssVo upload = sysOssService.upload(file);
|
||||
if (upload == null) {
|
||||
return false;
|
||||
}
|
||||
ossId = upload.getOssId();
|
||||
hash2OssId.putIfAbsent(hash, ossId);
|
||||
// 2.3 把 hash 写回记录(供下次去重)
|
||||
sysOssService.updateHashById(ossId, hash);
|
||||
}
|
||||
SysOssVo exist = sysOssService.updateHash(file, hash);
|
||||
// 2.1 已存在,直接复用
|
||||
long ossId = exist.getOssId();
|
||||
hash2OssId.putIfAbsent(hash, ossId);
|
||||
}
|
||||
// 4. 组装业务中间表
|
||||
List<AppBusinessFile> bizList = new ArrayList<>(bo.getDeviceIds().length * hash2OssId.size());
|
||||
|
||||
Reference in New Issue
Block a user