feat(detection): 更新影响量枚举和测试结果排序逻辑

- 在 AffectEnum 中添加 sort 字段用于报告小节排序,分为额定=1、单影响量=2、多影响量=3
- 添加多个新的多影响量组合类型枚举值,如电压和谐波间谐波影响等
- 移除硬编码的影响量文案映射,改为从 AffectEnum 统一获取描述信息
- 使用大小写不敏感的比较方式处理脚本子类型匹配
- 实现按影响量类型排序的逻辑,在最终内容生成时保持固定顺序
- 更新过滤条件使用忽略大小写的字符串比较方法
- 在 .gitignore 中添加对 Windows 保留设备名 nul 文件的忽略规则
This commit is contained in:
2026-06-30 15:55:37 +08:00
parent 88d3e00559
commit e3478e71d5
3 changed files with 49 additions and 28 deletions

3
.gitignore vendored
View File

@@ -54,3 +54,6 @@ CLAUDE.md
docs/
data/
.m2
# Windows 保留设备名误生成的真实文件(在 Git Bash 里把 2>nul 当成丢弃报错的写法,会真的建出名为 nul 的文件)
nul

View File

@@ -12,18 +12,32 @@ import lombok.Getter;
public enum AffectEnum {
BASE("base", "额定工作条件下的检测"),
VOL("vol", "电压对XX测量的影响"),
FREQ("freq", "频率对XX测量的影响"),
HARM("harm", "谐波对XX测量的影响");
// 第三个参数 sort 为报告小节排序档位:额定=1、单影响量=2、多影响量=3同档内再按 Script_Index 升序)
BASE("Base", "额定条件XX准确度测试", 1),
VOL("VOL", "电压幅值对XX测量的影响", 2),
FREQ("Freq", "频率变化对XX测量的影响", 2),
HARM("Harm", "谐波对XX测量的影响", 2),
// Single / Many 是检测树的分组标题,不会作为叶子 Script_SubType 落到设备数据上
SINGLE("Single", "单影响量下XX准确度测试", 2),
MANY("Many", "多影响量下XX准确度测试", 3),
// 以下为真实的多影响量组合 Script_SubType报告与检测树共用同一份文案
MANY_VOL_HARM_INHARM("Many-Vol-Harm-InHarm", "电压和谐波和间谐波对XX的影响", 3),
MANY_IMBV_HARM_INHARM("Many-IMBV-Harm-InHarm", "三项电压不平衡和谐波和间谐波对XX的影响", 3),
MANY_FREQ_HARM_INHARM("Many-Freq-Harm-InHarm", "频率和谐波和间谐波对XX的影响", 3);
private String key;
private String desc;
AffectEnum(String key, String desc) {
/**
* 报告小节排序档位:额定=1、单影响量=2、多影响量=3同档内再按 Script_Index 升序
*/
private int sort;
AffectEnum(String key, String desc, int sort) {
this.key = key;
this.desc = desc;
this.sort = sort;
}
/**

View File

@@ -327,16 +327,11 @@ public class ResultServiceImpl implements IResultService {
List<DictTree> dictTreeById = dictTreeService.getDictTreeById(new ArrayList<>(dtlsSortMap.keySet()));
Map<String, DictTree> dictTreeMap = dictTreeById.stream().collect(Collectors.toMap(DictTree::getId, Function.identity()));
Map<String, String> subName = new LinkedHashMap<>();
subName.put("Base", "额定条件XX准确度测试");
subName.put("VOL", "电压幅值对XX测量的影响");
subName.put("Freq", "频率变化对XX测量的影响");
subName.put("Harm", "谐波对XX测量的影响");
subName.put("Single", "单影响量下XX准确度测试");
subName.put("Many", "多影响量下XX准确度测试");
subName.put("Many-Vol-Harm-InHarm", "电压和谐波和间谐波对XX的影响");
subName.put("Many-IMBV-Harm-InHarm", "三项电压不平衡和谐波和间谐波对XX的影响");
subName.put("Many-Freq-Harm-InHarm", "频率和谐波和间谐波对XX的影响");
// 影响量文案统一由 AffectEnum 提供;大小写不敏感 Map兼容 Script_SubType 的大小写差异
Map<String, String> subName = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
for (AffectEnum affectEnum : AffectEnum.values()) {
subName.put(affectEnum.getKey(), affectEnum.getDesc());
}
Boolean isValueType = scriptMapper.selectScriptIsValueType(param.getScriptId());
List<TreeDataVO> infoVOS = new ArrayList<>();
@@ -353,7 +348,7 @@ public class ResultServiceImpl implements IResultService {
//额定条件下频率准确度测试
LinkedHashMap<String, List<PqScriptDtls>> subTypeMap = value.stream()
.sorted(Comparator.comparing(PqScriptDtls::getScriptIndex))
.filter(x -> "Base".equals(x.getScriptSubType()))
.filter(x -> "Base".equalsIgnoreCase(x.getScriptSubType()))
.collect(Collectors.groupingBy(PqScriptDtls::getScriptSubType, LinkedHashMap::new, Collectors.toList()));
subTypeMap.forEach((subKey, subValue) -> {
if (!"VOLTAGE".equals(dictTree.getCode())) {
@@ -392,7 +387,7 @@ public class ResultServiceImpl implements IResultService {
//单影响量下频率准确度测试
LinkedHashMap<String, List<PqScriptDtls>> subSingleTypeMap = value.stream()
.sorted(Comparator.comparing(PqScriptDtls::getScriptIndex))
.filter(x -> !"Base".equals(x.getScriptSubType()) && !x.getScriptSubType().contains("Many"))
.filter(x -> !"Base".equalsIgnoreCase(x.getScriptSubType()) && !StrUtil.containsIgnoreCase(x.getScriptSubType(), "Many"))
.collect(Collectors.groupingBy(PqScriptDtls::getScriptSubType, LinkedHashMap::new, Collectors.toList()));
if (CollUtil.isNotEmpty(subSingleTypeMap)) {
TreeDataVO subType = new TreeDataVO();
@@ -414,13 +409,13 @@ public class ResultServiceImpl implements IResultService {
dtlType.setIndex(index);
dtlType.setScriptType(scriptDtlIndexList.get(0).getScriptType());
dtlType.setScriptTypeCode(subKey);
if ("Harm".equals(subKey)) {
if ("Harm".equalsIgnoreCase(subKey)) {
harmScriptTypeName(scriptDtlIndexList, dictTree, isValueType, dtlType);
}
if ("VOL".equals(subKey)) {
if ("VOL".equalsIgnoreCase(subKey)) {
volScriptTypeName(scriptDtlIndexList, dictTree, isValueType, dtlType);
}
if ("Freq".equals(subKey)) {
if ("Freq".equalsIgnoreCase(subKey)) {
freqScriptTypeName(scriptDtlIndexList, dictTree, isValueType, dtlType);
}
dtlType.setSourceDesc(ScriptDtlsDesc.getStringBuffer(scriptDtlIndexList, false, isValueType).toString());
@@ -442,7 +437,7 @@ public class ResultServiceImpl implements IResultService {
//多影响量下xx
LinkedHashMap<String, List<PqScriptDtls>> subManyTypeMap = value.stream()
.sorted(Comparator.comparing(PqScriptDtls::getScriptIndex))
.filter(x -> x.getScriptSubType().contains("Many"))
.filter(x -> StrUtil.containsIgnoreCase(x.getScriptSubType(), "Many"))
.collect(Collectors.groupingBy(PqScriptDtls::getScriptSubType, LinkedHashMap::new, Collectors.toList()));
if (CollUtil.isNotEmpty(subManyTypeMap)) {
TreeDataVO subType = new TreeDataVO();
@@ -464,13 +459,13 @@ public class ResultServiceImpl implements IResultService {
dtlType.setIndex(index);
dtlType.setScriptType(scriptDtlIndexList.get(0).getScriptType());
dtlType.setScriptTypeCode(subKey);
if ("Many-Vol-Harm-InHarm".equals(subKey)) {
if ("Many-Vol-Harm-InHarm".equalsIgnoreCase(subKey)) {
volAndHarmAndInHarmScriptTypeName(scriptDtlIndexList, dictTree, isValueType, dtlType);
}
if ("Many-IMBV-Harm-InHarm".equals(subKey)) {
if ("Many-IMBV-Harm-InHarm".equalsIgnoreCase(subKey)) {
imbvAndHarmAndInHarmScriptTypeName(scriptDtlIndexList, dictTree, isValueType, dtlType);
}
if ("Many-Freq-Harm-InHarm".equals(subKey)) {
if ("Many-Freq-Harm-InHarm".equalsIgnoreCase(subKey)) {
freqAndHarmAndInHarmScriptTypeName(scriptDtlIndexList, dictTree, isValueType, dtlType);
}
dtlType.setSourceDesc(ScriptDtlsDesc.getStringBuffer(scriptDtlIndexList, false, isValueType).toString());
@@ -1431,10 +1426,19 @@ public class ResultServiceImpl implements IResultService {
@Override
public SingleTestResult getFinalContent(List<PqScriptDtlDataVO> dtlDataVOList, String planCode, String devId, Integer lineNo, List<String> tableKeys) {
SingleTestResult singleTestResult = new SingleTestResult();
Map<String/*subType影响量额定或某单影响量*/, List<Map<String/*误差范围*/, List<Map<String/*填充key*/, String/*实际值*/>>>>> finalContent = new HashMap<>();
// 用 LinkedHashMap 保住下方按 AffectEnum.sort + Script_Index 排好的影响量小节顺序,一路保到下游 fillContentInTemplate 按 entrySet 顺序消费
Map<String/*subType影响量额定或某单影响量*/, List<Map<String/*误差范围*/, List<Map<String/*填充key*/, String/*实际值*/>>>>> finalContent = new LinkedHashMap<>();
if (CollUtil.isNotEmpty(dtlDataVOList)) {
// 首先区分测试条件
Map<String, List<PqScriptDtlDataVO>> subTypeMap = dtlDataVOList.stream().collect(Collectors.groupingBy(PqScriptDtlDataVO::getScriptSubType));
// 首先区分测试条件;分组前先按 AffectEnum.sort额定→单影响→多影响排序同档内再按 Script_Index 升序,
// 收进 LinkedHashMap使各影响量小节顺序固定为额定、单影响量、多影响量
Map<String, List<PqScriptDtlDataVO>> subTypeMap = dtlDataVOList.stream()
.sorted(Comparator
.comparingInt((PqScriptDtlDataVO v) -> {
AffectEnum ae = AffectEnum.getByKey(v.getScriptSubType());
return ae == null ? Integer.MAX_VALUE : ae.getSort(); // 识别不了的 subType 沉底
})
.thenComparingInt(v -> v.getScriptIndex() == null ? Integer.MAX_VALUE : v.getScriptIndex()))
.collect(Collectors.groupingBy(PqScriptDtlDataVO::getScriptSubType, LinkedHashMap::new, Collectors.toList()));
subTypeMap.forEach((subType, scriptDtlDataVOList) -> {
AffectEnum affectEnum = AffectEnum.getByKey(subType);
if (Objects.nonNull(affectEnum)) {