weaver-hrm-salary/src/com/engine/salary/service/impl/FormulaRunServiceImpl.java

34 lines
1.2 KiB
Java
Raw Normal View History

2022-04-15 13:54:47 +08:00
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;
2022-04-18 14:45:12 +08:00
import com.ql.util.express.DefaultContext;
import com.ql.util.express.ExpressRunner;
import lombok.extern.slf4j.Slf4j;
2022-04-15 13:54:47 +08:00
import java.util.List;
2022-04-18 14:45:12 +08:00
@Slf4j
2022-04-15 13:54:47 +08:00
public class FormulaRunServiceImpl extends Service implements FormulaRunService {
@Override
public Object run(ExpressFormula expressFormula, List<FormulaVar> formulaVars, DataCollectionEmployee simpleEmployee) {
String formula = expressFormula.getFormula();
2022-04-18 14:45:12 +08:00
ExpressRunner runner = new ExpressRunner(true, false);
DefaultContext<String, Object> context = new DefaultContext<String, Object>();
2022-04-16 16:49:22 +08:00
formulaVars.forEach(v -> {
2022-04-18 14:45:12 +08:00
context.put(v.getFieldId(), v.getContent());
2022-04-15 13:54:47 +08:00
});
2022-04-18 14:45:12 +08:00
Object execute = null;
try {
execute = runner.execute(formula, context, null, true, false);
} catch (Exception e) {
log.error("公式执行异常", e);
}
2022-04-15 13:54:47 +08:00
return execute;
}
}