mybatisPlus的lambdaQueryWrapper的模糊和or和排序分页查询

        LambdaQueryWrapper lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(StoreConsumer::getStoreId, req.getStoreId());


        if (req.getName() != null) {
            lambdaQueryWrapper.like(StoreConsumer::getName, req.getName());
        }
        if (req.getMobile() != null) {
            lambdaQueryWrapper.like(StoreConsumer::getMobile, req.getMobile());
        }
        if (req.getPayCount() != null) {
            lambdaQueryWrapper.eq(StoreConsumer::getPayCount, req.getPayCount());
        }
        if (req.getIntegral() != null) {
            lambdaQueryWrapper.eq(StoreConsumer::getIntegral, req.getIntegral());
        }

        if (Objects.nonNull(req.getStartRegisterTime())) {
            lambdaQueryWrapper.apply((ObjectUtil.isNotNull(req.getStartRegisterTime())), "DATE_FORMAT(created, '%Y-%m-%d') >= {0}", req.getStartRegisterTime());
        }
        if (Objects.nonNull(req.getEndRegisterTime())) {
            lambdaQueryWrapper.apply((ObjectUtil.isNotNull(req.getEndRegisterTime())), "DATE_FORMAT(created, '%Y-%m-%d') <= {0}", req.getEndRegisterTime());
        }

        if (req.getOrigin() != null) {
            lambdaQueryWrapper.eq(StoreConsumer::getOrigin, req.getOrigin());
        }

        if (req.getTagId() != null) {
            //查询标签表
            StoreConsumerTag s = storeConsumerTagMapper.selectById(req.getTagId());
            lambdaQueryWrapper.and(
                    wrapper -> wrapper
                            .ge(StoreConsumer::getSuccessOrder, s.getSuccessOrder())
                            .or()
                            .ge(StoreConsumer::getPayCount, s.getPayCount())
                            .or()
                            .ge(StoreConsumer::getPayMoney, s.getPayMoney())
                            .or()
                            .ge(StoreConsumer::getIntegral, s.getIntegral())
            );
        }

        lambdaQueryWrapper.orderByDesc(StoreConsumer::getRegisterTime);

你可能感兴趣的:(mybatis-plus,java)