From cb12bd731d3c449d359dd1252892b0e7bfeb30df Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: Wed, 27 Nov 2024 22:44:22 +0800
Subject: [PATCH] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../iot/vmp/service/bean/RecordPlanItem.java  |  8 +--
 .../service/impl/RecordPlanServiceImpl.java   | 55 ++++++++++++++++++-
 .../vmp/storager/dao/RecordPlanMapper.java    |  6 +-
 .../src/components/dialog/editRecordPlan.vue  | 47 +++++++++-------
 数据库/2.7.3/初始化-mysql-2.7.3.sql           |  6 +-
 .../2.7.3/初始化-postgresql-kingbase-2.7.3.sql |  4 +-
 6 files changed, 91 insertions(+), 35 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/service/bean/RecordPlanItem.java b/src/main/java/com/genersoft/iot/vmp/service/bean/RecordPlanItem.java
index 14383cb15..31fa3214e 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/bean/RecordPlanItem.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/bean/RecordPlanItem.java
@@ -10,11 +10,11 @@ public class RecordPlanItem {
     @Schema(description = "计划项数据库ID")
     private int id;
 
-    @Schema(description = "计划开始时间")
-    private Long startTime;
+    @Schema(description = "计划开始时间的序号, 从0点开始,每半个小时增加1")
+    private Integer start;
 
-    @Schema(description = "计划结束时间")
-    private Long stopTime;
+    @Schema(description = "计划结束时间的序号, 从0点开始,每半个小时增加1")
+    private Integer stop;
 
     @Schema(description = "计划周几执行")
     private Integer weekDay;
diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/RecordPlanServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/RecordPlanServiceImpl.java
index 44b49ddde..dc3de6834 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/RecordPlanServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/RecordPlanServiceImpl.java
@@ -1,8 +1,14 @@
 package com.genersoft.iot.vmp.service.impl;
 
+import com.genersoft.iot.vmp.common.InviteInfo;
+import com.genersoft.iot.vmp.common.InviteSessionStatus;
 import com.genersoft.iot.vmp.conf.exception.ControllerException;
-import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel;
+import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException;
+import com.genersoft.iot.vmp.gb28181.bean.*;
 import com.genersoft.iot.vmp.gb28181.dao.CommonGBChannelMapper;
+import com.genersoft.iot.vmp.gb28181.service.IGbChannelService;
+import com.genersoft.iot.vmp.media.event.media.MediaArrivalEvent;
+import com.genersoft.iot.vmp.media.event.media.MediaDepartureEvent;
 import com.genersoft.iot.vmp.service.IRecordPlanService;
 import com.genersoft.iot.vmp.service.bean.RecordPlan;
 import com.genersoft.iot.vmp.service.bean.RecordPlanItem;
@@ -13,9 +19,15 @@ import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.event.EventListener;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.sip.InvalidArgumentException;
+import javax.sip.SipException;
+import java.text.ParseException;
 import java.util.List;
 
 @Service
@@ -28,6 +40,43 @@ public class RecordPlanServiceImpl implements IRecordPlanService {
     @Autowired
     private CommonGBChannelMapper channelMapper;
 
+    @Autowired
+    private IGbChannelService channelService;
+
+
+    /**
+     * 流到来的处理
+     */
+    @Async("taskExecutor")
+    @org.springframework.context.event.EventListener
+    public void onApplicationEvent(MediaArrivalEvent event) {
+
+    }
+
+    /**
+     * 流离开的处理
+     */
+    @Async("taskExecutor")
+    @EventListener
+    public void onApplicationEvent(MediaDepartureEvent event) {
+        // 流断开,检查是否还处于录像状态, 如果是则继续录像
+
+    }
+
+    @Scheduled(cron = "0 */30 * * * *")
+    public void execution() {
+        // 执行计划
+        // 查询startTime等于现在的, 开始录像
+
+        // 查询stopTime等于现在的,结束录像
+        // 查询处于中间的,验证录像是否正在进行
+
+
+        // TODO 无人观看要确保处于录像状态的通道不被移除
+    }
+
+    // 系统启动时
+
     @Override
     @Transactional
     public void add(RecordPlan plan) {
@@ -61,8 +110,8 @@ public class RecordPlanServiceImpl implements IRecordPlanService {
     public void update(RecordPlan plan) {
         plan.setUpdateTime(DateUtil.getNow());
         recordPlanMapper.update(plan);
-        recordPlanMapper.cleanItems(plan.getId());
-        if (plan.getPlanItemList() != null){
+        if (plan.getPlanItemList() != null && !plan.getPlanItemList().isEmpty()){
+            recordPlanMapper.cleanItems(plan.getId());
             recordPlanMapper.batchAddItem(plan.getId(), plan.getPlanItemList());
         }
         // TODO  更新录像队列
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/RecordPlanMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/RecordPlanMapper.java
index 705e59aae..2cdc6468e 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/dao/RecordPlanMapper.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/RecordPlanMapper.java
@@ -26,13 +26,13 @@ public interface RecordPlanMapper {
 
     @Insert(" <script>" +
             "INSERT INTO wvp_record_plan_item (" +
-            "start_time," +
-            "stop_time, " +
+            "start," +
+            "stop, " +
             "week_day," +
             "plan_id) " +
             "VALUES" +
             "<foreach collection='planItemList' index='index' item='item' separator=','> " +
-            "(#{item.startTime}, #{item.stopTime}, #{item.weekDay},#{planId})" +
+            "(#{item.start}, #{item.stop}, #{item.weekDay},#{planId})" +
             "</foreach> " +
             " </script>")
     void batchAddItem(@Param("planId") int planId, List<RecordPlanItem> planItemList);
diff --git a/web_src/src/components/dialog/editRecordPlan.vue b/web_src/src/components/dialog/editRecordPlan.vue
index 3772c4909..5ae900c3b 100644
--- a/web_src/src/components/dialog/editRecordPlan.vue
+++ b/web_src/src/components/dialog/editRecordPlan.vue
@@ -157,7 +157,6 @@ export default {
       // 把 336长度的 list 分成 7 组,每组 48 个
       for (let i = 0; i < this.byteTime.length; i += DayTimes) {
         let planArray = this.byteTime2Plan(this.byteTime.slice(i, i + DayTimes));
-        console.log(planArray)
         if(!planArray || planArray.length === 0) {
           week ++;
           continue
@@ -165,8 +164,8 @@ export default {
         for (let j = 0; j < planArray.length; j++) {
           planList.push({
             id: this.id,
-            startTime: planArray[j].startTime,
-            stopTime: planArray[j].stopTime,
+            start: planArray[j].start,
+            stop: planArray[j].stop,
             weekDay: week
           })
         }
@@ -175,44 +174,52 @@ export default {
       return planList
     },
     byteTime2Plan(weekItem){
-      let startTime = 0;
-      let endTime = 0;
+      let start = null;
+      let stop = null;
       let result = []
 
       for (let i = 0; i < weekItem.length; i++) {
         let item = weekItem[i]
-        if (item === '1') {
-          endTime = 30*i
-          if (startTime === 0 ) {
-            startTime = 30*i
+        if (item === '1') { // 表示选中
+          stop = i
+          if (start === null ) {
+            start = i
+          }
+          if (i === weekItem.length - 1) {
+            result.push({
+              start: start,
+              stop: stop,
+            })
           }
         } else {
-          if (endTime !== 0){
+          if (stop !== 0){
             result.push({
-              startTime: startTime * 60 * 1000,
-              stopTime: endTime * 60 * 1000,
+              start: start,
+              stop: stop,
             })
-            startTime = 0
-            endTime = 0
+            start = 0
+            stop = 0
           }
         }
       }
       return result;
     },
     plan2Byte(planList) {
-      console.log(planList);
       let byte = ""
       let indexArray = {}
       for (let i = 0; i < planList.length; i++) {
-        let index = planList[i].startTime/1000/60/30
-        let endIndex = planList[i].stopTime/1000/60/30
+
+        let weekDay = planList[i].weekDay
+        let index = planList[i].start
+        let endIndex = planList[i].stop
+        console.log(index + "===" + endIndex)
         for (let j = index; j <= endIndex; j++) {
-          indexArray[j + (planList[i].weekDay - 1 )*48] = j + i*48
+          indexArray["key_" + (j + (weekDay - 1 )*48)] = 1
+          console.log("key_" + (j + (weekDay - 1 )*48))
         }
       }
-      console.log(indexArray)
       for (let i = 0; i < 336; i++) {
-        if (indexArray[i]){
+        if (indexArray["key_" + i]){
           byte += "1"
         }else {
           byte += "0"
diff --git a/数据库/2.7.3/初始化-mysql-2.7.3.sql b/数据库/2.7.3/初始化-mysql-2.7.3.sql
index faada9cd4..e12677da5 100644
--- a/数据库/2.7.3/初始化-mysql-2.7.3.sql
+++ b/数据库/2.7.3/初始化-mysql-2.7.3.sql
@@ -440,10 +440,10 @@ create table wvp_record_plan
 create table wvp_record_plan_item
 (
     id              serial primary key,
-    start_time      bigint,
-    stop_time       bigint,
+    start           int,
+    stop            int,
     week_day        int,
-    plan_id        int,
+    plan_id         int,
     create_time     character varying(50),
     update_time     character varying(50)
 );
diff --git a/数据库/2.7.3/初始化-postgresql-kingbase-2.7.3.sql b/数据库/2.7.3/初始化-postgresql-kingbase-2.7.3.sql
index 9ef3e926b..c632f9a83 100644
--- a/数据库/2.7.3/初始化-postgresql-kingbase-2.7.3.sql
+++ b/数据库/2.7.3/初始化-postgresql-kingbase-2.7.3.sql
@@ -457,8 +457,8 @@ create table wvp_record_plan
 create table wvp_record_plan_item
 (
     id              serial primary key,
-    start_time      int8,
-    stop_time       int8,
+    start           int,
+    stop            int,
     week_day        int,
     plan_id        int,
     create_time     character varying(50),