|
|
@@ -738,10 +738,62 @@ public class DmService {
|
|
|
// 按 caseId 原子取走本次清洗缓冲后再落库:
|
|
|
// 缓冲已按案件分桶,不会把其他用户案件累积的人员冲进当前案件库
|
|
|
CleanCache.CleanSnapshot snapshot = CleanCache.drain();
|
|
|
- sseService.sendSee(new SseDTO(101, slowDownProgress.calculateNextProgress(), "[清洗] 正在合并人员库", new SeeDataDTO(0, 0)));
|
|
|
- personLibNoService.flushPerLib(snapshot.personLibNos());
|
|
|
- sseService.sendSee(new SseDTO(101, slowDownProgress.calculateNextProgress(), "[清洗] 正在创建对象", new SeeDataDTO(0, 0)));
|
|
|
- personBasicInfoService.flushPerson(snapshot.persons());
|
|
|
+ // 人员库/对象落库是「最后一条提取日志 → 终态推送」之间最长的静默段,
|
|
|
+ // 大批量导入时可达分钟级 —— 必须把数量与耗时实时播报出去,否则用户看到的
|
|
|
+ // 就是「提取早就完成了,最终结果却迟迟不推」。两个落库互不依赖(不同表,
|
|
|
+ // DuckDB 连接每次 getConnection() 都是 duplicate 出来的独立连接),并行压缩窗口。
|
|
|
+ int libCount = snapshot.personLibNos().size();
|
|
|
+ int personCount = snapshot.persons().size();
|
|
|
+ sseService.sendSee(new SseDTO(101, slowDownProgress.calculateNextProgress(),
|
|
|
+ "[清洗] 正在合并人员库(" + libCount + " 条)", new SeeDataDTO(0, 0)));
|
|
|
+ sseService.sendSee(new SseDTO(101, slowDownProgress.calculateNextProgress(),
|
|
|
+ "[清洗] 正在创建对象(" + personCount + " 个)", new SeeDataDTO(0, 0)));
|
|
|
+ Long flushCaseId = CaseContextHolder.get();
|
|
|
+ Long flushUserId = CaseContextHolder.getUserId();
|
|
|
+ AtomicReference<Throwable> flushFailure = new AtomicReference<>();
|
|
|
+ long flushStart = System.currentTimeMillis();
|
|
|
+ Thread libThread = Thread.startVirtualThread(() ->
|
|
|
+ CaseContextHolder.runWith(flushCaseId, flushUserId, () -> {
|
|
|
+ try {
|
|
|
+ long t0 = System.currentTimeMillis();
|
|
|
+ personLibNoService.flushPerLib(snapshot.personLibNos());
|
|
|
+ sseService.sendSee(new SseDTO(101, slowDownProgress.current(),
|
|
|
+ "[清洗] 人员库合并完成:" + libCount + " 条,耗时 "
|
|
|
+ + ((System.currentTimeMillis() - t0) / 1000) + " 秒",
|
|
|
+ new SeeDataDTO(0, 0)));
|
|
|
+ } catch (Throwable t) {
|
|
|
+ flushFailure.compareAndSet(null, t);
|
|
|
+ }
|
|
|
+ }));
|
|
|
+ Thread personThread = Thread.startVirtualThread(() ->
|
|
|
+ CaseContextHolder.runWith(flushCaseId, flushUserId, () -> {
|
|
|
+ try {
|
|
|
+ long t0 = System.currentTimeMillis();
|
|
|
+ personBasicInfoService.flushPerson(snapshot.persons());
|
|
|
+ sseService.sendSee(new SseDTO(101, slowDownProgress.current(),
|
|
|
+ "[清洗] 对象创建完成:" + personCount + " 个,耗时 "
|
|
|
+ + ((System.currentTimeMillis() - t0) / 1000) + " 秒",
|
|
|
+ new SeeDataDTO(0, 0)));
|
|
|
+ } catch (Throwable t) {
|
|
|
+ flushFailure.compareAndSet(null, t);
|
|
|
+ }
|
|
|
+ }));
|
|
|
+ try {
|
|
|
+ libThread.join();
|
|
|
+ personThread.join();
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
+ throw ServerException.build("人员库/对象落库被中断");
|
|
|
+ }
|
|
|
+ if (flushFailure.get() != null) {
|
|
|
+ // 落库失败不能静默吞掉:人员/对象缺失会让后续治理与画像直接少数据
|
|
|
+ log.error("人员库/对象落库失败", flushFailure.get());
|
|
|
+ sseService.sendSee(new SseDTO(101, slowDownProgress.current(),
|
|
|
+ "[清洗] 人员库/对象落库失败:" + StrUtil.maxLength(flushFailure.get().getMessage(), 120),
|
|
|
+ new SeeDataDTO(0, 0)));
|
|
|
+ }
|
|
|
+ log.info("人员库/对象落库完成: lib={}, person={}, 耗时={}ms",
|
|
|
+ libCount, personCount, System.currentTimeMillis() - flushStart);
|
|
|
List<FileInfo> fileInfoList = fileInfoMapper.selectList(Wrappers.lambdaQuery(FileInfo.class)
|
|
|
.eq(FileInfo::getBatchId, batchId)
|
|
|
.isNull(FileInfo::getFileType));
|