mongoTemplate 条件查询

构建条件方法

@Override
    public Query getQuery(ReportParam param){

        //check
        MeenoAssert.hasLength(param.getUuid(),"uuid can not empty!");
        MeenoAssert.notNull(param.getChartType(),"chartType can not empty!");

        Query query = new Query();

        //uuid
        if(!StringUtils.isEmpty(param.getUuid())){
            query.addCriteria(Criteria.where("uuid").is(param.getUuid()));
        }

        //chartType
        if(param.getChartType() != null){
            query.addCriteria(Criteria.where("chartType").is(param.getChartType()));
        }

        //rowName
        if(!StringUtils.isEmpty(param.getRowName())){
            query.addCriteria(Criteria.where("rowName").is(param.getRowName()));
        }

        //groupName
        if(!StringUtils.isEmpty(param.getGroupName())){
            query.addCriteria(Criteria.where("groupName").is(param.getGroupName()));
        }

        //风向
        if(!StringUtils.isEmpty(param.getWindDirection())){
            query.addCriteria(Criteria.where("windDirection").is(param.getWindDirection()));
        }

        //场景id
        if(param.getSceneId() != null){
            query.addCriteria(Criteria.where("sceneId").is(param.getSceneId()));
        }

        //物料id
        if(param.getMaterialId() != null){
            query.addCriteria(Criteria.where("materialId").is(param.getMaterialId()));
        }

        //火灾类型
        if(param.getFireType() != null){
            query.addCriteria(Criteria.where("fireType").is(param.getFireType()));
        }

        //障碍区
        if(param.getObstacleId() != null){
            query.addCriteria(Criteria.where("obstacleId").is(param.getObstacleId()));
        }

        //墙面
        if(!StringUtils.isEmpty(param.getWallFinish())){
            query.addCriteria(Criteria.where("wallFinish").is(param.getWallFinish()));
        }

        //观察点
        if(param.getObPointId() != null){
            query.addCriteria(Criteria.where("obPointId").is(param.getObPointId()));
        }

        //天气
        if (param.getClimateId() != null) {
            query.addCriteria(Criteria.where("climateId").is(param.getClimateId()));
        }

        return query;
    }

查询方法

@Override
    public String getReportContour(ReportParam param) {

        Query query = this.getQuery(param);

        List contours = this.mongoTemplate.find(query, Contour.class);

        List resultList = Lists.newArrayList();
        if(!com.alibaba.excel.util.CollectionUtils.isEmpty(contours)){
            resultList = contours.stream()
                    .map(curve -> {
                        if(!com.alibaba.excel.util.StringUtils.isEmpty(curve.getContent())){
                            JSONObject jsonObject = JSONObject.parseObject(curve.getContent());
                            return jsonObject;
                        }
                        return null;
                    })
                    .filter(Objects::nonNull)
                    .collect(Collectors.toList());
            return JSONObject.toJSONString(resultList);
        }

        return null;
    }

你可能感兴趣的:(stream,excel,filter,sql,es)