From ab11c91579b6c416c3bc6ab3bc2e1691ea993ba7 Mon Sep 17 00:00:00 2001 From: caozehui <2427765068@qq.com> Date: Thu, 16 Apr 2026 14:14:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=B3=E4=BA=8E=E6=97=B6=E9=97=B4=E7=B2=BE?= =?UTF-8?q?=E5=BA=A6=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SocketFreqConverterDevService.java | 33 +++++++++++++++---- .../handler/SocketFreqConverterService.java | 15 +++++---- .../util/socket/FormalTestManager.java | 10 ++---- .../IPqFreqConverterTestResService.java | 2 +- .../PqFreqConverterTestResServiceImpl.java | 2 +- 5 files changed, 39 insertions(+), 23 deletions(-) diff --git a/detection/src/main/java/com/njcn/gather/detection/handler/SocketFreqConverterDevService.java b/detection/src/main/java/com/njcn/gather/detection/handler/SocketFreqConverterDevService.java index f713d284..316fc35d 100644 --- a/detection/src/main/java/com/njcn/gather/detection/handler/SocketFreqConverterDevService.java +++ b/detection/src/main/java/com/njcn/gather/detection/handler/SocketFreqConverterDevService.java @@ -291,8 +291,15 @@ public class SocketFreqConverterDevService { private void initDipTestRes(PqDipData pqDipData) { Integer suffix = FormalTestManager.freqConverterTableSuffix; FreqConverterStatus lastStatusData = freqConverterService.getLastStatusData(suffix, pqDipData.getStartTime()); + if (Objects.isNull(lastStatusData)) { + return; + } + List statusList = freqConverterService.getDipDurationStatusData(suffix, lastStatusData.getTimestamp(), pqDipData.getStartTime().plusNanos(pqDipData.getDurationMs() * 1000_000L)); boolean originalTolerant = lastStatusData.getStatusWord1() != freqConverterConfig.getNoTolerant(); + LocalDateTime targetEndTime = pqDipData.getStartTime() + .plusNanos(pqDipData.getDurationMs() * 1000_000L) + .plusNanos(freqConverterConfig.getDt() * 1000_000L); if (CollUtil.isNotEmpty(statusList)) { FreqConverterStatus status = statusList.get(statusList.size() - 1); @@ -301,13 +308,25 @@ public class SocketFreqConverterDevService { testRes.setTolerant(originalTolerant ? status.getStatusWord1() != freqConverterConfig.getNoTolerant() : false); testRes.setStartTime(lastStatusData.getTimestamp()); - int collectCount = (int) Math.ceil((freqConverterConfig.getDt()) / freqConverterConfig.getSchedulePeriod()); - if (collectCount > 0) { - FormalTestManager.pendingDipTaskMap.put(pqDipData.getId(), new FormalTestManager.PendingDipTask(pqDipData.getId(), pqDipData.getStartTime(), originalTolerant, collectCount)); - } else { - testRes.setEndTime(status.getTimestamp()); - } - pqFreqConverterTestResService.saveTestRes(suffix, Collections.singletonList(testRes)); + FormalTestManager.pendingDipTaskMap.put(pqDipData.getId(), new FormalTestManager.PendingDipTask( + pqDipData.getId(), + pqDipData.getStartTime(), + targetEndTime, + originalTolerant + )); + testRes.setEndTime(status.getTimestamp()); + +// if (status.getTimestamp().isBefore(targetEndTime)) { +// FormalTestManager.pendingDipTaskMap.put(pqDipData.getId(), new FormalTestManager.PendingDipTask( +// pqDipData.getId(), +// pqDipData.getStartTime(), +// targetEndTime, +// originalTolerant +// )); +// } else { +// testRes.setEndTime(status.getTimestamp().isAfter(targetEndTime) ? targetEndTime : status.getTimestamp()); +// } + pqFreqConverterTestResService.saveOrUpdateTestRes(suffix, Collections.singletonList(testRes)); } } diff --git a/detection/src/main/java/com/njcn/gather/detection/handler/SocketFreqConverterService.java b/detection/src/main/java/com/njcn/gather/detection/handler/SocketFreqConverterService.java index d81184d0..d3042912 100644 --- a/detection/src/main/java/com/njcn/gather/detection/handler/SocketFreqConverterService.java +++ b/detection/src/main/java/com/njcn/gather/detection/handler/SocketFreqConverterService.java @@ -198,8 +198,8 @@ public class SocketFreqConverterService { // } else { // FormalTestManager.stopFlag = false; // } - freqConverterService.saveFreqConverterStatus(FormalTestManager.freqConverterTableSuffix, freqConverterStatus); this.consumePendingDipTasks(freqConverterStatus); + freqConverterService.saveFreqConverterStatus(FormalTestManager.freqConverterTableSuffix, freqConverterStatus); } private void handleCloseSerial(String converterChannelTag, FreqConverterRespDTO respDTO) { @@ -257,22 +257,23 @@ public class SocketFreqConverterService { List finishedDipIdList = new ArrayList<>(); List testResList = new ArrayList<>(); for (FormalTestManager.PendingDipTask task : FormalTestManager.pendingDipTaskMap.values()) { - if (task.getRemainingCount() <= 0) { + PqFreqConverterTestRes testRes = pqFreqConverterTestResService.getByDipId(suffix, task.getDipId()); + if (Objects.isNull(testRes)) { finishedDipIdList.add(task.getDipId()); continue; } - PqFreqConverterTestRes testRes = pqFreqConverterTestResService.getByDipId(suffix, task.getDipId()); - testRes.setEndTime(freqConverterStatus.getTimestamp()); + testRes.setEndTime(freqConverterStatus.getTimestamp().isAfter(task.getTargetEndTime()) + ? freqConverterStatus.getTimestamp() + : task.getTargetEndTime()); testRes.setTolerant(testRes.getTolerant() && (freqConverterStatus.getStatusWord1() != freqConverterConfig.getNoTolerant())); testResList.add(testRes); - task.decrementRemainingCount(); - if (task.getRemainingCount() <= 0) { + if (freqConverterStatus.getTimestamp().isAfter(task.getTargetEndTime())) { finishedDipIdList.add(task.getDipId()); } } - pqFreqConverterTestResService.saveTestRes(suffix, testResList); + pqFreqConverterTestResService.saveOrUpdateTestRes(suffix, testResList); for (String dipId : finishedDipIdList) { FormalTestManager.pendingDipTaskMap.remove(dipId); diff --git a/detection/src/main/java/com/njcn/gather/detection/util/socket/FormalTestManager.java b/detection/src/main/java/com/njcn/gather/detection/util/socket/FormalTestManager.java index cc628265..02c29518 100644 --- a/detection/src/main/java/com/njcn/gather/detection/util/socket/FormalTestManager.java +++ b/detection/src/main/java/com/njcn/gather/detection/util/socket/FormalTestManager.java @@ -229,18 +229,14 @@ public class FormalTestManager { public static class PendingDipTask { private final String dipId; private LocalDateTime startTime; + private LocalDateTime targetEndTime; private Boolean originalTolerant; - private int remainingCount; - public PendingDipTask(String dipId, LocalDateTime startTime, Boolean originalTolerant, int remainingCount) { + public PendingDipTask(String dipId, LocalDateTime startTime, LocalDateTime targetEndTime, Boolean originalTolerant) { this.dipId = dipId; this.startTime = startTime; + this.targetEndTime = targetEndTime; this.originalTolerant = originalTolerant; - this.remainingCount = remainingCount; - } - - public void decrementRemainingCount() { - this.remainingCount--; } } } diff --git a/detection/src/main/java/com/njcn/gather/freqConverter/service/IPqFreqConverterTestResService.java b/detection/src/main/java/com/njcn/gather/freqConverter/service/IPqFreqConverterTestResService.java index af27a3d1..3e6f2307 100644 --- a/detection/src/main/java/com/njcn/gather/freqConverter/service/IPqFreqConverterTestResService.java +++ b/detection/src/main/java/com/njcn/gather/freqConverter/service/IPqFreqConverterTestResService.java @@ -25,7 +25,7 @@ public interface IPqFreqConverterTestResService extends IService testResList); + boolean saveOrUpdateTestRes(Integer suffix, List testResList); /** * 查询结果记录 diff --git a/detection/src/main/java/com/njcn/gather/freqConverter/service/impl/PqFreqConverterTestResServiceImpl.java b/detection/src/main/java/com/njcn/gather/freqConverter/service/impl/PqFreqConverterTestResServiceImpl.java index 94e23944..2d108699 100644 --- a/detection/src/main/java/com/njcn/gather/freqConverter/service/impl/PqFreqConverterTestResServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/freqConverter/service/impl/PqFreqConverterTestResServiceImpl.java @@ -25,7 +25,7 @@ public class PqFreqConverterTestResServiceImpl extends ServiceImpl testResList) { + public boolean saveOrUpdateTestRes(Integer suffix, List testResList) { DynamicTableNameHandler.setTableName("pq_freq_converter_test_res_" + suffix); List existedTestResList = new ArrayList<>();