目录推送

This commit is contained in:
shikong 2023-09-13 13:56:44 +08:00
parent a5fed3e73b
commit 2fa97835fe
4 changed files with 45 additions and 30 deletions

View File

@ -22,8 +22,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Slf4j
@Tag(name = "设备信息")
@RestController
@ -59,8 +57,8 @@ public class DeviceController {
@Operation(summary = "根据国标id(20位) 查询指定设备信息")
@GetJson("/info/gbDeviceId")
public JsonResponse<List<MockingDevice>> infoByGbDeviceId(@RequestParam String gbDeviceId) {
List<MockingDevice> MockingDevice = deviceService.getDeviceByGbDeviceId(gbDeviceId);
public JsonResponse<MockingDevice> infoByGbDeviceId(@RequestParam String gbDeviceId) {
MockingDevice MockingDevice = deviceService.getDeviceByGbDeviceId(gbDeviceId).orElse(null);
return JsonResponse.success(MockingDevice);
}

View File

@ -5,6 +5,8 @@ import cn.skcks.docking.gb28181.mocking.core.sip.message.processor.message.reque
import cn.skcks.docking.gb28181.mocking.core.sip.message.processor.message.request.catalog.dto.CatalogItemDTO;
import cn.skcks.docking.gb28181.mocking.core.sip.message.processor.message.request.catalog.dto.CatalogRequestDTO;
import cn.skcks.docking.gb28181.mocking.core.sip.message.processor.message.request.catalog.dto.CatalogResponseDTO;
import cn.skcks.docking.gb28181.mocking.core.sip.request.SipRequestBuilder;
import cn.skcks.docking.gb28181.mocking.core.sip.sender.SipSender;
import cn.skcks.docking.gb28181.mocking.orm.mybatis.dynamic.model.MockingDevice;
import cn.skcks.docking.gb28181.mocking.service.device.DeviceService;
import gov.nist.javax.sip.message.SIPRequest;
@ -12,12 +14,16 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.sip.header.CallIdHeader;
import javax.sip.header.FromHeader;
import java.util.Collections;
import java.util.List;
@Slf4j
@RequiredArgsConstructor
@Component
public class CatalogCmdProcessor {
private final SipSender sender;
private final DeviceService deviceService;
public void process(SIPRequest request, byte[] content){
@ -25,15 +31,17 @@ public class CatalogCmdProcessor {
String sn = catalogRequestDTO.getSn();
String deviceId = catalogRequestDTO.getDeviceId();
List<MockingDevice> mockingDeviceList = deviceService.getDeviceByGbDeviceId(deviceId);
List<CatalogItemDTO> catalogItemDTOList = mockingDeviceList.stream()
.filter(MockingDevice::getEnable)
.map(item -> CatalogItemDTO.builder()
.deviceId(item.getGbChannelId())
.name(item.getName())
.address(item.getAddress())
.manufacturer(item.getName())
.build()).toList();
MockingDevice mockingDevice = deviceService.getDeviceByGbDeviceId(deviceId).orElse(null);
if(mockingDevice == null){
return;
}
CatalogItemDTO catalogItemDTO = CatalogItemDTO.builder()
.deviceId(mockingDevice.getGbChannelId())
.name(mockingDevice.getName())
.address(mockingDevice.getAddress())
.manufacturer(mockingDevice.getName())
.build();
List<CatalogItemDTO> catalogItemDTOList = Collections.singletonList(catalogItemDTO);
CatalogDeviceListDTO catalogDeviceListDTO = new CatalogDeviceListDTO(catalogItemDTOList.size(), catalogItemDTOList);
CatalogResponseDTO catalogResponseDTO = CatalogResponseDTO.builder()
.sn(sn)
@ -42,6 +50,13 @@ public class CatalogCmdProcessor {
.sumNum(Long.valueOf(catalogDeviceListDTO.getNum()))
.build();
long cSeq = request.getCSeq().getSeqNumber() + 1;
FromHeader fromHeader = request.getFromHeader();
sender.sendRequest((provider, ip, port)->{
CallIdHeader callIdHeader = provider.getNewCallId();
return SipRequestBuilder.createMessageRequest(mockingDevice,
ip, port, cSeq, XmlUtils.toXml(catalogResponseDTO), fromHeader.getTag(), callIdHeader);
});
}
}

View File

@ -1,10 +1,12 @@
package cn.skcks.docking.gb28181.mocking.core.sip.request;
import cn.skcks.docking.gb28181.core.sip.gb28181.constant.GB28181Constant;
import cn.skcks.docking.gb28181.core.sip.message.MessageHelper;
import cn.skcks.docking.gb28181.core.sip.utils.SipUtil;
import cn.skcks.docking.gb28181.mocking.config.sip.ServerConfig;
import cn.skcks.docking.gb28181.mocking.config.sip.SipConfig;
import cn.skcks.docking.gb28181.mocking.orm.mybatis.dynamic.model.MockingDevice;
import gov.nist.javax.sip.message.MessageFactoryImpl;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeansException;
@ -14,14 +16,11 @@ import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;
import javax.sip.InvalidArgumentException;
import javax.sip.PeerUnavailableException;
import javax.sip.SipFactory;
import javax.sip.address.Address;
import javax.sip.address.SipURI;
import javax.sip.header.*;
import javax.sip.message.Request;
import java.text.ParseException;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
@ -144,14 +143,15 @@ public class SipRequestBuilder implements ApplicationContextAware {
return request;
}
public static Request createMessageRequest(MockingDevice device, String ip, int port,String content, String viaTag, String fromTag, String toTag, CallIdHeader callIdHeader) throws ParseException, InvalidArgumentException, PeerUnavailableException {
@SneakyThrows
public static Request createMessageRequest(MockingDevice device, String ip, int port,long cSeq,String content, String fromTag, CallIdHeader callIdHeader) {
Request request;
String target = StringUtils.joinWith(":", serverConfig.getIp(), serverConfig.getPort());
// sip uri
SipURI requestURI = MessageHelper.createSipURI(serverConfig.getId(), target);
// via
List<ViaHeader> viaHeaders = getViaHeaders(serverConfig.getIp(), serverConfig.getPort(), sipConfig.getTransport(), viaTag);
List<ViaHeader> viaHeaders = getViaHeaders(serverConfig.getIp(), serverConfig.getPort(), sipConfig.getTransport(), null );
String from = StringUtils.joinWith(":", ip, port);
// from
@ -161,21 +161,23 @@ public class SipRequestBuilder implements ApplicationContextAware {
// to
SipURI toSipURI = MessageHelper.createSipURI(serverConfig.getId(), target);
Address toAddress = MessageHelper.createAddress(toSipURI);
ToHeader toHeader = MessageHelper.createToHeader(toAddress, toTag);
ToHeader toHeader = MessageHelper.createToHeader(toAddress, null);
// Forwards
MaxForwardsHeader maxForwards = MessageHelper.createMaxForwardsHeader(70);
// ceq
// CSeqHeader cSeqHeader = getSipFactory().createHeaderFactory().createCSeqHeader(getCSeq(), Request.MESSAGE);
CSeqHeader cSeqHeader = getSipFactory().createHeaderFactory().createCSeqHeader(cSeq, Request.MESSAGE);
// request = getSipFactory().createMessageFactory().createRequest(requestURI, Request.MESSAGE, callIdHeader, cSeqHeader, fromHeader,
// toHeader, viaHeaders, maxForwards);
// 使用 GB28181 默认编码 否则中文将会乱码
MessageFactoryImpl messageFactory = (MessageFactoryImpl) getSipFactory().createMessageFactory();
messageFactory.setDefaultContentEncodingCharset(GB28181Constant.CHARSET);
request = messageFactory.createRequest(requestURI, Request.MESSAGE, callIdHeader, cSeqHeader, fromHeader,
toHeader, viaHeaders, maxForwards);
// request.addHeader(SipUtil.createUserAgentHeader());
//
// ContentTypeHeader contentTypeHeader = getSipFactory().createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
// request.setContent(content, contentTypeHeader);
// return request;
return null;
request.addHeader(SipUtil.createUserAgentHeader());
ContentTypeHeader contentTypeHeader = getSipFactory().createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
request.setContent(content, contentTypeHeader);
return request;
}
}

View File

@ -36,8 +36,8 @@ public class DeviceService {
s.where(MockingDeviceDynamicSqlSupport.deviceCode, isEqualTo(deviceCode)));
}
public List<MockingDevice> getDeviceByGbDeviceId(String gbDeviceId){
return deviceMapper.select(s->
public Optional<MockingDevice> getDeviceByGbDeviceId(String gbDeviceId){
return deviceMapper.selectOne(s->
s.where(MockingDeviceDynamicSqlSupport.gbDeviceId,isEqualTo(gbDeviceId)));
}