|
|
@@ -1,14 +1,18 @@
|
|
|
package com.middle.platform.stream.biz.service;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
import com.middle.platform.common.core.exception.BusinessException;
|
|
|
import com.middle.platform.manage.api.feign.DeviceApi;
|
|
|
import com.middle.platform.manage.api.pojo.DevicesNameVo;
|
|
|
import com.middle.platform.manage.api.pojo.DevicesVo;
|
|
|
+import com.middle.platform.pagehelper.core.PageRes;
|
|
|
import com.middle.platform.stream.biz.domain.req.StreamAddRes;
|
|
|
import com.middle.platform.stream.biz.domain.req.StreamUpdateRes;
|
|
|
import com.middle.platform.stream.biz.domain.req.StreamUpdateStatusRes;
|
|
|
@@ -16,9 +20,11 @@ import com.middle.platform.stream.biz.domain.res.DevicesPathVo;
|
|
|
import com.middle.platform.stream.biz.domain.res.StreamPageRes;
|
|
|
import com.middle.platform.stream.biz.entity.SDevice;
|
|
|
import com.middle.platform.stream.biz.mapper.SDeviceMapper;
|
|
|
-import com.middle.platform.stream.biz.pojo.StreamPage;
|
|
|
import com.middle.platform.stream.biz.pojo.VideoPage;
|
|
|
import com.middle.platform.stream.biz.properties.StreamMediaProperties;
|
|
|
+import com.middle.platform.stream.biz.util.VideoPathUtil;
|
|
|
+import com.middle.platform.system.api.enums.DictType;
|
|
|
+import com.middle.platform.system.api.feign.DictApi;
|
|
|
import jakarta.annotation.Resource;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -27,6 +33,7 @@ import org.springframework.stereotype.Service;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
/**
|
|
|
* @author xucaiqin
|
|
|
@@ -42,6 +49,7 @@ public class SDeviceService extends ServiceImpl<SDeviceMapper, SDevice> {
|
|
|
|
|
|
@Resource
|
|
|
private DeviceApi deviceApi;
|
|
|
+ private DictApi dictApi;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -92,16 +100,19 @@ public class SDeviceService extends ServiceImpl<SDeviceMapper, SDevice> {
|
|
|
public int add(StreamAddRes streamAddRes) {
|
|
|
SDevice sDevice = new SDevice();
|
|
|
BeanUtil.copyProperties(streamAddRes, sDevice);
|
|
|
+ sDevice.setUseFlag(1);
|
|
|
int insert = sDeviceMapper.insert(sDevice);
|
|
|
//这里需要拉流一下
|
|
|
if (insert > 0) {
|
|
|
//视频流类型 1-rtsp 2-rtmp
|
|
|
- if (streamAddRes.getType() == 1) {
|
|
|
- apiProxy.rtspPull(sDevice.getPath(), sDevice.getTarget(), "");
|
|
|
- }
|
|
|
- if (streamAddRes.getType() == 2) {
|
|
|
- apiProxy.rtmpPull(sDevice.getPath(), sDevice.getTarget(), "");
|
|
|
- }
|
|
|
+ ThreadTask.addJob(() -> {
|
|
|
+ if (streamAddRes.getType() == 1) {
|
|
|
+ apiProxy.rtspPull(sDevice.getPath(), sDevice.getTarget(), "");
|
|
|
+ }
|
|
|
+ if (streamAddRes.getType() == 2) {
|
|
|
+ apiProxy.rtmpPull(sDevice.getPath(), sDevice.getTarget(), "");
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
return insert;
|
|
|
}
|
|
|
@@ -120,8 +131,9 @@ public class SDeviceService extends ServiceImpl<SDeviceMapper, SDevice> {
|
|
|
if (Objects.isNull(sDevice)) {
|
|
|
throw new BusinessException("视频流不存在");
|
|
|
}
|
|
|
- BeanUtil.copyProperties(streamUpdateStatusRes, sDevice);
|
|
|
- return sDeviceMapper.updateById(sDevice);
|
|
|
+ SDevice sDevice1 = new SDevice();
|
|
|
+ BeanUtil.copyProperties(streamUpdateStatusRes, sDevice1);
|
|
|
+ return sDeviceMapper.updateById(sDevice1);
|
|
|
}
|
|
|
|
|
|
public String getVideoUrl(Long id) {
|
|
|
@@ -129,7 +141,7 @@ public class SDeviceService extends ServiceImpl<SDeviceMapper, SDevice> {
|
|
|
if (Objects.isNull(sDevice)) {
|
|
|
throw new BusinessException("视频流不存在");
|
|
|
}
|
|
|
- return streamMediaProperties.getUrl() + sDevice.getPath();
|
|
|
+ return VideoPathUtil.videoUrl(streamMediaProperties.getUrl(),sDevice.getPath());
|
|
|
}
|
|
|
|
|
|
// /**
|
|
|
@@ -178,36 +190,42 @@ public class SDeviceService extends ServiceImpl<SDeviceMapper, SDevice> {
|
|
|
* @date 2024-05-09 09:10
|
|
|
*/
|
|
|
public Object pageQuery(VideoPage videoPage) {
|
|
|
- PageHelper.startPage(videoPage.getPage(), videoPage.getPageSize());
|
|
|
//根据设备名称模糊筛选设备,获得设备id列表
|
|
|
List<Long> ids = new ArrayList<>();
|
|
|
//如果有设备,需要先查出设备id
|
|
|
- DevicesNameVo devicesNameVo = new DevicesNameVo();
|
|
|
- devicesNameVo.setKeywords(videoPage.getKeywords());
|
|
|
- List<DevicesVo> devicesVos = deviceApi.devicesQuery(devicesNameVo);
|
|
|
- if (Objects.isNull(devicesVos)) {
|
|
|
- throw new BusinessException("查无产品");
|
|
|
- }
|
|
|
- for (DevicesVo devicesVo : devicesVos) {
|
|
|
- ids.add(devicesVo.getId());
|
|
|
+ if (StrUtil.isNotBlank(videoPage.getKeywords())) {
|
|
|
+ DevicesNameVo devicesNameVo = new DevicesNameVo();
|
|
|
+ devicesNameVo.setKeywords(videoPage.getKeywords());
|
|
|
+ List<DevicesVo> devicesVos = deviceApi.devicesQuery(devicesNameVo);
|
|
|
+ for (DevicesVo devicesVo : devicesVos) {
|
|
|
+ ids.add(devicesVo.getId());
|
|
|
+ }
|
|
|
}
|
|
|
- log.info("ids : {}", ids);
|
|
|
- List<SDevice> sDevices = sDeviceMapper.selectList(new LambdaQueryWrapper<SDevice>().in(SDevice::getDeviceId, ids));
|
|
|
+ PageHelper.startPage(videoPage.getPage(), videoPage.getPageSize());
|
|
|
+ List<SDevice> sDevices = sDeviceMapper.selectList(new LambdaQueryWrapper<SDevice>()
|
|
|
+ .eq(SDevice::getType, videoPage.getType())
|
|
|
+ .in(CollUtil.isNotEmpty(ids), SDevice::getDeviceId, ids));
|
|
|
+
|
|
|
if (Objects.isNull(sDevices)) {
|
|
|
- throw new BusinessException("查无产品");
|
|
|
+ return new PageRes<>();
|
|
|
}
|
|
|
+
|
|
|
+ PageInfo<SDevice> pageInfo = new PageInfo<>(sDevices);
|
|
|
StreamPageRes streamPageRes = new StreamPageRes();
|
|
|
List<StreamPageRes> streamPageRes2 = new ArrayList<>();
|
|
|
for (SDevice sDevice : sDevices) {
|
|
|
- sDevice.setPath(streamMediaProperties.getUrl() + sDevice.getPath());
|
|
|
- for (DevicesVo devicesVo : devicesVos) {
|
|
|
- if (devicesVo.getId().equals(sDevice.getDeviceId())) {
|
|
|
- BeanUtil.copyProperties(sDevice, streamPageRes);
|
|
|
- streamPageRes.setDeviceName(devicesVo.getName());
|
|
|
- streamPageRes2.add(streamPageRes);
|
|
|
- }
|
|
|
+ BeanUtil.copyProperties(sDevice, streamPageRes);
|
|
|
+ DevicesVo devicesVo = deviceApi.queryDevice(sDevice.getDeviceId());
|
|
|
+ if (Objects.nonNull(devicesVo)) {
|
|
|
+ streamPageRes.setDeviceName(devicesVo.getName());
|
|
|
}
|
|
|
+ Optional.ofNullable(dictApi.query(DictType.VIDEO_TYPE, String.valueOf(streamPageRes.getType()))).ifPresent(d -> streamPageRes.setTypeLabel(d.getLabel()));
|
|
|
+ Optional.ofNullable(dictApi.query(DictType.USE_FLAG_TYPE, String.valueOf(streamPageRes.getUseFlag()))).ifPresent(d -> streamPageRes.setUseFlagLabel(d.getLabel()));
|
|
|
+ Optional.ofNullable(dictApi.query(DictType.SAVE_RULE_TYPE, String.valueOf(streamPageRes.getSaveRule()))).ifPresent(d -> streamPageRes.setSaveRuleLabel(d.getLabel()));
|
|
|
+
|
|
|
+ streamPageRes2.add(streamPageRes);
|
|
|
}
|
|
|
- return streamPageRes2;
|
|
|
+
|
|
|
+ return PageRes.build(pageInfo, streamPageRes2);
|
|
|
}
|
|
|
}
|