| | |
| | | |
| | | } |
| | | if (topic.startsWith("$SYS/brokers/") && topic.endsWith("disconnected")) { |
| | | String clientid = messageJson.getString("clientid"); |
| | | redisUtil.del(MqttConstant.MQTT_ONLINE_CLIENT + clientid); |
| | | System.err.println(String.format("设备: %s下线", clientid)); |
| | | try { |
| | | String clientid = messageJson.getString("clientid"); |
| | | redisUtil.del(MqttConstant.MQTT_ONLINE_CLIENT + clientid); |
| | | System.err.println(String.format("设备: %s下线", clientid)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | parseAdminCommand(topic, mqttMessage); |
| | | |
| | |
| | | |
| | | // 接收设备实时数据 |
| | | case MqttConstant.TENANT_UP_PREFIX_REALTIME_DATA: |
| | | try { |
| | | RealTimeDataVo vo = JSON.parseObject(message, RealTimeDataVo.class); |
| | | realTimeDataService.realTimeDataHandle(vo); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | ThreadUtil.execute(() -> { |
| | | try { |
| | | RealTimeDataVo vo = JSON.parseObject(message, RealTimeDataVo.class); |
| | | realTimeDataService.realTimeDataHandle(vo); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | }); |
| | | |
| | | break; |
| | | case MqttConstant.TENANT_UP_PREFIX_EQU: |
| | | try { |
| | | DryEquipment equipment = (DryEquipment) messageJson.get("equipment"); |
| | | ThreadUtil.execute(() -> { |
| | | try { |
| | | DryEquipment equipment = (DryEquipment) messageJson.get("equipment"); |
| | | |
| | | DryEquipment dryEquipment = equipmentService.selectByTenantIdEquipmentId(equipment.getTenantId() + "", equipment.getCode()); |
| | | DryEquipment dryEquipment = equipmentService.selectByTenantIdEquipmentId(equipment.getTenantId() + "", equipment.getCode()); |
| | | if (dryEquipment == null) { |
| | | equipmentService.save(equipment); |
| | | } |
| | | |
| | | if (dryEquipment == null) { |
| | | equipmentService.save(equipment); |
| | | // 获取设备所属车间 |
| | | DryShop shop = (DryShop) messageJson.get("shop"); |
| | | shop.setTenantId(equipment.getTenantId()); |
| | | dryShopService.save(shop); |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | }); |
| | | |
| | | |
| | | |
| | | // 获取设备所属车间 |
| | | DryShop shop = (DryShop) messageJson.get("shop"); |
| | | shop.setTenantId(equipment.getTenantId()); |
| | | dryShopService.save(shop); |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | String clientId = mqttUtil.getMqttClient().getClientId(); |
| | | String tenant = clientId.substring(clientId.lastIndexOf("_")+1); |
| | | if (tenantId!=null && tenantId.equals(tenant)) { |
| | | TenantContext.setTenant(tenantId); |
| | | // 根据设备编码查询设备信息 |
| | | String code = messageJson.getString("code"); |
| | | DryEquipment equipmentVo = equipmentService.selectByTenantIdEquipmentId(tenantId,code); |
| | |
| | | |
| | | JSONObject res = new JSONObject(); |
| | | |
| | | res.put("tenant", clientId); |
| | | res.put("tenant", tenantId); |
| | | res.put("equipment", equipmentVo); |
| | | res.put("shop", shop); |
| | | res.put("eqpType", eqpType); |