码迷,mamicode.com
首页 > 其他好文 > 详细

mongoTemplate 条件查询

时间:2021-02-08 12:27:48      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:ring   override   tchar   add   point   null   getc   col   条件查询   

构建条件方法

@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<Contour> contours = this.mongoTemplate.find(query, Contour.class);

        List<JSONObject> 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;
    }

mongoTemplate 条件查询

标签:ring   override   tchar   add   point   null   getc   col   条件查询   

原文地址:https://www.cnblogs.com/GoslingWu/p/14385238.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!