| | |
| | | if(device.getDoorNameObj()!=null && Constants.equalsInteger(device.getType(),Constants.DEVICE_TYPE.duanluqi)){ |
| | | device.setDoorName(JSONObject.toJSONString(device.getDoorNameObj())); |
| | | } |
| | | Device model = deviceMapper.selectById(device.getId()); |
| | | if(model ==null){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | if(Constants.equalsInteger(model.getType(),Constants.DEVICE_TYPE.duanluqi)){ |
| | | //如果是斷路器 |
| | | if( Constants.equalsInteger(model.getIsUsed(),Constants.ZERO) |
| | | && StringUtils.equals(device.getDoorName(),model.getDoorName())){ |
| | | //如果配置参数发生了变化,设置状态未启用 |
| | | device.setIsUsed(Constants.ONE); |
| | | try { |
| | | MqttClient mqttClient = MqttClientCache.clientMapCache.get("device"+device.getId()); |
| | | if(mqttClient !=null){ |
| | | if(mqttClient.isConnected()){ |
| | | mqttClient.disconnect(); |
| | | } |
| | | mqttClient.close(); |
| | | MqttClientCache.clientMapCache.remove("device"+device.getId()); |
| | | } |
| | | }catch (Exception e){ |
| | | log.error("==============端口mqtt链接失败:"+model.getName()+e.getMessage()); |
| | | } |
| | | } |
| | | } |
| | | deviceMapper.updateById(device); |
| | | |
| | | } |
| | | |
| | | @Override |
| | |
| | | //如果系统不用了,端口mqtt连接 |
| | | try { |
| | | mqttClient = mqttBizService.unsubscribe(mqttClient,config ,topics); |
| | | if(mqttClient ==null){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"建立连接失败!"); |
| | | } |
| | | if(mqttClient.isConnected()){ |
| | | mqttClient.disconnect(); |
| | | if(mqttClient !=null){ |
| | | if(mqttClient.isConnected()){ |
| | | mqttClient.disconnect(); |
| | | } |
| | | mqttClient.close(); |
| | | MqttClientCache.clientMapCache.remove("device"+param.getId()); |
| | | } |
| | | }catch (Exception e){ |
| | | log.error("==============端口mqtt链接失败:"+model.getName()+e.getMessage()); |