refactor(icd-mapping): 重构ICD到XML转换服务以支持配置类型参数
- 移除generateFromIcd方法中的索引选择验证逻辑 - 在fillXmlContent方法中添加configType参数传递 - 在JsonToXmlConversionService中添加configType参数支持 - 删除convertFromJson方法的旧实现 - 更新buildXmlContentFromJson方法签名以包含configType参数 - 在applyRulesFromMapping和extractMetricsFromMapping方法中传递configType参数 - 添加针对PMS3.0配置类型的特殊处理逻辑 - 修复模板中线电压基波有效值描述文本错误
This commit is contained in:
@@ -10,6 +10,7 @@ import com.njcn.gather.icd.mapping.pojo.vo.*;
|
||||
import com.njcn.gather.icd.mapping.pojo.enums.GenerateStatus;
|
||||
import com.njcn.gather.icd.mapping.pojo.bo.mapping.MappingDocument;
|
||||
import com.njcn.gather.icd.mapping.utils.GeneratedFileNameUtil;
|
||||
import io.swagger.models.auth.In;
|
||||
import lombok.var;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -43,29 +44,6 @@ public class JsonToXmlConversionService {
|
||||
this.objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从JSON字符串转换为XML文件
|
||||
*
|
||||
* @param mappingJson JSON格式的映射文档
|
||||
* @param templateStream XML模板流
|
||||
* @param ruleStreams 规则文件流列表
|
||||
* @param indexMapping 索引映射配置
|
||||
* @return 生成的XML文件路径
|
||||
* @throws Exception 转换异常
|
||||
*/
|
||||
public String convertFromJson(String mappingJson,
|
||||
InputStream templateStream,
|
||||
List<InputStream> ruleStreams,
|
||||
IcdToXmlMappingService.IndexMappingConfig indexMapping) throws Exception {
|
||||
String xmlContent = buildXmlContentFromJson(mappingJson, templateStream, ruleStreams, indexMapping);
|
||||
|
||||
// 3. 保存为临时文件
|
||||
Path tempPath = Paths.get(System.getProperty("java.io.tmpdir"),
|
||||
GeneratedFileNameUtil.appendToday("converted_" + java.util.UUID.randomUUID().toString().replace("-", "") + ".xml"));
|
||||
Files.write(tempPath, xmlContent.getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE_NEW);
|
||||
|
||||
return tempPath.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 JSON 字符串转换为 XML 内容,供前端直接展示。
|
||||
@@ -74,24 +52,19 @@ public class JsonToXmlConversionService {
|
||||
* @param templateStream XML 模板流
|
||||
* @param ruleStreams 规则文件流列表
|
||||
* @param indexMapping 索引映射配置
|
||||
* @param configType pms3.0或者linux前置
|
||||
* @return 生成后的 XML 内容
|
||||
* @throws Exception 转换异常
|
||||
*/
|
||||
public String buildXmlContentFromJson(String mappingJson,
|
||||
InputStream templateStream,
|
||||
List<InputStream> ruleStreams,
|
||||
IcdToXmlMappingService.IndexMappingConfig indexMapping) throws Exception {
|
||||
return buildXmlContentFromJson(mappingJson, templateStream, ruleStreams, indexMapping, null);
|
||||
}
|
||||
|
||||
public String buildXmlContentFromJson(String mappingJson,
|
||||
InputStream templateStream,
|
||||
List<InputStream> ruleStreams,
|
||||
IcdToXmlMappingService.IndexMappingConfig indexMapping,
|
||||
Integer configType,
|
||||
List<String> methodDescribeList) throws Exception {
|
||||
// 反序列化 JSON 后复用现有规则引擎生成 XML,避免文件输出链路重复实现。
|
||||
MappingDocument mappingDocument = objectMapper.readValue(mappingJson, MappingDocument.class);
|
||||
return buildXmlFromMapping(mappingDocument, templateStream, ruleStreams, indexMapping, methodDescribeList);
|
||||
return buildXmlFromMapping(mappingDocument, templateStream, ruleStreams, indexMapping, configType, methodDescribeList);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,6 +74,7 @@ public class JsonToXmlConversionService {
|
||||
InputStream templateStream,
|
||||
List<InputStream> ruleStreams,
|
||||
IcdToXmlMappingService.IndexMappingConfig indexMapping,
|
||||
Integer configType,
|
||||
List<String> methodDescribeList) throws Exception {
|
||||
// 读取模板
|
||||
String templateContent = readInputStreamToString(templateStream);
|
||||
@@ -109,7 +83,7 @@ public class JsonToXmlConversionService {
|
||||
//填充ReportControls信息
|
||||
xmlContent = fillReportControlsFromMapping(xmlContent, mappingDocument);
|
||||
//填充do da信息
|
||||
xmlContent = applyRulesFromMapping(xmlContent, mappingDocument, ruleStreams, indexMapping, methodDescribeList);
|
||||
xmlContent = applyRulesFromMapping(xmlContent, mappingDocument, ruleStreams, indexMapping, configType,methodDescribeList);
|
||||
|
||||
return xmlContent;
|
||||
}
|
||||
@@ -345,11 +319,12 @@ public class JsonToXmlConversionService {
|
||||
MappingDocument mappingDocument,
|
||||
List<InputStream> ruleStreams,
|
||||
IcdToXmlMappingService.IndexMappingConfig indexMapping,
|
||||
Integer configType,
|
||||
List<String> methodDescribeList) throws Exception {
|
||||
//合并所有规则文件
|
||||
var mergedRules = mergeAllRulesDesc(ruleStreams, indexMapping);
|
||||
//读取mappingDocument
|
||||
var mappingMetrics = extractMetricsFromMapping(mappingDocument);
|
||||
var mappingMetrics = extractMetricsFromMapping(mappingDocument, configType);
|
||||
|
||||
addMethodDescribe(methodDescribeList, "========== 开始从JSON匹配规则 ==========");
|
||||
addMethodDescribe(methodDescribeList, "规则文件中定义规则总数: " + mergedRules.size());
|
||||
@@ -742,7 +717,7 @@ public class JsonToXmlConversionService {
|
||||
/**
|
||||
* 从MappingDocument提取指标信息
|
||||
*/
|
||||
private java.util.Map<String, MetricInfo> extractMetricsFromMapping(MappingDocument mappingDocument) {
|
||||
private java.util.Map<String, MetricInfo> extractMetricsFromMapping(MappingDocument mappingDocument,Integer configType) {
|
||||
java.util.Map<String, MetricInfo> metrics = new java.util.HashMap<>();
|
||||
|
||||
if (mappingDocument == null || mappingDocument.getDataSetList() == null) {
|
||||
@@ -770,6 +745,9 @@ public class JsonToXmlConversionService {
|
||||
continue;
|
||||
}
|
||||
String daPath = buildDaPath(sdiItem.getName(), typeItem.getName(), doiItem);
|
||||
if(2==configType && (sdiItem.getDesc().contains("AB")||sdiItem.getDesc().contains("BC")||sdiItem.getDesc().contains("CA"))){
|
||||
daPath = "1_" + daPath;
|
||||
}
|
||||
MetricInfo info = new MetricInfo();
|
||||
info.setLnClass(dataSetGroup.getLnClass());
|
||||
info.setLnInst(instItem.getInst());
|
||||
|
||||
@@ -72,44 +72,6 @@ public class IcdToXmlTaskAppService {
|
||||
/** 将 MMS JSON 中间态转换为 XML 内容。 */
|
||||
private final JsonToXmlConversionService jsonToXmlConversionService;
|
||||
|
||||
/**
|
||||
* 解析 ICD 并按索引绑定关系直接生成 XML 内容。
|
||||
*/
|
||||
public IcdToXmlGenerateResult generateFromIcd(IcdToXmlGenerateCommand command) {
|
||||
return executeTask(ICD_TO_XML_TASK_NAME, result -> {
|
||||
IcdToXmlTaskContext context = buildTaskContext(command, result);
|
||||
|
||||
if (isIndexSelectionEmpty(command.getIndexSelection())) {
|
||||
markNeedIndexSelection(result);
|
||||
return;
|
||||
}
|
||||
|
||||
ValidationResult validationResult = indexValidationService.validate(context.indexAnalysis, command.getIndexSelection());
|
||||
if (!validationResult.isValid()) {
|
||||
markNeedIndexSelection(result);
|
||||
result.getProblems().addAll(validationResult.getProblems());
|
||||
return;
|
||||
}
|
||||
|
||||
MappingDocument mappingDocument = mappingGenerationService.generate(
|
||||
context.icdDocument,
|
||||
context.template,
|
||||
context.indexAnalysis,
|
||||
command.getIndexSelection(),
|
||||
command.getVersion(),
|
||||
command.getAuthor()
|
||||
);
|
||||
result.setMappingDocument(mappingDocument);
|
||||
|
||||
String mappingJson = mappingDocumentSerializer.toPrettyJson(mappingDocument);
|
||||
bindIndexMapping(command.getIndexSelection());
|
||||
fillXmlContent(result, mappingJson, loadXmlResources());
|
||||
|
||||
result.setStatus(GenerateStatus.SUCCESS);
|
||||
result.setMessage(MAPPING_GENERATE_SUCCESS_MESSAGE);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接从 JSON 字符串生成 XML 内容。
|
||||
*
|
||||
@@ -124,7 +86,7 @@ public class IcdToXmlTaskAppService {
|
||||
return;
|
||||
}
|
||||
|
||||
fillXmlContent(result, mappingJson, loadXmlResources(configType));
|
||||
fillXmlContent(result, mappingJson, loadXmlResources(configType),configType);
|
||||
result.setStatus(GenerateStatus.SUCCESS);
|
||||
result.setMessage(XML_GENERATE_SUCCESS_MESSAGE);
|
||||
});
|
||||
@@ -210,13 +172,15 @@ public class IcdToXmlTaskAppService {
|
||||
*/
|
||||
private void fillXmlContent(IcdToXmlGenerateResult result,
|
||||
String mappingJson,
|
||||
XmlResourceContext xmlResourceContext) throws Exception {
|
||||
XmlResourceContext xmlResourceContext,
|
||||
Integer configType) throws Exception {
|
||||
List<String> methodDescribeList = new ArrayList<>();
|
||||
String xmlContent = jsonToXmlConversionService.buildXmlContentFromJson(
|
||||
mappingJson,
|
||||
xmlResourceContext.templateStream,
|
||||
xmlResourceContext.ruleStreams,
|
||||
icdToXmlMappingService.getIndexMapping(),
|
||||
configType,
|
||||
methodDescribeList
|
||||
);
|
||||
result.setXmlContent(xmlContent);
|
||||
|
||||
@@ -286,7 +286,7 @@
|
||||
<Value name="线电压偏差实时数据值" desc="实时线电压偏差" type="6" DO="MMXU$MX$LnVolDev" DA="phs*$cVal$mag$f" Coefficient="1"/>
|
||||
<Value name="线电压总有效值实时数据值" desc="实时线电压有效值" type="6" DO="MMXU$MX$LnPhV" DA="phs*$cVal$mag$f" BaseFlag="1" LimitUp="0*%U" LimitDown="150*%U" Coefficient="1" />
|
||||
<Value name="线电压谐波总畸变率实时数据值" desc="实时线电压总谐波畸变率" type="6" DO="MHAI$MX$ThdLnPhV" DA="phs*$cVal$mag$f" Coefficient="1"/>
|
||||
<Value name="相电压基波有效值实时数据角度" desc="实时基波线电压相角" type="6" DO="MHAI$MX$FundLnPhVAng" DA="phs*$cVal$ang$f" Coefficient="1" />
|
||||
<Value name="线电压基波有效值实时数据角度" desc="实时基波线电压相角" type="6" DO="MHAI$MX$FundLnPhVAng" DA="phs*$cVal$ang$f" Coefficient="1" />
|
||||
<Value name="线电压基波有效值实时数据值" desc="实时基波线电压有效值" type="6" DO="MHAI$MX$FundLnPhV" DA="phs*$cVal$mag$f" Coefficient="1"/>
|
||||
<Value name="线电压间谐波含有率序列间谐波实时数据值" desc="实时间谐波线电压含有率(f25-2475)" type="6" DO="MHAI$MX$HLnPhV" DA="phs*Har[%-0]$mag$f" Coefficient="1" Offset="0" />
|
||||
<Value name="线电压谐波含有率序列实时数据值" desc="实时谐波线电压含有率(2-50)" type="6" DO="MHAI$MX$HLnPhV" DA="phs*Har[%-2]$mag$f" Coefficient="1" Offset="0" />
|
||||
|
||||
Reference in New Issue
Block a user