diff --git a/io.sc.engine.rule.core/src/main/java/io/sc/engine/rule/core/code/ExecuteUnit4Resource.java b/io.sc.engine.rule.core/src/main/java/io/sc/engine/rule/core/code/ExecuteUnit4Resource.java index 92cd119f..419177be 100644 --- a/io.sc.engine.rule.core/src/main/java/io/sc/engine/rule/core/code/ExecuteUnit4Resource.java +++ b/io.sc.engine.rule.core/src/main/java/io/sc/engine/rule/core/code/ExecuteUnit4Resource.java @@ -16,6 +16,7 @@ import io.sc.engine.rule.core.po.lib.IndicatorProcessor; import io.sc.engine.rule.core.po.lib.Lib; import io.sc.engine.rule.core.po.model.Model; import io.sc.engine.rule.core.po.model.Parameter; +import io.sc.engine.rule.core.po.model.ParameterInOptionAddtion; import io.sc.engine.rule.core.po.model.ParameterInOptionItem; import io.sc.engine.rule.core.po.model.parameter.InOptionParameter; import io.sc.engine.rule.core.po.model.parameter.IndicatorParameter; @@ -66,59 +67,108 @@ public class ExecuteUnit4Resource extends ExecuteUnit { if (parameters == null || parameters.isEmpty()) { return; } - for(Parameter parameter : parameters){ - if(!StringUtils.hasText(parameter.getProperties())) { continue; } - List properties =ObjectMapperUtil.json().readValue(parameter.getProperties(), new TypeReference>() {}); - if(properties==null || properties.isEmpty()) { continue; } - for(ParameterProperty property : properties){ - // 替换 value - PlaceHolder placeHolder =PlaceHolder.extract(property.value); - Set enumRefs =placeHolder.getEnumRefs(); - if(enumRefs==null || enumRefs.isEmpty()) { continue; } - for(String enumRef : enumRefs){ - String enumValue =findEnumValue(enumRef); - if(!StringUtils.hasText(enumValue)){ continue; } - property.value =property.value.replace("#{" + enumRef.replace(".","}.#{") + "}",enumValue); - } + for(Parameter parameter : parameters) { + if (!StringUtils.hasText(parameter.getProperties())) { + continue; + } + List properties = ObjectMapperUtil.json().readValue(parameter.getProperties(), new TypeReference>() { + }); + //1) 处理参数的扩展属性中的枚举值 + if (properties != null && !properties.isEmpty()) { + for (ParameterProperty property : properties) { + // 替换 value + PlaceHolder placeHolder = PlaceHolder.extract(property.value); + Set enumRefs = placeHolder.getEnumRefs(); + if (enumRefs != null && !enumRefs.isEmpty()) { + for (String enumRef : enumRefs) { + String enumValue = findEnumValue(enumRef); + if (!StringUtils.hasText(enumValue)) { + continue; + } + property.value = property.value.replace("#{" + enumRef.replace(".", "}.#{") + "}", enumValue); + } + } - // 替换 prompt - placeHolder =PlaceHolder.extract(property.prompt); - enumRefs =placeHolder.getEnumRefs(); - if(enumRefs==null || enumRefs.isEmpty()) { continue; } - for(String enumRef : enumRefs){ - String enumValue =findEnumValue(enumRef); - if(!StringUtils.hasText(enumValue)){ continue; } - property.prompt =property.prompt.replace("#{" + enumRef.replace(".","}.#{") + "}",enumValue); + // 替换 prompt + placeHolder = PlaceHolder.extract(property.prompt); + enumRefs = placeHolder.getEnumRefs(); + if (enumRefs != null && !enumRefs.isEmpty()) { + for (String enumRef : enumRefs) { + String enumValue = findEnumValue(enumRef); + if (!StringUtils.hasText(enumValue)) { + continue; + } + property.prompt = property.prompt.replace("#{" + enumRef.replace(".", "}.#{") + "}", enumValue); + } + } } + parameter.setProperties(ObjectMapperUtil.json().writeValueAsString(properties)); } - parameter.setProperties(ObjectMapperUtil.json().writeValueAsString(properties)); - // 处理选项参数的选项 + // 2) 处理选项参数的选项中的枚举值 if(ParameterType.IN_OPTION.equals(parameter.getType())){ InOptionParameter inOptionParameter =(InOptionParameter)parameter; - //选项 List items =inOptionParameter.getOptions(); if(items==null || items.isEmpty()) { continue; } for(ParameterInOptionItem item : items){ + //显示条件 PlaceHolder placeHolder =PlaceHolder.extract(item.getCondition()); Set enumRefs =placeHolder.getEnumRefs(); - if(enumRefs==null || enumRefs.isEmpty()) { continue; } - for(String enumRef : enumRefs){ - String enumValue =findEnumValue(enumRef); - if(!StringUtils.hasText(enumValue)){ continue; } - item.setCondition(item.getCondition().replace("#{" + enumRef.replace(".","}.#{") + "}",enumValue)); + if(enumRefs!=null && !enumRefs.isEmpty()) { + for (String enumRef : enumRefs) { + String enumValue = findEnumValue(enumRef); + if (!StringUtils.hasText(enumValue)) { + continue; + } + item.setCondition(item.getCondition().replace("#{" + enumRef.replace(".", "}.#{") + "}", enumValue)); + } } - + //自动选择条件 placeHolder =PlaceHolder.extract(item.getConfig()); enumRefs =placeHolder.getEnumRefs(); - if(enumRefs==null || enumRefs.isEmpty()) { continue; } - for(String enumRef : enumRefs){ - String enumValue =findEnumValue(enumRef); - if(!StringUtils.hasText(enumValue)){ continue; } - item.setConfig(item.getConfig().replace("#{" + enumRef.replace(".","}.#{") + "}",enumValue)); + if(enumRefs!=null && !enumRefs.isEmpty()) { + for (String enumRef : enumRefs) { + String enumValue = findEnumValue(enumRef); + if (!StringUtils.hasText(enumValue)) { + continue; + } + item.setConfig(item.getConfig().replace("#{" + enumRef.replace(".", "}.#{") + "}", enumValue)); + } + } + } + } + + // 3) 处理选项参数不录项中的枚举值 + if(ParameterType.IN_OPTION.equals(parameter.getType())){ + InOptionParameter inOptionParameter =(InOptionParameter)parameter; + List additions =inOptionParameter.getAdditons(); + if(additions==null || additions.isEmpty()) { continue; } + for(ParameterInOptionAddtion addition : additions){ + //显示条件 + PlaceHolder placeHolder =PlaceHolder.extract(addition.getCondition()); + Set enumRefs =placeHolder.getEnumRefs(); + if(enumRefs!=null && !enumRefs.isEmpty()) { + for (String enumRef : enumRefs) { + String enumValue = findEnumValue(enumRef); + if (!StringUtils.hasText(enumValue)) { + continue; + } + addition.setCondition(addition.getCondition().replace("#{" + enumRef.replace(".", "}.#{") + "}", enumValue)); + } + } + //默认值 + placeHolder =PlaceHolder.extract(addition.getDefaultValue()); + enumRefs =placeHolder.getEnumRefs(); + if(enumRefs!=null && !enumRefs.isEmpty()) { + for (String enumRef : enumRefs) { + String enumValue = findEnumValue(enumRef); + if (!StringUtils.hasText(enumValue)) { + continue; + } + addition.setDefaultValue(addition.getDefaultValue().replace("#{" + enumRef.replace(".", "}.#{") + "}", enumValue)); + } } } - // } } }