1.QLExpress源码及使用简单示例
https://github.com/alibaba/QLExpress
2.如何使用QLExpress 调用Service方法实现复杂业务
场景之查询mongodb数据库数据是否存在该数据
public class ExpressRunnerFactory {
private volatile static ExpressRunner instance;
public static ExpressRunner getInstance() {
if (instance == null) {
synchronized (ExpressRunnerFactory.class) {
if (instance == null) {
instance = new ExpressRunner();
initFunctionOfServiceMethods(runner);
}
}
}
return instance;
}
private static void initFunctionOfServiceMethods(ExpressRunner runner) {
try {
DynamicParamsUtil.supportDynamicParams = true;
runner.addFunctionOfServiceMethod("EXIST", SpringUtil.getBean(FormDataValidate.class),"exist",new Class[] {String.class,String.class,Object.class,String.class},"存在");
} catch (Exception e) {
log.error("加载规则引擎失败==》", e);
throw new CloudBossException("初始化QlExpress,规则引擎失败!");
}
}
}
@Service
public class FormDataValidate {
@Autowired
CustomerMongoContext customerMongoContext;
public boolean exist(String formId,String id, Object value, String field){
if(ObjectUtil.isEmpty(value) || StrUtil.isBlank(field)){
return false;
}
MongoTemplate mongo=customerMongoContext.giveMeMongoTemplate(MongoResource.builder().formId(formId).build());
Query query = new Query();
Criteria criteria=Criteria.where(field).is(value).and(FormComponentContants.FIXED_FIELD_DEL_FLAG).is(0);
if(StrUtil.isNotBlank(id)){
criteria.and(FormComponentContants.FIXED_FIELD_ID).ne(id);
}
query.addCriteria(criteria);
return mongo.exists(query,formId);
}
}