Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指标信息内部类
|
||||
*/
|
||||
|
||||
@@ -60,14 +60,24 @@ public class RuleBasedXmlMappingService {
|
||||
private static final Pattern DO_INDEX_PATTERN = Pattern.compile("(MMXU|MHAI|MSQI|MFLK|QVVR)(\\d+)");
|
||||
private static final Pattern DO_NO_INDEX_PATTERN = Pattern.compile("(MMXU|MHAI|MSQI|MFLK|QVVR)\\$");
|
||||
|
||||
public InputStream loadDefaultXmlFile( ) throws Exception {
|
||||
ClassPathResource templateResource = new ClassPathResource("template/JiangSu_Config1.xml");
|
||||
public InputStream loadDefaultXmlFile() throws Exception {
|
||||
return loadDefaultXmlFile(1);
|
||||
}
|
||||
|
||||
public InputStream loadDefaultXmlFile(Integer configType) throws Exception {
|
||||
String fileName;
|
||||
if (configType != null && configType == 2) {
|
||||
fileName = "template/JiangSu_Config1.xml";
|
||||
} else {
|
||||
fileName = "template/JiangSu_Config2.xml";
|
||||
}
|
||||
|
||||
ClassPathResource templateResource = new ClassPathResource(fileName);
|
||||
|
||||
if (!templateResource.exists()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return templateResource.getInputStream();
|
||||
}
|
||||
|
||||
|
||||
@@ -165,9 +165,13 @@ public class MappingController extends BaseController {
|
||||
public IcdToXmlResponse getXmlFromJson(@Validated @RequestPart("request") JsonToXmlRequest request) {
|
||||
String methodDescribe = getMethodDescribe("getXmlFromJson") + ",开始将 MMS JSON 转换为 XML";
|
||||
|
||||
// 直接返回 XML 内容给前端展示,不再输出临时文件。
|
||||
Integer configType = request == null ? null : request.getConfigType();
|
||||
if (configType == null || (configType != 1 && configType != 2)) {
|
||||
configType = 2;
|
||||
}
|
||||
|
||||
IcdToXmlGenerateResult result =
|
||||
icdToXmlTaskAppService.generateXmlFromJson(request == null ? null : request.getMappingJson());
|
||||
icdToXmlTaskAppService.generateXmlFromJson(request == null ? null : request.getMappingJson(), configType);
|
||||
if (result.getMethodDescribe() != null && !result.getMethodDescribe().trim().isEmpty()) {
|
||||
methodDescribe = methodDescribe + "\n" + result.getMethodDescribe();
|
||||
}
|
||||
|
||||
@@ -13,6 +13,10 @@ public class JsonToXmlRequest {
|
||||
@ApiModelProperty(value = "MMS 映射 JSON 字符串", required = true)
|
||||
private String mappingJson;
|
||||
|
||||
/** 配置文件类型:1-读取 Jiangsuconfig2.xml,2-读取 Jiangsuconfig1.xml,空或错误时默认为 1。 */
|
||||
@ApiModelProperty(value = "配置文件类型:1-Jiangsuconfig2.xml,2-Jiangsuconfig1.xml,默认1")
|
||||
private Integer configType;
|
||||
|
||||
public String getMappingJson() {
|
||||
return mappingJson;
|
||||
}
|
||||
@@ -20,4 +24,12 @@ public class JsonToXmlRequest {
|
||||
public void setMappingJson(String mappingJson) {
|
||||
this.mappingJson = mappingJson;
|
||||
}
|
||||
|
||||
public Integer getConfigType() {
|
||||
return configType;
|
||||
}
|
||||
|
||||
public void setConfigType(Integer configType) {
|
||||
this.configType = configType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,16 +114,17 @@ public class IcdToXmlTaskAppService {
|
||||
* 直接从 JSON 字符串生成 XML 内容。
|
||||
*
|
||||
* @param mappingJson MMS 映射 JSON 字符串(由 getIcdMmsJson 接口返回)
|
||||
* @param configType 配置文件类型:1-读取 Jiangsuconfig2.xml,2-读取 Jiangsuconfig1.xml,空或错误时默认为 1
|
||||
* @return XML 生成结果
|
||||
*/
|
||||
public IcdToXmlGenerateResult generateXmlFromJson(String mappingJson) {
|
||||
public IcdToXmlGenerateResult generateXmlFromJson(String mappingJson, Integer configType) {
|
||||
return executeTask(JSON_TO_XML_TASK_NAME, result -> {
|
||||
if (isBlank(mappingJson)) {
|
||||
markFailed(result, JSON_TO_XML_TASK_NAME, MAPPING_JSON_EMPTY_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
fillXmlContent(result, mappingJson, loadXmlResources());
|
||||
fillXmlContent(result, mappingJson, loadXmlResources(configType));
|
||||
result.setStatus(GenerateStatus.SUCCESS);
|
||||
result.setMessage(XML_GENERATE_SUCCESS_MESSAGE);
|
||||
});
|
||||
@@ -179,7 +180,11 @@ public class IcdToXmlTaskAppService {
|
||||
* 加载 XML 模板和规则文件。
|
||||
*/
|
||||
private XmlResourceContext loadXmlResources() throws Exception {
|
||||
InputStream templateStream = ruleBasedXmlMappingService.loadDefaultXmlFile();
|
||||
return loadXmlResources(1);
|
||||
}
|
||||
|
||||
private XmlResourceContext loadXmlResources(Integer configType) throws Exception {
|
||||
InputStream templateStream = ruleBasedXmlMappingService.loadDefaultXmlFile(configType);
|
||||
if (templateStream == null) {
|
||||
throw new IllegalArgumentException(DEFAULT_XML_MISSING_MESSAGE);
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -82,7 +82,7 @@ public class JsonToXmlDebugRunner {
|
||||
if (VERBOSE_LOG) {
|
||||
System.out.println("正在转换 JSON 为 XML...");
|
||||
}
|
||||
IcdToXmlGenerateResult result = icdToXmlTaskAppService.generateXmlFromJson(mappingJson);
|
||||
IcdToXmlGenerateResult result = icdToXmlTaskAppService.generateXmlFromJson(mappingJson,2);
|
||||
|
||||
// 输出结果
|
||||
printResult(result, objectMapper);
|
||||
|
||||
Reference in New Issue
Block a user