|
@@ -13,10 +13,7 @@ import com.xy.config.DeviceThreadPoolConfig;
|
|
|
import com.xy.constants.SpiResponseConst;
|
|
|
import com.xy.device.EnumDeviceOnlineStatus;
|
|
|
import com.xy.dto.*;
|
|
|
-import com.xy.dto.spi.DeviceAlarmNotifyDTO;
|
|
|
-import com.xy.dto.spi.DeviceAttributesNotifyDTO;
|
|
|
-import com.xy.dto.spi.DeviceSetAttributesNotifyDTO;
|
|
|
-import com.xy.dto.spi.DeviceStatusChangeNotifyDTO;
|
|
|
+import com.xy.dto.spi.*;
|
|
|
import com.xy.entity.DeviceInfo;
|
|
|
import com.xy.entity.DeviceStatus;
|
|
|
import com.xy.service.*;
|
|
@@ -32,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 +227,46 @@ public class AliPayOpenDeviceFatoryImpl implements DeviceFactory, SpiDeviceServi
|
|
|
return SpiResponseConst.SUCCESS;
|
|
|
}
|
|
|
|
|
|
+ @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;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@ApiOperation("设备状态变更通知SPI")
|
|
|
public String deviceStatusChangeNotify(DeviceStatusChangeNotifyDTO deviceStatusChangeNotifyDTO) {
|