From 5d3f307b44aa8df32c9d893764fb8525d51eda5c Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期三, 01 十一月 2023 14:07:32 +0800
Subject: [PATCH] 将录像存储路径迁移至wvp中配置,assist以有在需要视频合成的时候才会用

---
 sql/初始化-mysql-2.6.9.sql                                                        |    2 
 src/main/java/com/genersoft/iot/vmp/storager/dao/CloudRecordServiceMapper.java |    4 
 src/main/resources/all-application.yml                                         |    4 +
 src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaServerItem.java         |   21 +++++-
 src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java         |   18 ------
 src/main/java/com/genersoft/iot/vmp/storager/dao/MediaServerMapper.java        |    8 ++
 sql/更新-postgresql-kingbase-2.6.9.sql                                           |    3 
 src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java                      |   27 ++++++++
 src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java                      |   10 ---
 src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java   |   18 +-----
 src/main/java/com/genersoft/iot/vmp/conf/CloudRecordTimer.java                 |   16 +---
 sql/更新-mysql-2.6.9.sql                                                         |    2 
 sql/初始化-postgresql-kingbase-2.6.9.sql                                          |    2 
 13 files changed, 69 insertions(+), 66 deletions(-)

diff --git "a/sql/\345\210\235\345\247\213\345\214\226-mysql-2.6.9.sql" "b/sql/\345\210\235\345\247\213\345\214\226-mysql-2.6.9.sql"
index bd8a4f5..9dab2a4 100644
--- "a/sql/\345\210\235\345\247\213\345\214\226-mysql-2.6.9.sql"
+++ "b/sql/\345\210\235\345\247\213\345\214\226-mysql-2.6.9.sql"
@@ -165,7 +165,7 @@
                                   update_time character varying(50),
                                   hook_alive_interval integer,
                                   record_path character varying(255),
-                                  record_date integer default 7,
+                                  record_day integer default 7,
                                   constraint uk_media_server_unique_ip_http_port unique (ip, http_port)
 );
 
diff --git "a/sql/\345\210\235\345\247\213\345\214\226-postgresql-kingbase-2.6.9.sql" "b/sql/\345\210\235\345\247\213\345\214\226-postgresql-kingbase-2.6.9.sql"
index 701fd76..ed239c3 100644
--- "a/sql/\345\210\235\345\247\213\345\214\226-postgresql-kingbase-2.6.9.sql"
+++ "b/sql/\345\210\235\345\247\213\345\214\226-postgresql-kingbase-2.6.9.sql"
@@ -165,7 +165,7 @@
                                   update_time character varying(50),
                                   hook_alive_interval integer,
                                   record_path character varying(255),
-                                  record_date integer default 7,
+                                  record_day integer default 7,
                                   constraint uk_media_server_unique_ip_http_port unique (ip, http_port)
 );
 
diff --git "a/sql/\346\233\264\346\226\260-mysql-2.6.9.sql" "b/sql/\346\233\264\346\226\260-mysql-2.6.9.sql"
index 00de8b2..c994d5b 100644
--- "a/sql/\346\233\264\346\226\260-mysql-2.6.9.sql"
+++ "b/sql/\346\233\264\346\226\260-mysql-2.6.9.sql"
@@ -496,6 +496,6 @@
     add record_path character varying(255);
 
 alter table wvp_media_server
-    add record_date integer default 7;
+    add record_day integer default 7;
 
 
diff --git "a/sql/\346\233\264\346\226\260-postgresql-kingbase-2.6.9.sql" "b/sql/\346\233\264\346\226\260-postgresql-kingbase-2.6.9.sql"
index 550d9b2..711f5b6 100644
--- "a/sql/\346\233\264\346\226\260-postgresql-kingbase-2.6.9.sql"
+++ "b/sql/\346\233\264\346\226\260-postgresql-kingbase-2.6.9.sql"
@@ -496,6 +496,7 @@
     add record_path character varying(255);
 
 alter table wvp_media_server
-    add record_date integer default 7;
+    add record_day integer default 7;
+
 
 
diff --git a/src/main/java/com/genersoft/iot/vmp/conf/CloudRecordTimer.java b/src/main/java/com/genersoft/iot/vmp/conf/CloudRecordTimer.java
index 7e11833..a58fe6d 100644
--- a/src/main/java/com/genersoft/iot/vmp/conf/CloudRecordTimer.java
+++ b/src/main/java/com/genersoft/iot/vmp/conf/CloudRecordTimer.java
@@ -41,8 +41,8 @@
     /**
      * 瀹氭椂鏌ヨ寰呭垹闄ょ殑褰曞儚鏂囦欢
      */
+//    @Scheduled(fixedRate = 5000) //姣忎簲绉掓墽琛屼竴娆★紝鏂逛究娴嬭瘯
     @Scheduled(cron = "0 0 0 * * ?")   //姣忓ぉ鐨�0鐐规墽琛�
-//    @Scheduled(fixedRate = 5000)
     public void execute(){
         logger.info("[褰曞儚鏂囦欢瀹氭椂娓呯悊] 寮�濮嬫竻鐞嗚繃鏈熷綍鍍忔枃浠�");
         // 鑾峰彇閰嶇疆浜哸ssist鐨勬祦濯掍綋鑺傜偣
@@ -54,10 +54,10 @@
         for (MediaServerItem mediaServerItem : mediaServerItemList) {
 
             Calendar lastCalendar = Calendar.getInstance();
-            if (mediaServerItem.getRecordDate() > 0) {
+            if (mediaServerItem.getRecordDay() > 0) {
                 lastCalendar.setTime(new Date());
                 // 鑾峰彇淇濆瓨鐨勬渶鍚庢埅鑷虫棩鏈燂紝鍥犱负姣忎釜鑺傜偣閮芥湁涓�涓棩鏈燂紝涔熷氨鏄敮鎸佹瘡涓妭鐐硅缃笉鍚岀殑淇濆瓨鏃ユ湡锛�
-                lastCalendar.add(Calendar.DAY_OF_MONTH, -mediaServerItem.getRecordDate());
+                lastCalendar.add(Calendar.DAY_OF_MONTH, -mediaServerItem.getRecordDay());
                 Long lastDate = lastCalendar.getTimeInMillis();
 
                 // 鑾峰彇鍒版埅鑷虫棩鏈熶箣鍓嶇殑褰曞儚鏂囦欢鍒楄〃锛屾枃浠跺垪琛ㄦ弧瓒虫湭琚敹钘忓拰淇濇寔鐨勩�傝繖涓や釜瀛楁鐩墠鍏辫兘涓�鑷达紝
@@ -66,22 +66,16 @@
                 if (cloudRecordItemList.isEmpty()) {
                     continue;
                 }
-                List<Integer> cloudRecordItemIdList = new ArrayList<>();
                 for (CloudRecordItem cloudRecordItem : cloudRecordItemList) {
                     String date = new File(cloudRecordItem.getFilePath()).getParentFile().getName();
                     JSONObject jsonObject = zlmresTfulUtils.deleteRecordDirectory(mediaServerItem, cloudRecordItem.getApp(),
                             cloudRecordItem.getStream(), date, cloudRecordItem.getFileName());
                     if (jsonObject.getInteger("code") == 0) {
-                        cloudRecordItemIdList.add(cloudRecordItem.getId());
                     }else {
-                        logger.warn("[褰曞儚鏂囦欢瀹氭椂娓呯悊] 鍒犻櫎纾佺洏鏂囦欢閿欒锛� {}", jsonObject);
+                        logger.warn("[褰曞儚鏂囦欢瀹氭椂娓呯悊] 鍒犻櫎纾佺洏鏂囦欢閿欒锛� {}:{}", cloudRecordItem.getFilePath(), jsonObject);
                     }
                 }
-                if (cloudRecordItemIdList.isEmpty()) {
-                    continue;
-                }
-                cloudRecordServiceMapper.deleteList(cloudRecordItemIdList, mediaServerItem.getId());
-                result += cloudRecordItemIdList.size();
+                result += cloudRecordServiceMapper.deleteList(cloudRecordItemList);
             }
         }
         logger.info("[褰曞儚鏂囦欢瀹氭椂娓呯悊] 鍏辨竻鐞唟}涓繃鏈熷綍鍍忔枃浠�", result);
diff --git a/src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java b/src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java
index 20ed8cb..3acc795 100644
--- a/src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java
+++ b/src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java
@@ -81,6 +81,12 @@
     @Value("${media.record-assist-port:0}")
     private Integer recordAssistPort = 0;
 
+    @Value("${media.record-date:7}")
+    private Integer recordDay = 7;
+
+    @Value("${media.record-path}")
+    private String recordPath;
+
     public String getId() {
         return id;
     }
@@ -212,13 +218,32 @@
         mediaServerItem.setSendRtpPortRange(rtpSendPortRange);
         mediaServerItem.setRecordAssistPort(recordAssistPort);
         mediaServerItem.setHookAliveInterval(30.00f);
-
+        mediaServerItem.setRecordDay(recordDay);
+        if (recordPath != null) {
+            mediaServerItem.setRecordPath(recordPath);
+        }
         mediaServerItem.setCreateTime(DateUtil.getNow());
         mediaServerItem.setUpdateTime(DateUtil.getNow());
 
         return mediaServerItem;
     }
 
+    public Integer getRecordDay() {
+        return recordDay;
+    }
+
+    public void setRecordDay(Integer recordDay) {
+        this.recordDay = recordDay;
+    }
+
+    public String getRecordPath() {
+        return recordPath;
+    }
+
+    public void setRecordPath(String recordPath) {
+        this.recordPath = recordPath;
+    }
+
     public String getRtpSendPortRange() {
         return rtpSendPortRange;
     }
diff --git a/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java b/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java
index aaeff0a..0d11df8 100644
--- a/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java
+++ b/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java
@@ -56,8 +56,6 @@
 
     private String serverId = "000000";
 
-    private String recordPath = null;
-
     private String thirdPartyGBIdReg = "[\\s\\S]*";
 
     private String civilCodeFile = "classpath:civilCode.csv";
@@ -250,14 +248,6 @@
 
     public void setRefuseChannelStatusChannelFormNotify(Boolean refuseChannelStatusChannelFormNotify) {
         this.refuseChannelStatusChannelFormNotify = refuseChannelStatusChannelFormNotify;
-    }
-
-    public String getRecordPath() {
-        return recordPath;
-    }
-
-    public void setRecordPath(String recordPath) {
-        this.recordPath = recordPath;
     }
 
     public int getMaxNotifyCountQueue() {
diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
index 9bff21f..885126c 100755
--- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
+++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
@@ -295,24 +295,6 @@
                 result.setEnable_mp4(true);
             }
         }
-        if (mediaInfo.getRecordAssistPort() > 0 && userSetting.getRecordPath() == null) {
-            logger.info("鎺ㄦ祦鏃跺彂鐜板皻鏈缃綍鍍忚矾寰勶紝浠巃ssist鏈嶅姟涓鍙�");
-            JSONObject info = assistRESTfulUtils.getInfo(mediaInfo, null);
-            if (info != null && info.getInteger("code") != null && info.getInteger("code") == 0 ) {
-                JSONObject dataJson = info.getJSONObject("data");
-                if (dataJson != null) {
-                    String recordPath = dataJson.getString("record");
-                    userSetting.setRecordPath(recordPath);
-                    result.setMp4_save_path(recordPath);
-                    // 淇敼zlm涓殑褰曞儚璺緞
-                    if (mediaInfo.isAutoConfig()) {
-                        taskExecutor.execute(() -> {
-                            mediaServerService.setZLMConfig(mediaInfo, false);
-                        });
-                    }
-                }
-            }
-        }
         if (param.getApp().equalsIgnoreCase("rtp")) {
             String receiveKey = VideoManagerConstants.WVP_OTHER_RECEIVE_RTP_INFO + userSetting.getServerId() + "_" + param.getStream();
             OtherRtpSendInfo otherRtpSendInfo = (OtherRtpSendInfo)redisTemplate.opsForValue().get(receiveKey);
diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaServerItem.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaServerItem.java
index 365f154..cebfec3 100755
--- a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaServerItem.java
+++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaServerItem.java
@@ -81,7 +81,10 @@
     private boolean defaultServer;
 
     @Schema(description = "褰曞儚瀛樺偍鏃堕暱")
-    private int recordDate;
+    private int recordDay;
+
+    @Schema(description = "褰曞儚瀛樺偍璺緞")
+    private String recordPath;
 
     public MediaServerItem() {
     }
@@ -300,11 +303,19 @@
         this.sendRtpPortRange = sendRtpPortRange;
     }
 
-    public int getRecordDate() {
-        return recordDate;
+    public int getRecordDay() {
+        return recordDay;
     }
 
-    public void setRecordDate(int recordDate) {
-        this.recordDate = recordDate;
+    public void setRecordDay(int recordDay) {
+        this.recordDay = recordDay;
+    }
+
+    public String getRecordPath() {
+        return recordPath;
+    }
+
+    public void setRecordPath(String recordPath) {
+        this.recordPath = recordPath;
     }
 }
diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java
index 889909a..56f2a0c 100755
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java
@@ -419,17 +419,6 @@
 
 
         if (serverItem.isAutoConfig()) {
-            // 鏌ョ湅assist鏈嶅姟鐨勫綍鍍忚矾寰勯厤缃�
-            if (serverItem.getRecordAssistPort() > 0 && userSetting.getRecordPath() == null) {
-                JSONObject info = assistRESTfulUtils.getInfo(serverItem, null);
-                if (info != null && info.getInteger("code") != null && info.getInteger("code") == 0 ) {
-                    JSONObject dataJson = info.getJSONObject("data");
-                    if (dataJson != null) {
-                        String recordPath = dataJson.getString("record");
-                        userSetting.setRecordPath(recordPath);
-                    }
-                }
-            }
             setZLMConfig(serverItem, "0".equals(zlmServerConfig.getHookEnable()));
         }
         final String zlmKeepaliveKey = zlmKeepaliveKeyPrefix + serverItem.getId();
@@ -606,10 +595,9 @@
             param.put("rtp_proxy.port_range", mediaServerItem.getRtpPortRange().replace(",", "-"));
         }
 
-        if (userSetting.getRecordPath() != null) {
-            File recordPathFile = new File(userSetting.getRecordPath());
-            File mp4SavePathFile = recordPathFile.getParentFile().getAbsoluteFile();
-            param.put("protocol.mp4_save_path", mp4SavePathFile.getAbsoluteFile());
+        if (mediaServerItem.getRecordPath() != null) {
+            File recordPathFile = new File(mediaServerItem.getRecordPath());
+            param.put("protocol.mp4_save_path", recordPathFile.getParentFile().getPath());
             param.put("record.appName", recordPathFile.getName());
         }
 
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/CloudRecordServiceMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/CloudRecordServiceMapper.java
index 775fe29..594bcee 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/dao/CloudRecordServiceMapper.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/CloudRecordServiceMapper.java
@@ -102,8 +102,8 @@
 
     @Delete(" <script>" +
             "delete from wvp_cloud_record where media_server_id=#{mediaServerId} and id in " +
-            " <foreach collection='cloudRecordItemIdList'  item='item'  open='(' separator=',' close=')' > #{item}</foreach>" +
+            " <foreach collection='cloudRecordItemIdList'  item='item'  open='(' separator=',' close=')' > #{item.id}</foreach>" +
             " </script>")
-    int deleteList(List<Integer> cloudRecordItemIdList, @Param("mediaServerId") String mediaServerId);
+    int deleteList(List<CloudRecordItem> cloudRecordItemIdList);
 
 }
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/MediaServerMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/MediaServerMapper.java
index 77f4f19..4678591 100755
--- a/src/main/java/com/genersoft/iot/vmp/storager/dao/MediaServerMapper.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/MediaServerMapper.java
@@ -31,6 +31,8 @@
             "rtp_port_range,"+
             "send_rtp_port_range,"+
             "record_assist_port,"+
+            "record_day,"+
+            "record_path,"+
             "default_server,"+
             "create_time,"+
             "update_time,"+
@@ -55,6 +57,8 @@
             "#{rtpPortRange}, " +
             "#{sendRtpPortRange}, " +
             "#{recordAssistPort}, " +
+            "#{recordDay}, " +
+            "#{recordPath}, " +
             "#{defaultServer}, " +
             "#{createTime}, " +
             "#{updateTime}, " +
@@ -82,6 +86,8 @@
             "<if test=\"secret != null\">, secret=#{secret}</if>" +
             "<if test=\"recordAssistPort != null\">, record_assist_port=#{recordAssistPort}</if>" +
             "<if test=\"hookAliveInterval != null\">, hook_alive_interval=#{hookAliveInterval}</if>" +
+            "<if test=\"recordDay != null\">, record_day=#{recordDay}</if>" +
+            "<if test=\"recordPath != null\">, record_path=#{recordPath}</if>" +
             "WHERE id=#{id}"+
             " </script>"})
     int update(MediaServerItem mediaServerItem);
@@ -105,6 +111,8 @@
             "<if test=\"sendRtpPortRange != null\">, send_rtp_port_range=#{sendRtpPortRange}</if>" +
             "<if test=\"secret != null\">, secret=#{secret}</if>" +
             "<if test=\"recordAssistPort != null\">, record_assist_port=#{recordAssistPort}</if>" +
+            "<if test=\"recordDay != null\">, record_day=#{recordDay}</if>" +
+            "<if test=\"recordPath != null\">, record_path=#{recordPath}</if>" +
             "<if test=\"hookAliveInterval != null\">, hook_alive_interval=#{hookAliveInterval}</if>" +
             "WHERE ip=#{ip} and http_port=#{httpPort}"+
             " </script>"})
diff --git a/src/main/resources/all-application.yml b/src/main/resources/all-application.yml
index 7a70c9e..59dac15 100644
--- a/src/main/resources/all-application.yml
+++ b/src/main/resources/all-application.yml
@@ -139,6 +139,10 @@
     auto-config: true
     # [鍙�塢 zlm鏈嶅姟鍣ㄧ殑hook.admin_params=secret
     secret: 035c73f7-bb6b-4889-a715-d9eb2d1925cc
+    # 褰曞儚璺緞
+    record-path: ./www/record
+    # 褰曞儚淇濆瓨鏃堕暱
+    record-date: 7
     # 鍚敤澶氱鍙fā寮�, 澶氱鍙fā寮忎娇鐢ㄧ鍙e尯鍒嗘瘡璺祦锛屽吋瀹规�ф洿濂姐�� 鍗曠鍙d娇鐢ㄦ祦鐨剆src鍖哄垎锛� 鐐规挱瓒呮椂寤鸿浣跨敤澶氱鍙f祴璇�
     rtp:
         # [鍙�塢 鏄惁鍚敤澶氱鍙fā寮�, 寮�鍚悗浼氬湪portRange鑼冨洿鍐呴�夋嫨绔彛鐢ㄤ簬濯掍綋娴佷紶杈�

--
Gitblit v1.8.0