package com.engine.salary.service.impl; import com.engine.core.impl.Service; import com.engine.salary.entity.datacollection.DataCollectionEmployee; import com.engine.salary.entity.salaryformula.ExpressFormula; import com.engine.salary.entity.salaryformula.po.FormulaVar; import com.engine.salary.service.FormulaRunService; import com.ql.util.express.DefaultContext; import com.ql.util.express.ExpressRunner; import lombok.extern.slf4j.Slf4j; import java.math.BigDecimal; import java.util.List; @Slf4j public class FormulaRunServiceImpl extends Service implements FormulaRunService { @Override public Object run(ExpressFormula expressFormula, List formulaVars, DataCollectionEmployee simpleEmployee) { String formula = expressFormula.getFormulaRunScript(); ExpressRunner runner = new ExpressRunner(true, false); DefaultContext context = new DefaultContext(); formulaVars.forEach(v -> { context.put(v.getFieldId(), new BigDecimal(v.getContent())); }); Object execute = null; try { execute = runner.execute(formula, context, null, true, false); } catch (Exception e) { log.error("公式执行异常", e); } return execute; } }