|
@@ -11,7 +11,9 @@ import com.dji.sample.manage.model.entity.DevicePayloadEntity;
|
|
|
import com.dji.sample.manage.model.entity.ManageDeviceLivestreamUrlEntity;
|
|
import com.dji.sample.manage.model.entity.ManageDeviceLivestreamUrlEntity;
|
|
|
import com.dji.sample.manage.model.entity.UserEntity;
|
|
import com.dji.sample.manage.model.entity.UserEntity;
|
|
|
import com.dji.sample.manage.model.enums.LiveUrlTypeEnum;
|
|
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.sample.manage.service.IManageDeviceLivestreamUrlService;
|
|
|
|
|
+import com.dji.sdk.cloudapi.device.DeviceSubTypeEnum;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -19,6 +21,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -42,10 +45,10 @@ public class ManageDeviceLivestreamUrlServiceImpl implements IManageDeviceLivest
|
|
|
|
|
|
|
|
|
|
|
|
|
QueryWrapper<UserEntity> userWrapper = new QueryWrapper<>();
|
|
QueryWrapper<UserEntity> userWrapper = new QueryWrapper<>();
|
|
|
- userWrapper.lambda().eq(UserEntity::getUserType,3).eq(UserEntity::getClientId,clientId);
|
|
|
|
|
|
|
+ userWrapper.lambda().eq(UserEntity::getUserType, UserTypeEnum.API.getVal()).eq(UserEntity::getClientId,clientId);
|
|
|
UserEntity userEntity = userMapper.selectOne(userWrapper);
|
|
UserEntity userEntity = userMapper.selectOne(userWrapper);
|
|
|
if (userEntity == null) {
|
|
if (userEntity == null) {
|
|
|
- log.debug("The user is already null.");
|
|
|
|
|
|
|
+ log.debug("The user is null.");
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
//密码解密
|
|
//密码解密
|
|
@@ -53,11 +56,13 @@ public class ManageDeviceLivestreamUrlServiceImpl implements IManageDeviceLivest
|
|
|
//获取token
|
|
//获取token
|
|
|
String token = CallSmsp.getSmspToken(userEntity.getUsername(),password);
|
|
String token = CallSmsp.getSmspToken(userEntity.getUsername(),password);
|
|
|
if(token == null) {
|
|
if(token == null) {
|
|
|
- log.debug("The smsp token is already null.");
|
|
|
|
|
|
|
+ log.debug("The smsp token is null.");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//获取rtmp地址
|
|
//获取rtmp地址
|
|
|
- ManageDeviceLivestreamUrlDTO rtmpDto = CallSmsp.getRtmp(token,deviceLivestreamUrlDTO.getDeviceSn(),deviceLivestreamUrlDTO.getPayload());
|
|
|
|
|
|
|
+ List<ManageDeviceLivestreamUrlDTO> rtmpList = CallSmsp.getRtmp(token,deviceLivestreamUrlDTO.getDeviceSn(),deviceLivestreamUrlDTO.getPayload());
|
|
|
|
|
+ ManageDeviceLivestreamUrlDTO rtmpDto = new ManageDeviceLivestreamUrlDTO();
|
|
|
|
|
+ //获取payload信息
|
|
|
QueryWrapper<DevicePayloadEntity> payloadWrapper = new QueryWrapper<>();
|
|
QueryWrapper<DevicePayloadEntity> payloadWrapper = new QueryWrapper<>();
|
|
|
payloadWrapper.lambda().eq(DevicePayloadEntity::getPayloadIndex,deviceLivestreamUrlDTO.getPayload())
|
|
payloadWrapper.lambda().eq(DevicePayloadEntity::getPayloadIndex,deviceLivestreamUrlDTO.getPayload())
|
|
|
.eq(DevicePayloadEntity::getDeviceSn,deviceLivestreamUrlDTO.getDeviceSn());
|
|
.eq(DevicePayloadEntity::getDeviceSn,deviceLivestreamUrlDTO.getDeviceSn());
|
|
@@ -65,45 +70,82 @@ public class ManageDeviceLivestreamUrlServiceImpl implements IManageDeviceLivest
|
|
|
|
|
|
|
|
deviceLivestreamUrlDTO.setPayload(payloadEntity.getPayloadName());
|
|
deviceLivestreamUrlDTO.setPayload(payloadEntity.getPayloadName());
|
|
|
deviceLivestreamUrlDTO.setPayloadIndex(payloadEntity.getPayloadIndex());
|
|
deviceLivestreamUrlDTO.setPayloadIndex(payloadEntity.getPayloadIndex());
|
|
|
- deviceLivestreamUrlDTO.setChannelId(rtmpDto.getChannelId());
|
|
|
|
|
|
|
|
|
|
- ManageDeviceLivestreamUrlEntity urlEntity = new ManageDeviceLivestreamUrlEntity();
|
|
|
|
|
|
|
+
|
|
|
|
|
+ //获取数据库中deviceSn对应的url信息
|
|
|
QueryWrapper<ManageDeviceLivestreamUrlEntity> wrapper = new QueryWrapper<>();
|
|
QueryWrapper<ManageDeviceLivestreamUrlEntity> wrapper = new QueryWrapper<>();
|
|
|
wrapper.lambda().eq(ManageDeviceLivestreamUrlEntity::getDeviceSn,deviceLivestreamUrlDTO.getDeviceSn())
|
|
wrapper.lambda().eq(ManageDeviceLivestreamUrlEntity::getDeviceSn,deviceLivestreamUrlDTO.getDeviceSn())
|
|
|
- .eq(ManageDeviceLivestreamUrlEntity::getWorkspaceId,deviceLivestreamUrlDTO.getWorkspaceId())
|
|
|
|
|
- .eq(ManageDeviceLivestreamUrlEntity::getPayloadIndex,deviceLivestreamUrlDTO.getPayloadIndex());
|
|
|
|
|
|
|
+ .eq(ManageDeviceLivestreamUrlEntity::getWorkspaceId,deviceLivestreamUrlDTO.getWorkspaceId());
|
|
|
List<ManageDeviceLivestreamUrlEntity> urlList = mapper.selectList(wrapper);
|
|
List<ManageDeviceLivestreamUrlEntity> urlList = mapper.selectList(wrapper);
|
|
|
- if (urlList.size() > 0) {
|
|
|
|
|
- for(int i = 0; i< urlList.size();i++) {
|
|
|
|
|
- urlEntity = urlList.get(i);
|
|
|
|
|
- if (urlEntity.getUrlType().equals(LiveUrlTypeEnum.RTMP.getVal())) {
|
|
|
|
|
- if(!urlEntity.getUrl().equals(rtmpDto.getRtmpUrl())) {
|
|
|
|
|
- urlEntity.setUrl(rtmpDto.getRtmpUrl());
|
|
|
|
|
- mapper.updateById(urlEntity);
|
|
|
|
|
|
|
+ if(urlList.size() < 0 && rtmpList.size() < 0 ){
|
|
|
|
|
+ log.debug("The result is null.");
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ //过滤payloadIndex
|
|
|
|
|
+ List<ManageDeviceLivestreamUrlEntity> filterIndexList = urlList.stream().filter(channelData -> payloadEntity.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()))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ if (channelList.size() > 0) {
|
|
|
|
|
+ //判断url是否一致
|
|
|
|
|
+ for(ManageDeviceLivestreamUrlEntity url : filterIndexList) {
|
|
|
|
|
+ if (url.getUrlType().equals(LiveUrlTypeEnum.RTMP.getVal())) {
|
|
|
|
|
+ if(!url.getUrl().equals(channelList.get(0).getRtmpUrl())) {
|
|
|
|
|
+ url.setUrl(channelList.get(0).getRtmpUrl());
|
|
|
|
|
+ mapper.updateById(url);}
|
|
|
|
|
+ } else if(url.getUrlType().equals(LiveUrlTypeEnum.WEBRTC.getVal())) {
|
|
|
|
|
+ if(!url.getUrl().equals(channelList.get(0).getWebRtcUrl())) {
|
|
|
|
|
+ url.setUrl(channelList.get(0).getWebRtcUrl());
|
|
|
|
|
+ mapper.updateById(url);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- } else if(urlEntity.getUrlType().equals(LiveUrlTypeEnum.WEBRTC.getVal())) {
|
|
|
|
|
- if(!urlEntity.getUrl().equals(rtmpDto.getWebRtcUrl())) {
|
|
|
|
|
- urlEntity.setUrl(rtmpDto.getWebRtcUrl());
|
|
|
|
|
- mapper.updateById(urlEntity);
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ rtmpDto.setRtmpUrl(channelList.get(0).getRtmpUrl());
|
|
|
|
|
+ rtmpDto.setWebRtcUrl(channelList.get(0).getWebRtcUrl());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //过滤channelId
|
|
|
|
|
+ channelList = rtmpList.stream().filter(channelData -> !urlList.contains(channelData.getChannelId()))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ for(ManageDeviceLivestreamUrlEntity url : filterIndexList) {
|
|
|
|
|
+ url.setChannelId(channelList.get(0).getChannelId());
|
|
|
|
|
+
|
|
|
|
|
+ if (url.getUrlType().equals(LiveUrlTypeEnum.RTMP.getVal())) {
|
|
|
|
|
+ url.setUrl(channelList.get(0).getRtmpUrl());
|
|
|
|
|
+ mapper.updateById(url);
|
|
|
|
|
+ } else if(url.getUrlType().equals(LiveUrlTypeEnum.WEBRTC.getVal())) {
|
|
|
|
|
+ url.setUrl(channelList.get(0).getWebRtcUrl());
|
|
|
|
|
+ mapper.updateById(url);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ rtmpDto.setRtmpUrl(channelList.get(0).getRtmpUrl());
|
|
|
|
|
+ rtmpDto.setWebRtcUrl(channelList.get(0).getWebRtcUrl());
|
|
|
}
|
|
}
|
|
|
- return rtmpDto;
|
|
|
|
|
} else {
|
|
} else {
|
|
|
- //dto转entity
|
|
|
|
|
- BeanUtils.copyProperties(deviceLivestreamUrlDTO,urlEntity);
|
|
|
|
|
- //存库Rtmp
|
|
|
|
|
- urlEntity.setSubType(1);
|
|
|
|
|
- urlEntity.setUrlType(LiveUrlTypeEnum.RTMP.getVal());
|
|
|
|
|
- urlEntity.setUrl(rtmpDto.getRtmpUrl());
|
|
|
|
|
- mapper.insert(urlEntity);
|
|
|
|
|
- //存库WEBRTC
|
|
|
|
|
- urlEntity.setId(null);
|
|
|
|
|
- urlEntity.setSubType(2);
|
|
|
|
|
- urlEntity.setUrlType(LiveUrlTypeEnum.WEBRTC.getVal());
|
|
|
|
|
- urlEntity.setUrl(rtmpDto.getWebRtcUrl());
|
|
|
|
|
- mapper.insert(urlEntity);
|
|
|
|
|
- return rtmpDto;
|
|
|
|
|
|
|
+ //过滤channelId
|
|
|
|
|
+ List<ManageDeviceLivestreamUrlDTO> channelList = rtmpList.stream().filter(channelData -> !urlList.contains(channelData.getChannelId()))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ ManageDeviceLivestreamUrlEntity urlEntity = new ManageDeviceLivestreamUrlEntity();
|
|
|
|
|
+ if(channelList.size() > 0) {
|
|
|
|
|
+ //dto转entity
|
|
|
|
|
+ BeanUtils.copyProperties(deviceLivestreamUrlDTO,urlEntity);
|
|
|
|
|
+ //存库Rtmp
|
|
|
|
|
+ urlEntity.setSubType(DeviceSubTypeEnum.ONE.getSubType());
|
|
|
|
|
+ urlEntity.setUrlType(LiveUrlTypeEnum.RTMP.getVal());
|
|
|
|
|
+ urlEntity.setChannelId(channelList.get(0).getChannelId());
|
|
|
|
|
+ urlEntity.setUrl(channelList.get(0).getRtmpUrl());
|
|
|
|
|
+ mapper.insert(urlEntity);
|
|
|
|
|
+ //存库WEBRTC
|
|
|
|
|
+ urlEntity.setId(null);
|
|
|
|
|
+ urlEntity.setSubType(DeviceSubTypeEnum.TWO.getSubType());
|
|
|
|
|
+ urlEntity.setUrlType(LiveUrlTypeEnum.WEBRTC.getVal());
|
|
|
|
|
+ urlEntity.setUrl(channelList.get(0).getWebRtcUrl());
|
|
|
|
|
+ mapper.insert(urlEntity);
|
|
|
|
|
+ rtmpDto.setRtmpUrl(channelList.get(0).getRtmpUrl());
|
|
|
|
|
+ rtmpDto.setWebRtcUrl(channelList.get(0).getWebRtcUrl());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ return rtmpDto;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|