Commit ec90519c90925accf157434130bcf4ac7958c17d

Authored by 648540858
1 parent b16923d1

添加设备离线原因

src/main/java/com/genersoft/iot/vmp/gb28181/event/device/RequestTimeoutEventImpl.java
1 package com.genersoft.iot.vmp.gb28181.event.device; 1 package com.genersoft.iot.vmp.gb28181.event.device;
2 2
3 import com.genersoft.iot.vmp.gb28181.bean.Device; 3 import com.genersoft.iot.vmp.gb28181.bean.Device;
4 -import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;  
5 import com.genersoft.iot.vmp.service.IDeviceService; 4 import com.genersoft.iot.vmp.service.IDeviceService;
6 import org.springframework.beans.factory.annotation.Autowired; 5 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.context.ApplicationListener; 6 import org.springframework.context.ApplicationListener;
@@ -9,8 +8,6 @@ import org.springframework.stereotype.Component; @@ -9,8 +8,6 @@ import org.springframework.stereotype.Component;
9 8
10 import javax.sip.ClientTransaction; 9 import javax.sip.ClientTransaction;
11 import javax.sip.address.SipURI; 10 import javax.sip.address.SipURI;
12 -import javax.sip.header.CallIdHeader;  
13 -import javax.sip.header.ToHeader;  
14 import javax.sip.message.Request; 11 import javax.sip.message.Request;
15 12
16 /** 13 /**
@@ -34,7 +31,7 @@ public class RequestTimeoutEventImpl implements ApplicationListener<RequestTimeo @@ -34,7 +31,7 @@ public class RequestTimeoutEventImpl implements ApplicationListener<RequestTimeo
34 if (device == null) { 31 if (device == null) {
35 return; 32 return;
36 } 33 }
37 - deviceService.offline(device.getDeviceId()); 34 + deviceService.offline(device.getDeviceId(), "等待消息超时");
38 } 35 }
39 36
40 } 37 }
src/main/java/com/genersoft/iot/vmp/gb28181/task/SipRunner.java
@@ -61,7 +61,7 @@ public class SipRunner implements CommandLineRunner { @@ -61,7 +61,7 @@ public class SipRunner implements CommandLineRunner {
61 61
62 for (Device device : deviceList) { 62 for (Device device : deviceList) {
63 if (deviceService.expire(device)){ 63 if (deviceService.expire(device)){
64 - deviceService.offline(device.getDeviceId()); 64 + deviceService.offline(device.getDeviceId(), "注册已过期");
65 }else { 65 }else {
66 deviceService.online(device); 66 deviceService.online(device);
67 } 67 }
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/RegisterRequestProcessor.java
@@ -182,7 +182,7 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen @@ -182,7 +182,7 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen
182 deviceService.online(device); 182 deviceService.online(device);
183 } else { 183 } else {
184 logger.info("[注销成功] deviceId: {}->{}" ,deviceId, requestAddress); 184 logger.info("[注销成功] deviceId: {}->{}" ,deviceId, requestAddress);
185 - deviceService.offline(deviceId); 185 + deviceService.offline(deviceId, "主动注销");
186 } 186 }
187 } catch (SipException | NoSuchAlgorithmException | ParseException e) { 187 } catch (SipException | NoSuchAlgorithmException | ParseException e) {
188 e.printStackTrace(); 188 e.printStackTrace();
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java
@@ -94,7 +94,7 @@ public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent imp @@ -94,7 +94,7 @@ public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent imp
94 // 刷新过期任务 94 // 刷新过期任务
95 String registerExpireTaskKey = VideoManagerConstants.REGISTER_EXPIRE_TASK_KEY_PREFIX + device.getDeviceId(); 95 String registerExpireTaskKey = VideoManagerConstants.REGISTER_EXPIRE_TASK_KEY_PREFIX + device.getDeviceId();
96 // 如果三次心跳失败,则设置设备离线 96 // 如果三次心跳失败,则设置设备离线
97 - dynamicTask.startDelay(registerExpireTaskKey, ()-> deviceService.offline(device.getDeviceId()), device.getKeepaliveIntervalTime()*1000*3); 97 + dynamicTask.startDelay(registerExpireTaskKey, ()-> deviceService.offline(device.getDeviceId(), "三次心跳失败"), device.getKeepaliveIntervalTime()*1000*3);
98 98
99 } 99 }
100 100
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceStatusResponseMessageHandler.java
1 package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd; 1 package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd;
2 2
3 import com.alibaba.fastjson2.JSONObject; 3 import com.alibaba.fastjson2.JSONObject;
4 -import com.genersoft.iot.vmp.common.VideoManagerConstants;  
5 import com.genersoft.iot.vmp.gb28181.bean.Device; 4 import com.genersoft.iot.vmp.gb28181.bean.Device;
6 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; 5 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
7 -import com.genersoft.iot.vmp.gb28181.event.EventPublisher;  
8 import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; 6 import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
9 import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; 7 import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
10 import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; 8 import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
@@ -26,7 +24,6 @@ import javax.sip.RequestEvent; @@ -26,7 +24,6 @@ import javax.sip.RequestEvent;
26 import javax.sip.SipException; 24 import javax.sip.SipException;
27 import javax.sip.message.Response; 25 import javax.sip.message.Response;
28 import java.text.ParseException; 26 import java.text.ParseException;
29 -import java.util.Objects;  
30 27
31 @Component 28 @Component
32 public class DeviceStatusResponseMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { 29 public class DeviceStatusResponseMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler {
@@ -76,7 +73,7 @@ public class DeviceStatusResponseMessageHandler extends SIPRequestProcessorParen @@ -76,7 +73,7 @@ public class DeviceStatusResponseMessageHandler extends SIPRequestProcessorParen
76 if ("ONLINE".equalsIgnoreCase(text.trim())) { 73 if ("ONLINE".equalsIgnoreCase(text.trim())) {
77 deviceService.online(device); 74 deviceService.online(device);
78 }else { 75 }else {
79 - deviceService.offline(device.getDeviceId()); 76 + deviceService.offline(device.getDeviceId(), "设备状态查询结果:" + text.trim());
80 } 77 }
81 RequestMessage msg = new RequestMessage(); 78 RequestMessage msg = new RequestMessage();
82 msg.setKey(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + device.getDeviceId()); 79 msg.setKey(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + device.getDeviceId());
src/main/java/com/genersoft/iot/vmp/service/IDeviceService.java
@@ -24,7 +24,7 @@ public interface IDeviceService { @@ -24,7 +24,7 @@ public interface IDeviceService {
24 * 设备下线 24 * 设备下线
25 * @param deviceId 设备编号 25 * @param deviceId 设备编号
26 */ 26 */
27 - void offline(String deviceId); 27 + void offline(String deviceId, String reason);
28 28
29 /** 29 /**
30 * 添加目录订阅 30 * 添加目录订阅
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
@@ -156,12 +156,12 @@ public class DeviceServiceImpl implements IDeviceService { @@ -156,12 +156,12 @@ public class DeviceServiceImpl implements IDeviceService {
156 // 刷新过期任务 156 // 刷新过期任务
157 String registerExpireTaskKey = VideoManagerConstants.REGISTER_EXPIRE_TASK_KEY_PREFIX + device.getDeviceId(); 157 String registerExpireTaskKey = VideoManagerConstants.REGISTER_EXPIRE_TASK_KEY_PREFIX + device.getDeviceId();
158 // 如果第一次注册那么必须在60 * 3时间内收到一个心跳,否则设备离线 158 // 如果第一次注册那么必须在60 * 3时间内收到一个心跳,否则设备离线
159 - dynamicTask.startDelay(registerExpireTaskKey, ()-> offline(device.getDeviceId()), device.getKeepaliveIntervalTime() * 1000 * 3); 159 + dynamicTask.startDelay(registerExpireTaskKey, ()-> offline(device.getDeviceId(), "首次注册后未能收到心跳"), device.getKeepaliveIntervalTime() * 1000 * 3);
160 } 160 }
161 161
162 @Override 162 @Override
163 - public void offline(String deviceId) {  
164 - logger.error("[设备离线], device:{}", deviceId); 163 + public void offline(String deviceId, String reason) {
  164 + logger.error("[设备离线],{}, device:{}", reason, deviceId);
165 Device device = deviceMapper.getDeviceByDeviceId(deviceId); 165 Device device = deviceMapper.getDeviceByDeviceId(deviceId);
166 if (device == null) { 166 if (device == null) {
167 return; 167 return;