diff --git a/tools/mms-mapping/src/main/java/com/njcn/gather/icd/mapping/component/RuleBasedXmlMappingService.java b/tools/mms-mapping/src/main/java/com/njcn/gather/icd/mapping/component/RuleBasedXmlMappingService.java index 8f68d6d..7a127d9 100644 --- a/tools/mms-mapping/src/main/java/com/njcn/gather/icd/mapping/component/RuleBasedXmlMappingService.java +++ b/tools/mms-mapping/src/main/java/com/njcn/gather/icd/mapping/component/RuleBasedXmlMappingService.java @@ -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(); } diff --git a/tools/mms-mapping/src/main/java/com/njcn/gather/icd/mapping/controller/MappingController.java b/tools/mms-mapping/src/main/java/com/njcn/gather/icd/mapping/controller/MappingController.java index 61c2e26..2694fc1 100644 --- a/tools/mms-mapping/src/main/java/com/njcn/gather/icd/mapping/controller/MappingController.java +++ b/tools/mms-mapping/src/main/java/com/njcn/gather/icd/mapping/controller/MappingController.java @@ -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(); } diff --git a/tools/mms-mapping/src/main/java/com/njcn/gather/icd/mapping/pojo/param/JsonToXmlRequest.java b/tools/mms-mapping/src/main/java/com/njcn/gather/icd/mapping/pojo/param/JsonToXmlRequest.java index c527f17..ae7d96e 100644 --- a/tools/mms-mapping/src/main/java/com/njcn/gather/icd/mapping/pojo/param/JsonToXmlRequest.java +++ b/tools/mms-mapping/src/main/java/com/njcn/gather/icd/mapping/pojo/param/JsonToXmlRequest.java @@ -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; + } } diff --git a/tools/mms-mapping/src/main/java/com/njcn/gather/icd/mapping/service/impl/IcdToXmlTaskAppService.java b/tools/mms-mapping/src/main/java/com/njcn/gather/icd/mapping/service/impl/IcdToXmlTaskAppService.java index b2462f3..f2c2326 100644 --- a/tools/mms-mapping/src/main/java/com/njcn/gather/icd/mapping/service/impl/IcdToXmlTaskAppService.java +++ b/tools/mms-mapping/src/main/java/com/njcn/gather/icd/mapping/service/impl/IcdToXmlTaskAppService.java @@ -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); } diff --git a/tools/mms-mapping/src/test/java/com/njcn/gather/icd/mapping/debug/JsonToXmlDebugRunner.java b/tools/mms-mapping/src/test/java/com/njcn/gather/icd/mapping/debug/JsonToXmlDebugRunner.java index cf42dad..ff3f810 100644 --- a/tools/mms-mapping/src/test/java/com/njcn/gather/icd/mapping/debug/JsonToXmlDebugRunner.java +++ b/tools/mms-mapping/src/test/java/com/njcn/gather/icd/mapping/debug/JsonToXmlDebugRunner.java @@ -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);