package com.changhong.epc.count.service.system.performer.impl; import com.changhong.epc.bean.count.MeInfo; import com.changhong.epc.bean.count.system.SystemMathExtend; import com.changhong.epc.bean.count.system.SystemMathParam; import com.changhong.epc.count.mapper.tenant.system.SystemMathMapper; import com.changhong.epc.count.service.count.data.paramiter.IParamIter; import com.changhong.epc.count.service.count.model.UnitInfo; import com.changhong.epc.count.service.system.model.SystemFunContextType; import com.changhong.epc.count.service.system.performer.IFormulaHandle; import com.changhong.epc.count.service.system.performer.verify.FuncFormatVerify; import com.iemsoft.framework.cloud.core.tools.ObjectUtil; import com.iemsoft.framework.cloud.core.tools.SpringUtil; import lombok.Data; import lombok.extern.slf4j.Slf4j; import java.util.*; @Data @Slf4j public class FunctionParam { /** * 函数参数名前缀 */ public static final String FUNC_ENV_NAME = "FUNPT_"; private IParamIter unitInfos; private SystemMathMapper systemMathMapper; private IFormulaHandle formulaHandle; private String expression; private SystemMathExtend systemMath; private Map originalEnv; private Map env; private Map val; public FunctionParam(){ systemMathMapper = SpringUtil.getBean(SystemMathMapper.class); formulaHandle = SpringUtil.getBean(IFormulaHandle.class); } public FunctionParam(Map val){ this(); this.val = val; } private Map getEnvCopy(){ Map copy = new HashMap<>(); for(Map.Entry entry: this.originalEnv.entrySet()){ copy.put(entry.getKey(), entry.getValue()); } return copy; } /** * 初始化数据 * ·计算费用 参数迭代器进行初始化 * * @param unitInfos */ public void initData(IParamIter unitInfos){ originalEnv = new HashMap<>(); if(unitInfos == null) return ; this.unitInfos = unitInfos; originalEnv.put(SystemFunContextType.ALL_JOURNEY.toString(), unitInfos.getOldUnitInfos()); originalEnv.put(SystemFunContextType.JOURNEY.toString(), unitInfos.getEachOldUnitInfo()); } /** * * @param mid */ public void prepare(int mid){ env = getEnvCopy(); systemMath = systemMathMapper.selectSystemSystemMathExtendById(mid); if(systemMath == null){ return; } expression = FuncFormatVerify.pretreatmentFun(systemMath.getCount()); List systemMathParam = systemMath.getSystemMathParam(); if(ObjectUtil.empty(systemMathParam)){ return; } for (SystemMathParam param : systemMathParam) { Object temp; // 引用类型 if(param.getPType() == 20){ FunctionParam functionParam = new FunctionParam(); functionParam.setOriginalEnv(this.getOriginalEnv()); functionParam.prepare(param.getJoinMathId()); temp = formulaHandle.execute(functionParam); } // 普通类型 else{ MeInfo meInfo = new MeInfo( param.getMdCode() , param.getMeCode() , Optional.ofNullable(val) .map(v->v.get(Objects.toString(param.getPIndex()))) .map(Object::toString) .orElse(param.getDefVal())); meInfo.setMdName(param.getMdName()); meInfo.setMeName(param.getMeName()); temp = meInfo; // temp = Optional.ofNullable(val) // .map(v->v.get(Objects.toString(param.getPIndex()))) // .map(Object::toString) // .orElse(param.getDefVal()); } String name = FUNC_ENV_NAME+param.getPIndex(); env.put(name, temp); expression = expression.replace("{"+param.getPIndex()+"}",name); } } public void setVal(String s) { } }