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
package com.changhong.epc.count.service.count.execution.impl;
 
import com.changhong.epc.bean.tenant.norm.extend.AppStanderExtend;
import com.changhong.epc.count.service.count.data.paramiter.IParamIter;
import com.changhong.epc.count.service.count.execution.ICounter;
import com.changhong.epc.count.service.count.model.UnitInfo;
import com.changhong.epc.count.service.system.performer.IFormulaHandle;
import com.changhong.epc.count.service.system.performer.impl.FunctionParam;
import com.iemsoft.framework.cloud.core.tools.JSONTool;
import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
 
/**
 * 系统变量计算器
 */
@Service
@Scope("prototype")
public class FuncCountImpl implements ICounter<AppStanderExtend, UnitInfo> {
 
    private Double money;
 
    @Resource
    private IFormulaHandle formulaHandle;
 
    @Override
    public Boolean exeCount(AppStanderExtend row, IParamIter<UnitInfo> t) {
        FunctionParam param = new FunctionParam(
                Optional.ofNullable(row.getAsDefValue())
                        .map(Object::toString)
                        .map(v->JSONTool.toObj(v, Map.class))
                        .orElse(Collections.EMPTY_MAP)
        );
 
        // 上下文
        param.initData(t);
        // 函数ID
        param.prepare(Integer.valueOf(row.getMasDefineCode()));
 
        Object val = formulaHandle.exeResult(
                formulaHandle.execute(param), row.getCount());
        if(ObjectUtil.notEmpty(formulaHandle.getErrSystemMsgs())) {
            t.getErrSystemMsgs().addAll(formulaHandle.getErrSystemMsgs());
        }
        switch (row.getEleType()) {
            case TJ:
            case BZ:
                return formulaHandle.resultBoolean(val);
            case JE:
                money = formulaHandle.resultDouble(val);
                return true;
            default:
                break;
        }
        return true;
    }
 
    @Override
    public Double gainMoney() {
        return money;
    }
}