如何用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

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐