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

---
 battery-business/src/main/java/com/battery/business/test/dto/TestConfigurationDto.java  |   15 ++
 ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/TestBatteryOptionVo.java          |    3 
 ruoyi-system/src/main/java/com/ruoyi/system/domain/TTestBatteryField.java               |    6 +
 ruoyi-system/src/main/resources/mapper/system/TBatteryGroupMapper.xml                   |   19 +-
 ruoyi-system/src/main/resources/mapper/system/TTestMapper.xml                           |   96 +++++++--------
 battery-business/src/main/java/com/battery/business/test/TestConfigurationService.java  |   14 ++
 ruoyi-system/src/main/java/com/ruoyi/system/mapper/TTestMapper.java                     |    3 
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBatteryGroupServiceImpl.java  |    5 
 battery-business/src/main/java/com/battery/business/battery/BatteryGroupService.java    |   14 ++
 battery-business/src/main/java/com/battery/business/battery/vo/BatteryGroupVo.java      |   15 ++
 ruoyi-system/src/main/java/com/ruoyi/system/domain/TTest.java                           |    3 
 ruoyi-system/src/main/java/com/ruoyi/system/domain/TTestChannelBinding.java             |    4 
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TTestServiceImpl.java          |   77 ++----------
 ruoyi-system/src/main/java/com/ruoyi/system/domain/TTestBattery.java                    |    4 
 ruoyi-system/src/main/java/com/ruoyi/system/domain/TBatteryGroupRelationField.java      |    2 
 ruoyi-system/src/main/java/com/ruoyi/system/domain/TBatteryGroup.java                   |    4 
 ruoyi-system/src/main/java/com/ruoyi/system/domain/TTestCollectorChannel.java           |    4 
 battery-business/src/main/java/com/battery/business/battery/dto/BatteryGroupDto.java    |   15 ++
 battery-business/src/main/java/com/battery/business/test/vo/TestConfigurationVo.java    |   11 +
 battery-business/src/main/java/com/battery/business/test/dto/TestBatteryBindingDto.java |   15 ++
 battery-business/src/main/java/com/battery/business/test/dto/ThresholdDto.java          |    6 +
 battery-business/src/main/java/com/battery/business/test/vo/TestBatteryVo.java          |   17 ++
 22 files changed, 228 insertions(+), 124 deletions(-)

diff --git a/battery-business/src/main/java/com/battery/business/battery/BatteryGroupService.java b/battery-business/src/main/java/com/battery/business/battery/BatteryGroupService.java
new file mode 100644
index 0000000..ca2f8ca
--- /dev/null
+++ b/battery-business/src/main/java/com/battery/business/battery/BatteryGroupService.java
@@ -0,0 +1,14 @@
+package com.battery.business.battery;
+
+import com.battery.business.battery.dto.BatteryGroupDto;
+import com.battery.business.battery.vo.BatteryGroupVo;
+
+/** 电池组业务边界;实现负责校验组内电池号和当前字段配置。 */
+public interface BatteryGroupService {
+    /** 查询电池组及其当前字段配置。 */
+    BatteryGroupVo get(Long groupId);
+    /** 创建电池组并校验组内电池号唯一。 */
+    BatteryGroupVo create(BatteryGroupDto request);
+    /** 更新电池组当前字段和电池号关系。 */
+    BatteryGroupVo update(BatteryGroupDto request);
+}
diff --git a/battery-business/src/main/java/com/battery/business/battery/dto/BatteryGroupDto.java b/battery-business/src/main/java/com/battery/business/battery/dto/BatteryGroupDto.java
new file mode 100644
index 0000000..d2134d1
--- /dev/null
+++ b/battery-business/src/main/java/com/battery/business/battery/dto/BatteryGroupDto.java
@@ -0,0 +1,15 @@
+package com.battery.business.battery.dto;
+
+import java.util.List;
+
+/** 电池组写入模型;字段值属于电池组当前配置,不属于测试快照。 */
+public record BatteryGroupDto(
+        Long groupId,
+        String groupName,
+        String model,
+        String purpose,
+        String status,
+        List<String> batteryNos,
+        List<FieldValueDto> fields) {
+    public record FieldValueDto(Long fieldId, String value) { }
+}
diff --git a/battery-business/src/main/java/com/battery/business/battery/vo/BatteryGroupVo.java b/battery-business/src/main/java/com/battery/business/battery/vo/BatteryGroupVo.java
new file mode 100644
index 0000000..34b0b5e
--- /dev/null
+++ b/battery-business/src/main/java/com/battery/business/battery/vo/BatteryGroupVo.java
@@ -0,0 +1,15 @@
+package com.battery.business.battery.vo;
+
+import java.util.List;
+
+/** 电池组读取模型,返回当前字段值和组内电池号。 */
+public record BatteryGroupVo(
+        Long groupId,
+        String groupName,
+        String model,
+        String purpose,
+        String status,
+        List<String> batteryNos,
+        List<FieldValueVo> fields) {
+    public record FieldValueVo(Long fieldId, String fieldName, String fieldType, String value) { }
+}
diff --git a/battery-business/src/main/java/com/battery/business/test/TestConfigurationService.java b/battery-business/src/main/java/com/battery/business/test/TestConfigurationService.java
new file mode 100644
index 0000000..0d3d71b
--- /dev/null
+++ b/battery-business/src/main/java/com/battery/business/test/TestConfigurationService.java
@@ -0,0 +1,14 @@
+package com.battery.business.test;
+
+import com.battery.business.test.dto.TestConfigurationDto;
+import com.battery.business.test.vo.TestConfigurationVo;
+
+/** 测试配置业务边界;实现负责测试电池及双设备通道唯一性校验。 */
+public interface TestConfigurationService {
+    /** 查询测试配置及当前电池组字段。 */
+    TestConfigurationVo get(Long testId);
+    /** 创建测试并校验检测柜、采集器绑定唯一性。 */
+    TestConfigurationVo create(TestConfigurationDto request);
+    /** 在尚未接收时更新测试配置及绑定。 */
+    TestConfigurationVo update(TestConfigurationDto request);
+}
diff --git a/battery-business/src/main/java/com/battery/business/test/dto/TestBatteryBindingDto.java b/battery-business/src/main/java/com/battery/business/test/dto/TestBatteryBindingDto.java
new file mode 100644
index 0000000..428bf00
--- /dev/null
+++ b/battery-business/src/main/java/com/battery/business/test/dto/TestBatteryBindingDto.java
@@ -0,0 +1,15 @@
+package com.battery.business.test.dto;
+
+import java.util.List;
+
+/** 单个测试电池及检测柜、采集器通道绑定请求。 */
+public record TestBatteryBindingDto(
+        Long testBatteryId,
+        Long groupId,
+        String batteryNo,
+        Long collectorId,
+        CabinetChannelDto cabinetChannel,
+        List<CollectorChannelDto> collectorChannels) {
+    public record CabinetChannelDto(Long channelId, String expectedBarcode) { }
+    public record CollectorChannelDto(String measurementCode, String measurementName, String channelCode) { }
+}
diff --git a/battery-business/src/main/java/com/battery/business/test/dto/TestConfigurationDto.java b/battery-business/src/main/java/com/battery/business/test/dto/TestConfigurationDto.java
new file mode 100644
index 0000000..7ce1034
--- /dev/null
+++ b/battery-business/src/main/java/com/battery/business/test/dto/TestConfigurationDto.java
@@ -0,0 +1,15 @@
+package com.battery.business.test.dto;
+
+import java.util.List;
+
+/** 测试创建/编辑请求;测试只保存绑定关系,不保存电池组字段快照。 */
+public record TestConfigurationDto(
+        Long testId,
+        String testName,
+        Long principalId,
+        Long testTypeId,
+        String testPurpose,
+        Integer monitorTimeoutMinutes,
+        String remark,
+        List<TestBatteryBindingDto> batteries,
+        List<ThresholdDto> thresholds) { }
diff --git a/battery-business/src/main/java/com/battery/business/test/dto/ThresholdDto.java b/battery-business/src/main/java/com/battery/business/test/dto/ThresholdDto.java
new file mode 100644
index 0000000..18f7322
--- /dev/null
+++ b/battery-business/src/main/java/com/battery/business/test/dto/ThresholdDto.java
@@ -0,0 +1,6 @@
+package com.battery.business.test.dto;
+
+import java.math.BigDecimal;
+
+/** 测试预警阈值请求。 */
+public record ThresholdDto(String metricCode, BigDecimal minValue, BigDecimal maxValue, String unit, String severity) { }
diff --git a/battery-business/src/main/java/com/battery/business/test/vo/TestBatteryVo.java b/battery-business/src/main/java/com/battery/business/test/vo/TestBatteryVo.java
new file mode 100644
index 0000000..4e7dea5
--- /dev/null
+++ b/battery-business/src/main/java/com/battery/business/test/vo/TestBatteryVo.java
@@ -0,0 +1,17 @@
+package com.battery.business.test.vo;
+
+import java.util.List;
+
+/** 测试电池读取模型,主键明确使用 testBatteryId。 */
+public record TestBatteryVo(
+        Long testBatteryId,
+        Long groupId,
+        String batteryNo,
+        Long collectorId,
+        CabinetBindingVo cabinetChannel,
+        List<CollectorBindingVo> collectorChannels,
+        List<FieldValueVo> currentFields) {
+    public record CabinetBindingVo(Long channelId, String expectedBarcode) { }
+    public record CollectorBindingVo(String measurementCode, String measurementName, String channelCode) { }
+    public record FieldValueVo(Long fieldId, String fieldName, String fieldType, String value) { }
+}
diff --git a/battery-business/src/main/java/com/battery/business/test/vo/TestConfigurationVo.java b/battery-business/src/main/java/com/battery/business/test/vo/TestConfigurationVo.java
new file mode 100644
index 0000000..7bd4c5c
--- /dev/null
+++ b/battery-business/src/main/java/com/battery/business/test/vo/TestConfigurationVo.java
@@ -0,0 +1,11 @@
+package com.battery.business.test.vo;
+
+import java.util.List;
+
+/** 测试详情读取模型;字段从所属电池组当前配置实时展开。 */
+public record TestConfigurationVo(
+        Long testId,
+        String testName,
+        String testStatus,
+        String receptionStatus,
+        List<TestBatteryVo> batteries) { }
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/TBatteryGroup.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/TBatteryGroup.java
index ed25cc0..cafcdeb 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/TBatteryGroup.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/TBatteryGroup.java
@@ -33,6 +33,8 @@
     private List<TBatteryGroupBattery> batteries;
     private Integer batteryCount;
     private List<TBatteryGroupRelationField> templateFields;
+    /** 电池组当前字段值;templateFields 为现有页面兼容名称。 */
+    private List<TBatteryGroupRelationField> fields;
 
     public Long getGroupId() { return groupId; } public void setGroupId(Long v) { groupId = v; }
     public String getGroupName() { return groupName; } public void setGroupName(String v) { groupName = v; }
@@ -55,4 +57,6 @@
     public List<TBatteryGroupBattery> getBatteries() { return batteries; } public void setBatteries(List<TBatteryGroupBattery> v) { batteries = v; }
     public Integer getBatteryCount() { return batteryCount; } public void setBatteryCount(Integer v) { batteryCount = v; }
     public List<TBatteryGroupRelationField> getTemplateFields() { return templateFields; } public void setTemplateFields(List<TBatteryGroupRelationField> v) { templateFields = v; }
+    public List<TBatteryGroupRelationField> getFields() { return fields != null ? fields : templateFields; }
+    public void setFields(List<TBatteryGroupRelationField> v) { fields = v; templateFields = v; }
 }
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/TBatteryGroupRelationField.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/TBatteryGroupRelationField.java
index 2d46732..cdf0fe2 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/TBatteryGroupRelationField.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/TBatteryGroupRelationField.java
@@ -18,6 +18,8 @@
     public Long getGroupId() { return groupId; } public void setGroupId(Long v) { groupId = v; }
     public Long getTemplateId() { return templateId; } public void setTemplateId(Long v) { templateId = v; }
     public Long getBatteryGroupFieldId() { return batteryGroupFieldId; } public void setBatteryGroupFieldId(Long v) { batteryGroupFieldId = v; }
+    public Long getFieldId() { return batteryGroupFieldId; }
+    public void setFieldId(Long v) { batteryGroupFieldId = v; }
     public String getFieldName() { return fieldName; } public void setFieldName(String v) { fieldName = v; }
     public String getFieldType() { return fieldType; } public void setFieldType(String v) { fieldType = v; }
     public String getFieldValue() { return fieldValue; } public void setFieldValue(String v) { fieldValue = v; }
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/TTest.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/TTest.java
index 9aeae19..0d760fa 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/TTest.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/TTest.java
@@ -4,6 +4,7 @@
 import java.util.List;
 import com.alibaba.fastjson2.annotation.JSONField;
 import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import jakarta.validation.Valid;
 import jakarta.validation.constraints.NotBlank;
 import jakarta.validation.constraints.NotEmpty;
@@ -54,6 +55,8 @@
     @Valid
     @NotEmpty(message = "阈值配置不能为空")
     private List<TTestWarningThreshold> thresholds;
+    /** 历史兼容字段,不再持久化或对外返回;当前字段从电池组关系实时读取。 */
+    @JsonIgnore
     private List<TTestFieldSnapshot> fieldSnapshots;
     private List<TTestResult> resultSummary;
     private String logicStepMappingsJson;
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/TTestBattery.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/TTestBattery.java
index ce1ac3c..b47d202 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/TTestBattery.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/TTestBattery.java
@@ -12,6 +12,8 @@
     private static final long serialVersionUID = 1L;
 
     private Long relationId;
+    /** 最终数据库主键;relationId 仅作为旧页面入参别名保留。 */
+    private Long testBatteryId;
     private Long testId;
     @NotNull(message = "电池组不能为空")
     private Long groupId;
@@ -30,6 +32,8 @@
 
     public Long getRelationId() { return relationId; }
     public void setRelationId(Long value) { relationId = value; }
+    public Long getTestBatteryId() { return testBatteryId != null ? testBatteryId : relationId; }
+    public void setTestBatteryId(Long value) { testBatteryId = value; relationId = value; }
     public Long getTestId() { return testId; }
     public void setTestId(Long value) { testId = value; }
     public Long getGroupId() { return groupId; }
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/TTestBatteryField.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/TTestBatteryField.java
index d5e0516..d34f615 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/TTestBatteryField.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/TTestBatteryField.java
@@ -11,6 +11,8 @@
 
     private Long fieldId;
     private Long relationId;
+    private Long fieldDefinitionId;
+    private String fieldType;
     @NotBlank(message = "扩展项名称不能为空")
     @Size(max = 100, message = "扩展项名称长度不能超过100个字符")
     private String fieldName;
@@ -20,12 +22,16 @@
 
     public Long getFieldId() { return fieldId; }
     public void setFieldId(Long fieldId) { this.fieldId = fieldId; }
+    public Long getFieldDefinitionId() { return fieldDefinitionId != null ? fieldDefinitionId : fieldId; }
+    public void setFieldDefinitionId(Long value) { fieldDefinitionId = value; fieldId = value; }
     public Long getRelationId() { return relationId; }
     public void setRelationId(Long relationId) { this.relationId = relationId; }
     public String getFieldName() { return fieldName; }
     public void setFieldName(String fieldName) { this.fieldName = fieldName; }
     public String getFieldValue() { return fieldValue; }
     public void setFieldValue(String fieldValue) { this.fieldValue = fieldValue; }
+    public String getFieldType() { return fieldType; }
+    public void setFieldType(String value) { fieldType = value; }
     public String getDelFlag() { return delFlag; }
     public void setDelFlag(String delFlag) { this.delFlag = delFlag; }
 }
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/TTestChannelBinding.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/TTestChannelBinding.java
index ed47411..4aff58f 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/TTestChannelBinding.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/TTestChannelBinding.java
@@ -12,6 +12,8 @@
     private Long bindingId;
     private Long testId;
     private Long batteryRelationId;
+    /** 最终数据库列名对应的测试电池主键。 */
+    private Long testBatteryId;
     @NotNull(message = "检测柜通道不能为空")
     private Long channelId;
     @Size(max = 100, message = "预期条码长度不能超过100个字符")
@@ -33,6 +35,8 @@
     public void setTestId(Long value) { testId = value; }
     public Long getBatteryRelationId() { return batteryRelationId; }
     public void setBatteryRelationId(Long value) { batteryRelationId = value; }
+    public Long getTestBatteryId() { return testBatteryId != null ? testBatteryId : batteryRelationId; }
+    public void setTestBatteryId(Long value) { testBatteryId = value; batteryRelationId = value; }
     public Long getChannelId() { return channelId; }
     public void setChannelId(Long value) { channelId = value; }
     public String getExpectedBarcode() { return expectedBarcode; }
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/TTestCollectorChannel.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/TTestCollectorChannel.java
index f5af607..4b91336 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/TTestCollectorChannel.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/TTestCollectorChannel.java
@@ -11,6 +11,8 @@
     private Long mappingId;
     private Long testId;
     private Long batteryRelationId;
+    /** 最终数据库列名对应的测试电池主键。 */
+    private Long testBatteryId;
     private Long collectorId;
     @NotBlank(message = "采集器测量项编码不能为空")
     private String measurementCode;
@@ -25,6 +27,8 @@
     public void setTestId(Long value) { testId = value; }
     public Long getBatteryRelationId() { return batteryRelationId; }
     public void setBatteryRelationId(Long value) { batteryRelationId = value; }
+    public Long getTestBatteryId() { return testBatteryId != null ? testBatteryId : batteryRelationId; }
+    public void setTestBatteryId(Long value) { testBatteryId = value; batteryRelationId = value; }
     public Long getCollectorId() { return collectorId; }
     public void setCollectorId(Long value) { collectorId = value; }
     public String getMeasurementCode() { return measurementCode; }
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/TestBatteryOptionVo.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/TestBatteryOptionVo.java
index 6b2a7d9..43d91dd 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/TestBatteryOptionVo.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/TestBatteryOptionVo.java
@@ -4,12 +4,15 @@
 public class TestBatteryOptionVo
 {
     private Long relationId;
+    private Long testBatteryId;
     private Long groupId;
     private String groupName;
     private String batteryNo;
 
     public Long getRelationId() { return relationId; }
     public void setRelationId(Long value) { relationId = value; }
+    public Long getTestBatteryId() { return testBatteryId != null ? testBatteryId : relationId; }
+    public void setTestBatteryId(Long value) { testBatteryId = value; relationId = value; }
     public Long getGroupId() { return groupId; }
     public void setGroupId(Long value) { groupId = value; }
     public String getGroupName() { return groupName; }
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 e5a2f5f..b19f56f 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
@@ -34,6 +34,7 @@
     int insertTest(TTest test);
     int updateTest(TTest test);
     int deleteTestById(@Param("testId") Long testId, @Param("updateBy") String updateBy);
+    int deleteTestThresholdRowsByTestId(Long testId);
     int deleteTestBindingsByTestId(Long testId);
     int deleteTestCollectorChannelsByTestId(Long testId);
     int deleteTestPlanStepsByTestId(Long testId);
@@ -49,6 +50,8 @@
     List<TTestPlanStep> selectTestPlanSteps(Long testId);
     List<TTestBattery> selectTestBatteries(Long testId);
     List<TTestBatteryField> selectTestBatteryFields(Long testId);
+    /** 读取测试所选电池组的当前字段值,不创建测试快照。 */
+    List<TTestBatteryField> selectCurrentBatteryFields(Long testId);
     List<TTestChannelBinding> selectTestChannelBindings(Long testId);
     List<TTestCollectorChannel> selectTestCollectorChannels(Long testId);
     List<TTestWarningThreshold> selectTestThresholds(Long testId);
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBatteryGroupServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBatteryGroupServiceImpl.java
index 9ca780c..d682c17 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBatteryGroupServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBatteryGroupServiceImpl.java
@@ -203,10 +203,11 @@
             {
                 throw new ServiceException("电池号不能重复或为空");
             }
+            // 电池号只要求在所属电池组内唯一;不同电池组可以复用同一业务编号。
             TBatteryGroupBattery existingBattery = batteryGroupMapper.selectBatteryByNo(normalized, group.getGroupId());
-            if (existingBattery != null && (group.getGroupId() == null || !group.getGroupId().equals(existingBattery.getGroupId())))
+            if (!update && existingBattery != null)
             {
-                throw new ServiceException("电池号已被其他电池组使用");
+                throw new ServiceException("所属电池组内电池号已存在");
             }
         }
         if (group.getTemplateId() == null)
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TTestServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TTestServiceImpl.java
index 6030b36..e301e8d 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TTestServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TTestServiceImpl.java
@@ -23,7 +23,6 @@
 import com.ruoyi.system.domain.TTestCollectorChannel;
 import com.ruoyi.system.domain.TTestPlanStep;
 import com.ruoyi.system.domain.TTestResult;
-import com.ruoyi.system.domain.TTestFieldSnapshot;
 import com.ruoyi.system.domain.TTestWarningThreshold;
 import com.ruoyi.system.domain.TTestLogicStepMapping;
 import com.ruoyi.system.domain.TTestConsoleDetail;
@@ -31,7 +30,6 @@
 import com.ruoyi.system.domain.vo.TestConfigurationOptionsVo;
 import com.ruoyi.system.mapper.TTestMapper;
 import com.ruoyi.system.service.ITTestService;
-import com.ruoyi.system.service.ISharedFieldSnapshotService;
 
 /** 测试配置服务,负责状态边界、关系校验、事务写入和只追加审计。 */
 @Service
@@ -48,9 +46,6 @@
 
     @Autowired
     private TTestMapper testMapper;
-
-    @Autowired
-    private ISharedFieldSnapshotService sharedFieldSnapshotService;
 
     @Override
     public TTest selectTestById(Long testId)
@@ -98,14 +93,11 @@
         validateConfiguration(test);
         test.setTestStatus(WAITING);
         test.setReceptionStatus(NOT_STARTED);
-        test.setFieldSnapshots(sharedFieldSnapshotService.createForBatteryGroup(
-                test.getBatteries().get(0).getGroupId()));
         test.setDelFlag("0");
         test.setCreateTime(new Date());
         testMapper.insertTest(test);
         saveConfiguration(test);
-        testMapper.insertTestAudit(test.getTestId(), "TEST_CREATED", test.getOperatorId(), test.getCreateBy(),
-                null, JSON.toJSONString(test));
+        // 最终基线移除了 t_test_audit;Controller 的 @Log 负责记录创建操作,业务表只保存配置事实。
         return test.getTestId();
     }
 
@@ -127,25 +119,16 @@
             test.setMonitorTimeoutMinutes(current.getMonitorTimeoutMinutes());
         validateBase(test, true);
         validateConfiguration(test);
-        Long currentGroupId = current.getBatteries().isEmpty() ? null : current.getBatteries().get(0).getGroupId();
-        Long nextGroupId = test.getBatteries().get(0).getGroupId();
-        test.setFieldSnapshots(sharedFieldSnapshotService.resolveForUpdate(
-                currentGroupId, nextGroupId, current.getFieldSnapshots()));
         test.setUpdateTime(new Date());
         int rows = testMapper.updateTest(test);
         if (rows != 1) throw new ServiceException("测试配置已变更,请刷新后重试");
 
-        // 开始接收前没有数据归属事实,配置关系可在同一事务内整体替换,审计记录仍只追加。
+        // 开始接收前没有数据归属事实,配置关系可在同一事务内整体替换;操作审计由 Controller @Log 追加。
         testMapper.deleteTestCollectorChannelsByTestId(test.getTestId());
         testMapper.deleteTestBindingsByTestId(test.getTestId());
-        testMapper.deleteTestPlanStepsByTestId(test.getTestId());
-        testMapper.deleteTestFieldsByTestId(test.getTestId());
         testMapper.deleteTestBatteriesByTestId(test.getTestId());
         testMapper.deleteTestThresholdsByTestId(test.getTestId());
-        sharedFieldSnapshotService.deleteByTestId(test.getTestId());
         saveConfiguration(test);
-        testMapper.insertTestAudit(test.getTestId(), "TEST_CONFIGURATION_UPDATED", test.getOperatorId(),
-                test.getUpdateBy(), JSON.toJSONString(current), JSON.toJSONString(test));
         return rows;
     }
 
@@ -285,10 +268,13 @@
             if (current == null) throw new ServiceException("测试不存在");
             if (!NOT_STARTED.equals(current.getReceptionStatus())) throw new ServiceException("开始接收后不能删除测试");
             loadConfiguration(current);
+            // 测试整体删除是无痕例外:先清理全部测试绑定和阈值,再删除主记录,不写审计。
+            testMapper.deleteTestCollectorChannelsByTestId(testId);
+            testMapper.deleteTestBindingsByTestId(testId);
+            testMapper.deleteTestThresholdRowsByTestId(testId);
+            testMapper.deleteTestBatteriesByTestId(testId);
             int deleted = testMapper.deleteTestById(testId, updateBy);
             if (deleted != 1) throw new ServiceException("测试配置已变更,请刷新后重试");
-            testMapper.insertTestAudit(testId, "TEST_DELETED", operatorId, updateBy,
-                    JSON.toJSONString(current), null);
             rows += deleted;
         }
         return rows;
@@ -385,25 +371,14 @@
     private void loadConfiguration(TTest test)
     {
         Long testId = test.getTestId();
-        List<TTestPlanStep> loadedPlanSteps = testMapper.selectTestPlanSteps(testId);
-        List<TTestPlanStep> planSteps = loadedPlanSteps == null ? mutable(test.getPlanSteps()) : mutable(loadedPlanSteps);
-        for (TTestPlanStep step : planSteps)
-        {
-            try
-            {
-                step.setParameters(JSON.parseObject(step.getParametersJson()));
-            }
-            catch (JSONException exception)
-            {
-                throw new ServiceException("计划工步参数无法解析");
-            }
-        }
-
         List<TTestBattery> loadedBatteries = testMapper.selectTestBatteries(testId);
         List<TTestBattery> batteries = loadedBatteries == null || (loadedBatteries.isEmpty() && test.getBatteries() != null
                 && !test.getBatteries().isEmpty()) ? mutable(test.getBatteries()) : mutable(loadedBatteries);
-        List<TTestBatteryField> loadedFields = testMapper.selectTestBatteryFields(testId);
-        List<TTestBatteryField> fields = loadedFields == null ? List.of() : mutable(loadedFields);
+        // 字段属于电池组当前配置;每次查询测试都重新读取,避免产生测试字段快照。
+        List<TTestBatteryField> currentFields = testMapper.selectCurrentBatteryFields(testId);
+        Map<Long, List<TTestBatteryField>> fieldsByBattery = new HashMap<>();
+        for (TTestBatteryField field : mutable(currentFields))
+            fieldsByBattery.computeIfAbsent(field.getRelationId(), ignored -> new ArrayList<>()).add(field);
         List<TTestCollectorChannel> loadedCollectorChannels = testMapper.selectTestCollectorChannels(testId);
         List<TTestCollectorChannel> collectorChannels = loadedCollectorChannels == null ? List.of() : mutable(loadedCollectorChannels);
         Map<Long, TTestChannelBinding> bindings = new HashMap<>();
@@ -416,22 +391,18 @@
         for (TTestBattery battery : batteries)
         {
             battery.setBinding(bindings.get(battery.getRelationId()));
-            if (loadedFields != null && (!loadedFields.isEmpty() || battery.getFields() == null))
-                battery.setFields(fields.stream()
-                        .filter(field -> battery.getRelationId().equals(field.getRelationId()))
-                        .toList());
+            battery.setFields(fieldsByBattery.getOrDefault(battery.getRelationId(), List.of()));
             if (loadedCollectorChannels != null && (!loadedCollectorChannels.isEmpty() || battery.getCollectorChannels() == null))
                 battery.setCollectorChannels(collectorChannels.stream()
                         .filter(mapping -> battery.getRelationId().equals(mapping.getBatteryRelationId()))
                         .toList());
         }
-        test.setPlanSteps(planSteps);
         test.setBatteries(batteries);
         test.setBatteryNo(joinBatteryNos(batteries));
         List<TTestWarningThreshold> loadedThresholds = testMapper.selectTestThresholds(testId);
         test.setThresholds(loadedThresholds == null ? mutable(test.getThresholds()) : mutable(loadedThresholds));
-        List<TTestFieldSnapshot> loadedSnapshots = sharedFieldSnapshotService.selectByTestId(testId);
-        test.setFieldSnapshots(loadedSnapshots == null ? mutable(test.getFieldSnapshots()) : loadedSnapshots);
+        // 测试不保存字段快照;字段值始终随电池组当前配置读取。
+        test.setFieldSnapshots(new ArrayList<>());
         String mappingJson = test.getLogicStepMappingsJson();
         try { test.setLogicStepMappings(mappingJson == null || mappingJson.isBlank()
                 ? new ArrayList<>() : JSON.parseArray(mappingJson, TTestLogicStepMapping.class)); }
@@ -467,8 +438,8 @@
 
     private void validateConfiguration(TTest test)
     {
-        // 新建测试只建立业务身份和通道关系,计划工步可在开始接收前补充。
-        if (test.getPlanSteps() == null) test.setPlanSteps(new ArrayList<>());
+        // 计划工步来自设备观测,不属于测试创建配置,也不写入业务库。
+        test.setPlanSteps(new ArrayList<>());
         validateBatteries(test.getBatteries());
         validatePlanSteps(test.getPlanSteps());
         validateThresholds(test.getThresholds());
@@ -616,23 +587,10 @@
 
     private void saveConfiguration(TTest test)
     {
-        for (TTestPlanStep step : test.getPlanSteps())
-        {
-            step.setTestId(test.getTestId());
-            testMapper.insertTestPlanStep(step);
-        }
         for (TTestBattery battery : test.getBatteries())
         {
             battery.setTestId(test.getTestId());
             testMapper.insertTestBattery(battery);
-            if (battery.getFields() != null)
-            {
-                for (TTestBatteryField field : battery.getFields())
-                {
-                    field.setRelationId(battery.getRelationId());
-                    testMapper.insertTestBatteryField(field);
-                }
-            }
             TTestChannelBinding binding = battery.getBinding();
             binding.setTestId(test.getTestId());
             binding.setBatteryRelationId(battery.getRelationId());
@@ -646,7 +604,6 @@
                 testMapper.insertTestCollectorChannel(mapping);
             }
         }
-        sharedFieldSnapshotService.saveForTest(test.getTestId(), test.getFieldSnapshots());
         for (TTestWarningThreshold threshold : test.getThresholds())
         {
             threshold.setTestId(test.getTestId());
diff --git a/ruoyi-system/src/main/resources/mapper/system/TBatteryGroupMapper.xml b/ruoyi-system/src/main/resources/mapper/system/TBatteryGroupMapper.xml
index 909a59d..074a204 100644
--- a/ruoyi-system/src/main/resources/mapper/system/TBatteryGroupMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/TBatteryGroupMapper.xml
@@ -6,8 +6,7 @@
     <resultMap type="TBatteryGroup" id="TBatteryGroupResult">
         <id property="groupId" column="group_id" /><result property="groupName" column="group_name" />
         <result property="model" column="model" /><result property="purpose" column="purpose" />
-        <result property="z" column="z" /><result property="h" column="h" /><result property="f" column="f" />
-        <result property="a" column="a" /><result property="b" column="b" /><result property="status" column="status" />
+        <result property="status" column="status" />
         <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="delFlag" column="del_flag" />
@@ -29,9 +28,9 @@
         <id property="templateId" column="template_id" />
         <result property="templateName" column="template_name" />
     </resultMap>
-    <sql id="groupColumns">select group_id, group_name, model, purpose, z, h, f, a, b, status, create_by, create_time, update_by, update_time, remark, del_flag from t_battery_group</sql>
+    <sql id="groupColumns">select group_id, group_name, model, purpose, status, create_by, create_time, update_by, update_time, remark, del_flag from t_battery_group</sql>
     <select id="selectBatteryGroupList" parameterType="TBatteryGroup" resultMap="TBatteryGroupResult">
-        select bg.group_id, bg.group_name, bg.model, bg.purpose, bg.z, bg.h, bg.f, bg.a, bg.b, bg.status,
+        select bg.group_id, bg.group_name, bg.model, bg.purpose, bg.status,
                bg.create_by, bg.create_time, bg.update_by, bg.update_time, bg.remark, bg.del_flag,
                (select count(1) from t_battery_group_battery bgb where bgb.group_id = bg.group_id and bgb.del_flag = '0') as battery_count
         from t_battery_group bg
@@ -59,13 +58,13 @@
     <select id="selectTemplate" resultMap="TBatteryGroupTemplateReferenceResult">select template_id, template_name from t_battery_group_template where template_id = #{templateId}</select>
     <select id="selectTemplateFieldIds" resultType="Long">select field_id from t_battery_group_template_field where template_id = #{templateId} and del_flag = '0' order by sort_order, relation_id</select>
     <select id="selectValidTemplateFields" resultMap="TBatteryGroupRelationFieldResult">select r.relation_id, r.template_id, r.field_id as battery_group_field_id, f.field_name, f.field_type, '0' as del_flag from t_battery_group_template_field r inner join t_battery_group_field f on f.field_id = r.field_id and f.del_flag = '0' where r.template_id = #{templateId} and r.del_flag = '0' and r.field_id in <foreach collection="fieldIds" item="fieldId" open="(" separator="," close=")">#{fieldId}</foreach></select>
-    <select id="selectBatteryByNo" resultMap="TBatteryGroupBatteryResult">select relation_id, group_id, battery_no, sort_order, del_flag from t_battery_group_battery where battery_no = #{batteryNo} and del_flag = '0' <if test="groupId != null">and group_id != #{groupId}</if> limit 1</select>
-    <insert id="insertBatteryGroup" parameterType="TBatteryGroup" useGeneratedKeys="true" keyProperty="groupId">insert into t_battery_group (group_name, model, purpose, z, h, f, a, b, status, create_by, create_time, remark, del_flag) values (#{groupName}, #{model}, #{purpose}, #{z}, #{h}, #{f}, #{a}, #{b}, #{status}, #{createBy}, sysdate(), #{remark}, '0')</insert>
-    <update id="updateBatteryGroup" parameterType="TBatteryGroup">update t_battery_group set group_name=#{groupName}, model=#{model}, purpose=#{purpose}, z=#{z}, h=#{h}, f=#{f}, a=#{a}, b=#{b}, status=#{status}, update_by=#{updateBy}, update_time=sysdate(), remark=#{remark} where group_id=#{groupId} and del_flag='0'</update>
+    <select id="selectBatteryByNo" resultMap="TBatteryGroupBatteryResult">select relation_id, group_id, battery_no, sort_order, del_flag from t_battery_group_battery where battery_no = #{batteryNo} and del_flag = 0 <choose><when test="groupId != null">and group_id = #{groupId}</when><otherwise>and 1 = 0</otherwise></choose> limit 1</select>
+    <insert id="insertBatteryGroup" parameterType="TBatteryGroup" useGeneratedKeys="true" keyProperty="groupId">insert into t_battery_group (group_name, model, purpose, status, create_by, create_time, remark, del_flag) values (#{groupName}, #{model}, #{purpose}, #{status}, #{createBy}, utc_timestamp(3), #{remark}, 0)</insert>
+    <update id="updateBatteryGroup" parameterType="TBatteryGroup">update t_battery_group set group_name=#{groupName}, model=#{model}, purpose=#{purpose}, status=#{status}, update_by=#{updateBy}, update_time=utc_timestamp(3), remark=#{remark} where group_id=#{groupId} and del_flag=0</update>
     <update id="updateBatteryGroupStatus" parameterType="TBatteryGroup">update t_battery_group set status=#{status}, update_by=#{updateBy}, update_time=sysdate() where group_id=#{groupId} and del_flag='0'</update>
-    <update id="deleteBatteryGroup">update t_battery_group set del_flag=cast(group_id as char), update_by=#{updateBy}, update_time=sysdate() where group_id=#{groupId} and del_flag='0'</update>
-    <update id="deleteBatteries">update t_battery_group_battery set del_flag=cast(relation_id as char) where group_id=#{groupId} and del_flag='0'</update>
-    <update id="deleteRelationFields">update t_battery_group_relation_field set del_flag=cast(relation_id as char) where group_id=#{groupId} and del_flag='0'</update>
+    <update id="deleteBatteryGroup">update t_battery_group set del_flag=group_id, update_by=#{updateBy}, update_time=utc_timestamp(3) where group_id=#{groupId} and del_flag=0</update>
+    <update id="deleteBatteries">update t_battery_group_battery set del_flag=relation_id where group_id=#{groupId} and del_flag=0</update>
+    <update id="deleteRelationFields">update t_battery_group_relation_field set del_flag=relation_id where group_id=#{groupId} and del_flag=0</update>
     <insert id="batchInsertBatteries">insert into t_battery_group_battery (group_id,battery_no,sort_order,del_flag) values <foreach collection="items" item="item" separator=",">(#{item.groupId},#{item.batteryNo},#{item.sortOrder},#{item.delFlag})</foreach></insert>
     <insert id="batchInsertRelationFields">insert into t_battery_group_relation_field (group_id,template_id,battery_group_field_id,field_value,del_flag) values <foreach collection="items" item="item" separator=",">(#{item.groupId},#{item.templateId},#{item.batteryGroupFieldId},#{item.fieldValue},#{item.delFlag})</foreach></insert>
     <select id="countTestingByGroupId" resultType="int">select count(1) from t_test_battery b inner join t_test t on t.test_id = b.test_id and t.del_flag = 0 where b.group_id=#{groupId} and b.del_flag=0 and t.test_status not in ('COMPLETED', 'COMPLETION_PENDING', 'TERMINATED')</select>
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