深圳定制西裝哪家好seo優(yōu)化網(wǎng)站模板
背景:最近項(xiàng)目需要,師傅可以查找訂單,而師傅是指定可以服務(wù)2到3個(gè)區(qū)域,故需要使用到and, or條件的組合,以下記一下代碼。
最重要的代碼是:
1、構(gòu)建List<Consumer<LambdaQueryWrapper<T>>> andConditions;
2、從列表中填好 andConditions使用 and, or;
3、queryWrapper使用and中使用for得到所有的條件。
// 通過staffId查找地域id
LambdaQueryWrapper<ServiceAreaStaff> areaQueryWrapper = new LambdaQueryWrapper<ServiceAreaStaff>().eq(ServiceAreaStaff::getStaffId, staff.getId());
List<ServiceAreaStaff> areasList = serviceAreaStaffMapper.selectList(areaQueryWrapper);
// 找到符合的訂單// 當(dāng)前師傅只能看到服務(wù)范圍內(nèi)的訂單數(shù)據(jù)
List<Consumer<LambdaQueryWrapper<Order>>> andConditions = new ArrayList<>();List<Long> areas = new ArrayList<Long>();
for(ServiceAreaStaff area : areasList) {andConditions.add(wq -> wq.or().eq(Order::getServiceAreaId, area.getServiceAreaId()));
}LambdaQueryWrapper<Order> queryWrapper = new LambdaQueryWrapper<Order>().and(true, wrapper -> {for (Consumer<LambdaQueryWrapper<Order>> condition : andConditions) {condition.accept(wrapper);}}).orderByDesc(Order::getId);