xucaiqin 1 سال پیش
والد
کامیت
77c766e8c6

+ 2 - 1
iot-module/iot-module-stream/iot-module-stream-biz/src/main/java/com/middle/platform/stream/biz/config/FeignConfig.java

@@ -1,6 +1,7 @@
 package com.middle.platform.stream.biz.config;
 
 import com.middle.platform.manage.api.feign.DeviceApi;
+import com.middle.platform.system.api.feign.DictApi;
 import org.springframework.cloud.openfeign.EnableFeignClients;
 import org.springframework.context.annotation.Configuration;
 
@@ -11,6 +12,6 @@ import org.springframework.context.annotation.Configuration;
  * @date 2023-12-19 11:00:25
  */
 @Configuration
-@EnableFeignClients(clients = {DeviceApi.class})
+@EnableFeignClients(clients = {DeviceApi.class, DictApi.class})
 public class FeignConfig {
 }

+ 8 - 14
iot-module/iot-module-stream/iot-module-stream-biz/src/main/java/com/middle/platform/stream/biz/controller/VideoController.java

@@ -7,6 +7,8 @@ import com.middle.platform.stream.biz.domain.req.StreamUpdateStatusRes;
 import com.middle.platform.stream.biz.pojo.VideoPage;
 import com.middle.platform.stream.biz.service.SDeviceService;
 import jakarta.annotation.Resource;
+import jakarta.validation.Valid;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 /**
@@ -22,44 +24,36 @@ public class VideoController {
     private SDeviceService sDeviceService;
 
 
-//    @GetMapping(value = "/getDeviceList", name = "获取设备信息")
-//    public Result<Object> getDeviceList(@RequestParam("keywords") String keywords) {
-//        List<DevicesVo> deviceList = sDeviceService.getDeviceList(keywords);
-//        if (!BeanUtil.isEmpty(deviceList)) {
-//            return Result.ok(deviceList, "获取成功");
-//        } else {
-//            return Result.failed("获取失败");
-//        }
-//    }
-
     /**
      * 分页查询
+     *
      * @param videoPage
      * @return
      */
     @PostMapping("/page")
-    public Result<Object> page(@RequestBody VideoPage videoPage) {
+    public Result<Object> page(@RequestBody @Validated VideoPage videoPage) {
         return Result.ok(sDeviceService.pageQuery(videoPage));
     }
 
 
     @PostMapping(value = "/add", name = "新增拉流信息")
-    public Result<Object> add(@RequestBody StreamAddRes streamAddRes) {
+    public Result<Object> add(@RequestBody @Valid StreamAddRes streamAddRes) {
         return Result.ok(sDeviceService.add(streamAddRes) != 0 ? "新增成功" : "新增失败");
     }
 
     @PostMapping(value = "/update", name = "更新拉流信息")
-    public Result<Object> update(@RequestBody StreamUpdateRes streamUpdateRes) {
+    public Result<Object> update(@RequestBody @Valid StreamUpdateRes streamUpdateRes) {
         return Result.ok(sDeviceService.update(streamUpdateRes) != 0 ? "更新成功" : "更新失败");
     }
 
     @PostMapping(value = "/updateStatus", name = "更新拉流信息状态")
-    public Result<Object> updateStatus(@RequestBody StreamUpdateStatusRes streamUpdateStatusRes) {
+    public Result<Object> updateStatus(@RequestBody @Valid StreamUpdateStatusRes streamUpdateStatusRes) {
         return Result.ok(sDeviceService.updateStatus(streamUpdateStatusRes) != 0 ? "更新状态成功" : "更新状态失败");
     }
 
     /**
      * 获取播放信息
+     *
      * @param id
      * @return
      */

+ 48 - 30
iot-module/iot-module-stream/iot-module-stream-biz/src/main/java/com/middle/platform/stream/biz/service/SDeviceService.java

@@ -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);
     }
 }

+ 25 - 0
iot-module/iot-module-stream/iot-module-stream-biz/src/main/java/com/middle/platform/stream/biz/service/ThreadTask.java

@@ -0,0 +1,25 @@
+package com.middle.platform.stream.biz.service;
+
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author xucaiqin
+ * @date 2023-12-25 09:03:26
+ */
+public class ThreadTask {
+
+    private ThreadTask() {
+    }
+
+    public static class Task {
+        private final static ThreadPoolExecutor THREAD_POOL_EXECUTOR =
+                new ThreadPoolExecutor(1, 1, 1, TimeUnit.MINUTES, new LinkedBlockingQueue<>(12));
+
+    }
+
+    public static void addJob(Runnable runnable) {
+        Task.THREAD_POOL_EXECUTOR.execute(runnable);
+    }
+}

+ 18 - 0
iot-module/iot-module-stream/iot-module-stream-biz/src/main/java/com/middle/platform/stream/biz/util/VideoPathUtil.java

@@ -0,0 +1,18 @@
+package com.middle.platform.stream.biz.util;
+
+/**
+ * @author xucaiqin
+ * @date 2024-05-09 10:33:08
+ */
+public class VideoPathUtil {
+    /**
+     * 拼接播放路径
+     *
+     * @param path
+     * @return
+     */
+    public static String videoUrl(String prefix, String path) {
+        prefix = prefix.endsWith("/") ? "" : prefix + "/";
+        return prefix + "fmp4/" + path + ".mp4";
+    }
+}