From 85eb2837e3b3bf5411b332aa2cc38d2755e0d3bf Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期六, 05 九月 2026 01:27:19 +0800
Subject: [PATCH] 完成电池组当前字段与测试绑定

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

diff --git a/ruoyi-system/src/main/resources/mapper/system/TTestMapper.xml b/ruoyi-system/src/main/resources/mapper/system/TTestMapper.xml
index 3e99a0c..11e314d 100644
--- a/ruoyi-system/src/main/resources/mapper/system/TTestMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/TTestMapper.xml
@@ -32,7 +32,8 @@
     </resultMap>
 
     <resultMap id="TTestBatteryResultMap" type="TTestBattery">
-        <id property="relationId" column="relation_id" />
+        <id property="relationId" column="test_battery_id" />
+        <result property="testBatteryId" column="test_battery_id" />
         <result property="testId" column="test_id" />
         <result property="groupId" column="group_id" />
         <result property="groupName" column="group_name" />
@@ -46,6 +47,7 @@
         <id property="fieldId" column="field_id" />
         <result property="relationId" column="relation_id" />
         <result property="fieldName" column="field_name" />
+        <result property="fieldType" column="field_type" />
         <result property="fieldValue" column="field_value" />
         <result property="delFlag" column="del_flag" />
     </resultMap>
@@ -53,7 +55,8 @@
     <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="batteryRelationId" column="test_battery_id" />
+        <result property="testBatteryId" column="test_battery_id" />
         <result property="channelId" column="channel_id" />
         <result property="expectedBarcode" column="expected_barcode" />
         <result property="claimStatus" column="claim_status" />
@@ -71,7 +74,8 @@
     <resultMap id="TTestCollectorChannelResultMap" type="TTestCollectorChannel">
         <id property="mappingId" column="mapping_id" />
         <result property="testId" column="test_id" />
-        <result property="batteryRelationId" column="battery_relation_id" />
+        <result property="batteryRelationId" column="test_battery_id" />
+        <result property="testBatteryId" column="test_battery_id" />
         <result property="collectorId" column="collector_id" />
         <result property="measurementCode" column="measurement_code" />
         <result property="measurementName" column="measurement_name" />
@@ -134,7 +138,7 @@
                cast(t.logic_step_mappings_json as char) logic_step_mappings_json,
                cast(t.console_detail_json as char) console_detail_json,
                (select count(1) from t_test_battery b where b.test_id = t.test_id and b.del_flag = 0) battery_count,
-               t.runtime_attach runtime_attach
+               0 runtime_attach
         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'
@@ -164,11 +168,11 @@
     </select>
 
     <select id="selectBatteryNosByTestIds" resultMap="TTestBatteryResultMap">
-        select test_id, battery_no
+        select test_id, test_battery_id, battery_no
         from t_test_battery
         where del_flag = 0 and test_id in
         <foreach collection="testIds" item="testId" open="(" separator="," close=")">#{testId}</foreach>
-        order by test_id, relation_id
+        order by test_id, test_battery_id
     </select>
 
     <select id="selectTestById" parameterType="Long" resultMap="TTestResultMap">
@@ -240,44 +244,31 @@
         where test_id = #{testId} and reception_status = 'NOT_STARTED' 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 reception_status = 'NOT_STARTED' and del_flag = 0
-    </update>
+    <delete id="deleteTestById">
+        delete from t_test where test_id = #{testId} and reception_status = 'NOT_STARTED' and del_flag = 0
+    </delete>
 
     <delete id="deleteTestBindingsByTestId">delete from t_test_channel_binding where test_id = #{testId}</delete>
     <delete id="deleteTestCollectorChannelsByTestId">delete from t_test_collector_channel 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>
+    <delete id="deleteTestThresholdRowsByTestId">delete from t_test_warning_threshold where test_id = #{testId}</delete>
+    <delete id="deleteTestBatteriesByTestId">
+        delete from t_test_battery where test_id = #{testId} and del_flag = 0
+    </delete>
     <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)
+        insert into t_test_channel_binding(test_id, test_battery_id, channel_id, expected_barcode, claim_status)
         values(#{testId}, #{batteryRelationId}, #{channelId}, #{expectedBarcode}, #{claimStatus})
     </insert>
     <insert id="insertTestCollectorChannel" parameterType="TTestCollectorChannel" useGeneratedKeys="true" keyProperty="mappingId">
         insert into t_test_collector_channel
-        (test_id, battery_relation_id, collector_id, measurement_code, measurement_name, channel_code)
+        (test_id, test_battery_id, collector_id, measurement_code, measurement_name, channel_code)
         values(#{testId}, #{batteryRelationId}, #{collectorId}, #{measurementCode}, #{measurementName}, #{channelCode})
     </insert>
     <insert id="insertTestThreshold" parameterType="TTestWarningThreshold" useGeneratedKeys="true" keyProperty="thresholdId">
@@ -285,30 +276,30 @@
         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,
+        select battery.test_battery_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
+        order by battery.test_battery_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 id="selectCurrentBatteryFields" parameterType="Long" resultMap="TTestBatteryFieldResultMap">
+        select battery.test_battery_id as relation_id, relation.battery_group_field_id as field_id,
+               definition.field_name, definition.field_type, relation.field_value, relation.del_flag
+        from t_test_battery battery
+        join t_battery_group_relation_field relation on relation.group_id = battery.group_id and relation.del_flag = 0
+        join t_battery_group_field definition on definition.field_id = relation.battery_group_field_id
+             and definition.del_flag = 0
+        where battery.test_id = #{testId} and battery.del_flag = 0
+        order by battery.test_battery_id, relation.relation_id
     </select>
     <select id="selectTestChannelBindings" parameterType="Long" resultMap="TTestBindingResultMap">
-        select binding.binding_id, binding.test_id, binding.battery_relation_id, binding.channel_id,
+        select binding.binding_id, binding.test_id, binding.test_battery_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,
+               adapter.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
@@ -316,13 +307,14 @@
         join t_detection_cabinet cabinet on cabinet.cabinet_id = channel_fact.cabinet_id
             and cabinet.status = '0' and cabinet.del_flag = 0
             and cabinet.registration_status = 'REGISTERED'
+        left join t_device_adapter adapter on adapter.adapter_id = channel_fact.adapter_id and adapter.del_flag = 0
         where binding.test_id = #{testId} order by binding.binding_id
     </select>
     <select id="selectTestCollectorChannels" parameterType="Long" resultMap="TTestCollectorChannelResultMap">
-        select mapping_id, test_id, battery_relation_id, collector_id,
+        select mapping_id, test_id, test_battery_id, collector_id,
                measurement_code, measurement_name, channel_code
         from t_test_collector_channel where test_id = #{testId}
-        order by battery_relation_id, mapping_id
+        order by test_battery_id, mapping_id
     </select>
     <select id="selectTestThresholds" parameterType="Long" resultMap="TTestThresholdResultMap">
         select threshold_id, test_id, metric_code, min_value, max_value, unit, severity, del_flag
@@ -394,7 +386,7 @@
                snapshot.extension_measurements_json extensionMeasurementsJson
         from t_test_realtime_snapshot snapshot
         join t_test_channel_binding binding on binding.binding_id = snapshot.binding_id
-        join t_test_battery battery on battery.relation_id = binding.battery_relation_id and battery.del_flag = 0
+        join t_test_battery battery on battery.test_battery_id = binding.test_battery_id and battery.del_flag = 0
         join t_detection_channel channel on channel.channel_id = snapshot.channel_id and channel.del_flag = 0
         join t_collector collector on collector.collector_id = snapshot.collector_id
         where snapshot.test_id = #{testId}
@@ -411,7 +403,7 @@
                sample.energy_wh energy, channel.adapter_id adapterId, channel.adapter_code adapterCode,
                channel.devtype devtype, channel.devid deviceId, channel.subdevid subdevid, channel.chlid channelId
         from t_test_sample sample
-        join t_test_battery battery on battery.relation_id = sample.binding_id and battery.del_flag = 0
+        join t_test_battery battery on battery.test_battery_id = sample.binding_id and battery.del_flag = 0
         join t_detection_channel channel on channel.channel_id = sample.channel_id and channel.del_flag = 0
         where sample.test_id = #{testId}
         order by sample.device_time_utc desc, sample.seq_id desc, sample.sample_id desc
@@ -433,7 +425,7 @@
                sample.adapter_code adapterCode
         from t_test_collector_sample sample
         join t_test_channel_binding binding on binding.binding_id = sample.binding_id
-        join t_test_battery battery on battery.relation_id = binding.battery_relation_id and battery.del_flag = 0
+        join t_test_battery battery on battery.test_battery_id = binding.test_battery_id and battery.del_flag = 0
         join t_collector collector on collector.collector_id = sample.collector_id
         where sample.test_id = #{testId}
         order by sample.device_time_utc desc, sample.sequence_id desc, sample.sample_id desc
@@ -466,7 +458,7 @@
                channel.adapter_id adapterId, channel.adapter_code adapterCode, channel.devtype devtype,
                channel.devid deviceId, channel.subdevid subdevid, channel.chlid channelId
         from t_test_sample sample
-        join t_test_battery battery on battery.relation_id = sample.binding_id and battery.del_flag = 0
+        join t_test_battery battery on battery.test_battery_id = sample.binding_id and battery.del_flag = 0
         join t_detection_channel channel on channel.channel_id = sample.channel_id and channel.del_flag = 0
         where sample.test_id = #{testId}
         group by sample.binding_id, battery.battery_no, channel.adapter_id, channel.adapter_code, channel.devtype,
@@ -491,7 +483,7 @@
                channel.adapter_id adapterId, channel.adapter_code adapterCode, channel.devtype devtype,
                channel.devid deviceId, channel.subdevid subdevid, channel.chlid channelId
         from t_test_sample sample
-        join t_test_battery battery on battery.relation_id = sample.binding_id and battery.del_flag = 0
+        join t_test_battery battery on battery.test_battery_id = sample.binding_id and battery.del_flag = 0
         join t_detection_channel channel on channel.channel_id = sample.channel_id and channel.del_flag = 0
         where sample.test_id = #{testId}
         group by sample.binding_id, battery.battery_no, channel.adapter_id, channel.adapter_code, channel.devtype,
@@ -500,7 +492,7 @@
     </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
+        join t_test_battery battery on battery.test_battery_id = result.relation_id
         where battery.test_id = #{testId} and result.del_flag = 0
           and exists (
               select 1 from t_test_audit start_action
@@ -571,7 +563,7 @@
         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,
+        select battery.relation_id relationId, battery.relation_id testBatteryId, 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
@@ -581,11 +573,12 @@
     <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,
+               adapter.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
+        left join t_device_adapter adapter on adapter.adapter_id = channel_fact.adapter_id and adapter.del_flag = 0
         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
@@ -688,7 +681,6 @@
     <update id="updateReceptionStarted">
         update t_test
         set test_status = 'RUNNING', reception_status = 'RECEIVING',
-            runtime_attach = #{runtimeAttach},
             started_at_utc = coalesce(started_at_utc, #{startedAtUtc}),
             update_by = #{updateBy}, update_time = #{startedAtUtc}
         where test_id = #{testId} and reception_status = 'NOT_STARTED' and del_flag = 0

--
Gitblit v1.7.1