|
|
@@ -42,46 +42,48 @@ public class ManageDeviceLivestreamUrlServiceImpl implements IManageDeviceLivest
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public ManageDeviceLivestreamUrlDTO getUrl(ManageDeviceLivestreamUrlDTO deviceLivestreamUrlDTO) {
|
|
|
+ public ManageDeviceLivestreamUrlDTO getUrl(ManageDeviceLivestreamUrlDTO deviceLivestreamUrlDTO,String protocal) {
|
|
|
|
|
|
|
|
|
QueryWrapper<UserEntity> userWrapper = new QueryWrapper<>();
|
|
|
userWrapper.lambda().eq(UserEntity::getUserType, UserTypeEnum.API.getVal()).eq(UserEntity::getClientId, CustomConfiguration.clientId);
|
|
|
UserEntity userEntity = userMapper.selectOne(userWrapper);
|
|
|
if (userEntity == null) {
|
|
|
- log.debug("The user is null.");
|
|
|
- throw new RuntimeException ("The user is null.");
|
|
|
+ log.info("接口用户不存在,ClientId:" + CustomConfiguration.clientId);
|
|
|
+ throw new RuntimeException ("接口用户不存在,无法获取流媒体地址信息");
|
|
|
}
|
|
|
//密码解密
|
|
|
String password = DesUtil.getDecryptData(userEntity.getPassword(),userEntity.getSalt());
|
|
|
//获取token
|
|
|
- Map<String,String> tokenMap = CallSmsp.getSmspToken(userEntity.getUsername(),password);
|
|
|
+ Map<String,String> tokenMap = CallSmsp.getSmspToken(userEntity.getUsername(),password,protocal);
|
|
|
if(tokenMap.get("Token") == null) {
|
|
|
- log.debug("The smsp token is null.");
|
|
|
+ log.info("调用流媒体服务,获取token失败");
|
|
|
}
|
|
|
|
|
|
//获取rtmp地址
|
|
|
- List<ManageDeviceLivestreamUrlDTO> rtmpList = CallSmsp.getRtmp(tokenMap.get("Token"),deviceLivestreamUrlDTO.getDeviceSn(),deviceLivestreamUrlDTO.getPayload());
|
|
|
+ List<ManageDeviceLivestreamUrlDTO> rtmpList = CallSmsp.getRtmp(tokenMap.get("Token"),deviceLivestreamUrlDTO.getDeviceSn(),protocal);
|
|
|
ManageDeviceLivestreamUrlDTO rtmpDto = new ManageDeviceLivestreamUrlDTO();
|
|
|
|
|
|
//获取数据库中deviceSn对应的url信息
|
|
|
QueryWrapper<ManageDeviceLivestreamUrlEntity> wrapper = new QueryWrapper<>();
|
|
|
wrapper.lambda().eq(ManageDeviceLivestreamUrlEntity::getDeviceSn,deviceLivestreamUrlDTO.getDeviceSn())
|
|
|
.eq(ManageDeviceLivestreamUrlEntity::getWorkspaceId,deviceLivestreamUrlDTO.getWorkspaceId());
|
|
|
- List<ManageDeviceLivestreamUrlEntity> urlList = mapper.selectList(wrapper);
|
|
|
- if(urlList.size() <= 0 && rtmpList.size() <= 0 ){
|
|
|
- log.debug("The result is null.");
|
|
|
+ List<ManageDeviceLivestreamUrlEntity> urlListFromDB = mapper.selectList(wrapper);
|
|
|
+ if(urlListFromDB.size() <= 0 && rtmpList.size() <= 0 ){
|
|
|
+ log.info("调用流媒体服务,没有获取到流媒体推流拉流地址");
|
|
|
throw new RuntimeException (tokenMap.get("message"));
|
|
|
}
|
|
|
- List<Integer> urlL = urlList.stream()
|
|
|
+ List<Integer> urlL = urlListFromDB.stream()
|
|
|
.map(ManageDeviceLivestreamUrlEntity::getChannelId)
|
|
|
.collect(Collectors.toList());
|
|
|
- //过滤payloadIndex
|
|
|
- List<ManageDeviceLivestreamUrlEntity> filterIndexList = urlList.stream().filter(channelData -> deviceLivestreamUrlDTO.getPayloadIndex().equals(channelData.getPayloadIndex()))
|
|
|
+ //筛选数据库中payloadIndex相同的记录
|
|
|
+ List<ManageDeviceLivestreamUrlEntity> filterIndexList =
|
|
|
+ urlListFromDB.stream().filter(channelData -> deviceLivestreamUrlDTO.getPayloadIndex().equals(channelData.getPayloadIndex()))
|
|
|
.collect(Collectors.toList());
|
|
|
if (filterIndexList.size() > 0) {
|
|
|
- //过滤channelId
|
|
|
- List<ManageDeviceLivestreamUrlDTO> channelList = rtmpList.stream().filter(channelData -> filterIndexList.get(0).getChannelId().equals(channelData.getChannelId()))
|
|
|
+ //筛选数据库中channelId相同的记录
|
|
|
+ List<ManageDeviceLivestreamUrlDTO> channelList =
|
|
|
+ rtmpList.stream().filter(channelData -> filterIndexList.get(0).getChannelId().equals(channelData.getChannelId()))
|
|
|
.collect(Collectors.toList());
|
|
|
if (channelList.size() > 0) {
|
|
|
update(filterIndexList,channelList);
|
|
|
@@ -89,7 +91,7 @@ public class ManageDeviceLivestreamUrlServiceImpl implements IManageDeviceLivest
|
|
|
rtmpDto.setWebRtcUrl(channelList.get(0).getWebRtcUrl());
|
|
|
} else {
|
|
|
if(rtmpList.size() > 0) {
|
|
|
- //过滤channelId
|
|
|
+ //筛选数据库中不存在的记录
|
|
|
channelList = rtmpList.stream().filter(channelData -> !urlL.contains(channelData.getChannelId()))
|
|
|
.collect(Collectors.toList());
|
|
|
update(filterIndexList,channelList);
|
|
|
@@ -106,17 +108,16 @@ public class ManageDeviceLivestreamUrlServiceImpl implements IManageDeviceLivest
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- //过滤channelId
|
|
|
- List<ManageDeviceLivestreamUrlDTO> channelList = rtmpList;
|
|
|
-
|
|
|
- if(urlList.size() > 0) {
|
|
|
- channelList = rtmpList.stream().filter(channelData -> !urlL.contains(channelData.getChannelId()))
|
|
|
- .collect(Collectors.toList());
|
|
|
- }
|
|
|
+ //数据库中不存在
|
|
|
+ List<ManageDeviceLivestreamUrlDTO> channelList =
|
|
|
+ rtmpList.stream().filter(channelData -> !urlL.contains(channelData.getChannelId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
ManageDeviceLivestreamUrlEntity urlEntity = new ManageDeviceLivestreamUrlEntity();
|
|
|
if(channelList.size() > 0) {
|
|
|
- //dto转entity
|
|
|
- BeanUtils.copyProperties(deviceLivestreamUrlDTO,urlEntity);
|
|
|
+ urlEntity.setDeviceSn(deviceLivestreamUrlDTO.getDeviceSn());
|
|
|
+ urlEntity.setWorkspaceId(deviceLivestreamUrlDTO.getWorkspaceId());
|
|
|
+ urlEntity.setPayload(deviceLivestreamUrlDTO.getPayload());
|
|
|
+ urlEntity.setPayloadIndex(deviceLivestreamUrlDTO.getPayloadIndex());
|
|
|
//存库Rtmp
|
|
|
urlEntity.setSubType(DeviceSubTypeEnum.ONE.getSubType());
|
|
|
urlEntity.setUrlType(LiveUrlTypeEnum.RTMP.getVal());
|
|
|
@@ -140,11 +141,17 @@ public class ManageDeviceLivestreamUrlServiceImpl implements IManageDeviceLivest
|
|
|
|
|
|
private void update(List<ManageDeviceLivestreamUrlEntity> entitys,List<ManageDeviceLivestreamUrlDTO> dtos) {
|
|
|
for(ManageDeviceLivestreamUrlEntity url : entitys) {
|
|
|
- url.setChannelId(dtos.get(0).getChannelId());
|
|
|
- if (url.getUrlType().equals(LiveUrlTypeEnum.RTMP.getVal())) {
|
|
|
+ Integer channelId = dtos.get(0).getChannelId();
|
|
|
+ if (url.getUrlType().equals(LiveUrlTypeEnum.RTMP.getVal())
|
|
|
+ && (!url.getChannelId().equals(channelId)
|
|
|
+ || !url.getUrl().equals(dtos.get(0).getRtmpUrl()))) {
|
|
|
+ url.setChannelId(channelId);
|
|
|
url.setUrl(dtos.get(0).getRtmpUrl());
|
|
|
mapper.updateById(url);
|
|
|
- } else if(url.getUrlType().equals(LiveUrlTypeEnum.WEBRTC.getVal())) {
|
|
|
+ } else if(url.getUrlType().equals(LiveUrlTypeEnum.WEBRTC.getVal())
|
|
|
+ && (!url.getChannelId().equals(channelId)
|
|
|
+ || !url.getUrl().equals(dtos.get(0).getWebRtcUrl()))) {
|
|
|
+ url.setChannelId(channelId);
|
|
|
url.setUrl(dtos.get(0).getWebRtcUrl());
|
|
|
mapper.updateById(url);
|
|
|
}
|