From 76cd5948e95ddbde9dd4411b466ee75ba20b562e Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期四, 03 九月 2026 17:28:29 +0800
Subject: [PATCH] 实现测试预警异常管理

---
 ruoyi-system/src/main/resources/mapper/system/TTestMapper.xml |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 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 3c7a660..ad993ce 100644
--- a/ruoyi-system/src/main/resources/mapper/system/TTestMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/TTestMapper.xml
@@ -100,6 +100,17 @@
         <result property="severity" column="severity" />
         <result property="delFlag" column="del_flag" />
     </resultMap>
+    <resultMap id="TTestWarningExceptionResultMap" type="com.ruoyi.system.domain.TTestWarningException">
+        <id property="exceptionId" column="exception_id"/><result property="testId" column="test_id"/>
+        <result property="testName" column="test_name"/><result property="sourceType" column="source_type"/>
+        <result property="sourceIdentity" column="source_identity"/><result property="metricCode" column="metric_code"/>
+        <result property="abnormalValue" column="abnormal_value"/><result property="unit" column="unit"/>
+        <result property="ruleSnapshot" column="rule_snapshot"/><result property="severity" column="severity"/>
+        <result property="exceptionStatus" column="exception_status"/><result property="firstOccurredAtUtc" column="first_occurred_at_utc"/>
+        <result property="lastOccurredAtUtc" column="last_occurred_at_utc"/><result property="occurrenceCount" column="occurrence_count"/>
+        <result property="handledBy" column="handled_by"/><result property="handledByName" column="handled_by_name"/>
+        <result property="handledAtUtc" column="handled_at_utc"/><result property="handlingNote" column="handling_note"/>
+    </resultMap>
 
     <resultMap id="TTestResultResultMap" type="TTestResult">
         <id property="resultId" column="result_id" />
@@ -317,6 +328,31 @@
         select threshold_id, test_id, metric_code, min_value, max_value, unit, severity, del_flag
         from t_test_warning_threshold where test_id = #{testId} and del_flag = 0 order by threshold_id
     </select>
+    <insert id="upsertWarningException">
+        insert into t_test_warning_exception
+        (test_id, threshold_id, source_type, source_identity, metric_code, abnormal_value, unit, rule_snapshot, severity,
+         exception_status, first_occurred_at_utc, last_occurred_at_utc, occurrence_count)
+        values (#{testId}, #{thresholdId}, #{sourceType}, #{sourceIdentity}, #{metricCode}, #{value}, #{unit},
+                cast(#{ruleSnapshot} as json), #{severity}, 'OPEN', #{occurredAt}, #{occurredAt}, 1)
+        on duplicate key update abnormal_value = values(abnormal_value), unit = values(unit),
+            last_occurred_at_utc = values(last_occurred_at_utc), occurrence_count = occurrence_count + 1,
+            source_identity = values(source_identity), severity = values(severity), rule_snapshot = values(rule_snapshot)
+    </insert>
+    <select id="selectWarningExceptions" resultMap="TTestWarningExceptionResultMap">
+        select e.*, t.test_name, u.nick_name handled_by_name
+        from t_test_warning_exception e join t_test t on t.test_id=e.test_id
+        left join sys_user u on u.user_id=e.handled_by
+        <where><if test="testId != null">e.test_id = #{testId}</if><if test="status != null and status != ''">and e.exception_status = #{status}</if></where>
+        order by e.last_occurred_at_utc desc, e.exception_id desc
+    </select>
+    <select id="selectWarningExceptionById" parameterType="long" resultMap="TTestWarningExceptionResultMap">
+        select e.*, t.test_name, u.nick_name handled_by_name from t_test_warning_exception e join t_test t on t.test_id=e.test_id
+        left join sys_user u on u.user_id=e.handled_by where e.exception_id=#{exceptionId}
+    </select>
+    <update id="closeWarningException">
+        update t_test_warning_exception set exception_status='CLOSED', handled_by=#{handledBy}, handled_at_utc=#{handledAt}, handling_note=#{handlingNote}
+        where exception_id=#{exceptionId} and exception_status='OPEN'
+    </update>
     <select id="selectReceivingTestIds" resultType="long">
         select test_id from t_test where del_flag = 0 and reception_status = 'RECEIVING' order by test_id
     </select>

--
Gitblit v1.7.1