From ec3308617909c8d6280e0d00ffb18350e372fbdf Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期日, 30 八月 2026 17:36:29 +0800
Subject: [PATCH] 实现采集器断线恢复与来源异常持久化

---
 ruoyi-system/src/main/resources/mapper/system/TTestMapper.xml |   61 ++++++++++++++++++++++++++++++
 1 files changed, 61 insertions(+), 0 deletions(-)

diff --git a/ruoyi-system/src/main/resources/mapper/system/TTestMapper.xml b/ruoyi-system/src/main/resources/mapper/system/TTestMapper.xml
index 657dab0..4bd94cf 100644
--- a/ruoyi-system/src/main/resources/mapper/system/TTestMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/TTestMapper.xml
@@ -108,6 +108,23 @@
         <result property="exceptionInfo" column="exception_info" />
         <result property="delFlag" column="del_flag" />
     </resultMap>
+    <resultMap id="TTestCollectorExceptionIntervalResultMap" type="TTestCollectorExceptionInterval">
+        <id property="intervalId" column="interval_id" />
+        <result property="testId" column="test_id" />
+        <result property="batteryRelationId" column="battery_relation_id" />
+        <result property="collectorId" column="collector_id" />
+        <result property="collectorCode" column="collector_code" />
+        <result property="collectorName" column="collector_name" />
+        <result property="collectorChannelCode" column="collector_channel_code" />
+        <result property="measurementName" column="measurement_name" />
+        <result property="exceptionType" column="exception_type" />
+        <result property="openedAtUtc" column="opened_at_utc" />
+        <result property="missingFromUtc" column="missing_from_utc" />
+        <result property="recoveredAtUtc" column="recovered_at_utc" />
+        <result property="missingToUtc" column="missing_to_utc" />
+        <result property="intervalStatus" column="interval_status" />
+        <result property="detail" column="detail" />
+    </resultMap>
 
     <sql id="selectTestBase">
         select t.test_id, t.test_name, t.creator_id, creator.nick_name creator_name,
@@ -458,4 +475,48 @@
             update_by = #{updateBy}, update_time = #{endedAtUtc}
         where test_id = #{testId} and reception_status in ('RECEIVING', 'PAUSED') and del_flag = 0
     </update>
+
+    <select id="selectReceivingCollectorSources" resultType="com.ruoyi.system.domain.TTestCollectorSource">
+        select test_fact.test_id testId, battery.relation_id batteryRelationId, battery.battery_no batteryNo,
+               collector.collector_id collectorId, collector.collector_code collectorCode,
+               mapping.channel_code channelCode
+        from t_test test_fact
+        join t_test_battery battery on battery.test_id = test_fact.test_id and battery.del_flag = 0
+        join t_collector collector on collector.collector_id = battery.collector_id
+            and collector.del_flag = 0
+        join t_test_collector_channel mapping on mapping.battery_relation_id = battery.relation_id
+            and mapping.test_id = test_fact.test_id
+        where test_fact.reception_status = 'RECEIVING' and test_fact.del_flag = 0
+        order by test_fact.test_id, battery.relation_id, mapping.mapping_id
+    </select>
+    <select id="selectOpenCollectorException" resultMap="TTestCollectorExceptionIntervalResultMap">
+        select * from t_test_collector_exception_interval
+        where test_id = #{testId} and battery_relation_id = #{batteryRelationId}
+          and collector_id = #{collectorId} and collector_channel_code = #{channelCode}
+          and exception_type = 'COLLECTOR_DISCONNECTED' and interval_status = 'OPEN'
+        order by interval_id desc limit 1
+    </select>
+    <insert id="insertCollectorExceptionInterval" parameterType="TTestCollectorExceptionInterval" useGeneratedKeys="true" keyProperty="intervalId">
+        insert into t_test_collector_exception_interval
+        (test_id, battery_relation_id, collector_id, collector_channel_code, exception_type,
+         opened_at_utc, missing_from_utc, detail)
+        values (#{testId}, #{batteryRelationId}, #{collectorId}, #{collectorChannelCode},
+                #{exceptionType}, #{openedAtUtc}, #{missingFromUtc}, #{detail})
+    </insert>
+    <update id="closeCollectorExceptionInterval">
+        update t_test_collector_exception_interval
+        set recovered_at_utc = #{recoveredAtUtc}, missing_to_utc = #{missingToUtc}, interval_status = 'CLOSED'
+        where interval_id = #{intervalId} and interval_status = 'OPEN'
+    </update>
+    <select id="selectCollectorExceptionIntervals" parameterType="Long" resultMap="TTestCollectorExceptionIntervalResultMap">
+        select exception_fact.*, collector.collector_code, collector.collector_name,
+               mapping.measurement_name
+        from t_test_collector_exception_interval exception_fact
+        left join t_collector collector on collector.collector_id = exception_fact.collector_id
+        left join t_test_collector_channel mapping on mapping.battery_relation_id = exception_fact.battery_relation_id
+            and mapping.collector_id = exception_fact.collector_id
+            and mapping.channel_code = exception_fact.collector_channel_code
+        where exception_fact.test_id = #{testId}
+        order by exception_fact.opened_at_utc, exception_fact.interval_id
+    </select>
 </mapper>

--
Gitblit v1.7.1