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
package com.changhong.epc.parsing.service.autosubmit.prop;
 
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
 
import org.apache.commons.beanutils.PropertyUtils;
 
import com.changhong.epc.parsing.service.autosubmit.info.Form;
import com.changhong.epc.parsing.service.autosubmit.info.FormCpn;
import com.changhong.epc.parsing.service.autosubmit.info.FormulaInfo.ResultInfo;
import com.changhong.epc.parsing.service.autosubmit.tool.AviatorTool;
 
/**
 * 公式结果处理类
 * @author WangYX
 *
 */
public class ResultType {
    
    private static final Map<Integer, Model> MODE = new HashMap<>();
    
    static{
        // 公式fx
        MODE.put(1, (form, resultInfo, formCpn)->{
            formCpn.put(resultInfo.getAttribute(), AviatorTool.execute(resultInfo.getCode(), form, Object.class));
        });
        // 控件下红字错误
        MODE.put(2, (form, resultInfo, formCpn)->{
            formCpn.put(CpnMsg.error, resultInfo.getMessage());
        });
        // 弹框消息
        MODE.put(3, (form, resultInfo, formCpn)->{
            formCpn.put(resultInfo.getMessageType(), resultInfo.getMessage());
        });
    }
    
    public static Model getModel(Integer type){
        return MODE.get(type);
    }
    
    /**
     * 返回值模型
     * @author WangYX
     *
     */
    @FunctionalInterface
    public static interface Model{
        
        default void executo(Form form, ResultInfo resultInfo) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException{
            FormCpn formCpn = (FormCpn)PropertyUtils.getProperty(form, resultInfo.getEventField());
            if(form.triggerEvent(formCpn))
                executo(form, resultInfo, formCpn);
            else
                return;
        }
        
        void executo(Form form, ResultInfo resultInfo, FormCpn formCpn);
        
    }
}