完成向上级联->删除的时候注销

This commit is contained in:
panlinlin 2021-01-07 13:15:39 +08:00
parent 627a14f37e
commit 54d7953179
11 changed files with 204 additions and 140 deletions

View File

@ -10,6 +10,8 @@ public class ParentPlatformCatch {
// 注册未回复次数
private int registerAliveReply;
private ParentPlatform parentPlatform;
public String getId() {
return id;
}
@ -33,4 +35,12 @@ public class ParentPlatformCatch {
public void setRegisterAliveReply(int registerAliveReply) {
this.registerAliveReply = registerAliveReply;
}
public ParentPlatform getParentPlatform() {
return parentPlatform;
}
public void setParentPlatform(ParentPlatform parentPlatform) {
this.parentPlatform = parentPlatform;
}
}

View File

@ -52,6 +52,7 @@ public class PlatformKeepaliveExpireEventLister implements ApplicationListener<P
}
ParentPlatform parentPlatform = storager.queryParentPlatById(event.getPlatformGbID());
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(event.getPlatformGbID());
parentPlatformCatch.setParentPlatform(parentPlatform);
if (parentPlatform == null) {
logger.debug("平台心跳到期事件事件触发,但平台已经删除!!! 平台国标ID" + event.getPlatformGbID());
return;

View File

@ -1,6 +1,9 @@
package com.genersoft.iot.vmp.gb28181.transmit.cmd;
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
import javax.sip.header.WWWAuthenticateHeader;
public interface ISIPCommanderForPlatform {
@ -11,7 +14,14 @@ public interface ISIPCommanderForPlatform {
*/
boolean register(ParentPlatform parentPlatform);
boolean register(ParentPlatform parentPlatform, String callId, String realm, String nonce, String scheme);
/**
* 向上级平台注销
* @param parentPlatform
* @return
*/
boolean unregister(ParentPlatform parentPlatform, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent);
boolean register(ParentPlatform parentPlatform, String callId, WWWAuthenticateHeader www, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent);
/**
* 向上级平发送心跳信息

View File

@ -20,10 +20,11 @@ import javax.sip.message.Request;
import javax.validation.constraints.NotNull;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.UUID;
/**
* @Description:摄像头命令request创造器 TODO 冗余代码太多待优化
* @author: swwheihei
* @Description: 平台命令request创造器 TODO 冗余代码太多待优化
* @author: panll
* @date: 2020年5月6日 上午9:29:02
*/
@Component
@ -79,7 +80,7 @@ public class SIPRequestHeaderPlarformProvider {
}
public Request createRegisterRequest(@NotNull ParentPlatform platform, String fromTag, String viaTag) throws ParseException, InvalidArgumentException, PeerUnavailableException {
public Request createRegisterRequest(@NotNull ParentPlatform platform, long CSeq, String fromTag, String viaTag) throws ParseException, InvalidArgumentException, PeerUnavailableException {
Request request = null;
String sipAddress = sipConfig.getSipIp() + ":" + sipConfig.getSipPort();
//请求行
@ -112,7 +113,7 @@ public class SIPRequestHeaderPlarformProvider {
MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70);
//ceq
CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(1L, Request.REGISTER);
CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(CSeq, Request.REGISTER);
request = sipFactory.createMessageFactory().createRequest(requestLine, Request.REGISTER, callIdHeader,
cSeqHeader,fromHeader, toHeader, viaHeaders, maxForwards);
@ -120,28 +121,73 @@ public class SIPRequestHeaderPlarformProvider {
.createSipURI(platform.getDeviceGBId(), sipAddress));
request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress));
ExpiresHeader expires = sipFactory.createHeaderFactory().createExpiresHeader(Integer.parseInt(platform.getExpires()));
request.addHeader(expires);
return request;
}
public Request createRegisterRequest(@NotNull ParentPlatform parentPlatform, String fromTag, String viaTag,
String callId, String realm, String nonce, String scheme) throws ParseException, PeerUnavailableException, InvalidArgumentException {
Request registerRequest = createRegisterRequest(parentPlatform, fromTag, viaTag);
String callId, WWWAuthenticateHeader www ) throws ParseException, PeerUnavailableException, InvalidArgumentException {
Request registerRequest = createRegisterRequest(parentPlatform, 2L, fromTag, viaTag);
String realm = www.getRealm();
String nonce = www.getNonce();
String scheme = www.getScheme();
// 参考 https://blog.csdn.net/y673533511/article/details/88388138
// qop 保护质量 包含auth默认的和auth-int增加了报文完整性检测两种策略
String qop = www.getQop();
CallIdHeader callIdHeader = (CallIdHeader)registerRequest.getHeader(CallIdHeader.NAME);
callIdHeader.setCallId(callId);
String uri = "sip:" + parentPlatform.getServerGBId() +
"@" + parentPlatform.getServerIP() +
":" + parentPlatform.getServerPort();
SipURI requestURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerIP() + ":" + parentPlatform.getServerPort());
String cNonce = null;
String nc = "00000001";
if (qop != null) {
if ("auth".equals(qop)) {
// 客户端随机数这是一个不透明的字符串值由客户端提供并且客户端和服务器都会使用以避免用明文文本
// 这使得双方都可以查验对方的身份并对消息的完整性提供一些保护
cNonce = UUID.randomUUID().toString();
}else if ("auth-int".equals(qop)){
// TODO
}
}
String HA1 = DigestUtils.md5DigestAsHex((parentPlatform.getDeviceGBId() + ":" + realm + ":" + parentPlatform.getPassword()).getBytes());
String HA2=DigestUtils.md5DigestAsHex((Request.REGISTER + ":" + uri).getBytes());
String RESPONSE = DigestUtils.md5DigestAsHex((HA1 + ":" + nonce + ":" + HA2).getBytes());
String HA2=DigestUtils.md5DigestAsHex((Request.REGISTER + ":" + requestURI.toString()).getBytes());
String authorizationHeaderContent = scheme + " username=\"" + parentPlatform.getDeviceGBId() + "\", " + "realm=\""
+ realm + "\", uri=\"" + uri + "\", response=\"" + RESPONSE + "\", nonce=\""
+ nonce + "\"";
AuthorizationHeader authorizationHeader = sipFactory.createHeaderFactory().createAuthorizationHeader(authorizationHeaderContent);
StringBuffer reStr = new StringBuffer(200);
reStr.append(HA1);
reStr.append(":");
reStr.append(nonce);
reStr.append(":");
if (qop != null) {
reStr.append(nc);
reStr.append(":");
reStr.append(cNonce);
reStr.append(":");
reStr.append(qop);
reStr.append(":");
}
reStr.append(HA2);
String RESPONSE = DigestUtils.md5DigestAsHex(reStr.toString().getBytes());
AuthorizationHeader authorizationHeader = sipFactory.createHeaderFactory().createAuthorizationHeader(scheme);
authorizationHeader.setUsername(parentPlatform.getDeviceGBId());
authorizationHeader.setRealm(realm);
authorizationHeader.setNonce(nonce);
authorizationHeader.setURI(requestURI);
authorizationHeader.setResponse(RESPONSE);
authorizationHeader.setAlgorithm("MD5");
if (qop != null) {
authorizationHeader.setQop(qop);
authorizationHeader.setCNonce(cNonce);
authorizationHeader.setNonceCount(1);
}
registerRequest.addHeader(authorizationHeader);
return registerRequest;

View File

@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.gb28181.transmit.cmd;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.UUID;
import javax.sip.InvalidArgumentException;
import javax.sip.PeerUnavailableException;
@ -167,109 +168,4 @@ public class SIPRequestHeaderProvider {
request.setContent(content, contentTypeHeader);
return request;
}
public Request createRegisterRequest(@NotNull ParentPlatform platform, long CSeq, String fromTag, String viaTag) throws ParseException, InvalidArgumentException, PeerUnavailableException {
Request request = null;
String sipAddress = sipConfig.getSipIp() + ":" + sipConfig.getSipPort();
//请求行
SipURI requestLine = sipFactory.createAddressFactory().createSipURI(platform.getDeviceGBId(),
platform.getServerIP() + ":" + platform.getServerPort());
//via
ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(platform.getServerIP(), platform.getServerPort(), platform.getTransport(), viaTag);
viaHeader.setRPort();
viaHeaders.add(viaHeader);
//from
SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(platform.getDeviceGBId(),sipAddress);
Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag);
//to
SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(platform.getDeviceGBId(),sipAddress);
Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress,null);
//callid
CallIdHeader callIdHeader = null;
if(platform.getTransport().equals("TCP")) {
callIdHeader = tcpSipProvider.getNewCallId();
}
if(platform.getTransport().equals("UDP")) {
callIdHeader = udpSipProvider.getNewCallId();
}
//Forwards
MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70);
//ceq
CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(CSeq, Request.REGISTER);
request = sipFactory.createMessageFactory().createRequest(requestLine, Request.REGISTER, callIdHeader,
cSeqHeader,fromHeader, toHeader, viaHeaders, maxForwards);
Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory()
.createSipURI(platform.getDeviceGBId(), sipAddress));
request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress));
ExpiresHeader expires = sipFactory.createHeaderFactory().createExpiresHeader(Integer.parseInt(platform.getExpires()));
request.addHeader(expires);
return request;
}
public Request createRegisterRequest(@NotNull ParentPlatform parentPlatform, String fromTag, String viaTag,
String callId, String realm, String nonce, String scheme) throws ParseException, PeerUnavailableException, InvalidArgumentException {
Request registerRequest = createRegisterRequest(parentPlatform, 2L, fromTag, viaTag);
CallIdHeader callIdHeader = (CallIdHeader)registerRequest.getHeader(CallIdHeader.NAME);
callIdHeader.setCallId(callId);
String uri = "sip:" + parentPlatform.getServerGBId() +
"@" + parentPlatform.getServerIP() +
":" + parentPlatform.getServerPort();
String HA1 = DigestUtils.md5DigestAsHex((parentPlatform.getDeviceGBId() + ":" + realm + ":" + parentPlatform.getPassword()).getBytes());
String HA2=DigestUtils.md5DigestAsHex((Request.REGISTER + ":" + uri).getBytes());
String RESPONSE = DigestUtils.md5DigestAsHex((HA1 + ":" + nonce + ":" + HA2).getBytes());
String authorizationHeaderContent = scheme + " username=\"" + parentPlatform.getDeviceGBId() + "\", " + "realm=\""
+ realm + "\", nonce=\"" + nonce + "\", uri=\"" + uri + "\", response=\"" + RESPONSE + "\"" + ", algorithm=MD5";
AuthorizationHeader authorizationHeader = sipFactory.createHeaderFactory().createAuthorizationHeader(authorizationHeaderContent);
registerRequest.addHeader(authorizationHeader);
return registerRequest;
}
// public Request createKeetpaliveMessageRequest(ParentPlatform parentPlatform, String content, String fromTag, String toTag, Object o) throws PeerUnavailableException, ParseException, InvalidArgumentException {
// Request request = null;
// // sipuri
// SipURI requestURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerIP() + ":" + parentPlatform.getServerPort());
// // via
// ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
// ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getSipIp(), sipConfig.getSipPort(),
// parentPlatform.getTransport(), null);
// viaHeader.setRPort();
// viaHeaders.add(viaHeader);
// // from
// SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(),
// sipConfig.getSipIp() + ":" + sipConfig.getSipPort());
// Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
// FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag);
// // to
// SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerGBDomain());
// Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
// ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, toTag);
// // callid
// CallIdHeader callIdHeader = parentPlatform.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
// : udpSipProvider.getNewCallId();
// // Forwards
// MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70);
// // ceq
// CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(1L, Request.MESSAGE);
//
// request = sipFactory.createMessageFactory().createRequest(requestURI, Request.MESSAGE, callIdHeader, cSeqHeader, fromHeader,
// toHeader, viaHeaders, maxForwards);
// ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "MANSCDP+xml");
// request.setContent(content, contentTypeHeader);
// return request;
// }
}

View File

@ -3,10 +3,13 @@ package com.genersoft.iot.vmp.gb28181.transmit.cmd.impl;
import com.genersoft.iot.vmp.conf.SipConfig;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch;
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderPlarformProvider;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderProvider;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@ -16,6 +19,7 @@ import org.springframework.stereotype.Component;
import javax.sip.*;
import javax.sip.header.CallIdHeader;
import javax.sip.header.WWWAuthenticateHeader;
import javax.sip.message.Request;
import java.text.ParseException;
import java.util.UUID;
@ -38,6 +42,12 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
@Autowired
private IVideoManagerStorager storager;
@Autowired
private IRedisCatchStorage redisCatchStorage;
@Autowired
private SipSubscribe sipSubscribe;
@Autowired
@Qualifier(value="tcpSipProvider")
private SipProvider tcpSipProvider;
@ -55,16 +65,29 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
}
@Override
public boolean register(ParentPlatform parentPlatform, @Nullable String callId, @Nullable String realm, @Nullable String nonce, @Nullable String scheme ) {
try {
Request request = null;
if (realm == null || nonce == null) {
request = headerProvider.createRegisterRequest(parentPlatform, 1L, null, null);
}else {
request = headerProvider.createRegisterRequest(parentPlatform, null, null, callId, realm, nonce, scheme);
public boolean unregister(ParentPlatform parentPlatform, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) {
parentPlatform.setExpires("0");
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getDeviceGBId());
if (parentPlatformCatch != null) {
parentPlatformCatch.setParentPlatform(parentPlatform);
redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
}
transmitRequest(parentPlatform, request);
return register(parentPlatform, null, null, errorEvent, okEvent);
}
@Override
public boolean register(ParentPlatform parentPlatform, @Nullable String callId, @Nullable WWWAuthenticateHeader www, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) {
try {
Request request = null;
if (www == null ) {
request = headerProviderPlarformProvider.createRegisterRequest(parentPlatform, 1L, null, null);
}else {
request = headerProviderPlarformProvider.createRegisterRequest(parentPlatform, null, null, callId, www);
}
transmitRequest(parentPlatform, request, errorEvent, okEvent);
return true;
} catch (ParseException e) {
e.printStackTrace();
@ -108,10 +131,29 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
}
private void transmitRequest(ParentPlatform parentPlatform, Request request) throws SipException {
transmitRequest(parentPlatform, request, null, null);
}
private void transmitRequest(ParentPlatform parentPlatform, Request request, SipSubscribe.Event errorEvent) throws SipException {
transmitRequest(parentPlatform, request, errorEvent, null);
}
private void transmitRequest(ParentPlatform parentPlatform, Request request, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) throws SipException {
if("TCP".equals(parentPlatform.getTransport())) {
tcpSipProvider.sendRequest(request);
} else if("UDP".equals(parentPlatform.getTransport())) {
udpSipProvider.sendRequest(request);
}
CallIdHeader callIdHeader = (CallIdHeader)request.getHeader(CallIdHeader.NAME);
// 添加错误订阅
if (errorEvent != null) {
sipSubscribe.addErrorSubscribe(callIdHeader.getCallId(), errorEvent);
}
// 添加订阅
if (okEvent != null) {
sipSubscribe.addOkSubscribe(callIdHeader.getCallId(), okEvent);
}
}
}

View File

@ -22,9 +22,11 @@ import javax.sip.ResponseEvent;
import javax.sip.address.Address;
import javax.sip.address.URI;
import javax.sip.header.CallIdHeader;
import javax.sip.header.ExpiresHeader;
import javax.sip.header.ToHeader;
import javax.sip.header.WWWAuthenticateHeader;
import javax.sip.message.Response;
import java.util.UUID;
/**
* @Description:Register响应处理器
@ -62,24 +64,28 @@ public class RegisterResponseProcessor implements ISIPResponseProcessor {
ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
SipUri uri = (SipUri)toHeader.getAddress().getURI();
String platformGBId = uri.getAuthority().getUser();
logger.info(String.format("收到 %s 的注册%S请求", platformGBId, response.getStatusCode() ));
ParentPlatform parentPlatform = storager.queryParentPlatById(platformGBId);
logger.info(String.format("收到 %s 的注册/注销%S响应", platformGBId, response.getStatusCode() ));
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(platformGBId);
if (parentPlatformCatch == null) {
logger.warn(String.format("收到 %s 的注册/注销%S请求, 但是平台缓存信息未查询到!!!", platformGBId, response.getStatusCode()));
return;
}
ParentPlatform parentPlatform = parentPlatformCatch.getParentPlatform();
if (parentPlatform == null) {
logger.warn(String.format("收到 %s 的注册%S请求, 但是平台信息未查询到!!!", platformGBId, response.getStatusCode()));
logger.warn(String.format("收到 %s 的注册/注销%S请求, 但是平台信息未查询到!!!", platformGBId, response.getStatusCode()));
return;
}
if (response.getStatusCode() == 401) {
WWWAuthenticateHeader www = (WWWAuthenticateHeader)response.getHeader(WWWAuthenticateHeader.NAME);
String realm = www.getRealm();
String nonce = www.getNonce();
String scheme = www.getScheme();
CallIdHeader callIdHeader = (CallIdHeader)response.getHeader(CallIdHeader.NAME);
String callId = callIdHeader.getCallId();
sipCommanderForPlatform.register(parentPlatform, callId, realm, nonce, scheme);
sipCommanderForPlatform.register(parentPlatform, callId, www, null, null);
}else if (response.getStatusCode() == 200){
// 注册成功
logger.info(String.format("%s 注册成功", platformGBId ));
@ -90,11 +96,8 @@ public class RegisterResponseProcessor implements ISIPResponseProcessor {
redisCatchStorage.updatePlatformKeepalive(parentPlatform);
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getDeviceGBId());
if (parentPlatformCatch == null) {
parentPlatformCatch = new ParentPlatformCatch();
parentPlatformCatch.setId(parentPlatform.getDeviceGBId());
}
parentPlatformCatch.setParentPlatform(parentPlatform);
redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
}
}

View File

@ -63,8 +63,14 @@ public interface IRedisCatchStorage {
ParentPlatformCatch queryPlatformCatchInfo(String platformGbId);
void delPlatformCatchInfo(String platformGbId);
void updatePlatformKeepalive(ParentPlatform parentPlatform);
void delPlatformKeepalive(String platformGbId);
void updatePlatformRegister(ParentPlatform parentPlatform);
void delPlatformRegister(String platformGbId);
}

View File

@ -189,4 +189,19 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
public ParentPlatformCatch queryPlatformCatchInfo(String platformGbId) {
return (ParentPlatformCatch)redis.get(VideoManagerConstants.PLATFORM_CATCH_PREFIX + platformGbId);
}
@Override
public void delPlatformCatchInfo(String platformGbId) {
redis.del(VideoManagerConstants.PLATFORM_CATCH_PREFIX + platformGbId);
}
@Override
public void delPlatformKeepalive(String platformGbId) {
redis.del(VideoManagerConstants.PLATFORM_KEEPLIVEKEY_PREFIX + platformGbId);
}
@Override
public void delPlatformRegister(String platformGbId) {
redis.del(VideoManagerConstants.PLATFORM_REGISTER_PREFIX + platformGbId);
}
}

View File

@ -4,6 +4,8 @@ import java.util.*;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper;
import com.genersoft.iot.vmp.storager.dao.DeviceMapper;
import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper;
@ -31,6 +33,10 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
@Autowired
private ParentPlatformMapper platformMapper;
@Autowired
private IRedisCatchStorage redisCatchStorage;
/**
@ -210,11 +216,21 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
@Override
public boolean updateParentPlatform(ParentPlatform parentPlatform) {
int result = 0;
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getDeviceGBId());
if ( platformMapper.getParentPlatById(parentPlatform.getDeviceGBId()) == null) {
result = platformMapper.addParentPlatform(parentPlatform);
if (parentPlatformCatch == null) {
parentPlatformCatch = new ParentPlatformCatch();
parentPlatformCatch.setParentPlatform(parentPlatform);
parentPlatformCatch.setId(parentPlatform.getDeviceGBId());
}
}else {
result = platformMapper.updateParentPlatform(parentPlatform);
}
// 更新缓存
parentPlatformCatch.setParentPlatform(parentPlatform);
redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
return result > 0;
}

View File

@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.vmanager.platform;
import com.alibaba.fastjson.JSONObject;
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
@ -24,6 +25,8 @@ public class PlatformController {
@Autowired
private IVideoManagerStorager storager;
@Autowired
private IRedisCatchStorage redisCatchStorage;
@Autowired
private ISIPCommanderForPlatform commanderForPlatform;
@ -75,7 +78,7 @@ public class PlatformController {
boolean updateResult = storager.updateParentPlatform(parentPlatform);
if (updateResult) {
commanderForPlatform.register(parentPlatform, null, null, null, null);
commanderForPlatform.register(parentPlatform);
return new ResponseEntity<>("success", HttpStatus.OK);
}else {
@ -94,7 +97,23 @@ public class PlatformController {
){
return new ResponseEntity<>("missing parameters", HttpStatus.BAD_REQUEST);
}
// 发送离线消息,
commanderForPlatform.unregister(parentPlatform, (event -> {
// 清空redis缓存
redisCatchStorage.delPlatformCatchInfo(parentPlatform.getDeviceGBId());
redisCatchStorage.delPlatformKeepalive(parentPlatform.getDeviceGBId());
redisCatchStorage.delPlatformRegister(parentPlatform.getDeviceGBId());
}), (event -> {
// 清空redis缓存
redisCatchStorage.delPlatformCatchInfo(parentPlatform.getDeviceGBId());
redisCatchStorage.delPlatformKeepalive(parentPlatform.getDeviceGBId());
redisCatchStorage.delPlatformRegister(parentPlatform.getDeviceGBId());
}));
boolean deleteResult = storager.deleteParentPlatform(parentPlatform);
if (deleteResult) {
return new ResponseEntity<>("success", HttpStatus.OK);
}else {