xucaiqin пре 1 година
родитељ
комит
ff925d1c2b

+ 32 - 29
iot-module/iot-module-stream/iot-module-stream-biz/src/main/java/com/middle/platform/stream/biz/controller/RecordController.java

@@ -1,16 +1,13 @@
 package com.middle.platform.stream.biz.controller;
 
-import cn.hutool.core.bean.BeanUtil;
+import com.middle.platform.common.core.modle.BasePara;
 import com.middle.platform.common.core.utils.Result;
-import com.middle.platform.stream.biz.domain.res.DevicesPathVo;
 import com.middle.platform.stream.biz.pojo.StreamRecordPage;
 import com.middle.platform.stream.biz.service.SDeviceService;
 import com.middle.platform.stream.biz.service.StreamMediaService;
 import jakarta.annotation.Resource;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.List;
-
 /**
  * 录像回放
  *
@@ -28,42 +25,48 @@ public class RecordController {
     /**
      * 录像回放- 模糊搜索设备名称
      *
-     * @param keywords
+     * @param basePara
      * @return
      */
-    @GetMapping(value = "/getDevicePathList", name = "获取设备列表(包含流标签信息)")
-    public Result<Object> getDevicePathList(@RequestParam("keywords") String keywords) {
-        List<DevicesPathVo> deviceList = sDeviceService.getDevicePathList(keywords);
-        if (!BeanUtil.isEmpty(deviceList)) {
-            return Result.ok(deviceList, "获取成功");
-        } else {
-            return Result.failed("获取失败");
-        }
+    @PostMapping(value = "/getDeviceList", name = "获取设备列表(包含流标签信息)")
+    public Result<Object> getDeviceList(@RequestBody BasePara basePara) {
+        return Result.ok(sDeviceService.getDevicePathList(basePara), "获取成功");
     }
 
+    /**
+     * 录像回放-视频分页查询
+     *
+     * @param streamRecordPage
+     * @return
+     */
     @PostMapping(value = "/page", name = "分页查询(根据流标签)")
     public Result<Object> page(@RequestBody StreamRecordPage streamRecordPage) {
         return Result.ok(streamMediaService.recordPage(streamRecordPage));
     }
-
-    /**
-     * 视频播放
-     */
-    @GetMapping(value = "/getVideoUrl", name = "获取回放播放信息")
-    public Result<Object> getVideoUrl(@RequestParam("path") String path) {
-        return Result.ok(streamMediaService.getRecordVideoUrl(path));
-    }
-    /**
-     * 视频下载
-     */
-    @GetMapping(value = "/getDownLoadUrl", name = "获取回放视频下载地址")
-    public Result<Object> getDownLoadUrl(@RequestParam("path") String path) {
-        return Result.ok(streamMediaService.getDownLoadUrl(path));
-    }
-
+//
+//    /**
+//     * 视频播放
+//     */
+//    @GetMapping(value = "/getVideoUrl", name = "获取回放播放信息")
+//    public Result<Object> getVideoUrl(@RequestParam("path") String path) {
+//        return Result.ok(streamMediaService.getRecordVideoUrl(path));
+//    }
+//
+//    /**
+//     * 视频下载
+//     */
+//    @GetMapping(value = "/getDownLoadUrl", name = "获取回放视频下载地址")
+//    public Result<Object> getDownLoadUrl(@RequestParam("path") String path) {
+//        return Result.ok(streamMediaService.getDownLoadUrl(path));
+//    }
 
 
     /**
      * 视频删除
      */
+    @DeleteMapping(value = "/delete", name = "删除视频")
+    public Result<Object> getDownLoadUrl(@RequestParam("path") String path) {
+        streamMediaService.delete(path);
+        return Result.ok(true, "删除成功");
+    }
 }

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

@@ -8,7 +8,6 @@ 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.*;
 
 /**
@@ -31,21 +30,38 @@ public class VideoController {
      * @return
      */
     @PostMapping("/page")
-    public Result<Object> page(@RequestBody @Validated VideoPage videoPage) {
+    public Result<Object> page(@RequestBody @Valid VideoPage videoPage) {
         return Result.ok(sDeviceService.pageQuery(videoPage));
     }
 
-
+    /**
+     * 新增拉流信息
+     *
+     * @param streamAddRes
+     * @return
+     */
     @PostMapping(value = "/add", name = "新增拉流信息")
     public Result<Object> add(@RequestBody @Valid StreamAddRes streamAddRes) {
         return Result.ok(sDeviceService.add(streamAddRes) != 0 ? "新增成功" : "新增失败");
     }
 
+    /**
+     * 更新拉流信息
+     *
+     * @param streamUpdateRes
+     * @return
+     */
     @PostMapping(value = "/update", name = "更新拉流信息")
     public Result<Object> update(@RequestBody @Valid StreamUpdateRes streamUpdateRes) {
         return Result.ok(sDeviceService.update(streamUpdateRes) != 0 ? "更新成功" : "更新失败");
     }
 
+    /**
+     * 更新拉流信息状态
+     *
+     * @param streamUpdateStatusRes
+     * @return
+     */
     @PostMapping(value = "/updateStatus", name = "更新拉流信息状态")
     public Result<Object> updateStatus(@RequestBody @Valid StreamUpdateStatusRes streamUpdateStatusRes) {
         return Result.ok(sDeviceService.updateStatus(streamUpdateStatusRes) != 0 ? "更新状态成功" : "更新状态失败");
@@ -61,7 +77,4 @@ public class VideoController {
     public Result<Object> getVideoUrl(@RequestParam("id") Long id) {
         return Result.ok(sDeviceService.getVideoUrl(id));
     }
-
-    //rtsp列表查询
-    //rtmp列表查询
 }

+ 2 - 1
iot-module/iot-module-stream/iot-module-stream-biz/src/main/java/com/middle/platform/stream/biz/domain/res/DevicesPathVo.java

@@ -8,6 +8,7 @@ import java.io.Serializable;
 
 /**
  * 设备以及流标签信息
+ *
  * @author Aick Spt
  * @date 2024-05-08 10:48
  */
@@ -19,7 +20,7 @@ public class DevicesPathVo implements Serializable {
     private static final long serialVersionUID = 1472407611278301516L;
 
     /**
-     * 设备id
+     * s_device.id
      */
     private Long id;
 

+ 13 - 16
iot-module/iot-module-stream/iot-module-stream-biz/src/main/java/com/middle/platform/stream/biz/domain/res/RecordPageRes.java

@@ -1,7 +1,8 @@
 package com.middle.platform.stream.biz.domain.res;
 
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.AllArgsConstructor;
 import lombok.Data;
-import lombok.extern.slf4j.Slf4j;
 
 import java.time.LocalDateTime;
 
@@ -9,32 +10,28 @@ import java.time.LocalDateTime;
  * @author Aick Spt
  * @date 2024-05-06 10:31
  */
-@Slf4j
 @Data
+@AllArgsConstructor
 public class RecordPageRes {
-
-
-
     /**
-     * 文件名称-path路径重唱
+     * 文件名称
      */
+    private String name;
+
     private String path;
 
     /**
-     * 封面地址
+     * 文件大小
      */
     private Long size;
 
     /**
-     * 封面地址
+     * 生成时间
      */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
     private LocalDateTime createTime;
-
-
-    public RecordPageRes(String path, Long size, LocalDateTime dateTime) {
-
-        this.path = path;
-        this.size = size;
-        this.createTime = dateTime;
-    }
+    /**
+     * 播放地址
+     */
+    private String url;
 }

+ 1 - 3
iot-module/iot-module-stream/iot-module-stream-biz/src/main/java/com/middle/platform/stream/biz/service/ApiProxy.java

@@ -189,10 +189,8 @@ public class ApiProxy {
         });
     }
     public Object recordDelete(String path) {
-        String sync = getHttp(ApiInfo.RECORD_DELETE, new HashMap<>() {{
+        return getHttp(ApiInfo.RECORD_DELETE, new HashMap<>() {{
             put("path", path);
         }});
-        return JSONObject.parseObject(sync, new TypeReference<>() {
-        });
     }
 }

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

@@ -4,11 +4,11 @@ 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.common.core.modle.BasePara;
 import com.middle.platform.manage.api.feign.DeviceApi;
 import com.middle.platform.manage.api.pojo.DevicesNameVo;
 import com.middle.platform.manage.api.pojo.DevicesVo;
@@ -58,37 +58,36 @@ public class SDeviceService extends ServiceImpl<SDeviceMapper, SDevice> {
      * @author Aick Spt
      * @date 2024-05-08 18:44
      */
-    public List<DevicesPathVo> getDevicePathList(String keywords) {
-        //查询出所有已新增在流表里的设备id
-        SDevice sDevice = new SDevice();
-        sDevice.setDelFlag(0);
-        sDevice.setUseFlag(1);
-        List<SDevice> sDevices = sDeviceMapper.selectList(new QueryWrapper<>(sDevice));
-        //获取到所有sDevices中的设备id,再去查设备表,获取到设备id和设备name
-        List<DevicesPathVo> devicesPathVos = new ArrayList<>();
+    public PageRes<DevicesPathVo> getDevicePathList(BasePara basePara) {
+        //根据设备名称模糊筛选设备,获得设备id列表
         List<Long> ids = new ArrayList<>();
-        for (SDevice sDevice1 : sDevices) {
-            ids.add(sDevice1.getDeviceId());
+        //如果有设备,需要先查出设备id
+        if (StrUtil.isNotBlank(basePara.getKeywords())) {
+            DevicesNameVo devicesNameVo = new DevicesNameVo();
+            devicesNameVo.setKeywords(basePara.getKeywords());
+            List<DevicesVo> devicesVos = deviceApi.devicesQuery(devicesNameVo);
+            for (DevicesVo devicesVo : devicesVos) {
+                ids.add(devicesVo.getId());
+            }
         }
-        //根据设备id查询设备表,获取到设备id和设备name
-        DevicesNameVo devicesNameVo = new DevicesNameVo();
-        devicesNameVo.setIds(ids);
-        devicesNameVo.setKeywords(keywords);
-        List<DevicesVo> devicesVos = deviceApi.devicesQuery(devicesNameVo);
-        //获取到设备id和设备name,再去查设备表,获取到设备id和设备path
-        DevicesPathVo devicesPathVo = new DevicesPathVo();
-        for (DevicesVo devicesVo : devicesVos) {
-            devicesPathVo.setId(devicesVo.getId());
-            devicesPathVo.setName(devicesVo.getName());
-            for (SDevice sDevice2 : sDevices) {
-                if (Objects.equals(sDevice2.getDeviceId(), devicesVo.getId())) {
-                    devicesPathVo.setPath(sDevice2.getPath());
-                    devicesPathVos.add(devicesPathVo);
-                    break;
-                }
+        PageHelper.startPage(basePara.getPage(), basePara.getPageSize());
+        List<SDevice> sDevices = sDeviceMapper.selectList(new LambdaQueryWrapper<SDevice>()
+                .in(CollUtil.isNotEmpty(ids), SDevice::getDeviceId, ids));
+
+        if (Objects.isNull(sDevices)) {
+            return new PageRes<>();
+        }
+        PageInfo<SDevice> pageInfo = new PageInfo<>(sDevices);
+        List<DevicesPathVo> res = new ArrayList<>();
+        for (SDevice sDevice : sDevices) {
+            DevicesPathVo devicesPathVo = BeanUtil.toBean(sDevice, DevicesPathVo.class);
+            DevicesVo devicesVo = deviceApi.queryDevice(sDevice.getDeviceId());
+            if (Objects.nonNull(devicesVo)) {
+                devicesPathVo.setName(devicesVo.getName());
             }
+            res.add(devicesPathVo);
         }
-        return devicesPathVos;
+        return PageRes.build(pageInfo, res);
     }
 
     /**
@@ -122,8 +121,14 @@ public class SDeviceService extends ServiceImpl<SDeviceMapper, SDevice> {
         if (Objects.isNull(sDevice)) {
             throw new BusinessException("视频流不存在");
         }
-        BeanUtil.copyProperties(streamUpdateRes, sDevice);
-        return sDeviceMapper.updateById(sDevice);
+        SDevice sDevice1 = new SDevice();
+        sDevice1.setId(streamUpdateRes.getId());
+        sDevice1.setDeviceId(streamUpdateRes.getDeviceId());
+        sDevice1.setCover(streamUpdateRes.getCover());
+//        sDevice1.setPath("");
+//        sDevice1.setTarget("");
+        sDevice1.setType(streamUpdateRes.getType());
+        return sDeviceMapper.updateById(sDevice1);
     }
 
     public int updateStatus(StreamUpdateStatusRes streamUpdateStatusRes) {
@@ -141,7 +146,7 @@ public class SDeviceService extends ServiceImpl<SDeviceMapper, SDevice> {
         if (Objects.isNull(sDevice)) {
             throw new BusinessException("视频流不存在");
         }
-        return VideoPathUtil.videoUrl(streamMediaProperties.getUrl(),sDevice.getPath());
+        return VideoPathUtil.videoUrl(streamMediaProperties.getUrl(), sDevice.getPath());
     }
 
 //    /**
@@ -211,10 +216,9 @@ public class SDeviceService extends ServiceImpl<SDeviceMapper, SDevice> {
         }
 
         PageInfo<SDevice> pageInfo = new PageInfo<>(sDevices);
-        StreamPageRes streamPageRes = new StreamPageRes();
         List<StreamPageRes> streamPageRes2 = new ArrayList<>();
         for (SDevice sDevice : sDevices) {
-            BeanUtil.copyProperties(sDevice, streamPageRes);
+            StreamPageRes streamPageRes = BeanUtil.toBean(sDevice, StreamPageRes.class);
             DevicesVo devicesVo = deviceApi.queryDevice(sDevice.getDeviceId());
             if (Objects.nonNull(devicesVo)) {
                 streamPageRes.setDeviceName(devicesVo.getName());

+ 4 - 15
iot-module/iot-module-stream/iot-module-stream-biz/src/main/java/com/middle/platform/stream/biz/service/StreamMediaService.java

@@ -1,11 +1,7 @@
 package com.middle.platform.stream.biz.service;
 
-import com.github.pagehelper.PageInfo;
-import com.middle.platform.stream.biz.domain.res.RecordPageRes;
 import com.middle.platform.stream.biz.pojo.StreamRecordPage;
 
-import java.util.ArrayList;
-
 /**
  * @author xucaiqin
  * @date 2024-04-26 11:21:39
@@ -20,16 +16,9 @@ public interface StreamMediaService {
     Object recordPage(StreamRecordPage streamRecordPage);
 
     /**
-     * 获取回放播放信息
-     * @author Aick Spt
-     * @date 2024-05-09 11:35
-     */
-    Object getRecordVideoUrl(String path);
-
-    /**
-     * 获取回放视频下载地址
-     * @author Aick Spt
-     * @date 2024-05-09 11:35
+     * 删除文件
+     *
+     * @param path
      */
-    Object getDownLoadUrl(String path);
+    void delete(String path);
 }

+ 30 - 33
iot-module/iot-module-stream/iot-module-stream-biz/src/main/java/com/middle/platform/stream/biz/service/impl/StreamMediaServiceImpl.java

@@ -1,6 +1,7 @@
 package com.middle.platform.stream.biz.service.impl;
 
-import com.github.pagehelper.PageInfo;
+import cn.hutool.core.collection.CollUtil;
+import com.middle.platform.pagehelper.core.PageRes;
 import com.middle.platform.stream.biz.domain.res.RecordPageRes;
 import com.middle.platform.stream.biz.pojo.RecordPage;
 import com.middle.platform.stream.biz.pojo.RecordPageFiles;
@@ -15,6 +16,7 @@ import org.springframework.stereotype.Service;
 import java.time.Instant;
 import java.time.LocalDateTime;
 import java.time.ZoneOffset;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -30,54 +32,49 @@ public class StreamMediaServiceImpl implements StreamMediaService {
     private final ApiProxy apiProxy;
 
     private final StreamMediaProperties streamMediaProperties;
+    private static final String type = "mp4";
 
     @Override
     public Object recordPage(StreamRecordPage streamRecordPage) {
-        log.info("recordPage in...");
-        PageInfo<RecordPageRes> pageInfo = new PageInfo<>();
+        PageRes<RecordPageRes> pageRes = new PageRes<>();
         //API调用
-        RecordPage recordPage = apiProxy.recordListPage("mp4", streamRecordPage.getPage(), streamRecordPage.getPageSize(), streamRecordPage.getPath());
-        log.info("recordPage:{}", recordPage);
-        pageInfo.setPageSize(streamRecordPage.getPageSize());
-        pageInfo.setPages(streamRecordPage.getPage());
-        pageInfo.setTotal(recordPage.getTotalCount());
-        List<RecordPageRes> recordPageResList = new java.util.ArrayList<>();
+        RecordPage recordPage = apiProxy.recordListPage(type, streamRecordPage.getPageSize(), streamRecordPage.getPage(), streamRecordPage.getPath());
+        pageRes.setPageSize(streamRecordPage.getPageSize());
+        pageRes.setPages(streamRecordPage.getPage());
+        pageRes.setTotal(recordPage.getTotalCount());
+        if (CollUtil.isEmpty(recordPage.getFiles())) {
+            pageRes.setList(new ArrayList<>());
+            return pageRes;
+        }
+        List<RecordPageRes> recordPageResList = new ArrayList<>();
         // 匹配字符串中的时间戳
-        Pattern pattern = Pattern.compile("\\d+\\.mp4$");
+        Pattern pattern = Pattern.compile("\\d+\\." + type + "$");
         for (RecordPageFiles recordPageFiles : recordPage.getFiles()) {
-            Matcher matcher = pattern.matcher(recordPageFiles.getPath());
+            String path = recordPageFiles.getPath();
+
+            Matcher matcher = pattern.matcher(path);
             // 提取时间戳字符串
             String timestampStr = "";
             if (matcher.find()) {
-                timestampStr = matcher.group().replace(".mp4", "");
+                timestampStr = matcher.group().replace("." + type, "");
             }
             // 转换为LocalDateTime格式
-            LocalDateTime dateTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(Long.parseLong(timestampStr)), ZoneOffset.UTC);
-            recordPageResList.add(new RecordPageRes(recordPageFiles.getPath(), recordPageFiles.getSize(), dateTime));
+            LocalDateTime dateTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(Long.parseLong(timestampStr)), ZoneOffset.systemDefault());
+            //视频文件的播放路径需要进行转换
+            String url = getUrl() + path.replaceAll("record/" + type, "record");
+            recordPageResList.add(new RecordPageRes(timestampStr + "." + type, path, recordPageFiles.getSize(), dateTime, url));
         }
-        pageInfo.setList(recordPageResList);
-        return pageInfo;
+        pageRes.setList(recordPageResList);
+        return pageRes;
     }
 
-    /**
-     * 获取回放播放信息
-     * @author Aick Spt
-     * @date 2024-05-09 11:35
-     */
     @Override
-    public Object getRecordVideoUrl(String path) {
-
-        return streamMediaProperties.getUrl() + path;
+    public void delete(String path) {
+         apiProxy.recordDelete(path);
     }
 
-    /**
-     * 获取回放视频下载地址
-     * @author Aick Spt
-     * @date 2024-05-09 11:37
-     */
-    @Override
-    public Object getDownLoadUrl(String path) {
-
-        return streamMediaProperties.getUrl() + path;
+    private String getUrl() {
+        String url = streamMediaProperties.getUrl();
+        return url.endsWith("/") ? url : url + "/";
     }
 }