package com.zt.plat.module.qms.core.qlexpress.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.alibaba.qlexpress4.Express4Runner;
import com.alibaba.qlexpress4.InitOptions;
import com.alibaba.qlexpress4.security.QLSecurityStrategy;
import com.zt.plat.module.qms.core.qlexpress.function.RoundToScaleHalfEven;

@Configuration(proxyBeanMethods = false)
public class QlExpressRuleEngineConfig {

	@Bean
	public Express4Runner expressRunner() {
		//兼容 3 的行为，则在新建 Express4Runner 时， 要将安全策略设置为 “开放”
		InitOptions initOptions = InitOptions.builder().securityStrategy(QLSecurityStrategy.open()).build();
		Express4Runner expressRunner = new Express4Runner(initOptions);
		expressRunner.addFunction("roundToScale", new RoundToScaleHalfEven());
		return expressRunner;
	}
}
