From f027c87f28485988b3d25f41b0cdf6e5bd42cd42 Mon Sep 17 00:00:00 2001 From: zhuguifei <zhuguifei@zhuguifeideiMac.local> Date: 星期三, 30 七月 2025 16:50:37 +0800 Subject: [PATCH] redis工单保存故障数据 --- jeecg-module-dry/jeecg-module-dry-biz/src/main/java/org/jeecg/modules/dry/mqtt/MqttConfig.java | 23 ++++++++++++++++------- 1 files changed, 16 insertions(+), 7 deletions(-) diff --git a/jeecg-module-dry/jeecg-module-dry-biz/src/main/java/org/jeecg/modules/dry/mqtt/MqttConfig.java b/jeecg-module-dry/jeecg-module-dry-biz/src/main/java/org/jeecg/modules/dry/mqtt/MqttConfig.java index ff7b934..65d41d6 100755 --- a/jeecg-module-dry/jeecg-module-dry-biz/src/main/java/org/jeecg/modules/dry/mqtt/MqttConfig.java +++ b/jeecg-module-dry/jeecg-module-dry-biz/src/main/java/org/jeecg/modules/dry/mqtt/MqttConfig.java @@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; import org.springframework.data.redis.core.RedisTemplate; import java.util.*; @@ -36,6 +37,8 @@ private String mqttClientId; @Value(value = "${jeecg.mqtt.role}") private String role; + @Value(value = "${jeecg.mqtt.enable}") + private boolean enable; @Autowired private MqttSampleCallback mqttSampleCallback; @@ -59,6 +62,7 @@ * mqtt杩炴帴閰嶇疆 */ private void conn() { + if (!isEnable()) return; MemoryPersistence persistence = new MemoryPersistence(); MqttConnectOptions mqttConnOpt = new MqttConnectOptions(); mqttConnOpt.setUserName(mqttName); @@ -69,7 +73,7 @@ mqttConnOpt.setAutomaticReconnect(false);//璁剧疆鏄惁鑷姩閲嶈繛 //閬楀槺娑堟伅 TODO qos2闇�瑕佸湪璁惧涓婄嚎鏃跺仛娓呴櫎娑堟伅鎿嶄綔 - mqttConnOpt.setWill("downline", ("鎴戞槸" + mqttName + "_" + mqttClientId + "锛屾垜涓嬬嚎浜�").getBytes(), 2, false); + //mqttConnOpt.setWill("downline", ("鎴戞槸" + mqttName + "_" + mqttClientId + "锛屾垜涓嬬嚎浜�").getBytes(), 2, false); try { MqttClient mqttClient = new MqttClient(broker, mqttClientId, persistence); @@ -98,8 +102,8 @@ mqttClient.subscribe(MqttConstant.MOBILE_UP); System.err.println("admin璁㈤槄" + MqttConstant.MOBILE_UP); // 璁㈤槄绉熸埛瀹炴椂鏁版嵁 - mqttClient.subscribe(MqttConstant.TENANT_UP_PREFIX_REALTIME_DATA); - System.out.println("admin璁㈤槄" + MqttConstant.TENANT_UP_PREFIX_REALTIME_DATA); + mqttClient.subscribe(MqttConstant.TENANT_UP_PREFIX_REALTIME_DATA_EQP); + System.out.println("admin璁㈤槄" + MqttConstant.TENANT_UP_PREFIX_REALTIME_DATA_EQP); // 璁㈤槄绉熸埛鎶ヨ鏁版嵁 mqttClient.subscribe(MqttConstant.TENANT_UP_PREFIX_REAL_FAULT_DATA); System.out.println("admin璁㈤槄" + MqttConstant.TENANT_UP_PREFIX_REAL_FAULT_DATA); @@ -132,6 +136,7 @@ //閲嶈繛 private void reconn() { + if (!isEnable()) return; Timer timer = new Timer(); TimerTask task = new TimerTask() { @@ -174,15 +179,19 @@ for (int i = 0; i < data.size(); i++) { JSONObject obj = data.getJSONObject(i); JSONObject item = new JSONObject(); + //clientid + String clientid = obj.getString("clientid"); + item.put("clientid", clientid); + //TODO 鏍¢獙绉熸埛id鏄惁瀛樺湪 + + + if(!clientid.matches("^[^-]+-[^-]+-[^-]+$")) continue; //username item.put("username", obj.get("username")); //杩炴帴鏃堕棿 String st = obj.getString("connected_at"); String upTime = DateUtils.zone2Str(st); item.put("connectedAt", upTime); - //clientid - String clientid = obj.getString("clientid"); - item.put("clientid", clientid); //鏄惁杩炴帴 Boolean connected = obj.getBoolean("connected"); item.put("connected", connected); @@ -191,7 +200,7 @@ String[] info = clientid.split("-"); item.put("type", info[0]); item.put("tenantId", info[1]); - //item.put("code", info[2]); + item.put("code", info[2]); if (connected) { redisUtil.hset(String.format(MqttConstant.MQTT_ONLINE_CLIENT,item.get("tenantId").toString()) , clientid, item); -- Gitblit v1.9.3