yeg
2026-08-30 ec3308617909c8d6280e0d00ffb18350e372fbdf
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
package com.ruoyi.system.service.impl;
 
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.domain.TBatteryGroup;
import com.ruoyi.system.domain.TBatteryGroupRelationField;
import com.ruoyi.system.domain.TTestFieldSnapshot;
import com.ruoyi.system.mapper.TSharedFieldSnapshotMapper;
import com.ruoyi.system.service.ITBatteryGroupService;
import com.ruoyi.system.service.ISharedFieldSnapshotService;
 
@Service
public class TSharedFieldSnapshotServiceImpl implements ISharedFieldSnapshotService
{
    @Autowired
    private ITBatteryGroupService batteryGroupService;
 
    @Autowired
    private TSharedFieldSnapshotMapper snapshotMapper;
 
    @Override
    public List<TTestFieldSnapshot> createForBatteryGroup(Long groupId)
    {
        TBatteryGroup group = batteryGroupService.selectBatteryGroupById(groupId);
        List<TTestFieldSnapshot> snapshots = new ArrayList<>();
        for (TBatteryGroupRelationField field : mutable(group.getTemplateFields()))
        {
            snapshots.add(snapshot(field.getBatteryGroupFieldId(), field.getFieldName(), field.getFieldType(),
                    field.getFieldValue()));
        }
        return snapshots;
    }
 
    @Override
    public List<TTestFieldSnapshot> resolveForUpdate(Long currentGroupId, Long nextGroupId,
            List<TTestFieldSnapshot> currentSnapshots)
    {
        // 同组编辑不能重新读取活动值,否则会静默改写测试创建时保存的业务事实。
        if (nextGroupId.equals(currentGroupId))
        {
            return mutable(currentSnapshots).stream()
                    .map(source -> snapshot(source.getFieldDefinitionId(), source.getFieldName(),
                            source.getFieldType(), source.getFieldValue()))
                    .toList();
        }
        return createForBatteryGroup(nextGroupId);
    }
 
    @Override
    public List<TTestFieldSnapshot> selectByTestId(Long testId)
    {
        return mutable(snapshotMapper.selectByTestId(testId));
    }
 
    @Override
    public void saveForTest(Long testId, List<TTestFieldSnapshot> snapshots)
    {
        for (TTestFieldSnapshot snapshot : mutable(snapshots))
        {
            snapshot.setTestId(testId);
            snapshotMapper.insert(snapshot);
        }
    }
 
    @Override
    public void deleteByTestId(Long testId)
    {
        snapshotMapper.deleteByTestId(testId);
    }
 
    private TTestFieldSnapshot snapshot(Long definitionId, String name, String type, String value)
    {
        TTestFieldSnapshot snapshot = new TTestFieldSnapshot();
        snapshot.setFieldDefinitionId(definitionId);
        snapshot.setFieldName(name);
        snapshot.setFieldType(type);
        snapshot.setFieldValue(value);
        return snapshot;
    }
 
    private <T> List<T> mutable(List<T> values)
    {
        return values == null ? new ArrayList<>() : new ArrayList<>(values);
    }
}