• LambdaQueryWrapper 自定义返回字段(分组后统计)


    1. QueryWrapper 指定想要返回的字段名,然后转化为LambdaQueryWrapper;
     QueryWrapper<RiskResultsDO> wrapper = new QueryWrapper<>();
            wrapper.select("count(1) as countNum,risk_level_code as riskLevelCode,whether_forecast as whetherForecast ");
            LambdaQueryWrapper<RiskResultsDO> searchInfo = riskResultsRepository.dealSearchInfo(req, wrapper.lambda());
            searchInfo.groupBy(RiskResultsDO::getWhetherForecast);
            searchInfo.groupBy(RiskResultsDO::getRiskLevelCode);
            List<Map<String, Object>> maps = riskResultsRepository.listMaps(searchInfo);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    1. 搜索条件处理
     public LambdaQueryWrapper<RiskResultsDO> dealSearchInfo(RiskResultsPageReq req, LambdaQueryWrapper<RiskResultsDO> lambdaQueryWrapper, SFunction<RiskResultsDO, ?> sortFiled, boolean whetherAsc) {
            lambdaQueryWrapper.eq(StringUtils.isNotBlank(req.getEvaluationTypeCode()), RiskResultsDO::getEvaluationTypeCode, req.getEvaluationTypeCode())
                    .ge(StringUtils.isNotBlank(req.getStartEvaluationTime()), RiskResultsDO::getEvaluationTime, req.getStartEvaluationTime() + DateUtilConstant.MIN_DAY_TIME)
                    .le(StringUtils.isNotBlank(req.getEndEvaluationTime()), RiskResultsDO::getEvaluationTime, req.getEndEvaluationTime() + DateUtilConstant.MAX_DAY_TIME)
                    .ge(StringUtils.isNotBlank(req.getStartForecastBelongTime()), RiskResultsDO::getForecastBelongTime, req.getStartForecastBelongTime() + DateUtilConstant.MIN_DAY_TIME)
                    .le(StringUtils.isNotBlank(req.getEndForecastBelongTime()), RiskResultsDO::getForecastBelongTime, req.getEndForecastBelongTime() + DateUtilConstant.MAX_DAY_TIME)
                    .apply(ObjectUtil.isNotNull(req.getAreaId()), " FIND_IN_SET (" + req.getAreaId() + ",area_ids) ")
                    .eq(ObjectUtil.isNotNull(req.getWhetherForecast()), RiskResultsDO::getWhetherForecast, req.getWhetherForecast())
                    .eq(ObjectUtil.isNotNull(req.getStationAreaId()), RiskResultsDO::getAreaId, req.getStationAreaId())
                    .eq(ObjectUtil.isNotNull(req.getRiskLevelCode()), RiskResultsDO::getRiskLevelCode, req.getRiskLevelCode())
                    .eq(ObjectUtil.isNotNull(req.getBelongTypeCode()), RiskResultsDO::getBelongTypeCode, req.getBelongTypeCode());
            if (ObjectUtil.isNotEmpty(req.getWhetherTown()) && req.getWhetherTown().equals(1)) {
                lambdaQueryWrapper.isNotNull(RiskResultsDO::getVillageTownId);
            }
            lambdaQueryWrapper.orderBy(true, whetherAsc, sortFiled);
            return lambdaQueryWrapper;
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    这个主要是不想维护常量字段名使用~

  • 相关阅读:
    教你 Java 注解与反射
    Open3D学习笔记
    10、matlab中字符、数字、矩阵、字符串和元胞合并为字符串并将字符串以不同格式写入读出excel
    Go-Python-Java-C-LeetCode高分解法-第九周合集
    对于噪声数据理解以及Min-Max 规范化和 Score规范化(零-均值规范化)的实例【数据预处理】
    Yocto创建自己的分区(基于STM32MP1)
    Symbol基本数据类型
    CentOS Docker 安装 & 常用命令
    电脑锁屏设置的方法,直接在系统设置里完成
    解析异常SAXParseExceptionis如何处理
  • 原文地址:https://blog.csdn.net/u010012932/article/details/126746286