parent
ec8c042a3d
commit
2b199c818d
4 changed files with 79 additions and 6 deletions
@ -0,0 +1,17 @@ |
|||||||
|
package org.springblade.desk.basic.constant; |
||||||
|
|
||||||
|
public interface FormulaAviatorConst { |
||||||
|
|
||||||
|
/** |
||||||
|
* 添加点 |
||||||
|
*/ |
||||||
|
String ADD = "add"; |
||||||
|
/** |
||||||
|
* 测量值 |
||||||
|
*/ |
||||||
|
String TEST = "test"; |
||||||
|
/** |
||||||
|
* 体积 |
||||||
|
*/ |
||||||
|
String VOL = "vol"; |
||||||
|
} |
||||||
@ -0,0 +1,46 @@ |
|||||||
|
package org.springblade.desk.basic.aviator.func; |
||||||
|
|
||||||
|
import com.googlecode.aviator.AviatorEvaluatorInstance; |
||||||
|
import com.googlecode.aviator.runtime.function.AbstractFunction; |
||||||
|
import com.googlecode.aviator.runtime.type.AviatorObject; |
||||||
|
import com.googlecode.aviator.runtime.type.AviatorString; |
||||||
|
import jakarta.annotation.Resource; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
import lombok.ToString; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.beans.factory.InitializingBean; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
@Component |
||||||
|
@Data |
||||||
|
@AllArgsConstructor |
||||||
|
@EqualsAndHashCode(callSuper = false) |
||||||
|
@ToString(callSuper = false) |
||||||
|
@Slf4j |
||||||
|
public class CustomFunctionRegistry implements InitializingBean { |
||||||
|
|
||||||
|
@Resource |
||||||
|
private AviatorEvaluatorInstance aviatorEvaluator; |
||||||
|
|
||||||
|
@Override |
||||||
|
public void afterPropertiesSet() throws Exception { |
||||||
|
// 注册自定义函数
|
||||||
|
// 此时 aviatorEvaluator 已被注入
|
||||||
|
aviatorEvaluator.addFunction(new AbstractFunction() { |
||||||
|
@Override |
||||||
|
public String getName() { |
||||||
|
return "myCustomFunc"; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public AviatorObject call(Map<String, Object> env, AviatorObject arg1) { |
||||||
|
String value = (String) arg1.getValue(env); |
||||||
|
return new AviatorString("自定义结果: " + value); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue