|
@@ -1,7 +1,15 @@
|
|
package com.xy.alipay;
|
|
package com.xy.alipay;
|
|
|
|
|
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
|
+import com.xy.consumer.disconnect.DisconnectedMqttConfiguration;
|
|
|
|
+import com.xy.consumer.disconnect.DisconnectedProducer;
|
|
|
|
+import com.xy.dto.DeviceErrorsRecordDto;
|
|
import com.xy.dto.spi.DeviceAlarmNotifyDTO;
|
|
import com.xy.dto.spi.DeviceAlarmNotifyDTO;
|
|
import com.xy.dto.spi.DeviceStatusChangeNotifyDTO;
|
|
import com.xy.dto.spi.DeviceStatusChangeNotifyDTO;
|
|
|
|
+import com.xy.entity.DeviceInfo;
|
|
|
|
+import com.xy.service.DeviceErrorsRecordServiceImpl;
|
|
|
|
+import com.xy.service.DeviceInfoServiceImpl;
|
|
|
|
+import com.xy.utils.enums.DeviceErrorTypesEnum;
|
|
import com.xy.work.SpiDeviceService;
|
|
import com.xy.work.SpiDeviceService;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -24,15 +32,51 @@ import java.util.Map;
|
|
@Api(tags = "支付宝设备相关SPI")
|
|
@Api(tags = "支付宝设备相关SPI")
|
|
public class SpiDeviceServiceImpl implements SpiDeviceService {
|
|
public class SpiDeviceServiceImpl implements SpiDeviceService {
|
|
|
|
|
|
|
|
+ private DeviceInfoServiceImpl deviceInfoService;
|
|
|
|
+
|
|
|
|
+ private DeviceErrorsRecordServiceImpl deviceErrorsRecordService;
|
|
|
|
+
|
|
|
|
+ private DisconnectedProducer disconnectedProducer;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
@ApiOperation("设备告警通知")
|
|
@ApiOperation("设备告警通知")
|
|
public void deviceAlarmNotify(Map<String, String> params, DeviceAlarmNotifyDTO deviceAlarmNotifyDTO) {
|
|
public void deviceAlarmNotify(Map<String, String> params, DeviceAlarmNotifyDTO deviceAlarmNotifyDTO) {
|
|
-
|
|
|
|
|
|
+ //查询设备信息
|
|
|
|
+ DeviceInfo deviceInfo = deviceInfoService.getById(Long.valueOf(deviceAlarmNotifyDTO.getTerminalId()));
|
|
|
|
+ String faultCode = deviceAlarmNotifyDTO.getFaultCode();
|
|
|
|
+ DeviceErrorTypesEnum deviceErrorTypesEnum = faultCode.equals("DeviceOffline") ? DeviceErrorTypesEnum.DEVICE_ERROR_TYPES_1
|
|
|
|
+ : faultCode.equals("DoorOpenedOnNoTrade") ? DeviceErrorTypesEnum.DEVICE_ERROR_TYPES_2
|
|
|
|
+ : null;
|
|
|
|
+ if (deviceErrorTypesEnum == null) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ //添加设备异常记录
|
|
|
|
+ DeviceErrorsRecordDto.Save save = new DeviceErrorsRecordDto.Save()
|
|
|
|
+ .setDeviceId(deviceInfo.getDeviceId());
|
|
|
|
+ save.setErrorType(deviceErrorTypesEnum.getKey());
|
|
|
|
+ save.setErrorDescript(deviceErrorTypesEnum.getMsg());
|
|
|
|
+ deviceErrorsRecordService.save(save);
|
|
|
|
+ //修改设备为离线
|
|
|
|
+ if (deviceErrorTypesEnum.getKey() == DeviceErrorTypesEnum.DEVICE_ERROR_TYPES_1.getKey()) {
|
|
|
|
+ JSONObject jsonObject = new JSONObject().set("clientid", deviceInfo.getDeviceId());
|
|
|
|
+ disconnectedProducer.sendToMqtt(jsonObject.toString(), DisconnectedMqttConfiguration.TOPIC, 1);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@ApiOperation("设备状态变更通知")
|
|
@ApiOperation("设备状态变更通知")
|
|
public void deviceStatusChangeNotify(Map<String, String> params, DeviceStatusChangeNotifyDTO deviceStatusChangeNotifyDTO) {
|
|
public void deviceStatusChangeNotify(Map<String, String> params, DeviceStatusChangeNotifyDTO deviceStatusChangeNotifyDTO) {
|
|
-
|
|
|
|
|
|
+ //查询设备信息
|
|
|
|
+ DeviceInfo deviceInfo = deviceInfoService.getById(Long.valueOf(deviceStatusChangeNotifyDTO.getTerminalId()));
|
|
|
|
+ Integer status = deviceStatusChangeNotifyDTO.getStatus();
|
|
|
|
+ if (deviceInfo.getFreezeStatus().equals(status)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ //修改冻结状态、运营状态
|
|
|
|
+ DeviceInfo updateDeviceInfo = new DeviceInfo()
|
|
|
|
+ .setDeviceId(deviceInfo.getDeviceId())
|
|
|
|
+ .setBusyState(status)
|
|
|
|
+ .setFreezeStatus(status);
|
|
|
|
+ deviceInfoService.updateById(updateDeviceInfo);
|
|
}
|
|
}
|
|
}
|
|
}
|