zoukankan      html  css  js  c++  java
  • 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; }



  • 相关阅读:
    LuaJIT 之 FFI
    rtmp时间戳问题导致的丢帧,帧率显示错误
    c# 调用 c++的 dll 中关于 char*传入传出参数
    “Microsoft”中不存在类型或命名空间名称“Office”(是否缺少程序集引用?)
    udp,select超时和recvfrom收不到数据原因
    rtmpdump应用在window中
    Win7下安装openssl
    debug模式不报错,release模式报错
    qt 断点无效
    http协议 c++ 接收
  • 原文地址:https://www.cnblogs.com/maocai2018/p/10117117.html
Copyright © 2011-2022 走看看