目录推送

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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List;
@Slf4j @Slf4j
@Tag(name = "设备信息") @Tag(name = "设备信息")
@RestController @RestController
@ -59,8 +57,8 @@ public class DeviceController {
@Operation(summary = "根据国标id(20位) 查询指定设备信息") @Operation(summary = "根据国标id(20位) 查询指定设备信息")
@GetJson("/info/gbDeviceId") @GetJson("/info/gbDeviceId")
public JsonResponse<List<MockingDevice>> infoByGbDeviceId(@RequestParam String gbDeviceId) { public JsonResponse<MockingDevice> infoByGbDeviceId(@RequestParam String gbDeviceId) {
List<MockingDevice> MockingDevice = deviceService.getDeviceByGbDeviceId(gbDeviceId); MockingDevice MockingDevice = deviceService.getDeviceByGbDeviceId(gbDeviceId).orElse(null);
return JsonResponse.success(MockingDevice); 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.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.CatalogRequestDTO;
import cn.skcks.docking.gb28181.mocking.core.sip.message.processor.message.request.catalog.dto.CatalogResponseDTO; 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.orm.mybatis.dynamic.model.MockingDevice;
import cn.skcks.docking.gb28181.mocking.service.device.DeviceService; import cn.skcks.docking.gb28181.mocking.service.device.DeviceService;
import gov.nist.javax.sip.message.SIPRequest; import gov.nist.javax.sip.message.SIPRequest;
@ -12,12 +14,16 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.sip.header.CallIdHeader;
import javax.sip.header.FromHeader;
import java.util.Collections;
import java.util.List; import java.util.List;
@Slf4j @Slf4j
@RequiredArgsConstructor @RequiredArgsConstructor
@Component @Component
public class CatalogCmdProcessor { public class CatalogCmdProcessor {
private final SipSender sender;
private final DeviceService deviceService; private final DeviceService deviceService;
public void process(SIPRequest request, byte[] content){ public void process(SIPRequest request, byte[] content){
@ -25,15 +31,17 @@ public class CatalogCmdProcessor {
String sn = catalogRequestDTO.getSn(); String sn = catalogRequestDTO.getSn();
String deviceId = catalogRequestDTO.getDeviceId(); String deviceId = catalogRequestDTO.getDeviceId();
List<MockingDevice> mockingDeviceList = deviceService.getDeviceByGbDeviceId(deviceId); MockingDevice mockingDevice = deviceService.getDeviceByGbDeviceId(deviceId).orElse(null);
List<CatalogItemDTO> catalogItemDTOList = mockingDeviceList.stream() if(mockingDevice == null){
.filter(MockingDevice::getEnable) return;
.map(item -> CatalogItemDTO.builder() }
.deviceId(item.getGbChannelId()) CatalogItemDTO catalogItemDTO = CatalogItemDTO.builder()
.name(item.getName()) .deviceId(mockingDevice.getGbChannelId())
.address(item.getAddress()) .name(mockingDevice.getName())
.manufacturer(item.getName()) .address(mockingDevice.getAddress())
.build()).toList(); .manufacturer(mockingDevice.getName())
.build();
List<CatalogItemDTO> catalogItemDTOList = Collections.singletonList(catalogItemDTO);
CatalogDeviceListDTO catalogDeviceListDTO = new CatalogDeviceListDTO(catalogItemDTOList.size(), catalogItemDTOList); CatalogDeviceListDTO catalogDeviceListDTO = new CatalogDeviceListDTO(catalogItemDTOList.size(), catalogItemDTOList);
CatalogResponseDTO catalogResponseDTO = CatalogResponseDTO.builder() CatalogResponseDTO catalogResponseDTO = CatalogResponseDTO.builder()
.sn(sn) .sn(sn)
@ -42,6 +50,13 @@ public class CatalogCmdProcessor {
.sumNum(Long.valueOf(catalogDeviceListDTO.getNum())) .sumNum(Long.valueOf(catalogDeviceListDTO.getNum()))
.build(); .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; 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.message.MessageHelper;
import cn.skcks.docking.gb28181.core.sip.utils.SipUtil; 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.ServerConfig;
import cn.skcks.docking.gb28181.mocking.config.sip.SipConfig; import cn.skcks.docking.gb28181.mocking.config.sip.SipConfig;
import cn.skcks.docking.gb28181.mocking.orm.mybatis.dynamic.model.MockingDevice; import cn.skcks.docking.gb28181.mocking.orm.mybatis.dynamic.model.MockingDevice;
import gov.nist.javax.sip.message.MessageFactoryImpl;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
@ -14,14 +16,11 @@ import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils; import org.springframework.util.DigestUtils;
import javax.sip.InvalidArgumentException;
import javax.sip.PeerUnavailableException;
import javax.sip.SipFactory; import javax.sip.SipFactory;
import javax.sip.address.Address; import javax.sip.address.Address;
import javax.sip.address.SipURI; import javax.sip.address.SipURI;
import javax.sip.header.*; import javax.sip.header.*;
import javax.sip.message.Request; import javax.sip.message.Request;
import java.text.ParseException;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -144,14 +143,15 @@ public class SipRequestBuilder implements ApplicationContextAware {
return request; 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; Request request;
String target = StringUtils.joinWith(":", serverConfig.getIp(), serverConfig.getPort()); String target = StringUtils.joinWith(":", serverConfig.getIp(), serverConfig.getPort());
// sip uri // sip uri
SipURI requestURI = MessageHelper.createSipURI(serverConfig.getId(), target); SipURI requestURI = MessageHelper.createSipURI(serverConfig.getId(), target);
// via // 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); String from = StringUtils.joinWith(":", ip, port);
// from // from
@ -161,21 +161,23 @@ public class SipRequestBuilder implements ApplicationContextAware {
// to // to
SipURI toSipURI = MessageHelper.createSipURI(serverConfig.getId(), target); SipURI toSipURI = MessageHelper.createSipURI(serverConfig.getId(), target);
Address toAddress = MessageHelper.createAddress(toSipURI); Address toAddress = MessageHelper.createAddress(toSipURI);
ToHeader toHeader = MessageHelper.createToHeader(toAddress, toTag); ToHeader toHeader = MessageHelper.createToHeader(toAddress, null);
// Forwards // Forwards
MaxForwardsHeader maxForwards = MessageHelper.createMaxForwardsHeader(70); MaxForwardsHeader maxForwards = MessageHelper.createMaxForwardsHeader(70);
// ceq // 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, // 使用 GB28181 默认编码 否则中文将会乱码
// toHeader, viaHeaders, maxForwards); 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()); request.addHeader(SipUtil.createUserAgentHeader());
//
// ContentTypeHeader contentTypeHeader = getSipFactory().createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml"); ContentTypeHeader contentTypeHeader = getSipFactory().createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
// request.setContent(content, contentTypeHeader); request.setContent(content, contentTypeHeader);
// return request; return request;
return null;
} }
} }

View File

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