LambdaQueryWrapper可自动生成sql表达式,对于复杂情况,可参考以下写法:
java
queryWrapper.and(true,wrapper->{
wrapper.eq(true, EmployeeCheckPO::getCid, employeeCheckPO.getCid());
wrapper.eq(StrUtil.isNotBlank(employeeCheckPO.getCheckMonth()), EmployeeCheckPO::getCheckMonth, employeeCheckPO.getCheckMonth());
wrapper.like(StringUtils.isNotBlank(employeeCheckPO.getUsername()), EmployeeCheckPO::getUsername, employeeCheckPO.getUsername());
});
queryWrapper.and(true,wrapperNew->{
wrapperNew.and(true,queryWrapper1->{
queryWrapper1.eq(EmployeeCheckPO::getDelFlag, DelFlagEnum.N.getValue());
queryWrapper1.eq(Objects.nonNull(employeeCheckPO.getCid()), EmployeeCheckPO::getCid, employeeCheckPO.getCid());
queryWrapper1.eq(EmployeeCheckPO::getStatus,0);
queryWrapper1.eq(EmployeeCheckPO::getUserId,employeeCheckPO.getUserId());
})
.or(true,queryWrapper2->{
queryWrapper2.eq(EmployeeCheckPO::getDelFlag, DelFlagEnum.N.getValue());
queryWrapper2.eq(Objects.nonNull(employeeCheckPO.getCid()), EmployeeCheckPO::getCid, employeeCheckPO.getCid());
queryWrapper2.eq(EmployeeCheckPO::getStatus,1);
queryWrapper2.eq(EmployeeCheckPO::getProcessSupervisorId,employeeCheckPO.getUserId());
}).or(true,queryWrapper3->{
queryWrapper3.eq(EmployeeCheckPO::getDelFlag, DelFlagEnum.N.getValue());
queryWrapper3.eq(Objects.nonNull(employeeCheckPO.getCid()), EmployeeCheckPO::getCid, employeeCheckPO.getCid());
queryWrapper3.eq(EmployeeCheckPO::getStatus,1);
queryWrapper3.isNull(EmployeeCheckPO::getProcessSupervisorId);
queryWrapper3.eq(EmployeeCheckPO::getProcessLeaderId,employeeCheckPO.getUserId());
});
});
queryWrapper.orderByDesc(EmployeeCheckPO::getCheckMonth);
上述sql逻辑解读为:wrapper集合 && (wrapperNew);
其中wrapperNew包括queryWrapper1 || queryWrapper2 || queryWrapper3