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

Posted maocai2018

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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; }



 






以上是关于List 多条件,多条件筛选集合的主要内容,如果未能解决你的问题,请参考以下文章

android实现多条件筛选列表菜单筛选菜单

安卓实现多条件筛选列表菜单筛选菜单

jquery实现多条件筛选特效代码分享

List集合多线程并发条件下不安全,如何解决?

java小技能:对list集合根据条件进行分组过滤和字段筛选

EXCEL中如何多条件筛选数据?