避免mqtt未开启时,类报错
This commit is contained in:
parent
56bd4dd4bd
commit
d771c1ba5c
|
|
@ -736,11 +736,16 @@ public class IotCommonP3ServiceImpl {
|
|||
|
||||
public boolean sendMqttDeviceQuery(SurvDeviceDeploy deploy, List<String> variables) {
|
||||
boolean result = true;
|
||||
log.error("===========预发送指令========={}============",variables.size());
|
||||
if(deploy!=null && variables!=null && !variables.isEmpty()){
|
||||
QueryCmd queryCmd = LhIotUtil.ConstructCmd(variables);
|
||||
String cmdStr = JSONObject.toJSONString(queryCmd);
|
||||
mqttService.sendMessage(deploy.getDeviceIotUrl(),cmdStr);
|
||||
try{
|
||||
log.error("===========预发送指令========={}============", variables.size());
|
||||
if (deploy != null && variables != null && !variables.isEmpty()) {
|
||||
QueryCmd queryCmd = LhIotUtil.ConstructCmd(variables);
|
||||
String cmdStr = JSONObject.toJSONString(queryCmd);
|
||||
mqttService.sendMessage(deploy.getDeviceIotUrl(), cmdStr);
|
||||
}
|
||||
}catch (Exception e){
|
||||
//抛出未注入时的报错
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import org.jeecg.modules.mqtt.service.MqttService;
|
|||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
|
@ -14,6 +15,7 @@ import java.util.Map;
|
|||
@RestController
|
||||
@RequestMapping("/api/mqtt")
|
||||
@RequiredArgsConstructor
|
||||
@ConditionalOnProperty(prefix = "mqtt", name = "enabled", havingValue = "true")
|
||||
public class MqttController {
|
||||
@Autowired(required = false)
|
||||
private final MqttService mqttService;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.eclipse.paho.client.mqttv3.MqttClient;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
|
@ -18,6 +19,7 @@ import java.util.concurrent.CompletableFuture;
|
|||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@ConditionalOnProperty(prefix = "mqtt", name = "enabled", havingValue = "true")
|
||||
public class MqttService {
|
||||
|
||||
private final MqttClient mqttClient;
|
||||
|
|
|
|||
Loading…
Reference in New Issue