优化设备状态查询

This commit is contained in:
lin 2026-01-13 17:15:29 +08:00
parent bca77f79cc
commit f396f5f29e
4 changed files with 24 additions and 14 deletions

View File

@ -82,7 +82,7 @@ public interface ISIPCommanderForPlatform {
* @param fromTag * @param fromTag
* @return * @return
*/ */
void deviceStatusResponse(Platform parentPlatform, String channelId, String sn, String fromTag, boolean status) throws SipException, InvalidArgumentException, ParseException; void deviceStatusResponse(Platform parentPlatform, String channelId, String sn, String fromTag, Boolean status) throws SipException, InvalidArgumentException, ParseException;
/** /**
* 向上级回复移动位置订阅消息 * 向上级回复移动位置订阅消息

View File

@ -329,22 +329,29 @@ public class SIPCommanderForPlatform implements ISIPCommanderForPlatform {
* @return * @return
*/ */
@Override @Override
public void deviceStatusResponse(Platform parentPlatform, String channelId, String sn, String fromTag, boolean status) throws SipException, InvalidArgumentException, ParseException { public void deviceStatusResponse(Platform parentPlatform, String channelId, String sn, String fromTag, Boolean status) throws SipException, InvalidArgumentException, ParseException {
if (parentPlatform == null) { if (parentPlatform == null) {
return ; return ;
} }
String statusStr = (status)?"ONLINE":"OFFLINE"; String statusStr = null;
if (status != null) {
statusStr = (status)?"ONLINE":"OFFLINE";
}
String characterSet = parentPlatform.getCharacterSet(); String characterSet = parentPlatform.getCharacterSet();
StringBuffer deviceStatusXml = new StringBuffer(600); StringBuffer deviceStatusXml = new StringBuffer(600);
deviceStatusXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\"?>\r\n") deviceStatusXml.append("<?xml version=\"1.0\" encoding=\"" + characterSet + "\"?>\r\n")
.append("<Response>\r\n") .append("<Response>\r\n")
.append("<CmdType>DeviceStatus</CmdType>\r\n") .append("<CmdType>DeviceStatus</CmdType>\r\n")
.append("<SN>" +sn + "</SN>\r\n") .append("<SN>" +sn + "</SN>\r\n")
.append("<DeviceID>" + channelId + "</DeviceID>\r\n") .append("<DeviceID>" + channelId + "</DeviceID>\r\n");
.append("<Result>OK</Result>\r\n") if (statusStr == null) {
deviceStatusXml.append("<Result>ERROR</Result>\r\n");
}else {
deviceStatusXml.append("<Result>OK</Result>\r\n")
.append("<Online>"+statusStr+"</Online>\r\n") .append("<Online>"+statusStr+"</Online>\r\n")
.append("<Status>OK</Status>\r\n") .append("<Status>OK</Status>\r\n");
.append("</Response>\r\n"); }
deviceStatusXml.append("</Response>\r\n");
CallIdHeader callIdHeader = sipSender.getNewCallIdHeader(parentPlatform.getDeviceIp(),parentPlatform.getTransport()); CallIdHeader callIdHeader = sipSender.getNewCallIdHeader(parentPlatform.getDeviceIp(),parentPlatform.getTransport());

View File

@ -86,14 +86,14 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
} else if (CmdType.CATALOG.equals(cmd)) { } else if (CmdType.CATALOG.equals(cmd)) {
processNotifyCatalogList(request, rootElement); processNotifyCatalogList(request, rootElement);
} else { } else {
log.info("接收到消息:" + cmd); log.info("接收到消息:{}", cmd);
Response response = getMessageFactory().createResponse(200, request); Response response = getMessageFactory().createResponse(200, request);
if (response != null) { if (response != null) {
ExpiresHeader expireHeader = getHeaderFactory().createExpiresHeader(30); ExpiresHeader expireHeader = getHeaderFactory().createExpiresHeader(30);
response.setExpires(expireHeader); response.setExpires(expireHeader);
} }
log.info("response : " + response); log.info("response : {}", response);
sipSender.transmitRequest(request.getLocalAddress().getHostAddress(), response); sipSender.transmitRequest(request.getLocalAddress().getHostAddress(), response);
} }
} catch (ParseException | SipException | InvalidArgumentException | DocumentException e) { } catch (ParseException | SipException | InvalidArgumentException | DocumentException e) {
@ -126,9 +126,6 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
.append("<DeviceID>").append(deviceId).append("</DeviceID>\r\n") .append("<DeviceID>").append(deviceId).append("</DeviceID>\r\n")
.append("<Result>OK</Result>\r\n") .append("<Result>OK</Result>\r\n")
.append("</Response>\r\n"); .append("</Response>\r\n");
try { try {
int expires = request.getExpires().getExpires(); int expires = request.getExpires().getExpires();
SIPResponse response = responseXmlAck(request, resultXml.toString(), platform, expires); SIPResponse response = responseXmlAck(request, resultXml.toString(), platform, expires);

View File

@ -73,7 +73,13 @@ public class DeviceStatusQueryMessageHandler extends SIPRequestProcessorParent i
} }
CommonGBChannel channel= channelService.queryOneWithPlatform(platform.getId(), channelId); CommonGBChannel channel= channelService.queryOneWithPlatform(platform.getId(), channelId);
if (channel ==null){ if (channel ==null){
log.error("[平台没有该通道的使用权限]:platformId"+platform.getServerGBId()+" deviceID:"+channelId); log.error("[平台没有该通道的使用权限]:platformId: {} deviceID:{}", platform.getServerGBId(), channelId);
// 上级平台查询本平台状态
try {
cmderFroPlatform.deviceStatusResponse(platform, channelId, sn, fromHeader.getTag(), null);
} catch (SipException | InvalidArgumentException | ParseException e) {
log.error("[命令发送失败] 国标级联 DeviceStatus查询回复: {}", e.getMessage());
}
return; return;
} }
try { try {