فهرست منبع

update content-service/disk CamController

reghao 6 ماه پیش
والد
کامیت
d83d970991
21فایلهای تغییر یافته به همراه163 افزوده شده و 358 حذف شده
  1. 29 64
      content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/controller/CamController.java
  2. 3 5
      content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/db/mapper/CamRecordMapper.java
  3. 19 0
      content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/dto/CamDeviceDto.java
  4. 3 5
      content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/dto/CamRecordDto.java
  5. 2 5
      content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/po/CamDevice.java
  6. 1 3
      content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/po/CamRecord.java
  7. 1 2
      content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/po/UserActivity.java
  8. 5 13
      content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/query/CamDeviceQuery.java
  9. 18 1
      content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/vo/CamDetail.java
  10. 12 1
      content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/vo/CamRecordDetail.java
  11. 7 23
      content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/vo/CamRecordInfo.java
  12. 6 0
      content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/vo/CamSearch.java
  13. 0 26
      content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/vo/CamUrl.java
  14. 0 15
      content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/vo/MarkDay.java
  15. 0 17
      content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/vo/RecordInfo.java
  16. 0 13
      content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/vo/ResultCount.java
  17. 19 68
      content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/service/CamRecordService.java
  18. 14 53
      content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/service/CamService.java
  19. 7 21
      content/content-service/src/main/resources/mapper/disk/CamDeviceMapper.xml
  20. 8 22
      content/content-service/src/main/resources/mapper/disk/CamRecordMapper.xml
  21. 9 1
      content/content-service/src/main/resources/mapper/disk/UserActivityMapper.xml

+ 29 - 64
content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/controller/CamController.java

@@ -3,11 +3,10 @@ package cn.reghao.tnb.content.app.disk.controller;
 import cn.reghao.jutil.jdk.result.Result;
 import cn.reghao.jutil.web.WebResult;
 import cn.reghao.tnb.common.auth.AuthUser;
+import cn.reghao.tnb.content.app.disk.model.dto.CamDeviceDto;
 import cn.reghao.tnb.content.app.disk.model.dto.CamRecordDto;
-import cn.reghao.tnb.content.app.disk.model.vo.CamRecordDetail;
-import cn.reghao.tnb.content.app.disk.model.vo.CamRecordInfo;
-import cn.reghao.tnb.content.app.disk.model.vo.CamSearch;
-import cn.reghao.tnb.content.app.disk.model.vo.MarkDay;
+import cn.reghao.tnb.content.app.disk.model.po.CamDevice;
+import cn.reghao.tnb.content.app.disk.model.vo.*;
 import cn.reghao.tnb.content.app.disk.service.CamRecordService;
 import cn.reghao.tnb.content.app.disk.service.CamService;
 import cn.reghao.tnb.content.app.geo.model.vo.SelectOption;
@@ -17,7 +16,6 @@ import org.springframework.http.MediaType;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
-import java.io.IOException;
 import java.time.LocalDate;
 import java.util.List;
 
@@ -38,16 +36,30 @@ public class CamController {
         this.camRecordService = camRecordService;
     }
 
-    @Operation(summary = "摄像头 key-value 列表", description = "N")
+    @Operation(summary = "添加摄像头", description = "N")
+    @PostMapping(value = "/device", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String addCamDevice(@RequestBody @Validated CamDeviceDto camDeviceDto) {
+        camService.addCamDevice(camDeviceDto);
+        return WebResult.success();
+    }
+
+    @Operation(summary = "添加录像文件", description = "N")
+    @PostMapping(value = "/record", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String addCamRecord(@Validated @RequestBody CamRecordDto camRecordDto) {
+        Result result = camRecordService.addCamRecord(camRecordDto);
+        return WebResult.result(result);
+    }
+
+    @Operation(summary = "摄像头 kv 列表", description = "N")
     @GetMapping("/kv")
     public String getCamKeyValues() {
         List<SelectOption> kvs = camService.getCamKeyValues();
         return WebResult.success(kvs);
     }
 
-    @Operation(summary = "摄像头详情页面", description = "N")
+    @Operation(summary = "摄像头详情", description = "N")
     @GetMapping("/detail")
-    public String getCamDetail(CamSearch camSearch) {
+    public String getCamDetail(@Validated CamSearch camSearch) {
         List<SelectOption> kvs = camService.getCamKeyValues();
         if (kvs.isEmpty()) {
             return WebResult.failWithMsg("No Cam");
@@ -61,59 +73,26 @@ public class CamController {
 
         Long camId = camSearch.getCamId();
         if (camId == null) {
-            camId = Long.parseLong(kvs.get(0).getLabel());
+            camId = Long.parseLong(kvs.get(0).getValue());
         }
 
-        String currentMonthStr = currentDayStr.substring(0, currentDayStr.lastIndexOf("-"));
-        List<MarkDay> markDays = camRecordService.getDaysInMonth(camId, currentMonthStr);
-        List<CamRecordInfo> dayRecords = camRecordService.getCamRecords(camId, currentDayStr);
-        if (!dayRecords.isEmpty()) {
-            CamRecordInfo camRecordInfo = dayRecords.get(0);
-            long recordId = camRecordInfo.getRecordId();
-            CamRecordDetail camRecordDetail = camRecordService.getCamRecord(recordId);
-            if (camRecordDetail != null) {
-                /*model.addAttribute("coverUrl", camRecordDetail.getCoverUrl());
-                model.addAttribute("videoUrl", camRecordDetail.getVideoUrl());*/
-            }
-        } else {
-            String videoUrl = "";
-            CamRecordDetail camRecordDetail = camRecordService.getLatestRecord(camId);
-            if (camRecordDetail != null) {
-                //videoUrl = camRecordDetail.getVideoUrl();
-                /*model.addAttribute("coverUrl", camRecordDetail.getCoverUrl());
-                model.addAttribute("videoUrl", videoUrl);*/
-            } else {
-                /*model.addAttribute("coverUrl", "");
-                model.addAttribute("videoUrl", videoUrl);*/
-            }
-        }
-
-        /*model.addAttribute("camId", camId);
-        model.addAttribute("kvs", kvs);
-        model.addAttribute("markDays", markDays);
-        model.addAttribute("dayRecords", dayRecords);
-        model.addAttribute("viewDate", currentDayStr);*/
-        return WebResult.success();
-    }
-
-    @Operation(summary = "添加录像", description = "N")
-    @PostMapping(value = "/record", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String addCamRecord(@Validated @RequestBody CamRecordDto camRecordDto) {
-        Result result = camRecordService.add(camRecordDto);
-        return WebResult.result(result);
+        CamDevice camDevice = camService.getCamDevice(camId);
+        List<CamRecordInfo> dayRecords = camRecordService.getCamRecordByDay(camId, currentDayStr);
+        CamDetail camDetail = new CamDetail(camDevice, yearMonthDay, dayRecords);
+        return WebResult.success(camDetail);
     }
 
     @Operation(summary = "某个月中哪些天有录像", description = "N")
     @GetMapping(value = "/record/month", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String getCamRecordByMonth(Long camId, String yearMonth) {
-        List<MarkDay> list = camRecordService.getDaysInMonth(camId, yearMonth);
+    public String getCamRecordByMonth(@Validated CamSearch camSearch) {
+        List<String> list = camRecordService.getDaysInMonth(camSearch.getCamId(), camSearch.getYearMonth());
         return WebResult.success(list);
     }
 
-    @Operation(summary = "获取录像", description = "N")
+    @Operation(summary = "获取某个录像的 URL", description = "N")
     @GetMapping(value = "/record/url/{recordId}", produces = MediaType.APPLICATION_JSON_VALUE)
     public String getCamRecord(@PathVariable("recordId") long recordId) {
-        CamRecordDetail camRecord = camRecordService.getCamRecord(recordId);
+        CamRecordDetail camRecord = camRecordService.getCamRecordDetail(recordId);
         if (camRecord != null) {
             return WebResult.success(camRecord);
         }
@@ -121,20 +100,6 @@ public class CamController {
         return WebResult.fail();
     }
 
-    @Operation(summary = "开启/关闭摄像头", description = "N")
-    @PostMapping(value = "/data", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String submit(String deviceId, String content) throws IOException {
-        camService.setCamState(deviceId);
-        return WebResult.success();
-    }
-
-    @Operation(summary = "设置 cam 状态", description = "N")
-    @PostMapping(value = "/state", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String updateCamState(String deviceId, boolean onStream) throws IOException {
-        camService.updateCamState(deviceId, onStream);
-        return WebResult.success();
-    }
-
     @Operation(summary = "添加活动接口", description = "N")
     @PostMapping(value = "/activity", produces = MediaType.APPLICATION_JSON_VALUE)
     public String addActivity() {

+ 3 - 5
content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/db/mapper/CamRecordMapper.java

@@ -3,8 +3,7 @@ package cn.reghao.tnb.content.app.disk.db.mapper;
 import cn.reghao.jutil.jdk.db.BaseMapper;
 import cn.reghao.jutil.jdk.db.Page;
 import cn.reghao.tnb.content.app.disk.model.po.CamRecord;
-import cn.reghao.tnb.content.app.disk.model.vo.RecordInfo;
-import cn.reghao.tnb.content.app.disk.model.vo.ResultCount;
+import cn.reghao.tnb.content.app.disk.model.vo.CamRecordInfo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -17,8 +16,7 @@ import java.util.List;
 @Mapper
 public interface CamRecordMapper extends BaseMapper<CamRecord> {
     List<CamRecord> findByCamId(@Param("camId") long camId, @Param("page") Page page);
-    List<RecordInfo> findByCamIdAndStartAt(@Param("camId") long camId, @Param("dayStr") String dayStr);
-    CamRecord findLatestRecord(long camId);
+    List<CamRecordInfo> findByCamIdAndStartAt(@Param("camId") long camId, @Param("dayStr") String dayStr);
     CamRecord findByRecordId(long recordId);
-    List<ResultCount> findGroupByYearMonth(@Param("camId") long camId, @Param("yearMonth") String yearMonth);
+    List<String> findGroupByYearMonth(@Param("camId") long camId, @Param("yearMonth") String yearMonth);
 }

+ 19 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/dto/CamDeviceDto.java

@@ -0,0 +1,19 @@
+package cn.reghao.tnb.content.app.disk.model.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotBlank;
+
+/**
+ * @author reghao
+ * @date 2025-09-02 13:59:33
+ */
+@Getter
+@Setter
+public class CamDeviceDto {
+    @NotBlank
+    private String deviceId;
+    @NotBlank
+    private String camName;
+}

+ 3 - 5
content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/dto/CamRecordDto.java

@@ -19,10 +19,8 @@ public class CamRecordDto {
     private Long startAt;
     @NotNull
     private Integer duration;
-    //@NotBlank
-    private String videoFileId;
-
-    private Integer coverChannelCode;
-    private String coverFileId;
+    @NotNull
     private Integer videoChannelCode;
+    @NotBlank
+    private String videoFileId;
 }

+ 2 - 5
content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/po/CamDevice.java

@@ -16,22 +16,19 @@ import java.time.LocalDateTime;
 @Setter
 @Getter
 public class CamDevice extends BaseObject<Integer> {
-    private String deviceId;
     private Long camId;
     private String camName;
-    private Boolean online;
     private Boolean state;
     private LocalDateTime addAt;
-    private Long owner;
+    private Long addBy;
     private String pushUrl;
     private String pullUrl;
 
     public CamDevice(Long camId, String camName) {
         this.camId = camId;
         this.camName = camName;
-        this.online = true;
         this.state = false;
         this.addAt = LocalDateTime.now();
-        this.owner = UserContext.getUserId();
+        this.addBy = UserContext.getUserId();
     }
 }

+ 1 - 3
content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/po/CamRecord.java

@@ -18,15 +18,13 @@ public class CamRecord extends BaseObject<Integer> {
     private Long camId;
     private Long recordId;
     private String videoFileId;
-    private String coverUrl;
     private LocalDateTime startAt;
     private Integer duration;
 
-    public CamRecord(long camId, long recordId, String videoFileId, String coverUrl, int duration, LocalDateTime startAt) {
+    public CamRecord(long camId, long recordId, String videoFileId, int duration, LocalDateTime startAt) {
         this.camId = camId;
         this.recordId = recordId;
         this.videoFileId = videoFileId;
-        this.coverUrl = coverUrl;
         this.startAt = startAt;
         this.duration = duration;
     }

+ 1 - 2
content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/po/UserActivity.java

@@ -1,6 +1,5 @@
 package cn.reghao.tnb.content.app.disk.model.po;
 
-import cn.reghao.jutil.jdk.db.BaseObject;
 import cn.reghao.tnb.common.auth.UserContext;
 
 import java.time.LocalDateTime;
@@ -10,7 +9,7 @@ import java.util.UUID;
  * @author reghao
  * @date 2024-08-30 20:51:33
  */
-public class UserActivity extends BaseObject<Integer> {
+public class UserActivity {
     private String id;
     private Integer activity;
     private LocalDateTime createTime;

+ 5 - 13
content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/query/CamDeviceQuery.java

@@ -10,21 +10,18 @@ import lombok.Getter;
 public class CamDeviceQuery {
     private Long camId;
     private String camName;
-    private String deviceId;
-    private Long owner;
+    private Long addBy;
 
     private CamDeviceQuery(Builder builder) {
         this.camId = builder.camId;
         this.camName = builder.camName;
-        this.deviceId = builder.deviceId;
-        this.owner = builder.owner;
+        this.addBy = builder.addBy;
     }
 
     public static final class Builder {
         private Long camId;
         private String camName;
-        private String deviceId;
-        private Long owner;
+        private Long addBy;
 
         public Builder() {
         }
@@ -39,13 +36,8 @@ public class CamDeviceQuery {
             return this;
         }
 
-        public Builder deviceId(String deviceId) {
-            this.deviceId = deviceId;
-            return this;
-        }
-
-        public Builder owner(long owner) {
-            this.owner = owner;
+        public Builder addBy(long addBy) {
+            this.addBy = addBy;
             return this;
         }
 

+ 18 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/vo/CamDetail.java

@@ -1,14 +1,31 @@
 package cn.reghao.tnb.content.app.disk.model.vo;
 
+import cn.reghao.tnb.content.app.disk.model.po.CamDevice;
+import lombok.Getter;
+import lombok.Setter;
+
 import java.util.List;
 
 /**
  * @author reghao
  * @date 2025-09-01 17:53:06
  */
+@Getter
+@Setter
 public class CamDetail {
     private long camId;
     private String camName;
+    private boolean onLive;
+    private String liveUrl;
     private String date;
-    private List<RecordInfo> recordInfoList;
+    private List<CamRecordInfo> dayRecords;
+
+    public CamDetail(CamDevice camDevice, String date, List<CamRecordInfo> dayRecords) {
+        this.camId = camDevice.getCamId();
+        this.camName = camDevice.getCamName();
+        this.onLive = camDevice.getState();
+        this.liveUrl = camDevice.getPullUrl();
+        this.date = date;
+        this.dayRecords = dayRecords;
+    }
 }

+ 12 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/vo/CamRecordDetail.java

@@ -1,8 +1,11 @@
 package cn.reghao.tnb.content.app.disk.model.vo;
 
+import cn.reghao.jutil.jdk.converter.DateTimeConverter;
+import cn.reghao.tnb.content.app.disk.model.po.CamRecord;
 import lombok.AllArgsConstructor;
 import lombok.Getter;
 import lombok.NoArgsConstructor;
+import lombok.Setter;
 
 /**
  * @author reghao
@@ -10,10 +13,18 @@ import lombok.NoArgsConstructor;
  */
 @NoArgsConstructor
 @AllArgsConstructor
+@Setter
 @Getter
 public class CamRecordDetail {
     private Long camId;
     private Long recordId;
     private String recordTime;
-    private CamUrl camUrl;
+    private String url;
+
+    public CamRecordDetail(CamRecord camRecord, String signedUrl) {
+        this.camId = camRecord.getCamId();
+        this.recordId = camRecord.getRecordId();
+        this.recordTime = DateTimeConverter.format(camRecord.getStartAt());
+        this.url = signedUrl;
+    }
 }

+ 7 - 23
content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/vo/CamRecordInfo.java

@@ -1,33 +1,17 @@
 package cn.reghao.tnb.content.app.disk.model.vo;
 
-import cn.reghao.jutil.jdk.converter.DateTimeConverter;
-import cn.reghao.tnb.content.app.disk.model.po.CamRecord;
-import lombok.AllArgsConstructor;
 import lombok.Getter;
 
+import java.time.LocalDateTime;
+
 /**
  * @author reghao
- * @date 2024-03-22 22:13:31
+ * @date 2025-08-28 22:57:45
  */
 @Getter
-@AllArgsConstructor
 public class CamRecordInfo {
-    private Long camId;
-    private Long recordId;
-    private String startAt;
-    private Integer duration;
-
-    public CamRecordInfo(CamRecord camRecord) {
-        this.camId = camRecord.getCamId();
-        this.recordId = camRecord.getRecordId();
-        this.startAt = DateTimeConverter.format(camRecord.getStartAt());
-        this.duration = camRecord.getDuration();
-    }
-
-    public CamRecordInfo(RecordInfo recordInfo) {
-        this.camId = recordInfo.getCamId();
-        this.recordId = recordInfo.getRecordId();
-        this.startAt = DateTimeConverter.format(recordInfo.getStartAt());
-        this.duration = recordInfo.getDuration();
-    }
+    private long camId;
+    private long recordId;
+    private String startTime;
+    private int duration;
 }

+ 6 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/vo/CamSearch.java

@@ -1,6 +1,8 @@
 package cn.reghao.tnb.content.app.disk.model.vo;
 
 import lombok.Getter;
+import lombok.Setter;
+import org.hibernate.validator.constraints.Length;
 
 import javax.validation.constraints.NotNull;
 
@@ -8,9 +10,13 @@ import javax.validation.constraints.NotNull;
  * @author reghao
  * @date 2025-09-01 17:40:26
  */
+@Setter
 @Getter
 public class CamSearch {
+    @NotNull
     private Long camId;
+    @Length(max = 7, message = "2025-09 格式")
     private String yearMonth;
+    @Length(max = 10, message = "2025-09-02 格式")
     private String yearMonthDay;
 }

+ 0 - 26
content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/vo/CamUrl.java

@@ -1,26 +0,0 @@
-package cn.reghao.tnb.content.app.disk.model.vo;
-
-import lombok.Getter;
-
-/**
- * @author reghao
- * @date 2025-03-06 20:27:53
- */
-@Getter
-public class CamUrl {
-    private String urlType;
-    private String videoUrl;
-    private boolean live;
-
-    public CamUrl(String videoUrl) {
-        this.urlType = "mp4";
-        this.videoUrl = videoUrl;
-        this.live = false;
-    }
-
-    public CamUrl(String videoUrl, boolean live) {
-        this.urlType = "flv";
-        this.videoUrl = videoUrl;
-        this.live = live;
-    }
-}

+ 0 - 15
content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/vo/MarkDay.java

@@ -1,15 +0,0 @@
-package cn.reghao.tnb.content.app.disk.model.vo;
-
-/**
- * @author reghao
- * @date 2024-08-31 20:41:12
- */
-public class MarkDay {
-    private String day;
-    private String style;
-
-    public MarkDay(String day) {
-        this.day = day;
-        this.style = "red";
-    }
-}

+ 0 - 17
content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/vo/RecordInfo.java

@@ -1,17 +0,0 @@
-package cn.reghao.tnb.content.app.disk.model.vo;
-
-import lombok.Getter;
-
-import java.time.LocalDateTime;
-
-/**
- * @author reghao
- * @date 2025-08-28 22:57:45
- */
-@Getter
-public class RecordInfo {
-    private long camId;
-    private long recordId;
-    private LocalDateTime startAt;
-    private int duration;
-}

+ 0 - 13
content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/vo/ResultCount.java

@@ -1,13 +0,0 @@
-package cn.reghao.tnb.content.app.disk.model.vo;
-
-import lombok.Getter;
-
-/**
- * @author reghao
- * @date 2025-08-28 22:57:52
- */
-@Getter
-public class ResultCount {
-    private String key;
-    private int value;
-}

+ 19 - 68
content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/service/CamRecordService.java

@@ -5,9 +5,7 @@ import cn.reghao.jutil.jdk.converter.DateTimeConverter;
 import cn.reghao.jutil.jdk.db.Page;
 import cn.reghao.jutil.jdk.result.Result;
 import cn.reghao.jutil.tool.id.SnowFlake;
-import cn.reghao.oss.sdk.model.dto.media.ImageInfo;
 import cn.reghao.oss.sdk.model.dto.media.VideoInfo;
-import cn.reghao.tnb.common.auth.UserContext;
 import cn.reghao.tnb.content.app.disk.db.mapper.CamDeviceMapper;
 import cn.reghao.tnb.content.app.disk.db.mapper.CamRecordMapper;
 import cn.reghao.tnb.content.app.disk.model.dto.CamRecordDto;
@@ -42,30 +40,28 @@ public class CamRecordService {
         this.camRecordMapper = camRecordMapper;
     }
 
-    @Deprecated
-    public Result add(CamRecordDto camRecordDto) {
-        try {
-            int coverChannelCode = camRecordDto.getCoverChannelCode();
-            String coverFileId = camRecordDto.getCoverFileId();
-            ImageInfo imageInfo = ossService.getImageInfo(coverChannelCode, coverFileId);
-            String coverUrl = imageInfo.getUrl();
+    public Result addCamRecord(CamRecordDto camRecordDto) {
+        String camName = camRecordDto.getCamName();
+        CamDeviceQuery camDeviceQuery = new CamDeviceQuery.Builder()
+                .camName(camName)
+                .build();
+        Page page = new Page(1, 10);
+        List<CamDevice> camDeviceList = camDeviceMapper.findCamDeviceQueryByPage(page, camDeviceQuery);
+        if (camDeviceList.isEmpty()) {
+            return Result.fail("cam not exist");
+        }
 
+        long camId = camDeviceList.get(0).getCamId();
+        try {
             int videoChannelCode = camRecordDto.getVideoChannelCode();
             String videoFileId = camRecordDto.getVideoFileId();
             VideoInfo videoInfo = ossService.getVideoInfo(videoChannelCode, videoFileId);
 
-            String camName = camRecordDto.getCamName();
-            CamDeviceQuery camDeviceQuery = new CamDeviceQuery.Builder()
-                    .camName(camName)
-                    .build();
-            Page page = new Page(1, 10);
-            List<CamDevice> camDeviceList = camDeviceMapper.findCamDeviceQueryByPage(page, camDeviceQuery);
-            long camId = camDeviceList.get(0).getCamId();
             int duration = videoInfo.getDuration();
             long recordId = idGenerator.nextId();
             long startAt = camRecordDto.getStartAt();
             LocalDateTime startAt1 = DateTimeConverter.localDateTime(startAt);
-            CamRecord camRecord = new CamRecord(camId, recordId, videoFileId, coverUrl, duration, startAt1);
+            CamRecord camRecord = new CamRecord(camId, recordId, videoFileId, duration, startAt1);
             camRecordMapper.save(camRecord);
             return Result.success();
         } catch (Exception e) {
@@ -75,24 +71,6 @@ public class CamRecordService {
         return Result.fail("");
     }
 
-    public Result add(String videoFileId, CamRecordDto camRecordDto) {
-        String coverUrl = "";
-        String camName = camRecordDto.getCamName();
-        CamDeviceQuery camDeviceQuery = new CamDeviceQuery.Builder()
-                .camName(camName)
-                .build();
-        Page page = new Page(1, 10);
-        List<CamDevice> camDeviceList = camDeviceMapper.findCamDeviceQueryByPage(page, camDeviceQuery);
-        long camId = camDeviceList.get(0).getCamId();
-        int duration = camRecordDto.getDuration();
-        long recordId = idGenerator.nextId();
-        long startAt = camRecordDto.getStartAt();
-        LocalDateTime startAt1 = DateTimeConverter.localDateTime(startAt);
-        CamRecord camRecord = new CamRecord(camId, recordId, videoFileId, coverUrl, duration, startAt1);
-        camRecordMapper.save(camRecord);
-        return Result.success();
-    }
-
     /**
      * 获取某天的监控录像
      *
@@ -100,12 +78,11 @@ public class CamRecordService {
      * @return
      * @date 2024-08-31 18:08:972
      */
-    public List<CamRecordInfo> getCamRecords(Long camId, String dayStr) {
-        List<RecordInfo> list = camRecordMapper.findByCamIdAndStartAt(camId, dayStr);
-        return list.stream().map(CamRecordInfo::new).collect(Collectors.toList());
+    public List<CamRecordInfo> getCamRecordByDay(Long camId, String dayStr) {
+        return camRecordMapper.findByCamIdAndStartAt(camId, dayStr);
     }
 
-    public CamRecordDetail getCamRecord(long recordId) {
+    public CamRecordDetail getCamRecordDetail(long recordId) {
         CamRecord camRecord = camRecordMapper.findByRecordId(recordId);
         return camRecord == null ? null : getCamRecordDetail(camRecord);
     }
@@ -117,41 +94,15 @@ public class CamRecordService {
      * @return
      * @date 2024-08-31 20:08:873
      */
-    public List<MarkDay> getDaysInMonth(Long camId, String yearMonth) {
-        return camRecordMapper.findGroupByYearMonth(camId, yearMonth).stream()
-                .map(resultCount -> {
-                    String day = resultCount.getKey();
-                    return new MarkDay(day);
-                })
-                .collect(Collectors.toList());
-    }
-
-    public CamRecordDetail getLatestRecord(long camId) {
-        long loginUser = UserContext.getUserId();
-        CamDeviceQuery camDeviceQuery = new CamDeviceQuery.Builder()
-                .camId(camId)
-                .owner(loginUser)
-                .build();
-        Page page = new Page(1, 1);
-        List<CamDevice> camDeviceList = camDeviceMapper.findCamDeviceQueryByPage(page, camDeviceQuery);
-        CamDevice camDevice = camDeviceList.get(0);
-        if (camDevice.getState()) {
-            String liveUrl = camDevice.getPullUrl();
-            CamUrl camUrl = new CamUrl(liveUrl, true);
-        }
-
-        CamRecord camRecord = camRecordMapper.findLatestRecord(camId);
-        return camRecord == null ? null : getCamRecordDetail(camRecord);
+    public List<String> getDaysInMonth(Long camId, String yearMonth) {
+        return camRecordMapper.findGroupByYearMonth(camId, yearMonth);
     }
 
     private CamRecordDetail getCamRecordDetail(CamRecord camRecord) {
-        String recordTime = DateTimeConverter.format(camRecord.getStartAt());
-        long recordId = camRecord.getRecordId();
         String videoFileId = camRecord.getVideoFileId();
         try {
             String signedUrl = ossService.getSignedUrlByUrl(channelCode, videoFileId);
-            CamUrl camUrl = new CamUrl(signedUrl);
-            return new CamRecordDetail(camRecord.getCamId(), recordId, recordTime, camUrl);
+            return new CamRecordDetail(camRecord, signedUrl);
         } catch (Exception e) {
             e.printStackTrace();
         }

+ 14 - 53
content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/service/CamService.java

@@ -1,24 +1,18 @@
 package cn.reghao.tnb.content.app.disk.service;
 
-import cn.reghao.jutil.jdk.converter.DateTimeConverter;
 import cn.reghao.jutil.jdk.db.Page;
-import cn.reghao.jutil.jdk.db.PageList;
-import cn.reghao.jutil.jdk.result.Result;
 import cn.reghao.jutil.tool.id.SnowFlake;
 import cn.reghao.tnb.common.auth.UserContext;
 import cn.reghao.tnb.content.app.disk.db.mapper.CamDeviceMapper;
-import cn.reghao.tnb.content.app.disk.db.mapper.CamRecordMapper;
 import cn.reghao.tnb.content.app.disk.db.mapper.UserActivityMapper;
+import cn.reghao.tnb.content.app.disk.model.dto.CamDeviceDto;
 import cn.reghao.tnb.content.app.disk.model.po.CamDevice;
-import cn.reghao.tnb.content.app.disk.model.po.CamRecord;
 import cn.reghao.tnb.content.app.disk.model.po.UserActivity;
 import cn.reghao.tnb.content.app.disk.model.query.CamDeviceQuery;
-import cn.reghao.tnb.content.app.disk.model.vo.CamRecordDetail;
 import cn.reghao.tnb.content.app.geo.model.vo.SelectOption;
 import cn.reghao.tnb.content.app.util.RandomUtil;
 import org.springframework.stereotype.Service;
 
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -29,84 +23,51 @@ import java.util.stream.Collectors;
  */
 @Service
 public class CamService {
+    private int pageSize = 10;
     private final SnowFlake idGenerator;
     private final CamDeviceMapper camDeviceMapper;
-    private final CamRecordMapper camRecordMapper;
     private final UserActivityMapper userActivityMapper;
 
-    public CamService(CamDeviceMapper camDeviceMapper, CamRecordMapper camRecordMapper,
-                      UserActivityMapper userActivityMapper) {
+    public CamService(CamDeviceMapper camDeviceMapper, UserActivityMapper userActivityMapper) {
         this.idGenerator = new SnowFlake(1L, 1L);
         this.camDeviceMapper = camDeviceMapper;
-        this.camRecordMapper = camRecordMapper;
         this.userActivityMapper = userActivityMapper;
     }
 
-    public Result addCam(String camName) {
+    public void addCamDevice(CamDeviceDto camDeviceDto) {
+        String camName = camDeviceDto.getCamName();
         long camId = idGenerator.nextId();
         CamDevice camDevice = new CamDevice(camId, camName);
-
         camDeviceMapper.save(camDevice);
-        return Result.success();
     }
 
     public List<SelectOption> getCamKeyValues() {
         long loginUser = UserContext.getUserId();
         CamDeviceQuery camDeviceQuery = new CamDeviceQuery.Builder()
-                .owner(loginUser)
+                .addBy(loginUser)
                 .build();
-        Page page = new Page(1, 100);
+        Page page = new Page(1, pageSize);
         List<CamDevice> camDeviceList = camDeviceMapper.findCamDeviceQueryByPage(page, camDeviceQuery);
         return camDeviceList.stream().map(camDevice -> {
             long camId = camDevice.getCamId();
             String camName = camDevice.getCamName();
-            return new SelectOption(camId+"", camName);
+            return new SelectOption(camName, camId+"");
         }).collect(Collectors.toList());
     }
 
-    public PageList<CamDevice> getCamDevices(int pageNumber) {
-        int pageSize = 10;
+    public CamDevice getCamDevice(long camId) {
+        Page page = new Page(1, pageSize);
         long loginUser = UserContext.getUserId();
         CamDeviceQuery camDeviceQuery = new CamDeviceQuery.Builder()
-                .owner(loginUser)
+                .addBy(loginUser)
+                .camId(camId)
                 .build();
-        Page page = new Page(pageNumber, pageSize);
         List<CamDevice> camDeviceList = camDeviceMapper.findCamDeviceQueryByPage(page, camDeviceQuery);
-        int total = camDeviceList.size();
-        return PageList.pageList(pageNumber, pageSize, total, camDeviceList);
-    }
-
-    public CamRecordDetail getLatestRecord(long camId) {
-        int pageSize = 10;
-        Page page = new Page(1, pageSize);
-        //PageRequest pageRequest = PageRequest.of(0, 1, Sort.by(Sort.Direction.DESC, "createTime"));
-        List<CamRecord> camRecordList = camRecordMapper.findByCamId(camId, page);
-        CamRecord camRecord = camRecordList.get(0);
-        String recordTime = DateTimeConverter.format(camRecord.getStartAt());
-        long recordId = camRecord.getRecordId();
-        String coverUrl = camRecord.getCoverUrl();
-        String videoFileId = camRecord.getVideoFileId();
-        /*DiskFile diskFile = fileService.getDiskFile(videoFileId);
-        if (diskFile != null) {
-            long loginUser = UserContext.getUserId();
-            long owner = diskFile.getOwner();
-            if (loginUser == owner) {
-                String videoUrl = String.format("/%s", diskFile.getObjectName());
-                return new CamRecordDetail(camRecord.getCamId(), recordId, recordTime, coverUrl, videoUrl);
-            }
-        }*/
-
-        return null;
-    }
-
-    public void setCamState(String deviceId) throws IOException {
-    }
-
-    public void updateCamState(String deviceId, boolean onStream) {
+        return camDeviceList.isEmpty() ? null : camDeviceList.get(0);
     }
 
     public void addActivity() {
-        int total = RandomUtil.getNumber(5, 20);
+        int total = RandomUtil.getNumber(10, 100);
         List<UserActivity> list = new ArrayList<>();
         while (total-- > 0) {
             UserActivity userActivity = new UserActivity();

+ 7 - 21
content/content-service/src/main/resources/mapper/disk/CamDeviceMapper.xml

@@ -4,17 +4,9 @@
 <mapper namespace="cn.reghao.tnb.content.app.disk.db.mapper.CamDeviceMapper">
     <insert id="save" useGeneratedKeys="true" keyProperty="id">
         insert into my_cam_device
-        (`album_id`,`post_id`,`pos`,`added_at`)
+        (`cam_id`,`cam_name`,`state`,`add_at`,`add_by`,`pull_url`,`push_url`)
         values
-        (#{albumId},#{postId},#{pos},#{addedAt})
-    </insert>
-    <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
-        insert into my_cam_device
-        (`album_id`,`post_id`,`pos`,`added_at`)
-        values
-        <foreach collection="list" item="item" index="index" separator=",">
-            (#{item.albumId},#{item.postId},#{item.pos},#{item.addedAt})
-        </foreach>
+        (#{camId},#{camName},#{state},#{addAt},#{addBy},#{pullUrl},#{pushUrl})
     </insert>
 
     <select id="countByCamDeviceQuery" resultType="java.lang.Integer">
@@ -25,18 +17,15 @@
             <if test="camId != null">
                 and cam_id=#{camId}
             </if>
-            <if test="owner != null">
-                and owner=#{owner}
+            <if test="addBy != null">
+                and `add_by`=#{addBy}
             </if>
             <if test="camName != null">
                 and cam_name=#{camName}
             </if>
-            <if test="deviceId != null">
-                and device_id=#{deviceId}
-            </if>
         </where>
     </select>
-    <select id="findCamDeviceQueryByPage" resultType="cn.reghao.tnb.content.app.disk.model.po.NetDisk">
+    <select id="findCamDeviceQueryByPage" resultType="cn.reghao.tnb.content.app.disk.model.po.CamDevice">
         select *
         from my_cam_device
         <where>
@@ -44,15 +33,12 @@
             <if test="camDeviceQuery.camId != null">
                 and cam_id=#{camDeviceQuery.camId}
             </if>
-            <if test="camDeviceQuery.owner != null">
-                and owner=#{owner}
+            <if test="camDeviceQuery.addBy != null">
+                and `add_by`=#{camDeviceQuery.addBy}
             </if>
             <if test="camDeviceQuery.camName != null">
                 and cam_name=#{camDeviceQuery.camName}
             </if>
-            <if test="camDeviceQuery.deviceId != null">
-                and device_id=#{camDeviceQuery.deviceId}
-            </if>
         </where>
     </select>
 </mapper>

+ 8 - 22
content/content-service/src/main/resources/mapper/disk/CamRecordMapper.xml

@@ -4,17 +4,9 @@
 <mapper namespace="cn.reghao.tnb.content.app.disk.db.mapper.CamRecordMapper">
     <insert id="save" useGeneratedKeys="true" keyProperty="id">
         insert into my_cam_record
-        (`album_id`,`post_id`,`pos`,`added_at`)
+        (`cam_id`,`record_id`,`video_file_id`,`start_at`,`duration`)
         values
-        (#{albumId},#{postId},#{pos},#{addedAt})
-    </insert>
-    <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
-        insert into my_cam_record
-        (`album_id`,`post_id`,`pos`,`added_at`)
-        values
-        <foreach collection="list" item="item" index="index" separator=",">
-            (#{item.albumId},#{item.postId},#{item.pos},#{item.addedAt})
-        </foreach>
+        (#{camId},#{recordId},#{videoFileId},#{startAt},#{duration})
     </insert>
 
     <delete id="deleteByAlbumIdAndPostId">
@@ -27,27 +19,21 @@
         from my_cam_record
         where cam_id=#{camId}
     </select>
-    <select id="findByCamIdAndStartAt" resultType="cn.reghao.tnb.content.app.disk.model.vo.RecordInfo">
-        select *
+    <select id="findByCamIdAndStartAt" resultType="cn.reghao.tnb.content.app.disk.model.vo.CamRecordInfo">
+        select cam_id,record_id,DATE_FORMAT(start_at,'%T') as startTime,duration
         from my_cam_record
         where cam_id=#{camId} and DATE_FORMAT(start_at,'%Y-%m-%d')=#{dayStr}
-    </select>
-    <select id="findLatestRecord" resultType="cn.reghao.tnb.content.app.disk.model.po.CamRecord">
-        select *
-        from my_cam_record
-        where cam_id=#{camId}
-        order by start_at desc
-        limit 1
+        order by start_at asc
     </select>
     <select id="findByRecordId" resultType="cn.reghao.tnb.content.app.disk.model.po.CamRecord">
         select *
         from my_cam_record
         where record_id=#{recordId}
     </select>
-    <select id="findGroupByYearMonth" resultType="cn.reghao.tnb.content.app.disk.model.vo.ResultCount">
-        select DATE_FORMAT(start_at,'%Y-%m-%d') as `key`, count(*) as `value`
+    <select id="findGroupByYearMonth" resultType="java.lang.String">
+        select DATE_FORMAT(start_at,'%Y-%m-%d') as yearMonthDay
         from my_cam_record
         where cam_id=#{camId} and DATE_FORMAT(start_at,'%Y-%m')=#{yearMonth}
-        group by `key`
+        group by yearMonthDay
     </select>
 </mapper>

+ 9 - 1
content/content-service/src/main/resources/mapper/disk/UserActivityMapper.xml

@@ -3,9 +3,17 @@
 
 <mapper namespace="cn.reghao.tnb.content.app.disk.db.mapper.UserActivityMapper">
     <insert id="save" useGeneratedKeys="true" keyProperty="id">
-        insert into disk_user_activity
+        insert into my_user_activity
         (`id`,`activity`,`create_time`,`create_by`)
         values
         (#{id},#{activity},#{createTime},#{createBy})
     </insert>
+    <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
+        insert into my_user_activity
+        (`id`,`activity`,`create_time`,`create_by`)
+        values
+        <foreach collection="list" item="item" index="index" separator=",">
+            (#{item.id},#{item.activity},#{item.createTime},#{item.createBy})
+        </foreach>
+    </insert>
 </mapper>