| | |
| | | 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.*; |
| | |
| | | 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); |
| | |
| | | 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); |
| | |
| | | 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); |