refactor(mms-mapping): 更新江苏配置模板并增强JSON到XML转换服务

- 将JiangSu_Config1.xml和JiangSu_Config2.xml中的Value标签注释格式统一
- 在JsonToXmlConversionService中改进规则匹配统计信息显示
- 添加XML模板中Value标签数量统计功能
- 实现匹配成功和未匹配Value标签的计数统计
- 增加未匹配标签的详细描述列表输出
- 新增countXmlValueTags方法用于统计XML中Value标签总数
- 新增countMatchedValueTags方法用于统计已匹配的Value标签数
- 新增findUnmatchedValueTags方法用于查找未匹配的Value标签描述
This commit is contained in:
周宇 蔡
2026-06-12 09:50:51 +08:00
parent c0cf4de315
commit 1343d235c8
3 changed files with 137 additions and 27 deletions

View File

@@ -352,13 +352,28 @@ public class JsonToXmlConversionService {
var mappingMetrics = extractMetricsFromMapping(mappingDocument);
addMethodDescribe(methodDescribeList, "========== 开始从JSON匹配规则 ==========");
addMethodDescribe(methodDescribeList, "规则总数: " + mergedRules.size());
addMethodDescribe(methodDescribeList, "规则文件中定义规则总数: " + mergedRules.size());
addMethodDescribe(methodDescribeList, "JSON中指标总数: " + mappingMetrics.size());
var applicableRules = findApplicableRulesDesc(mergedRules, mappingMetrics, methodDescribeList);
addMethodDescribe(methodDescribeList, "匹配成功: " + applicableRules.size() + " 条规则");
addMethodDescribe(methodDescribeList, "匹配失败: " + (mergedRules.size() - applicableRules.size()) + " 条规则");
int xmlValueTagCount = countXmlValueTags(xmlContent);
int matchedValueTagCount = countMatchedValueTags(xmlContent, applicableRules);
int unmatchedValueTagCount = xmlValueTagCount - matchedValueTagCount;
addMethodDescribe(methodDescribeList, "========== XML模板配置统计 ==========");
addMethodDescribe(methodDescribeList, "XML模板中需要配置的<Value>标签总数: " + xmlValueTagCount);
addMethodDescribe(methodDescribeList, "成功匹配的<Value>标签数: " + matchedValueTagCount);
addMethodDescribe(methodDescribeList, "未匹配的<Value>标签数: " + unmatchedValueTagCount);
if (unmatchedValueTagCount > 0) {
List<String> unmatchedDescList = findUnmatchedValueTags(xmlContent, applicableRules);
addMethodDescribe(methodDescribeList, "未匹配的标签desc列表:");
for (String desc : unmatchedDescList) {
addMethodDescribe(methodDescribeList, " - " + desc);
}
}
addMethodDescribe(methodDescribeList, "========== JSON规则匹配结束 ==========");
return applyRulesToXml(xmlContent, applicableRules);
@@ -1107,6 +1122,101 @@ public class JsonToXmlConversionService {
methodDescribeList.add(message);
}
/**
* 统计 XML 模板中 <Value> 标签的总数
*/
private int countXmlValueTags(String xmlContent) {
if (xmlContent == null || xmlContent.isEmpty()) {
return 0;
}
java.util.regex.Pattern valueTagPattern = java.util.regex.Pattern.compile(
"<Value\\s+[^>]+/>",
java.util.regex.Pattern.CASE_INSENSITIVE
);
java.util.regex.Matcher matcher = valueTagPattern.matcher(xmlContent);
int count = 0;
while (matcher.find()) {
count++;
}
return count;
}
/**
* 统计 XML 模板中成功匹配的 <Value> 标签数
*/
private int countMatchedValueTags(String xmlContent,
java.util.Map<String, RuleBasedXmlMappingService.ValueRule> applicableRules) {
if (xmlContent == null || xmlContent.isEmpty() || applicableRules == null) {
return 0;
}
java.util.regex.Pattern valueTagPattern = java.util.regex.Pattern.compile(
"<Value\\s+([^>]+)/>",
java.util.regex.Pattern.CASE_INSENSITIVE
);
java.util.regex.Pattern attributePattern = java.util.regex.Pattern.compile(
"desc=\"([^\"]*)\"",
java.util.regex.Pattern.CASE_INSENSITIVE
);
java.util.regex.Matcher matcher = valueTagPattern.matcher(xmlContent);
int matchedCount = 0;
while (matcher.find()) {
String attributesStr = matcher.group(1);
java.util.regex.Matcher attrMatcher = attributePattern.matcher(attributesStr);
if (attrMatcher.find()) {
String desc = attrMatcher.group(1);
if (applicableRules.containsKey(desc)) {
matchedCount++;
}
}
}
return matchedCount;
}
/**
* 查找 XML 模板中未匹配的 <Value> 标签的 desc 属性列表
*/
private List<String> findUnmatchedValueTags(String xmlContent,
java.util.Map<String, RuleBasedXmlMappingService.ValueRule> applicableRules) {
List<String> unmatchedList = new ArrayList<>();
if (xmlContent == null || xmlContent.isEmpty() || applicableRules == null) {
return unmatchedList;
}
java.util.regex.Pattern valueTagPattern = java.util.regex.Pattern.compile(
"<Value\\s+([^>]+)/>",
java.util.regex.Pattern.CASE_INSENSITIVE
);
java.util.regex.Pattern attributePattern = java.util.regex.Pattern.compile(
"desc=\"([^\"]*)\"",
java.util.regex.Pattern.CASE_INSENSITIVE
);
java.util.regex.Matcher matcher = valueTagPattern.matcher(xmlContent);
while (matcher.find()) {
String attributesStr = matcher.group(1);
java.util.regex.Matcher attrMatcher = attributePattern.matcher(attributesStr);
if (attrMatcher.find()) {
String desc = attrMatcher.group(1);
if (!applicableRules.containsKey(desc) && !desc.isEmpty()) {
unmatchedList.add(desc);
}
}
}
return unmatchedList;
}
/**
* 指标信息内部类
*/

View File

@@ -76,11 +76,11 @@
<Sequence name="SEQ" value="7" desc="相别" type="5">
<Value name="MAG" desc="残余电压" type="6" DO="" DA="" />
<Value name="DUR" desc="持续时间" type="6" DO="" DA="" />
<!--Value name="SEQ" desc="相别" type="6" DO="" DA="" />
<Value name="STARTTIME" desc="开始时间" type="6" DO="" DA="" />
<Value name="ENDTIME" desc="结束时间" type="6" DO="" DA="" />
<Value name="DISKIND" desc="暂降类型" type="6" DO="" DA="" />
<Value name="WAVEFILE" desc="波形文件名称" type="6" DO="" DA="" /-->
<!--Value name="SEQ" desc="相别" type="6" DO="" DA="" /-->
<!--Value name="STARTTIME" desc="开始时间" type="6" DO="" DA="" /-->
<!--Value name="ENDTIME" desc="结束时间" type="6" DO="" DA="" /-->
<!--Value name="DISKIND" desc="暂降类型" type="6" DO="" DA="" /-->
<!--Value name="WAVEFILE" desc="波形文件名称" type="6" DO="" DA="" /-->
</Sequence>
</Item>
</Monitor>
@@ -446,10 +446,10 @@
<Sequence name="SEQ" value="-" desc="相别" type="5">
<Value name="MAG" desc="实时残余电压" type="6" DO="" DA="" Coefficient="1" />
<Value name="DUR" desc="实时持续时间" type="6" DO="" DA="" Coefficient="1" />
<!--Value name="STARTTIME" desc="开始时间" type="6" DO="" DA="" Coefficient="1" />
<Value name="ENDTIME" desc="结束时间" type="6" DO="" DA="" Coefficient="1" />
<Value name="DISKIND" desc="暂降类型" type="6" DO="" DA="" Coefficient="1" />
<Value name="WAVEFILE" desc="波形文件名称" type="6" DO="" DA="" Coefficient="1" /-->
<!--Value name="STARTTIME" desc="开始时间" type="6" DO="" DA="" Coefficient="1" /-->
<!--Value name="ENDTIME" desc="结束时间" type="6" DO="" DA="" Coefficient="1" /-->
<!--Value name="DISKIND" desc="暂降类型" type="6" DO="" DA="" Coefficient="1" /-->
<!--Value name="WAVEFILE" desc="波形文件名称" type="6" DO="" DA="" Coefficient="1" /-->
</Sequence>
</Item>
</Monitor>

View File

@@ -64,11 +64,11 @@
<Sequence name="SEQ" value="7" desc="相别" type="5">
<Value name="MAG" desc="残余电压" type="6" DO="" DA="" />
<Value name="DUR" desc="持续时间" type="6" DO="" DA="" />
<Value name="SEQ" desc="相别" type="6" DO="" DA="" />
<Value name="STARTTIME" desc="开始时间" type="6" DO="" DA="" />
<Value name="ENDTIME" desc="结束时间" type="6" DO="" DA="" />
<Value name="DISKIND" desc="暂降类型" type="6" DO="" DA="" />
<Value name="WAVEFILE" desc="波形文件名称" type="6" DO="" DA="" />
<!--Value name="SEQ" desc="相别" type="6" DO="" DA="" /-->
<!--Value name="STARTTIME" desc="开始时间" type="6" DO="" DA="" /-->
<!--Value name="ENDTIME" desc="结束时间" type="6" DO="" DA="" /-->
<!--Value name="DISKIND" desc="暂降类型" type="6" DO="" DA="" /-->
<!--Value name="WAVEFILE" desc="波形文件名称" type="6" DO="" DA="" /-->
</Sequence>
</Item>
</Monitor>