|
|
@@ -4,27 +4,22 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.dji.sample.common.smsp.CallSmsp;
|
|
|
import com.dji.sample.common.util.DesUtil;
|
|
|
import com.dji.sample.configuration.CustomConfiguration;
|
|
|
-import com.dji.sample.manage.dao.IDevicePayloadMapper;
|
|
|
import com.dji.sample.manage.dao.IManageDeviceLivestreamUrlMapper;
|
|
|
import com.dji.sample.manage.dao.IUserMapper;
|
|
|
import com.dji.sample.manage.model.dto.ManageDeviceLivestreamUrlDTO;
|
|
|
import com.dji.sample.manage.model.dto.RtmpUrlDTO;
|
|
|
-import com.dji.sample.manage.model.entity.DevicePayloadEntity;
|
|
|
import com.dji.sample.manage.model.entity.ManageDeviceLivestreamUrlEntity;
|
|
|
import com.dji.sample.manage.model.entity.UserEntity;
|
|
|
import com.dji.sample.manage.model.enums.LiveUrlTypeEnum;
|
|
|
import com.dji.sample.manage.model.enums.UserTypeEnum;
|
|
|
import com.dji.sample.manage.service.IManageDeviceLivestreamUrlService;
|
|
|
import com.dji.sdk.cloudapi.device.DeviceSubTypeEnum;
|
|
|
-import com.dji.sdk.common.HttpResultResponse;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -43,57 +38,58 @@ 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地址
|
|
|
- RtmpUrlDTO rtmpUrlDTO = CallSmsp.getRtmp(tokenMap.get("Token"),deviceLivestreamUrlDTO.getDeviceSn());
|
|
|
+ RtmpUrlDTO rtmpUrlDTO = 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);
|
|
|
+ List<ManageDeviceLivestreamUrlEntity> urlListFromDB = mapper.selectList(wrapper);
|
|
|
|
|
|
- if(urlList.size() == 0 && rtmpUrlDTO.getMessage() != null ){
|
|
|
- log.debug("The result is null.");
|
|
|
+ if(urlListFromDB.size() == 0 && rtmpUrlDTO.getMessage() != null ){
|
|
|
if(tokenMap.get("message") != null) {
|
|
|
throw new RuntimeException (tokenMap.get("message"));
|
|
|
}
|
|
|
if(rtmpUrlDTO.getMessage() != null) {
|
|
|
throw new RuntimeException (rtmpUrlDTO.getMessage());
|
|
|
}
|
|
|
- throw new RuntimeException ("The result is null.");
|
|
|
+ throw new RuntimeException ("获取推流拉流地址异常,请联系技术人员确认!");
|
|
|
}
|
|
|
List<ManageDeviceLivestreamUrlDTO> rtmpList = new ArrayList<>();
|
|
|
if (rtmpUrlDTO.getList().size() > 0) {
|
|
|
rtmpList = rtmpUrlDTO.getList();
|
|
|
}
|
|
|
- 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);
|
|
|
@@ -101,7 +97,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);
|
|
|
@@ -118,17 +114,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());
|
|
|
@@ -144,7 +139,7 @@ public class ManageDeviceLivestreamUrlServiceImpl implements IManageDeviceLivest
|
|
|
rtmpDto.setRtmpUrl(channelList.get(0).getRtmpUrl());
|
|
|
rtmpDto.setWebRtcUrl(channelList.get(0).getWebRtcUrl());
|
|
|
} else {
|
|
|
- throw new RuntimeException("the url is null.");
|
|
|
+ throw new RuntimeException("没有获取到可以使用的推流和拉流地址");
|
|
|
}
|
|
|
}
|
|
|
return rtmpDto;
|
|
|
@@ -163,4 +158,5 @@ public class ManageDeviceLivestreamUrlServiceImpl implements IManageDeviceLivest
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|