如何用LambdaWrapper去实现去重查询

我们知道,LambdaWrapper比较好用,但是LambdaWrapper却不能实现select(String s),那只需要进行QueryWrapper与LambdaQueryWrapper的混合使用就可以了,所以巧妙转换很重要

@Override
    public Integer getCountAbPressure(String customerId, LocalDateTime firstDay, LocalDateTime lastDay, List<String> list, Integer type) {
        QueryWrapper<CustomerBodyMetricsEntity> wrapper = new QueryWrapper<>();
        wrapper.select("DISTINCT version")
                .lambda()
                .eq(CustomerBodyMetricsEntity::getCustomerId, customerId)
                .ge(CustomerBodyMetricsEntity::getVersion, DateTimeUtil.dateTimeToTimestamp(firstDay))
                .le(CustomerBodyMetricsEntity::getVersion, DateTimeUtil.dateTimeToTimestamp(lastDay))
                .in(CustomerBodyMetricsEntity::getMetric, list)
                .ne(CustomerBodyMetricsEntity::getLabel, 20);
        return this.count(wrapper);
    }

QueryWrapper转换成LambdaWrapper,只需要lambda()方法即可

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐