commit | author | age
|
a18bfa
|
1 |
package com.changhong.epc.parsing.service.autosubmit.info.impl; |
Z |
2 |
|
|
3 |
import java.lang.reflect.InvocationTargetException; |
|
4 |
import java.util.List; |
|
5 |
import java.util.Objects; |
|
6 |
|
|
7 |
import org.apache.commons.lang3.StringUtils; |
|
8 |
|
|
9 |
import com.changhong.epc.parsing.service.autosubmit.info.Form; |
|
10 |
import com.changhong.epc.parsing.service.autosubmit.info.FormulaInfo; |
|
11 |
import com.changhong.epc.parsing.service.autosubmit.info.FormulaInfo.ResultInfo; |
|
12 |
import com.changhong.epc.parsing.service.autosubmit.prop.ResultType; |
|
13 |
import com.changhong.epc.parsing.service.autosubmit.prop.ResultType.Model; |
|
14 |
import com.changhong.epc.parsing.service.autosubmit.tool.AviatorTool; |
|
15 |
import lombok.extern.slf4j.Slf4j; |
|
16 |
|
|
17 |
@Slf4j |
|
18 |
public class FormulaListenerTool { |
|
19 |
|
|
20 |
/** |
|
21 |
* 触发事件,过滤执行 |
|
22 |
* @param formField |
|
23 |
* @param evn |
|
24 |
* @param doEvent |
|
25 |
*/ |
|
26 |
public static void count(List<FormulaInfo> formulas, Form form,final String doEvent) { |
|
27 |
if(formulas == null) |
|
28 |
return; |
|
29 |
formulas.stream() |
|
30 |
// 传事件了就筛选,不传就全执行 |
|
31 |
.filter(formula->doEvent != null ? Objects.equals(formula.getEvent().getDoEvent(), doEvent) : true) |
|
32 |
.forEach(formula->executo(formula, form)); |
|
33 |
|
|
34 |
} |
|
35 |
|
|
36 |
/** |
|
37 |
* 执行公式 |
|
38 |
* @param formula |
|
39 |
* @param evn |
|
40 |
*/ |
|
41 |
public static void executo(FormulaInfo formula, Form evn) { |
|
42 |
String conditionCode = formula.getConditionCode(); |
|
43 |
Boolean result = null; |
|
44 |
if(StringUtils.isBlank(conditionCode)) |
|
45 |
result = true; |
|
46 |
else |
|
47 |
result = AviatorTool.execute(conditionCode, evn, Boolean.class, e->false); |
|
48 |
if(result != null && result){ |
|
49 |
formula.getResults().stream().forEach(resultInfo->executoResult(resultInfo, evn)); |
|
50 |
} |
|
51 |
} |
|
52 |
|
|
53 |
/** |
|
54 |
* 执行结果集 |
|
55 |
* @param resultInfo |
|
56 |
* @param evn |
|
57 |
*/ |
|
58 |
public static void executoResult(ResultInfo resultInfo, Form evn) { |
|
59 |
Model model = ResultType.getModel(resultInfo.getMode()); |
|
60 |
if(model == null) |
|
61 |
return; |
|
62 |
try { |
|
63 |
model.executo(evn, resultInfo); |
|
64 |
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { |
|
65 |
log.error(e.getMessage(), e); |
|
66 |
} |
|
67 |
} |
|
68 |
} |