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 { private Double money; @Resource private IFormulaHandle formulaHandle; @Override public Boolean exeCount(AppStanderExtend row, IParamIter 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; } }