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-10-13 01:24:33