From 9c0fd80309b277420c492180ae9f98f779f0f5c8 Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期日, 30 八月 2026 23:29:33 +0800
Subject: [PATCH] 实现设备自然结束与区间补采恢复

---
 ruoyi-system/src/main/java/com/ruoyi/system/mapper/TTestMapper.java |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TTestMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TTestMapper.java
index 2dd1aeb..780e742 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TTestMapper.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TTestMapper.java
@@ -14,6 +14,7 @@
 import com.ruoyi.system.domain.TTestCollectorSource;
 import com.ruoyi.system.domain.TTestCollectorExceptionInterval;
 import com.ruoyi.system.domain.TTestReceptionInterval;
+import com.ruoyi.system.domain.TTestBackfillCursor;
 import com.ruoyi.system.domain.TDetectionChannel;
 import com.ruoyi.system.domain.vo.TestBatteryOptionVo;
 import com.ruoyi.system.domain.vo.TestChannelOptionVo;
@@ -59,6 +60,7 @@
     int countRegisteredChannel(Long channelId);
     int countCollectorEnabled(Long collectorId);
     Integer selectCollectorChannelCount(Long collectorId);
+    String selectCollectorCode(Long collectorId);
     List<TestUserOptionVo> selectEnabledUserOptions();
     List<TestTypeOptionVo> selectEnabledTestTypeOptions();
     List<TestBatteryOptionVo> selectEnabledBatteryOptions();
@@ -111,4 +113,48 @@
     int closeCollectorExceptionInterval(@Param("intervalId") Long intervalId,
             @Param("recoveredAtUtc") Date recoveredAtUtc, @Param("missingToUtc") Date missingToUtc);
     List<TTestCollectorExceptionInterval> selectCollectorExceptionIntervals(Long testId);
+
+    /** 查询需要自然结束或继续补采的测试。 */
+    List<TTest> selectTestsForNaturalEnd();
+    List<TTest> selectTestsForBackfill();
+    /** 按稳定来源身份锁定补采游标,避免应用重启重复推进。 */
+    TTestBackfillCursor selectBackfillCursorForUpdate(@Param("testId") Long testId,
+            @Param("bindingId") Long bindingId, @Param("sourceType") String sourceType,
+            @Param("sourceId") Long sourceId, @Param("sourceChannelCode") String sourceChannelCode);
+    int insertBackfillCursor(TTestBackfillCursor cursor);
+    int updateBackfillCursor(TTestBackfillCursor cursor);
+    int updateTestBackfillStarted(@Param("testId") Long testId, @Param("updatedAtUtc") Date updatedAtUtc);
+    int updateTestBackfillWaiting(@Param("testId") Long testId, @Param("updatedAtUtc") Date updatedAtUtc,
+            @Param("error") String error);
+    int updateTestBackfillCompleted(@Param("testId") Long testId, @Param("updatedAtUtc") Date updatedAtUtc);
+    int updateTestNaturallyEnded(@Param("testId") Long testId, @Param("endedAtUtc") Date endedAtUtc);
+    String selectSampleContentHash(@Param("channelId") Long channelId, @Param("btsTestId") String btsTestId,
+            @Param("sequenceId") Long sequenceId);
+    int insertBtsSample(@Param("testId") Long testId, @Param("bindingId") Long bindingId,
+            @Param("channelId") Long channelId, @Param("intervalId") Long intervalId,
+            @Param("btsTestId") String btsTestId, @Param("sequenceId") Long sequenceId,
+            @Param("deviceTimeUtc") Date deviceTimeUtc, @Param("deviceTimeRaw") String deviceTimeRaw,
+            @Param("receivedAtUtc") Date receivedAtUtc, @Param("cycleNo") Integer cycleNo,
+            @Param("stepNo") Integer stepNo, @Param("stepType") String stepType,
+            @Param("testTimeMs") Long testTimeMs, @Param("voltageV") java.math.BigDecimal voltageV,
+            @Param("currentA") java.math.BigDecimal currentA, @Param("capacityAh") java.math.BigDecimal capacityAh,
+            @Param("energyWh") java.math.BigDecimal energyWh, @Param("contentSha256") byte[] contentSha256);
+    int insertBtsMeasurement(@Param("sampleId") Long sampleId, @Param("metricCode") String metricCode,
+            @Param("metricValue") java.math.BigDecimal metricValue, @Param("unit") String unit,
+            @Param("sourceType") String sourceType);
+    Long selectBtsSampleId(@Param("channelId") Long channelId, @Param("btsTestId") String btsTestId,
+            @Param("sequenceId") Long sequenceId);
+    int insertCollectorSample(@Param("testId") Long testId, @Param("bindingId") Long bindingId,
+            @Param("collectorId") Long collectorId, @Param("channelCode") String channelCode,
+            @Param("sequenceId") Long sequenceId, @Param("deviceTimeUtc") Date deviceTimeUtc,
+            @Param("deviceTimeRaw") String deviceTimeRaw, @Param("receivedAtUtc") Date receivedAtUtc,
+            @Param("metricCode") String metricCode, @Param("metricValue") java.math.BigDecimal metricValue,
+            @Param("unit") String unit, @Param("contentSha256") byte[] contentSha256);
+    Long selectCollectorSampleId(@Param("collectorId") Long collectorId, @Param("channelCode") String channelCode,
+            @Param("sequenceId") Long sequenceId, @Param("metricCode") String metricCode);
+    String selectCollectorSampleContentHash(@Param("collectorId") Long collectorId,
+            @Param("channelCode") String channelCode, @Param("sequenceId") Long sequenceId,
+            @Param("metricCode") String metricCode);
+    int insertBackfillConflict(@Param("testId") Long testId, @Param("channelId") Long channelId,
+            @Param("detail") String detail);
 }

--
Gitblit v1.7.1