Cui YongXing 2024-09-10 09:11:40 +08:00
parent c26b0a3284
commit 97817318d3
2 changed files with 18 additions and 11 deletions

View File

@ -1,5 +1,6 @@
package com.muyu.rule.common.engine; package com.muyu.rule.common.engine;
import com.muyu.etl.domain.DataValue; import com.muyu.etl.domain.DataValue;
import com.muyu.rule.common.basic.abstracts.DataEngineValueActuator; import com.muyu.rule.common.basic.abstracts.DataEngineValueActuator;
import com.muyu.rule.common.domain.DataValueFie; import com.muyu.rule.common.domain.DataValueFie;

View File

@ -128,40 +128,35 @@ public class RuleEngineVersionController {
// 根据类型确定父类 // 根据类型确定父类
String parentClass = determineParentClass(type); String parentClass = determineParentClass(type);
String dataClass = determineDataClass(type);
// 定义模板字符串 // 定义模板字符串
String template = "package com.muyu.rule.common.engine;\n" + String template = "package com.muyu.rule.common.engine;\n" +
"\n" + "\n" +
"import com.muyu.etl.domain.DataValue;\n" + "import com.muyu.etl.domain.DataValue;\n" +
"import com.muyu.common.domain.${dataClass};\n" +
"import com.muyu.rule.common.basic.abstracts.${parentClass};\n" + "import com.muyu.rule.common.basic.abstracts.${parentClass};\n" +
"import com.muyu.rule.common.exception.DeliteException;\n" + "import com.muyu.rule.common.exception.DeliteException;\n" +
"import com.alibaba.fastjson2.JSON;" +
"\n" + "\n" +
"\n" + "\n" +
"/**\n" + "/**\n" +
" * @Author张承志\n" +
" * @Packagecom.muyu.rule.server.basic.engine\n" + " * @Packagecom.muyu.rule.server.basic.engine\n" +
" * @Projectcloud-etl-rule\n" + " * @Projectcloud-etl-rule\n" +
" * @name${className}\n" + " * @name${className}\n" +
" * @Date2024/8/30 11:13\n" +
" */\n" + " */\n" +
"\n" + "\n" +
"public class ${className} extends ${parentClass} {\n" + "public class ${className} extends ${parentClass} {\n" +
"\n" + "\n" +
" @Override\n" + " @Override\n" +
" public void run() {\n" + " public void run() {\n" +
" DataValue[][] dataValues = get();\n" +
" if (dataValues == null || \"\".equals(dataValues) || \"null\".equals(dataValues)) {\n" +
" throw new DeliteException();\n" +
" }else {\n" +
" System.out.println(\"数据检测无异常\");\n" +
" }\n" +
" }\n" + " }\n" +
"}\n"; "}\n";
// 使用Map进行模板替换 // 使用Map进行模板替换
Map<String, String> replacements = Map.of( Map<String, String> replacements = Map.of(
"${className}", versionAddReq.getClassName(), "${className}", versionAddReq.getClassName(),
"${parentClass}", parentClass "${parentClass}", parentClass,
"${dataClass}",dataClass
); );
// 替换模板中的变量 // 替换模板中的变量
@ -185,7 +180,18 @@ public class RuleEngineVersionController {
throw new IllegalArgumentException("Invalid type provided"); throw new IllegalArgumentException("Invalid type provided");
} }
} }
private String determineDataClass(Integer type) {
switch (type) {
case 1:
return "DataValueFie";
case 2:
return "DataValueRow";
case 3:
return "DataValueRows";
default:
throw new IllegalArgumentException("Invalid type provided");
}
}
// 辅助方法用于替换模板中的占位符 // 辅助方法用于替换模板中的占位符
private String replacePlaceholders(String template, Map<String, String> replacements) { private String replacePlaceholders(String template, Map<String, String> replacements) {
for (Map.Entry<String, String> entry : replacements.entrySet()) { for (Map.Entry<String, String> entry : replacements.entrySet()) {