|
@@ -2,9 +2,14 @@ package com.xy.consumer.connected;
|
|
|
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
+import com.xy.config.DeviceThreadPoolConfig;
|
|
|
import com.xy.consumer.MqttConsumer;
|
|
|
+import com.xy.dto.DeviceNetRecordDto;
|
|
|
import com.xy.dto.DeviceStatusDto;
|
|
|
+import com.xy.service.DeviceNetRecordServiceImpl;
|
|
|
import com.xy.service.DeviceStatusServiceImpl;
|
|
|
+import com.xy.utils.ThreadPoolUtils;
|
|
|
+import com.xy.utils.enums.DictSonEnum;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -24,10 +29,11 @@ public class ConnectedConsumer implements MqttConsumer {
|
|
|
|
|
|
private DeviceStatusServiceImpl deviceStatusService;
|
|
|
|
|
|
+ private DeviceNetRecordServiceImpl deviceNetRecordService;
|
|
|
+
|
|
|
@Override
|
|
|
public boolean message(String topic, String payload) {
|
|
|
- log.info("设备上线监听:{}", payload);
|
|
|
- return exc(payload, 1);
|
|
|
+ return exc(payload, DictSonEnum.DEVICE_ONLINE_STATUS_1.getKeyInt());
|
|
|
}
|
|
|
|
|
|
public boolean exc(String payload, int netState) {
|
|
@@ -39,9 +45,20 @@ public class ConnectedConsumer implements MqttConsumer {
|
|
|
} catch (Exception e) {
|
|
|
return true;
|
|
|
}
|
|
|
- DeviceStatusDto.Up up = new DeviceStatusDto.Up().setDeviceId(deviceId);
|
|
|
- up.setNetState(netState);
|
|
|
- int code = deviceStatusService.up(up).getCode();
|
|
|
- return code == 200;
|
|
|
+ String msg = netState == DictSonEnum.DEVICE_ONLINE_STATUS_1.getKeyInt() ? "上线" : "离线";
|
|
|
+ log.info("设备" + msg + "监听:{}", payload);
|
|
|
+ ThreadPoolUtils.excPoll(DeviceThreadPoolConfig.DEVICE_NETWORK_POLL, 1)
|
|
|
+ .execute(() -> {
|
|
|
+ //上报状态
|
|
|
+ DeviceStatusDto.Up up = new DeviceStatusDto.Up().setDeviceId(deviceId);
|
|
|
+ up.setNetState(netState);
|
|
|
+ deviceStatusService.up(up).getCode();
|
|
|
+ //添加联网记录
|
|
|
+ DeviceNetRecordDto.Save save = new DeviceNetRecordDto.Save()
|
|
|
+ .setDeviceId(deviceId);
|
|
|
+ save.setNetStatus(netState);
|
|
|
+ deviceNetRecordService.save(new DeviceNetRecordDto.Save());
|
|
|
+ });
|
|
|
+ return true;
|
|
|
}
|
|
|
}
|