枚举
This commit is contained in:
parent
3402e89dd8
commit
2b58f2a8e6
@ -226,6 +226,7 @@ public class EnhancedConfigProcessor {
|
||||
|
||||
// 1. 应用正则表达式
|
||||
if (configValue.getRegexPattern() != null && configValue.getRegexReplacement() != null) {
|
||||
System.out.println();
|
||||
log.info("{}", String.format(ParserProcessConstant.LOG_GROUP_LINE, "应用正则表达式"));
|
||||
log.info("RegexPattern = {}", configValue.getRegexPattern());
|
||||
log.info("RegexReplacement = {}", configValue.getRegexReplacement());
|
||||
@ -240,13 +241,20 @@ public class EnhancedConfigProcessor {
|
||||
|
||||
// 2. 应用枚举映射
|
||||
if (configValue.getEnumMapping() != null && configValue.getEnumMapping().containsKey(strValue)) {
|
||||
System.out.println();
|
||||
log.info("{}", String.format(ParserProcessConstant.LOG_GROUP_LINE, "应用枚举映射"));
|
||||
log.info("EnumMapping = {}", JSON.toJSONString(configValue.getEnumMapping()));
|
||||
strValue = configValue.getEnumMapping().get(strValue);
|
||||
for(String dict : configValue.getEnumMapping().keySet()) {
|
||||
if(configValue.getEnumMapping().containsKey(dict)) {
|
||||
strValue = configValue.getEnumMapping().get(dict).get(strValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 应用工具函数
|
||||
if (configValue.getUtilFunction() != null && !configValue.getUtilFunction().isEmpty()) {
|
||||
System.out.println();
|
||||
log.info("{}", String.format(ParserProcessConstant.LOG_GROUP_LINE, "应用工具函数"));
|
||||
log.info("Function = {}", JSON.toJSONString(configValue.getUtilFunction()));
|
||||
strValue = applyUtilFunction(strValue, configValue.getUtilFunction(), context, loopIndex);
|
||||
|
@ -386,7 +386,7 @@ public class EnhancedTemplateGenerator {
|
||||
Object enumMappingObj = map.get("enumMapping");
|
||||
if (enumMappingObj instanceof Map) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> enumMapping = (Map<String, String>) enumMappingObj;
|
||||
Map<String, Map<String, String>> enumMapping = (Map<String, Map<String, String>>) enumMappingObj;
|
||||
builder.enumMapping(enumMapping);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
package com.example.demo.parser.process.domain;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -84,7 +86,7 @@ public class ConfigValue {
|
||||
*
|
||||
* <p><b>格式说明:</b>key为原始值,value为映射后的值</p>
|
||||
*/
|
||||
private Map<String, String> enumMapping;
|
||||
private Map<String, Map<String, String>> enumMapping;
|
||||
|
||||
/**
|
||||
* 工具函数调用配置
|
||||
@ -97,4 +99,50 @@ public class ConfigValue {
|
||||
* </ul>
|
||||
*/
|
||||
private Map<String, Object> utilFunction;
|
||||
|
||||
public static void main(String[] args) {
|
||||
ConfigValue configValue = ConfigValue.builder().build();
|
||||
Map<String, Map<String, String>> enumMapping = new HashMap<>();
|
||||
enumMapping = JSON.parseObject(data2, Map.class);
|
||||
System.out.println(enumMapping);
|
||||
configValue.setEnumMapping(enumMapping);
|
||||
System.out.println(JSON.toJSONString(configValue));
|
||||
}
|
||||
|
||||
private static String data1 = """
|
||||
{
|
||||
"航线点类型": [
|
||||
{
|
||||
"起飞点": "N1"
|
||||
},
|
||||
{
|
||||
"航路点": "N2"
|
||||
},
|
||||
{
|
||||
"降落点": "N3"
|
||||
},
|
||||
{
|
||||
"拐弯点": "N4"
|
||||
},
|
||||
{
|
||||
"爬坡点": "N5"
|
||||
},
|
||||
{
|
||||
"返航点": "N6"
|
||||
}
|
||||
]
|
||||
}
|
||||
""";
|
||||
private static String data2 = """
|
||||
{
|
||||
"航线点类型": {
|
||||
"起飞点": "N1",
|
||||
"航路点": "N2",
|
||||
"降落点": "N3",
|
||||
"拐弯点": "N4",
|
||||
"爬坡点": "N5",
|
||||
"返航点": "N6"
|
||||
}
|
||||
}
|
||||
""";
|
||||
}
|
||||
|
@ -60,17 +60,19 @@
|
||||
"values": [
|
||||
{
|
||||
"combined": false,
|
||||
"value": "{{任务航线.航线点类型}}"
|
||||
"value": "{{任务航线.航线点类型}}",
|
||||
"enumMapping": {
|
||||
"航线点类型": {
|
||||
"起飞点": "N1",
|
||||
"航路点": "N2",
|
||||
"降落点": "N3",
|
||||
"拐弯点": "N4",
|
||||
"爬坡点": "N5",
|
||||
"返航点": "N6"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"enumMapping": {
|
||||
"起飞点": "N1",
|
||||
"航路点": "N2",
|
||||
"降落点": "N3",
|
||||
"拐弯点": "N4",
|
||||
"爬坡点": "N5",
|
||||
"返航点": "N6"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"comment": "准时到达时间",
|
||||
|
Loading…
x
Reference in New Issue
Block a user