package com.changhong.epc.parsing.service.autosubmit.info.impl;
|
|
import java.lang.reflect.InvocationTargetException;
|
import java.util.List;
|
import java.util.Objects;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import com.changhong.epc.parsing.service.autosubmit.info.Form;
|
import com.changhong.epc.parsing.service.autosubmit.info.FormulaInfo;
|
import com.changhong.epc.parsing.service.autosubmit.info.FormulaInfo.ResultInfo;
|
import com.changhong.epc.parsing.service.autosubmit.prop.ResultType;
|
import com.changhong.epc.parsing.service.autosubmit.prop.ResultType.Model;
|
import com.changhong.epc.parsing.service.autosubmit.tool.AviatorTool;
|
import lombok.extern.slf4j.Slf4j;
|
|
@Slf4j
|
public class FormulaListenerTool {
|
|
/**
|
* 触发事件,过滤执行
|
* @param formField
|
* @param evn
|
* @param doEvent
|
*/
|
public static void count(List<FormulaInfo> formulas, Form form,final String doEvent) {
|
if(formulas == null)
|
return;
|
formulas.stream()
|
// 传事件了就筛选,不传就全执行
|
.filter(formula->doEvent != null ? Objects.equals(formula.getEvent().getDoEvent(), doEvent) : true)
|
.forEach(formula->executo(formula, form));
|
|
}
|
|
/**
|
* 执行公式
|
* @param formula
|
* @param evn
|
*/
|
public static void executo(FormulaInfo formula, Form evn) {
|
String conditionCode = formula.getConditionCode();
|
Boolean result = null;
|
if(StringUtils.isBlank(conditionCode))
|
result = true;
|
else
|
result = AviatorTool.execute(conditionCode, evn, Boolean.class, e->false);
|
if(result != null && result){
|
formula.getResults().stream().forEach(resultInfo->executoResult(resultInfo, evn));
|
}
|
}
|
|
/**
|
* 执行结果集
|
* @param resultInfo
|
* @param evn
|
*/
|
public static void executoResult(ResultInfo resultInfo, Form evn) {
|
Model model = ResultType.getModel(resultInfo.getMode());
|
if(model == null)
|
return;
|
try {
|
model.executo(evn, resultInfo);
|
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
log.error(e.getMessage(), e);
|
}
|
}
|
}
|