Merge branch 'dev-czy'

This commit is contained in:
周宇 蔡
2026-06-12 08:53:25 +08:00
5 changed files with 40 additions and 9 deletions

View File

@@ -61,13 +61,23 @@ public class RuleBasedXmlMappingService {
private static final Pattern DO_NO_INDEX_PATTERN = Pattern.compile("(MMXU|MHAI|MSQI|MFLK|QVVR)\\$"); private static final Pattern DO_NO_INDEX_PATTERN = Pattern.compile("(MMXU|MHAI|MSQI|MFLK|QVVR)\\$");
public InputStream loadDefaultXmlFile() throws Exception { public InputStream loadDefaultXmlFile() throws Exception {
ClassPathResource templateResource = new ClassPathResource("template/JiangSu_Config1.xml"); 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()) { if (!templateResource.exists()) {
return null; return null;
} }
return templateResource.getInputStream(); return templateResource.getInputStream();
} }

View File

@@ -165,9 +165,13 @@ public class MappingController extends BaseController {
public IcdToXmlResponse getXmlFromJson(@Validated @RequestPart("request") JsonToXmlRequest request) { public IcdToXmlResponse getXmlFromJson(@Validated @RequestPart("request") JsonToXmlRequest request) {
String methodDescribe = getMethodDescribe("getXmlFromJson") + ",开始将 MMS JSON 转换为 XML"; 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 = 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()) { if (result.getMethodDescribe() != null && !result.getMethodDescribe().trim().isEmpty()) {
methodDescribe = methodDescribe + "\n" + result.getMethodDescribe(); methodDescribe = methodDescribe + "\n" + result.getMethodDescribe();
} }

View File

@@ -13,6 +13,10 @@ public class JsonToXmlRequest {
@ApiModelProperty(value = "MMS 映射 JSON 字符串", required = true) @ApiModelProperty(value = "MMS 映射 JSON 字符串", required = true)
private String mappingJson; private String mappingJson;
/** 配置文件类型1-读取 Jiangsuconfig2.xml2-读取 Jiangsuconfig1.xml空或错误时默认为 1。 */
@ApiModelProperty(value = "配置文件类型1-Jiangsuconfig2.xml2-Jiangsuconfig1.xml默认1")
private Integer configType;
public String getMappingJson() { public String getMappingJson() {
return mappingJson; return mappingJson;
} }
@@ -20,4 +24,12 @@ public class JsonToXmlRequest {
public void setMappingJson(String mappingJson) { public void setMappingJson(String mappingJson) {
this.mappingJson = mappingJson; this.mappingJson = mappingJson;
} }
public Integer getConfigType() {
return configType;
}
public void setConfigType(Integer configType) {
this.configType = configType;
}
} }

View File

@@ -114,16 +114,17 @@ public class IcdToXmlTaskAppService {
* 直接从 JSON 字符串生成 XML 内容。 * 直接从 JSON 字符串生成 XML 内容。
* *
* @param mappingJson MMS 映射 JSON 字符串(由 getIcdMmsJson 接口返回) * @param mappingJson MMS 映射 JSON 字符串(由 getIcdMmsJson 接口返回)
* @param configType 配置文件类型1-读取 Jiangsuconfig2.xml2-读取 Jiangsuconfig1.xml空或错误时默认为 1
* @return XML 生成结果 * @return XML 生成结果
*/ */
public IcdToXmlGenerateResult generateXmlFromJson(String mappingJson) { public IcdToXmlGenerateResult generateXmlFromJson(String mappingJson, Integer configType) {
return executeTask(JSON_TO_XML_TASK_NAME, result -> { return executeTask(JSON_TO_XML_TASK_NAME, result -> {
if (isBlank(mappingJson)) { if (isBlank(mappingJson)) {
markFailed(result, JSON_TO_XML_TASK_NAME, MAPPING_JSON_EMPTY_MESSAGE); markFailed(result, JSON_TO_XML_TASK_NAME, MAPPING_JSON_EMPTY_MESSAGE);
return; return;
} }
fillXmlContent(result, mappingJson, loadXmlResources()); fillXmlContent(result, mappingJson, loadXmlResources(configType));
result.setStatus(GenerateStatus.SUCCESS); result.setStatus(GenerateStatus.SUCCESS);
result.setMessage(XML_GENERATE_SUCCESS_MESSAGE); result.setMessage(XML_GENERATE_SUCCESS_MESSAGE);
}); });
@@ -179,7 +180,11 @@ public class IcdToXmlTaskAppService {
* 加载 XML 模板和规则文件。 * 加载 XML 模板和规则文件。
*/ */
private XmlResourceContext loadXmlResources() throws Exception { 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) { if (templateStream == null) {
throw new IllegalArgumentException(DEFAULT_XML_MISSING_MESSAGE); throw new IllegalArgumentException(DEFAULT_XML_MISSING_MESSAGE);
} }

View File

@@ -82,7 +82,7 @@ public class JsonToXmlDebugRunner {
if (VERBOSE_LOG) { if (VERBOSE_LOG) {
System.out.println("正在转换 JSON 为 XML..."); System.out.println("正在转换 JSON 为 XML...");
} }
IcdToXmlGenerateResult result = icdToXmlTaskAppService.generateXmlFromJson(mappingJson); IcdToXmlGenerateResult result = icdToXmlTaskAppService.generateXmlFromJson(mappingJson,2);
// 输出结果 // 输出结果
printResult(result, objectMapper); printResult(result, objectMapper);