同时,在不同的场景下,“标准”的判定会有一定的差别,这就要求系统的质检,具有可以灵活调整的能力,规则的制定需要随着业务发展进行调整。
按照一通会话对应一次质检,每天需要生成对应数量的质检单。针对每条质检单还需要有对应的质检项,最终质检系统需要对这些质检项,按照配置好的质检规则进行质检。
4.1 数据大宽表
支持 +,-,*,/,<,>,<=,>=,==,!=,<>【等同于!=】,%,mod【取模等同于%】,++,--,
/in【类似sql】,like【sql语法】,&&,||,!,等操作符
支持for,break、continue、if then else 等标准的程序控制逻辑
逻辑三元操作 a > b ? a : b;
不支持try{}catch{}
不支持java8的lambda表达式
不支持for循环集合操作for (Item item : list)
java对象操作
date = new Date();
System.out.println(date.getTime());
扩展操作符
重命名
runner.addOperatorWithAlias("如果", "if", null);
runner.addOperatorWithAlias("则", "then", null);
runner.addOperatorWithAlias("否则", "else", null);
express = "如果 (A > B) 则 {return a;} 否则 {return b;}";
DefaultContext<String, Object> context = new DefaultContext<String, Object>();
runner.execute(express, context, null, false, false, null);
自定义操作符
//定义一个join方法
public class JoinOperator extends Operator {
@Override
public Object executeInner(Object[] list) throws Exception {
Object opdata1 = list[0];
Object opdata2 = list[1];
if (opdata1 instanceof List) {
((List)opdata1).add(opdata2);
return opdata1;
} else {
List result = new ArrayList();
for (Object opdata : list) {
result.add(opdata);
}
return result;
}
}
}
5.3 系统实现
总体架构
主流程
离线数据
自动质检
质检脚本
算子
配置页面如下:
质检规则
上次催单=距离最近时间(@I,@A,false);
承诺催单=A && !E;
催单时间=距离最近时间(@B,@C,true);
创单时间=距离最近时间(@D,@C,true);
重启时间=距离最近时间(@F,@C,true);
备注时间=距离最近时间(@G,@C,true);
if(承诺催单){
if(分钟差(上次催单,@A)>10){
return (!B || (@J < 催单时间 && 分钟差(@J,催单时间)>10)) && !D && !F;
}else{
return (!G || (@J < 备注时间 && 分钟差(@J,备注时间)>10));
}
}
return false;
脚本执行
public int timeDiff_Minute(Long t1,Long t2){
if(Objects.isNull(t1) || Objects.isNull(t2)){
throw new QlExpressException(4000,"计算分钟差失败,时间参数为空");
}
return (int)TimeUnit.MILLISECONDS.toMinutes(timeDiff(t1,t2));
}
QlExpressFunc qlExpressFunc = new QlExpressFunc();
runner.addFunctionOfServiceMethod("分钟差", qlExpressFunc, "timeDiff_Minute",
new Class[]{Long.class, Long.class}, null);
上下文CONTEXT
上下文context本质为Map对象,用于传递脚本执行时所需的参数。一般使用DefaultContext,也可通过实现IExpressContext接口自定义context。
public class DefaultContext<K,V> extends HashMap<K,V> implements IExpressContext<K,V> {
}
*文/边城
关注得物技术,每周一三五晚18:30更新技术干货
要是觉得文章对你有帮助的话,欢迎评论转发点赞~
活动推荐
主题:
得物无线技术沙龙(第三期)
时间:
12月4日 14:00 - 18:00
报名方式:
更多详情,请点击「沙龙详情」