Commit cf30bb6b7e8ad83e01cd5f5d3c787aa51ca27841
1 parent
708b19e1
优化存储流程
Showing
2 changed files
with
26 additions
and
17 deletions
src/main/java/top/panll/assist/config/StartConfig.java
| ... | ... | @@ -176,30 +176,23 @@ public class StartConfig implements CommandLineRunner { |
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | 178 | logger.info("数据收集完成, 待处理数据为: {}条", cloudRecordItemList.size()); |
| 179 | + if (cloudRecordItemList.size() == 0) { | |
| 180 | + System.exit(1); | |
| 181 | + } | |
| 179 | 182 | logger.info("开始将数据写入数据库"); |
| 183 | + // 检查记录是否存在,存在则不写入 | |
| 180 | 184 | TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); |
| 181 | - int limitCount = 50; | |
| 182 | - if (cloudRecordItemList.size() > 0) { | |
| 183 | - if (cloudRecordItemList.size() > limitCount) { | |
| 184 | - for (int i = 0; i < cloudRecordItemList.size(); i += limitCount) { | |
| 185 | - int toIndex = i + limitCount; | |
| 186 | - if (i + limitCount > cloudRecordItemList.size()) { | |
| 187 | - toIndex = cloudRecordItemList.size(); | |
| 188 | - } | |
| 189 | - int length = cloudRecordServiceMapper.batchAdd(cloudRecordItemList.subList(i, toIndex)); | |
| 185 | + if (!cloudRecordItemList.isEmpty()) { | |
| 186 | + for (CloudRecordItem cloudRecordItem : cloudRecordItemList) { | |
| 187 | + CloudRecordItem cloudRecordItemInDb = cloudRecordServiceMapper.query(cloudRecordItem.getApp(), cloudRecordItem.getStream(),cloudRecordItem.getCallId(), cloudRecordItem.getFilePath()); | |
| 188 | + if (cloudRecordItemInDb == null) { | |
| 189 | + int length = cloudRecordServiceMapper.add(cloudRecordItem); | |
| 190 | 190 | if (length == 0) { |
| 191 | 191 | logger.info("数据写入数据库失败"); |
| 192 | 192 | dataSourceTransactionManager.rollback(transactionStatus); |
| 193 | 193 | System.exit(1); |
| 194 | 194 | } |
| 195 | 195 | } |
| 196 | - } else { | |
| 197 | - int length = cloudRecordServiceMapper.batchAdd(cloudRecordItemList); | |
| 198 | - if (length == 0) { | |
| 199 | - logger.info("数据写入数据库失败"); | |
| 200 | - dataSourceTransactionManager.rollback(transactionStatus); | |
| 201 | - System.exit(1); | |
| 202 | - } | |
| 203 | 196 | } |
| 204 | 197 | dataSourceTransactionManager.commit(transactionStatus); |
| 205 | 198 | } |
| ... | ... | @@ -214,12 +207,13 @@ public class StartConfig implements CommandLineRunner { |
| 214 | 207 | boolean result = oldFile.renameTo(new File(renameMap.get(oldFileName))); |
| 215 | 208 | if (result) { |
| 216 | 209 | logger.info("重命名成功: " + oldFileName + "===" + renameMap.get(oldFileName)); |
| 210 | + }else { | |
| 211 | + logger.info("重命名失败: " + oldFileName + "===" + renameMap.get(oldFileName)); | |
| 217 | 212 | } |
| 218 | 213 | } |
| 219 | 214 | logger.info("修改磁盘文件完成"); |
| 220 | 215 | logger.info("清理失效文件夹"); |
| 221 | 216 | for (String streamFileStr : streamFileList) { |
| 222 | - System.out.println(streamFileStr); | |
| 223 | 217 | File deleteFile = new File(streamFileStr); |
| 224 | 218 | deleteFile(deleteFile); |
| 225 | 219 | } |
| ... | ... | @@ -232,6 +226,7 @@ public class StartConfig implements CommandLineRunner { |
| 232 | 226 | |
| 233 | 227 | |
| 234 | 228 | public void deleteFile(File file) { |
| 229 | + logger.warn("[删除文件] {} ", file.getAbsolutePath()); | |
| 235 | 230 | if (!file.exists()) { |
| 236 | 231 | logger.warn("[删除文件] {} 不存在 ", file.getAbsolutePath()); |
| 237 | 232 | }else { | ... | ... |
src/main/java/top/panll/assist/mapper/CloudRecordServiceMapper.java
| ... | ... | @@ -20,6 +20,8 @@ public interface CloudRecordServiceMapper { |
| 20 | 20 | " folder," + |
| 21 | 21 | " file_path," + |
| 22 | 22 | " file_size," + |
| 23 | + " collect," + | |
| 24 | + " reserve," + | |
| 23 | 25 | " time_len ) " + |
| 24 | 26 | "VALUES (" + |
| 25 | 27 | " #{app}," + |
| ... | ... | @@ -32,6 +34,8 @@ public interface CloudRecordServiceMapper { |
| 32 | 34 | " #{folder}," + |
| 33 | 35 | " #{filePath}," + |
| 34 | 36 | " #{fileSize}," + |
| 37 | + " #{collect}," + | |
| 38 | + " #{reserve}," + | |
| 35 | 39 | " #{timeLen})" + |
| 36 | 40 | " </script>") |
| 37 | 41 | int add(CloudRecordItem cloudRecordItem); |
| ... | ... | @@ -102,4 +106,14 @@ public interface CloudRecordServiceMapper { |
| 102 | 106 | "</foreach> " + |
| 103 | 107 | "</script>") |
| 104 | 108 | int batchAdd(@Param("cloudRecordItems") List<CloudRecordItem> cloudRecordItems); |
| 109 | + | |
| 110 | + @Select(" <script>" + | |
| 111 | + "select *" + | |
| 112 | + " from wvp_cloud_record " + | |
| 113 | + " where app = #{app} and stream = #{stream} and call_id = #{callId} and file_path=#{filePath}" + | |
| 114 | + " </script>") | |
| 115 | + CloudRecordItem query(@Param("app") String app, | |
| 116 | + @Param("stream") String stream, | |
| 117 | + @Param("callId") String callId, | |
| 118 | + @Param("filePath") String filePath); | |
| 105 | 119 | } | ... | ... |