package com.iailab.module.data.common.utils; import javax.annotation.Resource; import cn.hutool.script.JavaScriptEngine; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import javax.script.ScriptEngine; import javax.script.ScriptException; /** * @author PanZhibao * @date 2021年06月04日 16:01 */ @Slf4j @Component public class JavaScriptHandler { @Resource ScriptEngine scriptEngine; public String eval (String script) { try { return scriptEngine.eval(script).toString(); } catch (ScriptException e) { log.error("计算异常,计算公式:" + script); e.printStackTrace(); return null; } } }