|
@@ -2,6 +2,7 @@ package com.xy.alipay;
|
|
|
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import com.xy.constants.SpiResponseConst;
|
|
|
+import com.xy.consumer.connected.ConnectedProducer;
|
|
|
import com.xy.consumer.disconnect.DisconnectedMqttConfiguration;
|
|
|
import com.xy.consumer.disconnect.DisconnectedProducer;
|
|
|
import com.xy.dto.DeviceEventMsgDto;
|
|
@@ -9,10 +10,12 @@ import com.xy.dto.spi.DeviceAlarmNotifyDTO;
|
|
|
import com.xy.dto.spi.DeviceStatusChangeNotifyDTO;
|
|
|
import com.xy.entity.DeviceCharging;
|
|
|
import com.xy.entity.DeviceInfo;
|
|
|
+import com.xy.entity.DeviceStatus;
|
|
|
import com.xy.entity.SysDictRedis;
|
|
|
import com.xy.service.DeviceChargingServiceImpl;
|
|
|
import com.xy.service.DeviceEventMsgServiceImpl;
|
|
|
import com.xy.service.DeviceInfoServiceImpl;
|
|
|
+import com.xy.service.DeviceStatusServiceImpl;
|
|
|
import com.xy.utils.SysDictUtils;
|
|
|
import com.xy.utils.enums.DeviceErrorRecordTypesEnum;
|
|
|
import com.xy.utils.enums.DictsEnum;
|
|
@@ -40,11 +43,15 @@ public class SpiDeviceServiceImpl implements SpiDeviceService {
|
|
|
|
|
|
private DeviceInfoServiceImpl deviceInfoService;
|
|
|
|
|
|
+ private DeviceStatusServiceImpl deviceStatusService;
|
|
|
+
|
|
|
private DeviceEventMsgServiceImpl deviceEventMsgService;
|
|
|
|
|
|
+ private DeviceChargingServiceImpl deviceChargingService;
|
|
|
+
|
|
|
private DisconnectedProducer disconnectedProducer;
|
|
|
|
|
|
- private DeviceChargingServiceImpl deviceChargingService;
|
|
|
+ private ConnectedProducer connectedProducer;
|
|
|
|
|
|
@Override
|
|
|
@ApiOperation("设备告警通知")
|
|
@@ -64,11 +71,6 @@ public class SpiDeviceServiceImpl implements SpiDeviceService {
|
|
|
save.setCode(deviceErrorRecordTypesEnum.getCode());
|
|
|
save.setMsg(deviceAlarmNotifyDTO.getFaultMsg());
|
|
|
deviceEventMsgService.save(save);
|
|
|
- //修改设备为离线
|
|
|
- if (deviceErrorRecordTypesEnum.getCode() == DeviceErrorRecordTypesEnum.NET.getCode()) {
|
|
|
- JSONObject jsonObject = new JSONObject().set("clientid", deviceInfo.getDeviceId());
|
|
|
- disconnectedProducer.sendToMqtt(jsonObject.toString(), DisconnectedMqttConfiguration.TOPIC, 1);
|
|
|
- }
|
|
|
return SpiResponseConst.SPI_SUCCESS;
|
|
|
}
|
|
|
|
|
@@ -106,6 +108,22 @@ public class SpiDeviceServiceImpl implements SpiDeviceService {
|
|
|
}
|
|
|
}
|
|
|
deviceInfoService.updateById(updateDeviceInfo);
|
|
|
+ //修改在线状态
|
|
|
+ Boolean online = deviceStatusChangeNotifyDTO.getOnline();
|
|
|
+ if (online != null) {
|
|
|
+ DeviceStatus deviceStatus = deviceStatusService.getById(deviceInfo.getDeviceId());
|
|
|
+ int netState = online ? 1 : 2;
|
|
|
+ if (netState != deviceStatus.getNetState()) {
|
|
|
+ JSONObject jsonObject = new JSONObject().set("clientid", deviceInfo.getDeviceId());
|
|
|
+ if (online) {
|
|
|
+ //在线
|
|
|
+ connectedProducer.sendToMqtt(jsonObject.toString(), DisconnectedMqttConfiguration.TOPIC, 1);
|
|
|
+ } else {
|
|
|
+ //离线
|
|
|
+ disconnectedProducer.sendToMqtt(jsonObject.toString(), DisconnectedMqttConfiguration.TOPIC, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
return SpiResponseConst.SPI_SUCCESS;
|
|
|
}
|
|
|
}
|