Commit d7d49dee69b020279eef97717011e4a9695891a0

Authored by 648540858
1 parent 23b676e4

添加对旧录像文件的处理

src/main/java/top/panll/assist/config/StartConfig.java
... ... @@ -68,13 +68,14 @@ public class StartConfig implements CommandLineRunner {
68 68 }
69 69 List<CloudRecordItem> cloudRecordItemList = new ArrayList<>();
70 70 Map<String, String> renameMap = new HashMap<>();
  71 + List<String> streamFileList = new ArrayList<>();
71 72 // 搜集数据
72   - for (File file : appFiles) {
73   - if (!file.isDirectory()) {
  73 + for (File appFile : appFiles) {
  74 + if (!appFile.isDirectory()) {
74 75 continue;
75 76 }
76   - String app = file.getName();
77   - File[] streamFiles = file.listFiles();
  77 + String app = appFile.getName();
  78 + File[] streamFiles = appFile.listFiles();
78 79 if (streamFiles == null || streamFiles.length == 0) {
79 80 continue;
80 81 }
... ... @@ -95,6 +96,7 @@ public class StartConfig implements CommandLineRunner {
95 96 if (dateFiles == null || dateFiles.length == 0) {
96 97 continue;
97 98 }
  99 + streamFileList.add(streamFile.getAbsolutePath());
98 100 // TODC 确定关联和归档分别使用了什么类型名称
99 101 boolean collect = false;
100 102 boolean reserve = false;
... ... @@ -151,7 +153,7 @@ public class StartConfig implements CommandLineRunner {
151 153 cloudRecordItem.setFolder(streamFile.getAbsolutePath());
152 154 cloudRecordItem.setFileSize(videoFile.length());
153 155 cloudRecordItem.setTimeLen(timeLength);
154   - cloudRecordItem.setFilePath(videoFile.getParentFile().getAbsolutePath() + File.separator + cloudRecordItem.getFileName());
  156 + cloudRecordItem.setFilePath(appFile.getAbsolutePath() + File.separator + stream + File.separator + dateFile.getName() + File.separator + cloudRecordItem.getFileName());
155 157 cloudRecordItemList.add(cloudRecordItem);
156 158 renameMap.put(videoFile.getAbsolutePath(), cloudRecordItem.getFilePath());
157 159 System.out.println(cloudRecordItem.getFilePath());
... ... @@ -174,15 +176,36 @@ public class StartConfig implements CommandLineRunner {
174 176 }
175 177 int length = cloudRecordServiceMapper.batchAdd(cloudRecordItemList.subList(i, toIndex));
176 178 if (length == 0) {
  179 + logger.info("数据写入数据库失败");
177 180 dataSourceTransactionManager.rollback(transactionStatus);
  181 + System.exit(1);
178 182 }
179 183 }
180 184 } else {
181   - cloudRecordServiceMapper.batchAdd(cloudRecordItemList);
  185 + int length = cloudRecordServiceMapper.batchAdd(cloudRecordItemList);
  186 + if (length == 0) {
  187 + logger.info("数据写入数据库失败");
  188 + dataSourceTransactionManager.rollback(transactionStatus);
  189 + System.exit(1);
  190 + }
182 191 }
183 192 dataSourceTransactionManager.commit(transactionStatus);
184 193 }
185 194 logger.info("数据写入数据库完成");
  195 + logger.info("开始修改磁盘文件");
  196 + for (String oldFileName : renameMap.keySet()) {
  197 + File oldFile = new File(oldFileName);
  198 + boolean result = oldFile.renameTo(new File(renameMap.get(oldFileName)));
  199 + if (result) {
  200 + logger.info("重命名成功: " + oldFileName + "===" + renameMap.get(oldFileName));
  201 + }
  202 + }
  203 + logger.info("修改磁盘文件完成");
  204 + logger.info("清理失效文件夹");
  205 + for (String streamFileStr : streamFileList) {
  206 + new File(streamFileStr).delete();
  207 + }
  208 + logger.info("清理失效文件夹结束");
186 209 }
187 210  
188 211  
... ...
src/main/resources/application.yml
... ... @@ -17,7 +17,7 @@ user-settings:
17 17 id: 1111
18 18 media-server-id: 11212
19 19 # [可选 ] zlm配置的录像路径,不配置则使用当前目录下的record目录 即: ./record
20   - record: /home/lin/record/
  20 + record: /home/lin/record1/
21 21 # [可选 ] 录像保存时长(单位: 天)每天晚12点自动对过期文件执行清理, 不配置则不删除
22 22 recordDay: 7
23 23 # [可选 ] 录像下载合成临时文件保存时长, 不配置默认取值recordDay(单位: 天)每天晚12点自动对过期文件执行清理
... ...