zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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);
        }
    }
}