yeg
2026-08-27 5a18d863778ffabcc45da185f7f77e7462289bb9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.TTestMapper">
 
    <resultMap id="TTestResultMap" type="TTest">
        <id property="testId" column="test_id" />
        <result property="testName" column="test_name" />
        <result property="creatorId" column="creator_id" />
        <result property="creatorName" column="creator_name" />
        <result property="principalId" column="principal_id" />
        <result property="principalName" column="principal_name" />
        <result property="testTypeId" column="test_type_id" />
        <result property="testTypeName" column="test_type_name" />
        <result property="testPurpose" column="test_purpose" />
        <result property="testStatus" column="test_status" />
        <result property="monitoringStatus" column="monitoring_status" />
        <result property="monitorTimeoutMinutes" column="monitor_timeout_minutes" />
        <result property="startedAtUtc" column="started_at_utc" />
        <result property="endedAtUtc" column="ended_at_utc" />
        <result property="delFlag" column="del_flag" />
        <result property="createBy" column="create_by" />
        <result property="createTime" column="create_time" />
        <result property="updateBy" column="update_by" />
        <result property="updateTime" column="update_time" />
        <result property="remark" column="remark" />
        <result property="batteryCount" column="battery_count" />
    </resultMap>
 
    <resultMap id="TTestBatteryResultMap" type="TTestBattery">
        <id property="relationId" column="relation_id" />
        <result property="testId" column="test_id" />
        <result property="groupId" column="group_id" />
        <result property="groupName" column="group_name" />
        <result property="batteryNo" column="battery_no" />
        <result property="collectorId" column="collector_id" />
        <result property="collectorName" column="collector_name" />
        <result property="delFlag" column="del_flag" />
    </resultMap>
 
    <resultMap id="TTestBatteryFieldResultMap" type="TTestBatteryField">
        <id property="fieldId" column="field_id" />
        <result property="relationId" column="relation_id" />
        <result property="fieldName" column="field_name" />
        <result property="fieldValue" column="field_value" />
        <result property="delFlag" column="del_flag" />
    </resultMap>
 
    <resultMap id="TTestBindingResultMap" type="TTestChannelBinding">
        <id property="bindingId" column="binding_id" />
        <result property="testId" column="test_id" />
        <result property="batteryRelationId" column="battery_relation_id" />
        <result property="channelId" column="channel_id" />
        <result property="expectedBarcode" column="expected_barcode" />
        <result property="claimStatus" column="claim_status" />
        <result property="cabinetId" column="cabinet_id" />
        <result property="cabinetCode" column="cabinet_code" />
        <result property="cabinetName" column="cabinet_name" />
        <result property="adapterCode" column="adapter_code" />
        <result property="devtype" column="devtype" />
        <result property="devid" column="devid" />
        <result property="subdevid" column="subdevid" />
        <result property="chlid" column="chlid" />
        <result property="displayNo" column="display_no" />
    </resultMap>
 
    <resultMap id="TTestPlanStepResultMap" type="TTestPlanStep">
        <id property="planStepId" column="plan_step_id" />
        <result property="testId" column="test_id" />
        <result property="cycleNo" column="cycle_no" />
        <result property="stepNo" column="step_no" />
        <result property="stepType" column="step_type" />
        <result property="stepName" column="step_name" />
        <result property="parametersJson" column="parameters_json" />
        <result property="sortOrder" column="sort_order" />
    </resultMap>
 
    <resultMap id="TTestThresholdResultMap" type="TTestWarningThreshold">
        <id property="thresholdId" column="threshold_id" />
        <result property="testId" column="test_id" />
        <result property="metricCode" column="metric_code" />
        <result property="minValue" column="min_value" />
        <result property="maxValue" column="max_value" />
        <result property="unit" column="unit" />
        <result property="severity" column="severity" />
        <result property="delFlag" column="del_flag" />
    </resultMap>
 
    <resultMap id="TTestResultResultMap" type="TTestResult">
        <id property="resultId" column="result_id" />
        <result property="relationId" column="relation_id" />
        <result property="testId" column="test_id" />
        <result property="channelNo" column="channel_no" />
        <result property="resultValue" column="result_value" />
        <result property="resultTime" column="result_time" />
        <result property="exceptionInfo" column="exception_info" />
        <result property="delFlag" column="del_flag" />
    </resultMap>
 
    <sql id="selectTestBase">
        select t.test_id, t.test_name, t.creator_id, creator.nick_name creator_name,
               t.principal_id, principal.nick_name principal_name,
               t.test_type_id, ty.test_type_name, t.test_purpose,
               t.test_status, t.monitoring_status, t.monitor_timeout_minutes,
               t.started_at_utc, t.ended_at_utc, t.del_flag,
               t.create_by, t.create_time, t.update_by, t.update_time, t.remark,
               (select count(1) from t_test_battery b where b.test_id = t.test_id and b.del_flag = 0) battery_count
        from t_test t
        left join sys_user creator on creator.user_id = t.creator_id and creator.del_flag = '0'
        left join sys_user principal on principal.user_id = t.principal_id and principal.del_flag = '0'
        left join t_test_type ty on ty.test_type_id = t.test_type_id and ty.del_flag = 0
    </sql>
 
    <select id="selectTestList" parameterType="TTest" resultMap="TTestResultMap">
        <include refid="selectTestBase" />
        <where>
            t.del_flag = 0
            <if test="testId != null">and t.test_id = #{testId}</if>
            <if test="testName != null and testName != ''">and t.test_name like concat('%', #{testName}, '%')</if>
            <if test="testTypeId != null">and t.test_type_id = #{testTypeId}</if>
            <if test="batteryNo != null and batteryNo != ''">and exists (select 1 from t_test_battery fb where fb.test_id = t.test_id and fb.battery_no = #{batteryNo} and fb.del_flag = 0)</if>
            <if test="testStatus != null and testStatus != ''">and t.test_status = #{testStatus}</if>
            <if test="monitoringStatus != null and monitoringStatus != ''">and t.monitoring_status = #{monitoringStatus}</if>
            <if test="beginCreateTime != null">and t.create_time &gt;= #{beginCreateTime}</if>
            <if test="endCreateTime != null">and t.create_time &lt;= #{endCreateTime}</if>
        </where>
        order by t.create_time desc, t.test_id desc
    </select>
 
    <select id="selectTestById" parameterType="Long" resultMap="TTestResultMap">
        <include refid="selectTestBase" />
        where t.test_id = #{testId} and t.del_flag = 0
    </select>
 
    <select id="selectTestByIdForUpdate" parameterType="Long" resultMap="TTestResultMap">
        <include refid="selectTestBase" />
        where t.test_id = #{testId} and t.del_flag = 0
        for update
    </select>
 
    <select id="selectTestByName" parameterType="String" resultMap="TTestResultMap">
        <include refid="selectTestBase" />
        where t.test_name = #{testName} and t.del_flag = 0 limit 1
    </select>
 
    <insert id="insertTest" parameterType="TTest" useGeneratedKeys="true" keyProperty="testId">
        insert into t_test
        (test_name, creator_id, principal_id, test_type_id, test_purpose, test_status, monitoring_status,
         monitor_timeout_minutes, del_flag, create_by, create_time, remark)
        values
        (#{testName}, #{creatorId}, #{principalId}, #{testTypeId}, #{testPurpose}, #{testStatus}, #{monitoringStatus},
         #{monitorTimeoutMinutes}, 0, #{createBy}, #{createTime}, #{remark})
    </insert>
 
    <update id="updateTest" parameterType="TTest">
        update t_test
        set test_name = #{testName}, principal_id = #{principalId}, test_type_id = #{testTypeId},
            test_purpose = #{testPurpose}, monitor_timeout_minutes = #{monitorTimeoutMinutes},
            remark = #{remark}, update_by = #{updateBy}, update_time = #{updateTime}
        where test_id = #{testId} and monitoring_status = 'NOT_MONITORED' and del_flag = 0
    </update>
 
    <update id="deleteTestById">
        update t_test set del_flag = test_id, update_by = #{updateBy}, update_time = sysdate()
        where test_id = #{testId} and monitoring_status = 'NOT_MONITORED' and del_flag = 0
    </update>
 
    <delete id="deleteTestBindingsByTestId">delete from t_test_channel_binding where test_id = #{testId}</delete>
    <delete id="deleteTestPlanStepsByTestId">delete from t_test_plan_step where test_id = #{testId}</delete>
    <update id="deleteTestFieldsByTestId">
        update t_test_battery_field f join t_test_battery b on b.relation_id = f.relation_id
        set f.del_flag = f.field_id where b.test_id = #{testId} and f.del_flag = 0
    </update>
    <update id="deleteTestBatteriesByTestId">
        update t_test_battery set del_flag = relation_id where test_id = #{testId} and del_flag = 0
    </update>
    <update id="deleteTestThresholdsByTestId">
        update t_test_warning_threshold set del_flag = threshold_id where test_id = #{testId} and del_flag = 0
    </update>
 
    <insert id="insertTestPlanStep" parameterType="TTestPlanStep" useGeneratedKeys="true" keyProperty="planStepId">
        insert into t_test_plan_step(test_id, cycle_no, step_no, step_type, step_name, parameters_json, sort_order)
        values(#{testId}, #{cycleNo}, #{stepNo}, #{stepType}, #{stepName}, cast(#{parametersJson} as json), #{sortOrder})
    </insert>
    <insert id="insertTestBattery" parameterType="TTestBattery" useGeneratedKeys="true" keyProperty="relationId">
        insert into t_test_battery(test_id, group_id, battery_no, collector_id, del_flag)
        values(#{testId}, #{groupId}, #{batteryNo}, #{collectorId}, 0)
    </insert>
    <insert id="insertTestBatteryField" parameterType="TTestBatteryField" useGeneratedKeys="true" keyProperty="fieldId">
        insert into t_test_battery_field(relation_id, field_name, field_value, del_flag)
        values(#{relationId}, #{fieldName}, #{fieldValue}, 0)
    </insert>
    <insert id="insertTestChannelBinding" parameterType="TTestChannelBinding" useGeneratedKeys="true" keyProperty="bindingId">
        insert into t_test_channel_binding(test_id, battery_relation_id, channel_id, expected_barcode, claim_status)
        values(#{testId}, #{batteryRelationId}, #{channelId}, #{expectedBarcode}, #{claimStatus})
    </insert>
    <insert id="insertTestThreshold" parameterType="TTestWarningThreshold" useGeneratedKeys="true" keyProperty="thresholdId">
        insert into t_test_warning_threshold(test_id, metric_code, min_value, max_value, unit, severity, del_flag)
        values(#{testId}, #{metricCode}, #{minValue}, #{maxValue}, #{unit}, #{severity}, 0)
    </insert>
 
    <select id="selectTestPlanSteps" parameterType="Long" resultMap="TTestPlanStepResultMap">
        select plan_step_id, test_id, cycle_no, step_no, step_type, step_name,
               cast(parameters_json as char) parameters_json, sort_order
        from t_test_plan_step where test_id = #{testId} order by sort_order, plan_step_id
    </select>
    <select id="selectTestBatteries" parameterType="Long" resultMap="TTestBatteryResultMap">
        select battery.relation_id, battery.test_id, battery.group_id, battery_group.group_name,
               battery.battery_no, battery.collector_id, collector.collector_name, battery.del_flag
        from t_test_battery battery
        join t_battery_group battery_group on battery_group.group_id = battery.group_id
        left join t_collector collector on collector.collector_id = battery.collector_id
        where battery.test_id = #{testId} and battery.del_flag = 0
        order by battery.relation_id
    </select>
    <select id="selectTestBatteryFields" parameterType="Long" resultMap="TTestBatteryFieldResultMap">
        select field.* from t_test_battery_field field
        join t_test_battery battery on battery.relation_id = field.relation_id
        where battery.test_id = #{testId} and field.del_flag = 0 order by field.field_id
    </select>
    <select id="selectTestChannelBindings" parameterType="Long" resultMap="TTestBindingResultMap">
        select binding.binding_id, binding.test_id, binding.battery_relation_id, binding.channel_id,
               binding.expected_barcode, binding.claim_status, channel_fact.cabinet_id,
               cabinet.cabinet_code, cabinet.cabinet_name,
               coalesce(channel_fact.adapter_code, cabinet.adapter_code) adapter_code,
               channel_fact.devtype, channel_fact.devid, channel_fact.subdevid, channel_fact.chlid, channel_fact.display_no
        from t_test_channel_binding binding
        join t_detection_channel channel_fact on channel_fact.channel_id = binding.channel_id
        join t_detection_cabinet cabinet on cabinet.cabinet_id = channel_fact.cabinet_id
        where binding.test_id = #{testId} order by binding.binding_id
    </select>
    <select id="selectTestThresholds" parameterType="Long" resultMap="TTestThresholdResultMap">
        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>
    <select id="selectTestResults" parameterType="TTestResult" resultMap="TTestResultResultMap">
        select result.*, battery.test_id from t_test_result result
        join t_test_battery battery on battery.relation_id = result.relation_id
        where battery.test_id = #{testId} and result.del_flag = 0
        <if test="relationId != null">and result.relation_id = #{relationId}</if>
        <if test="channelNo != null">and result.channel_no = #{channelNo}</if>
        <if test="beginResultTime != null">and result.result_time &gt;= #{beginResultTime}</if>
        <if test="endResultTime != null">and result.result_time &lt;= #{endResultTime}</if>
        order by result.result_time, result.result_id
    </select>
 
    <select id="countTestTypeEnabled" resultType="int">
        select count(1) from t_test_type where test_type_id = #{testTypeId} and status = '0' and del_flag = 0
    </select>
    <select id="countUserEnabled" resultType="int">
        select count(1) from sys_user where user_id = #{userId} and status = '0' and del_flag = '0'
    </select>
    <select id="countBatteryInEnabledGroup" resultType="int">
        select count(1) from t_battery_group_battery battery
        join t_battery_group battery_group on battery_group.group_id = battery.group_id
        where battery.group_id = #{groupId} and battery.battery_no = #{batteryNo}
          and battery.del_flag = 0 and battery_group.status = '0' and battery_group.del_flag = 0
    </select>
    <select id="countRegisteredChannel" resultType="int">
        select count(1) from t_detection_channel channel_fact
        join t_detection_cabinet cabinet on cabinet.cabinet_id = channel_fact.cabinet_id
        where channel_fact.channel_id = #{channelId} and channel_fact.status = '0' and channel_fact.del_flag = 0
          and cabinet.registration_status = 'REGISTERED' and cabinet.status = '0' and cabinet.del_flag = 0
    </select>
    <select id="countCollectorEnabled" resultType="int">
        select count(1) from t_collector where collector_id = #{collectorId} and status = '0' and del_flag = 0
    </select>
 
    <select id="selectEnabledUserOptions" resultType="com.ruoyi.system.domain.vo.TestUserOptionVo">
        select user_id userId, user_name userName, nick_name nickName
        from sys_user where status = '0' and del_flag = '0' order by nick_name, user_id
    </select>
    <select id="selectEnabledTestTypeOptions" resultType="com.ruoyi.system.domain.vo.TestTypeOptionVo">
        select test_type_id testTypeId, test_type_name testTypeName
        from t_test_type where status = '0' and del_flag = 0 order by test_type_name, test_type_id
    </select>
    <select id="selectEnabledBatteryOptions" resultType="com.ruoyi.system.domain.vo.TestBatteryOptionVo">
        select battery.relation_id relationId, battery.group_id groupId,
               battery_group.group_name groupName, battery.battery_no batteryNo
        from t_battery_group_battery battery
        join t_battery_group battery_group on battery_group.group_id = battery.group_id
        where battery.del_flag = 0 and battery_group.status = '0' and battery_group.del_flag = 0
        order by battery_group.group_name, battery.sort_order, battery.relation_id
    </select>
    <select id="selectRegisteredChannelOptions" resultType="com.ruoyi.system.domain.vo.TestChannelOptionVo">
        select channel_fact.channel_id channelId, channel_fact.cabinet_id cabinetId,
               cabinet.cabinet_code cabinetCode, cabinet.cabinet_name cabinetName,
               coalesce(channel_fact.adapter_code, cabinet.adapter_code) adapterCode,
               channel_fact.devtype devtype, channel_fact.devid devid, channel_fact.subdevid subdevid,
               channel_fact.chlid chlid, channel_fact.display_no displayNo
        from t_detection_channel channel_fact
        join t_detection_cabinet cabinet on cabinet.cabinet_id = channel_fact.cabinet_id
        where channel_fact.status = '0' and channel_fact.del_flag = 0
          and cabinet.registration_status = 'REGISTERED' and cabinet.status = '0' and cabinet.del_flag = 0
        order by cabinet.cabinet_name, channel_fact.chlid, channel_fact.channel_id
    </select>
    <select id="selectEnabledCollectorOptions" resultType="com.ruoyi.system.domain.vo.TestCollectorOptionVo">
        select collector_id collectorId, collector_code collectorCode, collector_name collectorName
        from t_collector where status = '0' and del_flag = 0 order by collector_name, collector_id
    </select>
 
    <insert id="insertTestAudit">
        insert into t_test_audit
        (test_id, event_type, actor_id, actor_name, occurred_at_utc, previous_value, new_value, correlation_id)
        values
        (#{testId}, #{eventType}, #{actorId}, #{actorName}, utc_timestamp(3),
         <choose><when test="previousValue != null">cast(#{previousValue} as json)</when><otherwise>null</otherwise></choose>,
         <choose><when test="newValue != null">cast(#{newValue} as json)</when><otherwise>null</otherwise></choose>,
         uuid())
    </insert>
</mapper>