Closed eric521237 closed 4 months ago
补充一下,round 是自定义的 @Component("round") public class MathRoundFunc extends MathRoundFunction {
@Override
public String getName() {
return "round";
}
@Override
public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) {
Number val = FunctionUtils.getNumberValue(arg1, env);
Number precision = FunctionUtils.getNumberValue(arg2, env);
if(val == null) {
throw new NullPointerException("round: arg is null");
}
if(precision == null) {
throw new NullPointerException("round: precision is null");
}
BigDecimal bigDecimal = new BigDecimal(val.toString());
bigDecimal = bigDecimal.setScale(precision.intValue(), BigDecimal.ROUND_HALF_UP);
return FunctionUtils.wrapReturn(bigDecimal);
}
}
@test public void getFunTest02(){ Map<String, Object> p = new HashMap<>(); p.put("ycly_a", 2); p.put("sxcn_ydccl", 3); p.put("sxcn_jjgzzey", 4); p.put("mbcn_ydccl", 2); p.put("mbcn_jjgzzey", 5); p.put("qwcn_ydccl", 7); p.put("bdcn_ydccl", 1); p.put("qwcn_ndccl", 8); p.put("qwcn_jjgzzey", 11); p.put("bdcn_jjgzzey", 6);
Object execute = executor.execute("round(if ( ycly_a >= sxcn_ydccl ) { sxcn_jjgzzey } elsif ( ycly_a >= mbcn_ydccl && ycly_a < sxcn_ydccl ) { ( mbcn_jjgzzey * ( ( ycly_a / mbcn_ydccl -1 ) *0.8 +1 ) ) } elsif ( ycly_a >= qwcn_ydccl && ycly_a < mbcn_ydccl ) { ( mbcn_jjgzzey / ( ( mbcn_ydccl / ycly_a -1 ) *0.7 +1 ) ) } elsif ( ycly_a >= bdcn_ydccl && ycly_a < qwcn_ndccl ) { ( qwcn_jjgzzey / ( ( qwcn_ydccl / ycly_a -1 ) *0.65 +1 ) ) } elsif ( ycly_a < bdcn_ydccl ) { bdcn_jjgzzey } else {0 } ,0)", p); System.out.println(execute); }
出现如下保留字错误 下面错误信息不对 我看表达式报错是if保留关键字出错 在表达式解析器里com.googlecode.aviator.exception.ExpressionSyntaxErrorException: Syntax error: unexpect token '{', maybe forget to insert ';' to complete last expression at 5, lineNumber: 1, token : [type='Char',lexeme='{',index=5], while parsing expression: ` round{^^^
@test public void getFunTest02(){ Map<String, Object> p = new HashMap<>(); p.put("ycly_a", 2); p.put("sxcn_ydccl", 3); p.put("sxcn_jjgzzey", 4); p.put("mbcn_ydccl", 2); p.put("mbcn_jjgzzey", 5); p.put("qwcn_ydccl", 7); p.put("bdcn_ydccl", 1); p.put("qwcn_ndccl", 8); p.put("qwcn_jjgzzey", 11); p.put("bdcn_jjgzzey", 6);
Object execute = executor.execute("round(if ( ycly_a >= sxcn_ydccl ) { sxcn_jjgzzey } elsif ( ycly_a >= mbcn_ydccl && ycly_a < sxcn_ydccl ) { ( mbcn_jjgzzey * ( ( ycly_a / mbcn_ydccl -1 ) *0.8 +1 ) ) } elsif ( ycly_a >= qwcn_ydccl && ycly_a < mbcn_ydccl ) { ( mbcn_jjgzzey / ( ( mbcn_ydccl / ycly_a -1 ) *0.7 +1 ) ) } elsif ( ycly_a >= bdcn_ydccl && ycly_a < qwcn_ndccl ) { ( qwcn_jjgzzey / ( ( qwcn_ydccl / ycly_a -1 ) *0.65 +1 ) ) } elsif ( ycly_a < bdcn_ydccl ) { bdcn_jjgzzey } else {0 } ,0)", p); System.out.println(execute); }
出现如下保留字错误 下面错误信息不对 我看表达式报错是if保留关键字出错 在表达式解析器里com.googlecode.aviator.exception.ExpressionSyntaxErrorException: Syntax error: unexpect token '{', maybe forget to insert ';' to complete last expression at 5, lineNumber: 1, token : [type='Char',lexeme='{',index=5], while parsing expression: ` round{^^^
而且我把最外层round去掉,在每个判断条件结果里用round是没问题,只有在最外层使用round时 表达式解析器有个check词法报错 抛关于if的异常
@Test public void getFunTest02(){ Map<String, Object> p = new HashMap<>(); p.put("ycly_a", 2); p.put("sxcn_ydccl", 3); p.put("sxcn_jjgzzey", 4); p.put("mbcn_ydccl", 2); p.put("mbcn_jjgzzey", 5); p.put("qwcn_ydccl", 7); p.put("bdcn_ydccl", 1); p.put("qwcn_ndccl", 8); p.put("qwcn_jjgzzey", 11); p.put("bdcn_jjgzzey", 6);
出现如下保留字错误 com.googlecode.aviator.exception.ExpressionSyntaxErrorException: Syntax error: unexpect token '{', maybe forget to insert ';' to complete last expression at 5, lineNumber: 1, token : [type='Char',lexeme='{',index=5], while parsing expression: ` round{^^^