|
@ -0,0 +1,77 @@
|
|
|
package com.yihu.quota.etl.formula;
|
|
|
|
|
|
import com.yihu.ehr.util.datetime.DateUtil;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
/**
|
|
|
* 算法执行器
|
|
|
*
|
|
|
* @author l4qiang
|
|
|
*/
|
|
|
public class FormulaExecutor {
|
|
|
static HashMap<String, Functioner> functionerHashMap;
|
|
|
|
|
|
/**
|
|
|
* @param clazz 算法类名,包含完整路径,在配置时维护。如:com.yihu.quota.etl.formula.DivisionFunc
|
|
|
* @param args 参数,需要替换参数使用${code}方式进行标识,在配置时维护.如:string:${province};number:1
|
|
|
* @param values 值,需要赋值的值使用${code}方式进行标识
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public void run(String clazz, String args, HashMap<String, String> values) throws Exception {
|
|
|
Functioner functioner = functionerHashMap.get(clazz);
|
|
|
if (functioner == null) {
|
|
|
functioner = (Functioner) Class.forName(clazz).newInstance();
|
|
|
functionerHashMap.put(clazz, functioner);
|
|
|
}
|
|
|
|
|
|
if (functioner != null) {
|
|
|
String[] metaList = args.split(";");
|
|
|
Object[] parameter = new Object[metaList.length];
|
|
|
for (int i = 0; i < metaList.length; i++) {
|
|
|
String arg = metaList[i];
|
|
|
String[] split = arg.split(":");
|
|
|
if (split.length != 2) {
|
|
|
throw new Exception("wrong args");
|
|
|
}
|
|
|
|
|
|
switch (split[0]) {
|
|
|
case "number": {
|
|
|
String temp = getValue(values, split[1]);
|
|
|
parameter[i] = Integer.parseInt(temp);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case "string": {
|
|
|
String temp = getValue(values, split[1]);
|
|
|
parameter[i] = temp;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case "date": {
|
|
|
String temp = getValue(values, split[1]);
|
|
|
parameter[i] = DateUtil.formatCharDateYMD(temp);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
functioner.execute(parameter);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private String getValue(HashMap<String, String> values, String defaultValue) {
|
|
|
String value = values.get(defaultValue);
|
|
|
if (value != null) {
|
|
|
return value;
|
|
|
}
|
|
|
|
|
|
return defaultValue;
|
|
|
}
|
|
|
|
|
|
}
|