tanbin преди 11 месеца
родител
ревизия
062f8d5add
променени са 1 файла, в които са добавени 38 реда и са изтрити 0 реда
  1. 38 0
      device-api-service/src/main/java/com/xy/service/factory/device/impl/alipay/AliPayOpenDeviceFatoryImpl.java

+ 38 - 0
device-api-service/src/main/java/com/xy/service/factory/device/impl/alipay/AliPayOpenDeviceFatoryImpl.java

@@ -29,6 +29,10 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
 import java.util.Arrays;
 import java.util.List;
 
@@ -226,6 +230,40 @@ public class AliPayOpenDeviceFatoryImpl implements DeviceFactory, SpiDeviceServi
     @ApiOperation("设备异常通知SPI")
     @Override
     public String deviceExceptionNotify(DeviceExceptionNotifyDTO deviceExceptionNotifyDTO) {
+        String terminalId = deviceExceptionNotifyDTO.getTerminalId();
+        String action = deviceExceptionNotifyDTO.getAction();
+        String exceptionDesc = deviceExceptionNotifyDTO.getExceptionDesc();
+        //triggerTime 示例 1551156574510
+        Long triggerTime = deviceExceptionNotifyDTO.getTriggerTime();
+        LocalDateTime triggerDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(triggerTime), ZoneId.systemDefault());
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        String formattedDateTime = triggerDateTime.format(formatter);
+        String devCode = "";
+        if ("恢复".equals(action)) {
+            if (exceptionDesc.contains("重力")) {
+                devCode = "DEV6004";
+            } else if (exceptionDesc.contains("摄像头")) {
+                devCode = "DEV6001";
+            }
+        } else if ("故障".equals(action)) {
+            if (exceptionDesc.contains("重力")) {
+                devCode = "DEV6003";
+            } else if (exceptionDesc.contains("摄像头")) {
+                devCode = "DEV6000";
+            }
+        }
+
+        if (StrUtil.isEmpty(devCode)) {
+            log.error("设备异常通知SPI->未知的异常类型:{}", JSONUtil.toJsonPrettyStr(deviceExceptionNotifyDTO));
+            return SpiResponseConst.FAIL;
+        }
+        //添加设备异常记录
+        DeviceEventMsgDto.Save save = new DeviceEventMsgDto.Save()
+                .setDeviceId(Long.valueOf(terminalId));
+        save.setCode(devCode);
+        save.setMsg(exceptionDesc + ";发生时间:" + formattedDateTime);
+        deviceEventMsgService.save(save);
+
         return SpiResponseConst.SUCCESS;
     }