master
parent
c26b0a3284
commit
97817318d3
|
@ -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;
|
||||||
|
|
|
@ -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" +
|
|
||||||
" * @Package:com.muyu.rule.server.basic.engine\n" +
|
" * @Package:com.muyu.rule.server.basic.engine\n" +
|
||||||
" * @Project:cloud-etl-rule\n" +
|
" * @Project:cloud-etl-rule\n" +
|
||||||
" * @name:${className}\n" +
|
" * @name:${className}\n" +
|
||||||
" * @Date:2024/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()) {
|
||||||
|
|
Loading…
Reference in New Issue