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.formlua.entity.parameter.DataType; 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 { private static ExpressRunner runner; static { runner = new ExpressRunner(true,false); } @Override public Object run(ExpressFormula expressFormula, List formulaVars, DataCollectionEmployee simpleEmployee) { DefaultContext context = new DefaultContext(); formulaVars.forEach(v -> { if (DataType.NUMBER.equals(v.getFieldType())) { context.put(v.getFieldId(), new BigDecimal(v.getContent())); } else { context.put(v.getFieldId(), v.getContent()); } }); Object execute = null; try { String formula = expressFormula.getFormulaRunScript(); execute = runner.execute(formula, context, null, true, false); } catch (Exception e) { log.error("express execute fail", e); } return execute; } }