List 多条件,多条件筛选集合

public List<DeviceStatePojoVo> getState(int deviceType, String precinctId,
                                            String deviceName, String onLine) {
        List<CfgDevice> deviceList = cfgDeviceMapper.findAllDevice();//查所有
        StringBuffer s = new StringBuffer();
        Map<String, CfgDevice> deviceMap = new HashMap<>();//以indexCode为KEY
        for (CfgDevice device1 : deviceList) {
            s.append(device1.getUserDeviceId() + ",");
            deviceMap.put(device1.getUserDeviceId(), device1);
        }
        //查所有海康的设备状态
        String hkState = getHKState(s.toString(), ITF_ADDRESS_POST_RESULT_STATE);
        Gson gson = new Gson();
        HKVqdResult<DeviceState> vqdResult = gson.fromJson(hkState, new TypeToken<HKVqdResult<DeviceState>>() {
        }.getType());
        //根据查询条件放在集合里
        List<DeviceStatePojoVo> deviceStatePojoVoList = new ArrayList<DeviceStatePojoVo>();
        for (DeviceState deviceState : vqdResult.getData()) {
            String indexCode = deviceState.getIndexCode();
            //根据KEY取出对应的对象
            CfgDevice cfgDevice = deviceMap.get(indexCode);
            //封装
            DeviceStatePojoVo deviceStatePojoVo = new DeviceStatePojoVo();
            deviceStatePojoVo.setPrecinctName(cfgDevice.getPrecinctName());
            deviceStatePojoVo.setDeviceType(cfgDevice.getDeviceType());
            deviceStatePojoVo.setDeviceId(cfgDevice.getDeviceId());
            deviceStatePojoVo.setTime(deviceState.getUpdateTime());
            deviceStatePojoVo.setNetState(deviceState.getStatus());
            deviceStatePojoVo.setDeviceName(cfgDevice.getDeviceName());
            deviceStatePojoVo.setPrecinctId(cfgDevice.getPrecinctId());

            deviceStatePojoVoList.add(deviceStatePojoVo);
        }
        //筛选条件
        if (deviceName != null && !deviceName.isEmpty()) {
            List<String> strings = cfgDeviceMapper.queryLikeDeviceName(deviceName);
            deviceStatePojoVoList = deviceStatePojoVoList.stream()
                    .filter((DeviceStatePojoVo dd) -> strings.contains(dd.getDeviceName()))
                    .collect(Collectors.toList());
        }
        //筛选条件集合
        List result = new ArrayList();//
        if (deviceType != 0) {
            result.add(deviceType);//把要筛选的条件添加到集合里               // 要筛选的集合跟筛选条件集合比较  重新赋值给原来的集合             集合对象                 条件集合   对比    对象里的属性
            deviceStatePojoVoList = deviceStatePojoVoList.stream().filter((DeviceStatePojoVo dd) -> result.contains(dd.getDeviceType())).collect(Collectors.toList());
        }
        if (precinctId != null && !precinctId.isEmpty()) {
            result.add(precinctId);
            deviceStatePojoVoList = deviceStatePojoVoList.stream()
                    .filter((DeviceStatePojoVo dd) -> result.contains(dd.getPrecinctId()))
                    .collect(Collectors.toList());
        }
        if (onLine != null && !onLine.isEmpty()) {
            result.add(onLine);
            deviceStatePojoVoList = deviceStatePojoVoList.stream()
                    .filter((DeviceStatePojoVo dd) -> result.contains(dd.getNetState()))
                    .collect(Collectors.toList());
        }

        return deviceStatePojoVoList;
    }

原文地址:https://www.cnblogs.com/maocai2018/p/10117117.html

时间: 2024-08-10 10:51:53

List 多条件,多条件筛选集合的相关文章

[python基础(四)]条件和条件语句

1.print和import1.1 print 略1.2 import(1)impore somemodule (2)from somemodule import somefunction(3)from somemodule import somefunction,anotherfunction(4)from somemodule import*(5)import somemodule as somename #为整个模块提供别名(6)from somemodule import somefun

Python从菜鸟到高手(9):条件和条件语句

1.布尔(Boolean)值和布尔变量 ??在讲条件语句之前,首先应该了解一下布尔类型.条件语句(if)需要为其指定布尔值或布尔类型的变量,才能根据条件判断是否要指定代码块中的语句.布尔值只有两个值:True和False,可以将这两个值翻译成"真"和"假". ??现在我们已经了解了布尔值是用来做什么的,但Python语言会将哪些值看做布尔值呢?其实在Python语言中,每一种类型的值都可以被解释成布尔类型的值.例如,下面的值都会被解释成布尔值中的False. Non

如何从List&lt;T&gt;中筛选符合条件的数据的集合或个数

ChannelList就是一个List类型的数据,IsOpen 是其元素的属性 channelCount = (from channel in DevicesManager.Instance.CurrentDevice.ChannelList where channel.IsOpen group channel by channel.ChannelID).Count();

使用mybatis框架实现带条件查询-多条件(传入Map集合)

我们发现我们可以通过传入javaBean的方式实现我们的需求,但是就两个条件,思考:现在就给他传入一个实体类,对系统性能的开销是不是有点大了. 现在改用传入Map集合的方式: 奥!对了,在创建map集合时候,居然报错了,The type java.util.Map$Entry cannot be resolved. It is indirectly referenced from required .class. 是因为myeclipse的jdk和你安装的jdk的版本不一致导致的,只要将两者调成

WordPress页面,文章,分类等的条件判断的标签集合

is_home()判断是否为首页. The Front Page 首页头版消息设置is_front_page()判断是否为首页头版消息. (无论是日志或是页面).当系统显示博客主页且管理面板的设置>阅读菜单下 “主页显示为”选项设 为最近发表的文章”,或者’设置>阅读菜单下”主页显示为”选项设为且”主页”是当前被显示的页面时,is_front_page() 标签返回 TRUE. The Administration Panels 管理控制面板is_admin()判断是否为后台管理控制面板. A

java多条件不定条件查询

网站或各类管理系统都会用到搜索,会用到一个或多个不确定条件搜索,单条件搜索比较简单,有时候会有多个条件共同查询,如果系统中已经提供了相关的方法供你使用最好,像我做这老系统改版,需要添加搜索,就要自己写了.开始也没管那么多,就是拼sql,但是后来发现要加搜索地方不少,总是这样写既增加了工作量,还要做很多重复工作,说不定以后还会做这样的工作,所以还是写一个比较通用的查询方法. package com.test; import java.util.Iterator; import java.util.

Spring学习笔记--在SpEL中筛选集合

要用到Spring的util(包括util:list等),xml文件中的beans中需要添加一些有关util的信息: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&q

附近可对方条件的条件附件图如果。。

http://blog.csdn.net/zjj_sir/article/details/44181791 http://blog.csdn.net/zjj_sir/article/details/44181811 http://blog.csdn.net/zjj_sir/article/details/44181817 http://blog.csdn.net/zjj_sir/article/details/44181851 http://blog.csdn.net/zjj_sir/artic

PHP获取当前URL路径的处理(适用于多条件筛选列表)

原文网址:http://blog.csdn.net/liuxinmingcode/article/details/8029372 <?php /** * PHP获取当前url路径的函数及服务器变量 * $_SERVER["QUERY_STRING"] 查询(query)的字符串 * $_SERVER["REQUEST_URI"] 访问此页面所需的URI * $_SERVER["SCRIPT_NAME"] 包含当前脚本的路径 * $_SERV