zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
commit | author | age
a18bfa 1 package com.changhong.epc.count.service.system.performer.impl;
Z 2
3 import com.changhong.epc.bean.count.MeInfo;
4 import com.changhong.epc.bean.count.system.SystemMathExtend;
5 import com.changhong.epc.bean.count.system.SystemMathParam;
6 import com.changhong.epc.count.mapper.tenant.system.SystemMathMapper;
7 import com.changhong.epc.count.service.count.data.paramiter.IParamIter;
8 import com.changhong.epc.count.service.count.model.UnitInfo;
9 import com.changhong.epc.count.service.system.model.SystemFunContextType;
10 import com.changhong.epc.count.service.system.performer.IFormulaHandle;
11 import com.changhong.epc.count.service.system.performer.verify.FuncFormatVerify;
12 import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
13 import com.iemsoft.framework.cloud.core.tools.SpringUtil;
14 import lombok.Data;
15 import lombok.extern.slf4j.Slf4j;
16
17 import java.util.*;
18
19 @Data
20 @Slf4j
21 public class FunctionParam {
22
23     /**
24      * 函数参数名前缀
25      */
26     public static final String FUNC_ENV_NAME = "FUNPT_";
27
28     private IParamIter<UnitInfo> unitInfos;
29
30     private SystemMathMapper systemMathMapper;
31
32     private IFormulaHandle formulaHandle;
33
34     private String expression;
35     
36     private SystemMathExtend systemMath;
37     private Map<String,Object> originalEnv;
38     
39     private Map<String,Object> env;
40
41     private Map<String,Object> val;
42
43     public FunctionParam(){
44         systemMathMapper = SpringUtil.getBean(SystemMathMapper.class);
45         formulaHandle = SpringUtil.getBean(IFormulaHandle.class);
46     }
47     public FunctionParam(Map<String, Object> val){
48         this();
49         this.val = val;
50     }
51
52     private Map<String,Object> getEnvCopy(){
53         Map<String,Object> copy = new HashMap<>();
54         for(Map.Entry<String,Object> entry: this.originalEnv.entrySet()){
55             copy.put(entry.getKey(), entry.getValue());
56         }
57         return copy;
58     }
59     
60     /**
61      * 初始化数据  
62      *     ·计算费用 参数迭代器进行初始化    
63      *     
64      * @param unitInfos
65      */
66     public void initData(IParamIter<UnitInfo> unitInfos){
67         originalEnv = new HashMap<>();
68         if(unitInfos == null)
69             return ;
70         this.unitInfos = unitInfos;
71         
72         originalEnv.put(SystemFunContextType.ALL_JOURNEY.toString(), unitInfos.getOldUnitInfos());
73         originalEnv.put(SystemFunContextType.JOURNEY.toString(), unitInfos.getEachOldUnitInfo());
74     }
75     
76     /**
77      * 
78      * @param mid
79      */
80     public void prepare(int mid){
81         env = getEnvCopy();
82         systemMath = systemMathMapper.selectSystemSystemMathExtendById(mid);
83
84         if(systemMath == null){
85             return;
86         }
87
88         expression = FuncFormatVerify.pretreatmentFun(systemMath.getCount());
89
90         List<SystemMathParam> systemMathParam = systemMath.getSystemMathParam();
91
92         if(ObjectUtil.empty(systemMathParam)){
93             return;
94         }
95
96         for (SystemMathParam param : systemMathParam) {
97             Object temp;
98             // 引用类型
99             if(param.getPType() == 20){
100                 FunctionParam functionParam = new FunctionParam();
101                 functionParam.setOriginalEnv(this.getOriginalEnv());
102                 functionParam.prepare(param.getJoinMathId());
103                 temp = formulaHandle.execute(functionParam);
104             }
105             // 普通类型
106             else{
107
108                 MeInfo meInfo = new MeInfo(
109                         param.getMdCode()
110                         , param.getMeCode()
111                         , Optional.ofNullable(val)
112                                 .map(v->v.get(Objects.toString(param.getPIndex())))
113                                 .map(Object::toString)
114                             .orElse(param.getDefVal()));
115                 meInfo.setMdName(param.getMdName());
116                 meInfo.setMeName(param.getMeName());
117                 temp = meInfo;
118 //                temp = Optional.ofNullable(val)
119 //                        .map(v->v.get(Objects.toString(param.getPIndex())))
120 //                        .map(Object::toString)
121 //                        .orElse(param.getDefVal());
122             }
123             
124             String name = FUNC_ENV_NAME+param.getPIndex();
125             env.put(name, temp);
126             expression = expression.replace("{"+param.getPIndex()+"}",name);
127         }
128         
129     }
130
131     public void setVal(String s) {
132     }
133 }