|
@@ -2,9 +2,8 @@ package com.kuyuntech.vrv.platform.configuration.core;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.kuyuntech.vrv.coreapi.bean.core.DeviceParamBean;
|
|
|
+import com.kuyuntech.vrv.coreapi.bean.mqtt.DeviceParam;
|
|
|
import com.kuyuntech.vrv.coreapi.service.core.DeviceParamService;
|
|
|
-import com.kuyuntech.vrv.platform.readJson.Test;
|
|
|
-import com.kuyuntech.vrv.platform.util.core.CompareParamValue;
|
|
|
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
@@ -66,7 +65,7 @@ public class MqttConfiguration {
|
|
|
@Bean
|
|
|
public MessageProducer inbound() {
|
|
|
// Paho客户端消息驱动通道适配器,主要用来订阅主题
|
|
|
- MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter("consumerClient-paho",
|
|
|
+ MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter("askin-paho",
|
|
|
mqttClientFactory(), "mqtt/335102012203A500/data", "mqtt/335102012203A500/cmd", "battery", "+/sensor");
|
|
|
adapter.setCompletionTimeout(5000);
|
|
|
|
|
@@ -107,7 +106,7 @@ public class MqttConfiguration {
|
|
|
String devices = jsonObject.getString("devices");
|
|
|
|
|
|
//取里面
|
|
|
- List<Test> list = JSONObject.parseArray(devices, Test.class);
|
|
|
+ List<DeviceParam> list = JSONObject.parseArray(devices, DeviceParam.class);
|
|
|
|
|
|
//CK1
|
|
|
String deviceId = list.get(0).getDeviceId();
|
|
@@ -124,137 +123,137 @@ public class MqttConfiguration {
|
|
|
//先将数据存入redis,检验所有数据,如果出现数据改变,就执行update更新数据库,并更新redis
|
|
|
|
|
|
//用长度做判断
|
|
|
- Long size = redisTemplate.opsForHash().size("paramKeyValue");
|
|
|
- Long size2 = redisTemplate.opsForHash().size("paramKeyValueCK2");
|
|
|
- System.out.println(size);
|
|
|
- System.out.println(size2);
|
|
|
-
|
|
|
- if (size == 0) {
|
|
|
- //遍历CK1数据
|
|
|
- for (Map.Entry<String, String> entry : deviceData.entrySet()) {
|
|
|
-
|
|
|
- String name = entry.getKey();
|
|
|
- String value = entry.getValue();
|
|
|
-
|
|
|
- //存入hash
|
|
|
- redisTemplate.opsForHash().put("paramKeyValue", name, value);
|
|
|
-
|
|
|
- System.out.println("CK1存入redis成功!");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (size2 == 0) {
|
|
|
- //遍历CK2数据
|
|
|
- for (Map.Entry<String, String> entry : deviceData2.entrySet()) {
|
|
|
-
|
|
|
- String name = entry.getKey();
|
|
|
- String value = entry.getValue();
|
|
|
-
|
|
|
- //存入hash
|
|
|
- redisTemplate.opsForHash().put("paramKeyValueCK2", name, value);
|
|
|
-
|
|
|
- System.out.println("CK2存入redis成功!");
|
|
|
- }
|
|
|
- }
|
|
|
+// Long size = redisTemplate.opsForHash().size("paramKeyValue");
|
|
|
+// Long size2 = redisTemplate.opsForHash().size("paramKeyValueCK2");
|
|
|
+// System.out.println(size);
|
|
|
+// System.out.println(size2);
|
|
|
+
|
|
|
+// if (size == 0) {
|
|
|
+// //遍历CK1数据
|
|
|
+// for (Map.Entry<String, String> entry : deviceData.entrySet()) {
|
|
|
+//
|
|
|
+// String name = entry.getKey();
|
|
|
+// String value = entry.getValue();
|
|
|
+//
|
|
|
+// //存入hash
|
|
|
+// redisTemplate.opsForHash().put("paramKeyValue", name, value);
|
|
|
+//
|
|
|
+// System.out.println("CK1存入redis成功!");
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (size2 == 0) {
|
|
|
+// //遍历CK2数据
|
|
|
+// for (Map.Entry<String, String> entry : deviceData2.entrySet()) {
|
|
|
+//
|
|
|
+// String name = entry.getKey();
|
|
|
+// String value = entry.getValue();
|
|
|
+//
|
|
|
+// //存入hash
|
|
|
+// redisTemplate.opsForHash().put("paramKeyValueCK2", name, value);
|
|
|
+//
|
|
|
+// System.out.println("CK2存入redis成功!");
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
//遍历redis中hash的每一个键值对和mqtt传过来的数据进行比较
|
|
|
|
|
|
//获取paramKeyValue键值对
|
|
|
- HashMap<String, String> paramKeyValue = (HashMap<String, String>) redisTemplate.opsForHash().entries("paramKeyValue");
|
|
|
- HashMap<String, String> paramKeyValueCK2 = (HashMap<String, String>) redisTemplate.opsForHash().entries("paramKeyValueCK2");
|
|
|
+// HashMap<String, String> paramKeyValue = (HashMap<String, String>) redisTemplate.opsForHash().entries("paramKeyValue");
|
|
|
+// HashMap<String, String> paramKeyValueCK2 = (HashMap<String, String>) redisTemplate.opsForHash().entries("paramKeyValueCK2");
|
|
|
|
|
|
- System.out.println("----------------------------");
|
|
|
- System.out.println(deviceData);
|
|
|
- System.out.println(paramKeyValue);
|
|
|
- System.out.println("----------------------------");
|
|
|
- System.out.println(deviceData2);
|
|
|
- System.out.println(paramKeyValueCK2);
|
|
|
- System.out.println("----------------------------");
|
|
|
+// System.out.println("----------------------------");
|
|
|
+// System.out.println(deviceData);
|
|
|
+// System.out.println(paramKeyValue);
|
|
|
+// System.out.println("----------------------------");
|
|
|
+// System.out.println(deviceData2);
|
|
|
+// System.out.println(paramKeyValueCK2);
|
|
|
+// System.out.println("----------------------------");
|
|
|
|
|
|
- boolean result = CompareParamValue.CompareParamValue(paramKeyValue, deviceData);
|
|
|
- boolean result2 = CompareParamValue.CompareParamValue(paramKeyValueCK2, deviceData2);
|
|
|
+// boolean result = CompareParamValue.CompareParamValue(paramKeyValue, deviceData);
|
|
|
+// boolean result2 = CompareParamValue.CompareParamValue(paramKeyValueCK2, deviceData2);
|
|
|
|
|
|
- System.out.println("CK1比较的结果:" + result);
|
|
|
- System.out.println("CK2比较的结果:" + result2);
|
|
|
+// System.out.println("CK1比较的结果:" + result);
|
|
|
+// System.out.println("CK2比较的结果:" + result2);
|
|
|
|
|
|
//如果不相等,清除缓存,重新加入,并更新数据库
|
|
|
- if (result == false) {
|
|
|
- //清除redis缓存
|
|
|
- redisTemplate.delete("paramKeyValue");
|
|
|
+// if (result == false) {
|
|
|
+ //清除redis缓存
|
|
|
+// redisTemplate.delete("paramKeyValue");
|
|
|
|
|
|
- //重新存入redis
|
|
|
- for (Map.Entry<String, String> entry : deviceData.entrySet()) {
|
|
|
+ //重新存入redis
|
|
|
+// for (Map.Entry<String, String> entry : deviceData.entrySet()) {
|
|
|
+//
|
|
|
+// String name = entry.getKey();
|
|
|
+// String value = entry.getValue();
|
|
|
+//
|
|
|
+// //存入hash
|
|
|
+// redisTemplate.opsForHash().put("paramKeyValue", name, value);
|
|
|
+//
|
|
|
+// System.out.println("重新存入redis成功!");
|
|
|
+// }
|
|
|
|
|
|
- String name = entry.getKey();
|
|
|
- String value = entry.getValue();
|
|
|
+ long id = 199;
|
|
|
|
|
|
- //存入hash
|
|
|
- redisTemplate.opsForHash().put("paramKeyValue", name, value);
|
|
|
+ //更新数据库
|
|
|
+ for (Map.Entry<String, String> entry : deviceData.entrySet()) {
|
|
|
+ DeviceParamBean deviceParamBean = new DeviceParamBean();
|
|
|
|
|
|
- System.out.println("重新存入redis成功!");
|
|
|
- }
|
|
|
-
|
|
|
- long id = 199;
|
|
|
-
|
|
|
- //更新数据库
|
|
|
- for (Map.Entry<String, String> entry : deviceData.entrySet()) {
|
|
|
- DeviceParamBean deviceParamBean = new DeviceParamBean();
|
|
|
+ deviceParamBean.setSn(deviceId);
|
|
|
|
|
|
- deviceParamBean.setSn(deviceId);
|
|
|
+ String name = entry.getKey();
|
|
|
+ String value = entry.getValue();
|
|
|
|
|
|
- String name = entry.getKey();
|
|
|
- String value = entry.getValue();
|
|
|
|
|
|
+ deviceParamBean.setId(id);
|
|
|
|
|
|
- deviceParamBean.setId(id);
|
|
|
+ id = id + 1;
|
|
|
|
|
|
- id = id + 1;
|
|
|
+ deviceParamBean.setName(name);
|
|
|
+ deviceParamBean.setValue(value);
|
|
|
|
|
|
- deviceParamBean.setName(name);
|
|
|
- deviceParamBean.setValue(value);
|
|
|
+ deviceParamBean = this.deviceParamService.updateParam(deviceParamBean);
|
|
|
|
|
|
- deviceParamBean = this.deviceParamService.updateParam(deviceParamBean);
|
|
|
+ System.out.println("id为:" + id + "-- 更新后的数据:" + deviceParamBean);
|
|
|
|
|
|
- System.out.println("id为:" + id + "-- 更新后的数据:" + deviceParamBean);
|
|
|
-
|
|
|
- }
|
|
|
}
|
|
|
+// }
|
|
|
|
|
|
//如果不相等,清除缓存,重新加入,并更新数据库
|
|
|
- if (result2 == false) {
|
|
|
- //清除redis缓存
|
|
|
- redisTemplate.delete("paramKeyValueCK2");
|
|
|
-
|
|
|
- //重新存入redis
|
|
|
- for (Map.Entry<String, String> entry : deviceData2.entrySet()) {
|
|
|
-
|
|
|
- String name = entry.getKey();
|
|
|
- String value = entry.getValue();
|
|
|
-
|
|
|
- //存入hash
|
|
|
- redisTemplate.opsForHash().put("paramKeyValueCK2", name, value);
|
|
|
-
|
|
|
- System.out.println("重新存入redis成功!");
|
|
|
+// if (result2 == false) {
|
|
|
+ //清除redis缓存
|
|
|
+// redisTemplate.delete("paramKeyValueCK2");
|
|
|
+
|
|
|
+ //重新存入redis
|
|
|
+// for (Map.Entry<String, String> entry : deviceData2.entrySet()) {
|
|
|
+//
|
|
|
+// String name = entry.getKey();
|
|
|
+// String value = entry.getValue();
|
|
|
+//
|
|
|
+// //存入hash
|
|
|
+// redisTemplate.opsForHash().put("paramKeyValueCK2", name, value);
|
|
|
+//
|
|
|
+// System.out.println("重新存入redis成功!");
|
|
|
+// }
|
|
|
+
|
|
|
+ //更新数据库
|
|
|
+ for (Map.Entry<String, String> entry : deviceData2.entrySet()) {
|
|
|
+ DeviceParamBean deviceParamBean = new DeviceParamBean();
|
|
|
+ deviceParamBean.setSn(deviceId2);
|
|
|
+
|
|
|
+ for (long i = 298; i < 300; i++) {
|
|
|
+ deviceParamBean.setId(i);
|
|
|
}
|
|
|
|
|
|
- //更新数据库
|
|
|
- for (Map.Entry<String, String> entry : deviceData2.entrySet()) {
|
|
|
- DeviceParamBean deviceParamBean = new DeviceParamBean();
|
|
|
- deviceParamBean.setSn(deviceId2);
|
|
|
+ String name = entry.getKey();
|
|
|
+ String value = entry.getValue();
|
|
|
|
|
|
- for (long i = 298; i < 300; i++) {
|
|
|
- deviceParamBean.setId(i);
|
|
|
- }
|
|
|
+ deviceParamBean.setName(name);
|
|
|
+ deviceParamBean.setValue(value);
|
|
|
|
|
|
- String name = entry.getKey();
|
|
|
- String value = entry.getValue();
|
|
|
-
|
|
|
- deviceParamBean.setName(name);
|
|
|
- deviceParamBean.setValue(value);
|
|
|
-
|
|
|
- deviceParamBean = this.deviceParamService.updateParam(deviceParamBean);
|
|
|
- }
|
|
|
+ deviceParamBean = this.deviceParamService.updateParam(deviceParamBean);
|
|
|
}
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
};
|