Merge branch 'refs/heads/master' into dev/1078-newUI

This commit is contained in:
648540858
2025-05-13 21:22:01 +08:00
13 changed files with 129 additions and 130 deletions

View File

@@ -1,27 +1,16 @@
package com.genersoft.iot.vmp.gb28181.bean;
import lombok.Data;
import javax.sip.Dialog;
import java.util.EventObject;
public class DeviceNotFoundEvent extends EventObject {
@Data
public class DeviceNotFoundEvent {
private String callId;
/**
* Constructs a prototypical Event.
*
* @param dialog
* @throws IllegalArgumentException if source is null.
*/
public DeviceNotFoundEvent(Dialog dialog) {
super(dialog);
}
public String getCallId() {
return callId;
}
public void setCallId(String callId) {
public DeviceNotFoundEvent(String callId) {
this.callId = callId;
}
}

View File

@@ -83,17 +83,17 @@ public class SipSubscribe {
failedResult
}
public static class EventResult<EventObject>{
public static class EventResult<T>{
public int statusCode;
public EventResultType type;
public String msg;
public String callId;
public EventObject event;
public T event;
public EventResult() {
}
public EventResult(EventObject event) {
public EventResult(T event) {
this.event = event;
if (event instanceof ResponseEvent) {
ResponseEvent responseEvent = (ResponseEvent)event;

View File

@@ -120,85 +120,83 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
List<DeviceChannel> updateChannels = new ArrayList<>();
HashMap<String, DeviceChannel> channelsInStore = new HashMap<>();
int result = 0;
if (channels != null && !channels.isEmpty()) {
List<DeviceChannel> channelList = channelMapper.queryChannelsByDeviceDbId(device.getId());
if (channelList.isEmpty()) {
for (DeviceChannel channel : channels) {
channel.setDataDeviceId(device.getId());
InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, channel.getId());
if (inviteInfo != null && inviteInfo.getStreamInfo() != null) {
channel.setStreamId(inviteInfo.getStreamInfo().getStream());
}
String now = DateUtil.getNow();
List<DeviceChannel> channelList = channelMapper.queryChannelsByDeviceDbId(device.getId());
if (channelList.isEmpty()) {
for (DeviceChannel channel : channels) {
channel.setDataDeviceId(device.getId());
InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, channel.getId());
if (inviteInfo != null && inviteInfo.getStreamInfo() != null) {
channel.setStreamId(inviteInfo.getStreamInfo().getStream());
}
String now = DateUtil.getNow();
channel.setUpdateTime(now);
channel.setCreateTime(now);
addChannels.add(channel);
}
}else {
for (DeviceChannel deviceChannel : channelList) {
channelsInStore.put(deviceChannel.getDataDeviceId() + deviceChannel.getDeviceId(), deviceChannel);
}
for (DeviceChannel channel : channels) {
InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, channel.getId());
if (inviteInfo != null && inviteInfo.getStreamInfo() != null) {
channel.setStreamId(inviteInfo.getStreamInfo().getStream());
}
String now = DateUtil.getNow();
channel.setUpdateTime(now);
DeviceChannel deviceChannelInDb = channelsInStore.get(channel.getDataDeviceId() + channel.getDeviceId());
if ( deviceChannelInDb != null) {
channel.setId(deviceChannelInDb.getId());
channel.setUpdateTime(now);
updateChannels.add(channel);
}else {
channel.setCreateTime(now);
channel.setUpdateTime(now);
addChannels.add(channel);
}
}else {
for (DeviceChannel deviceChannel : channelList) {
channelsInStore.put(deviceChannel.getDataDeviceId() + deviceChannel.getDeviceId(), deviceChannel);
}
for (DeviceChannel channel : channels) {
InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, channel.getId());
if (inviteInfo != null && inviteInfo.getStreamInfo() != null) {
channel.setStreamId(inviteInfo.getStreamInfo().getStream());
}
String now = DateUtil.getNow();
channel.setUpdateTime(now);
DeviceChannel deviceChannelInDb = channelsInStore.get(channel.getDataDeviceId() + channel.getDeviceId());
if ( deviceChannelInDb != null) {
channel.setId(deviceChannelInDb.getId());
channel.setUpdateTime(now);
updateChannels.add(channel);
}else {
channel.setCreateTime(now);
channel.setUpdateTime(now);
addChannels.add(channel);
}
}
}
Set<String> channelSet = new HashSet<>();
// 滤重
List<DeviceChannel> addChannelList = new ArrayList<>();
List<DeviceChannel> updateChannelList = new ArrayList<>();
addChannels.forEach(channel -> {
if (channelSet.add(channel.getDeviceId())) {
addChannelList.add(channel);
}
});
channelSet.clear();
updateChannels.forEach(channel -> {
if (channelSet.add(channel.getDeviceId())) {
updateChannelList.add(channel);
}
});
}
Set<String> channelSet = new HashSet<>();
// 滤重
List<DeviceChannel> addChannelList = new ArrayList<>();
List<DeviceChannel> updateChannelList = new ArrayList<>();
addChannels.forEach(channel -> {
if (channelSet.add(channel.getDeviceId())) {
addChannelList.add(channel);
}
});
channelSet.clear();
updateChannels.forEach(channel -> {
if (channelSet.add(channel.getDeviceId())) {
updateChannelList.add(channel);
}
});
int limitCount = 500;
if (!addChannelList.isEmpty()) {
if (addChannelList.size() > limitCount) {
for (int i = 0; i < addChannelList.size(); i += limitCount) {
int toIndex = i + limitCount;
if (i + limitCount > addChannelList.size()) {
toIndex = addChannelList.size();
}
result += channelMapper.batchAdd(addChannelList.subList(i, toIndex));
int limitCount = 500;
if (!addChannelList.isEmpty()) {
if (addChannelList.size() > limitCount) {
for (int i = 0; i < addChannelList.size(); i += limitCount) {
int toIndex = i + limitCount;
if (i + limitCount > addChannelList.size()) {
toIndex = addChannelList.size();
}
}else {
result += channelMapper.batchAdd(addChannelList);
result += channelMapper.batchAdd(addChannelList.subList(i, toIndex));
}
}else {
result += channelMapper.batchAdd(addChannelList);
}
if (!updateChannelList.isEmpty()) {
if (updateChannelList.size() > limitCount) {
for (int i = 0; i < updateChannelList.size(); i += limitCount) {
int toIndex = i + limitCount;
if (i + limitCount > updateChannelList.size()) {
toIndex = updateChannelList.size();
}
result += channelMapper.batchUpdate(updateChannelList.subList(i, toIndex));
}
if (!updateChannelList.isEmpty()) {
if (updateChannelList.size() > limitCount) {
for (int i = 0; i < updateChannelList.size(); i += limitCount) {
int toIndex = i + limitCount;
if (i + limitCount > updateChannelList.size()) {
toIndex = updateChannelList.size();
}
}else {
result += channelMapper.batchUpdate(updateChannelList);
result += channelMapper.batchUpdate(updateChannelList.subList(i, toIndex));
}
}else {
result += channelMapper.batchUpdate(updateChannelList);
}
}
return result;

View File

@@ -293,7 +293,7 @@ public class DeviceServiceImpl implements IDeviceService {
}
}
}else {
log.info("[移除移动位置订阅]失败,设备已经离线 : {}", device.getDeviceId());
log.info("[移除目录订阅订阅]失败,设备已经离线 : {}", device.getDeviceId());
if (callback != null) {
callback.run(false);
}

View File

@@ -70,10 +70,10 @@ public class SIPSender {
}
}
CallIdHeader callIdHeader = (CallIdHeader) message.getHeader(CallIdHeader.NAME);
CSeqHeader cSeqHeader = (CSeqHeader) message.getHeader(CSeqHeader.NAME);
String key = callIdHeader.getCallId() + cSeqHeader.getSeqNumber();
if (okEvent != null || errorEvent != null) {
CallIdHeader callIdHeader = (CallIdHeader) message.getHeader(CallIdHeader.NAME);
CSeqHeader cSeqHeader = (CSeqHeader) message.getHeader(CSeqHeader.NAME);
String key = callIdHeader.getCallId() + cSeqHeader.getSeqNumber();
SipEvent sipEvent = SipEvent.getInstance(key, eventResult -> {
sipSubscribe.removeSubscribe(key);
if(okEvent != null) {
@@ -87,30 +87,34 @@ public class SIPSender {
}), timeout == null ? sipConfig.getTimeout() : timeout);
sipSubscribe.addSubscribe(key, sipEvent);
}
try {
if ("TCP".equals(transport)) {
SipProviderImpl tcpSipProvider = sipLayer.getTcpSipProvider(ip);
if (tcpSipProvider == null) {
log.error("[发送信息失败] 未找到tcp://{}的监听信息", ip);
return;
}
if (message instanceof Request) {
tcpSipProvider.sendRequest((Request) message);
} else if (message instanceof Response) {
tcpSipProvider.sendResponse((Response) message);
}
if ("TCP".equals(transport)) {
SipProviderImpl tcpSipProvider = sipLayer.getTcpSipProvider(ip);
if (tcpSipProvider == null) {
log.error("[发送信息失败] 未找到tcp://{}的监听信息", ip);
return;
}
if (message instanceof Request) {
tcpSipProvider.sendRequest((Request) message);
} else if (message instanceof Response) {
tcpSipProvider.sendResponse((Response) message);
}
} else if ("UDP".equals(transport)) {
SipProviderImpl sipProvider = sipLayer.getUdpSipProvider(ip);
if (sipProvider == null) {
log.error("[发送信息失败] 未找到udp://{}的监听信息", ip);
return;
}
if (message instanceof Request) {
sipProvider.sendRequest((Request) message);
} else if (message instanceof Response) {
sipProvider.sendResponse((Response) message);
} else if ("UDP".equals(transport)) {
SipProviderImpl sipProvider = sipLayer.getUdpSipProvider(ip);
if (sipProvider == null) {
log.error("[发送信息失败] 未找到udp://{}的监听信息", ip);
return;
}
if (message instanceof Request) {
sipProvider.sendRequest((Request) message);
} else if (message instanceof Response) {
sipProvider.sendResponse((Response) message);
}
}
}catch (SipException e) {
sipSubscribe.removeSubscribe(key);
throw e;
}
}

View File

@@ -70,8 +70,6 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen
/**
* 收到注册请求 处理
*
* @param evt
*/
@Override
public void process(RequestEvent evt) {

View File

@@ -98,8 +98,7 @@ public class MessageRequestProcessor extends SIPRequestProcessorParent implement
log.warn("[设备未找到 ]deviceId: {}, callId: {}", deviceId, callIdHeader.getCallId());
SipEvent sipEvent = sipSubscribe.getSubscribe(callIdHeader.getCallId() + cSeqHeader.getSeqNumber());
if (sipEvent != null && sipEvent.getErrorEvent() != null){
DeviceNotFoundEvent deviceNotFoundEvent = new DeviceNotFoundEvent(evt.getDialog());
deviceNotFoundEvent.setCallId(callIdHeader.getCallId());
DeviceNotFoundEvent deviceNotFoundEvent = new DeviceNotFoundEvent(callIdHeader.getCallId());
SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(deviceNotFoundEvent);
sipEvent.getErrorEvent().response(eventResult);
}