|
@@ -23,6 +23,8 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
@RestController
|
|
@@ -353,7 +355,50 @@ public class ArchiveFileClientImpl implements ArchiveFileClient {
|
|
|
|
|
|
@Override
|
|
|
public void updateArchiveFileEx(List<ArchiveFile> files) {
|
|
|
- iArchiveFileService.updateBatchById(files);
|
|
|
+ // 1. 提取传入文件列表中的所有ID(过滤空值)
|
|
|
+ List<Long> ids = files.stream()
|
|
|
+ .map(ArchiveFile::getId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (ids.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 根据ID批量查询现有记录
|
|
|
+ LambdaQueryWrapper<ArchiveFile> wrapper = Wrappers.lambdaQuery();
|
|
|
+ wrapper.in(ArchiveFile::getId, ids);
|
|
|
+ List<ArchiveFile> existFiles = iArchiveFileService.list(wrapper);
|
|
|
+
|
|
|
+ // 3. 将传入文件列表转换为Map<ID, 文件对象>便于查找
|
|
|
+ Map<Long, ArchiveFile> externalFileMap = files.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ ArchiveFile::getId,
|
|
|
+ Function.identity(),
|
|
|
+ (existing, replacement) -> existing // 处理重复ID,保留第一个
|
|
|
+ ));
|
|
|
+
|
|
|
+ // 4. 更新需要同步的字段
|
|
|
+ List<ArchiveFile> updateList = existFiles.stream()
|
|
|
+ .map(local -> {
|
|
|
+ ArchiveFile external = externalFileMap.get(local.getId());
|
|
|
+ if (external != null) {
|
|
|
+ // 仅更新指定字段(根据业务需求调整)
|
|
|
+ local.setFileUrl(external.getFileUrl());
|
|
|
+ local.setEVisaFile(external.getEVisaFile());
|
|
|
+ local.setPdfPageUrl(external.getPdfPageUrl());
|
|
|
+ local.setFilePage(external.getFilePage());
|
|
|
+ local.setFileSize(external.getFileSize());
|
|
|
+ local.setUtime(external.getUtime());
|
|
|
+ }
|
|
|
+ return local;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 5. 批量更新(建议分批处理,如每500条一次)
|
|
|
+ if (!updateList.isEmpty()) {
|
|
|
+ iArchiveFileService.updateBatchById(updateList);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|