前言
我们在使用mybatisPlus 查询数据的时候,有时候可能会没法想直接使用mybatisPlus 的java语句进行查询。这里贴出一个例子供查询参考。
实践
queryWrapper.and(wq -> {
if(!CollectionUtils.isEmpty(orgList)){
wq.or(wq0 -> wq0.in(PatrolPlan::getOrgId, orgList));
wq.or(wq1 -> wq1.eq(PatrolPlan::getPlanExecType, PlanExecTypeEnum.ORG.getCode()).in(PatrolPlan::getPlanExecTypeId, orgList));
}
wq.or(wq2 -> wq2.eq(PatrolPlan::getPlanExecType, PlanExecTypeEnum.PERSON.getCode()).eq(PatrolPlan::getPlanExecTypeId, userId));
});
//业务类型
Long typeId = data.getTypeId();
if (Objects.nonNull(typeId)) {
queryWrapper.eq(PatrolPlan::getTypeId, typeId);
}
对应sql
(((org_id IN (?)) OR (plan_exec_type = ? AND plan_exec_type_id IN (?)) OR (plan_exec_type = ? AND plan_exec_type_id = ?)) and type_id = ?