Commit 88153af0832b432d459cba0586f76afa2d57f738

Authored by 648540858
1 parent 1aafeae6

优化代码结构

src/main/java/top/panll/assist/controller/RecordController.java
@@ -81,7 +81,7 @@ public class RecordController { @@ -81,7 +81,7 @@ public class RecordController {
81 WVPResult<PageInfo<String>> result = new WVPResult<>(); 81 WVPResult<PageInfo<String>> result = new WVPResult<>();
82 List<String> resultData = new ArrayList<>(); 82 List<String> resultData = new ArrayList<>();
83 List<File> appList = videoFileService.getAppList(true); 83 List<File> appList = videoFileService.getAppList(true);
84 - if (appList != null) { 84 + if (appList.size() > 0) {
85 for (File file : appList) { 85 for (File file : appList) {
86 resultData.add(file.getName()); 86 resultData.add(file.getName());
87 } 87 }
@@ -253,7 +253,7 @@ public class RecordController { @@ -253,7 +253,7 @@ public class RecordController {
253 startTimeDate = formatter.parse(startTime); 253 startTimeDate = formatter.parse(startTime);
254 } 254 }
255 if (endTime != null ) { 255 if (endTime != null ) {
256 - endTimeDate = formatter.parse(endTime); 256 + endTimeDate = formatter.parse(endTime);
257 } 257 }
258 } catch (ParseException e) { 258 } catch (ParseException e) {
259 e.printStackTrace(); 259 e.printStackTrace();
src/main/java/top/panll/assist/service/VideoFileService.java
@@ -53,7 +53,7 @@ public class VideoFileService { @@ -53,7 +53,7 @@ public class VideoFileService {
53 53
54 public List<File> getAppList(Boolean sort) { 54 public List<File> getAppList(Boolean sort) {
55 File recordFile = new File(userSettings.getRecord()); 55 File recordFile = new File(userSettings.getRecord());
56 - if (recordFile != null && recordFile.isDirectory()) { 56 + if (recordFile.isDirectory()) {
57 File[] files = recordFile.listFiles((File dir, String name) -> { 57 File[] files = recordFile.listFiles((File dir, String name) -> {
58 File currentFile = new File(dir.getAbsolutePath() + File.separator + name); 58 File currentFile = new File(dir.getAbsolutePath() + File.separator + name);
59 return currentFile.isDirectory(); 59 return currentFile.isDirectory();
@@ -247,6 +247,9 @@ public class VideoFileService { @@ -247,6 +247,9 @@ public class VideoFileService {
247 Date fileDate = null; 247 Date fileDate = null;
248 Date startDate = null; 248 Date startDate = null;
249 Date endDate = null; 249 Date endDate = null;
  250 + if (new File(dir + File.separator + name).isFile()) {
  251 + return false;
  252 + }
250 if (startTime != null) { 253 if (startTime != null) {
251 startDate = new Date(startTime.getTime() - ((startTime.getTime() + 28800000) % (86400000))); 254 startDate = new Date(startTime.getTime() - ((startTime.getTime() + 28800000) % (86400000)));
252 } 255 }
@@ -277,7 +280,8 @@ public class VideoFileService { @@ -277,7 +280,8 @@ public class VideoFileService {
277 // TODO 按时间获取文件 280 // TODO 按时间获取文件
278 File[] files = dateFile.listFiles((File dir, String name) ->{ 281 File[] files = dateFile.listFiles((File dir, String name) ->{
279 boolean filterResult = true; 282 boolean filterResult = true;
280 - if (name.contains(":") && name.endsWith(".mp4") && !name.startsWith(".")){ 283 + File currentFile = new File(dir + File.separator + name);
  284 + if (currentFile.isFile() && name.contains(":") && name.endsWith(".mp4") && !name.startsWith(".")){
281 String[] timeArray = name.split("-"); 285 String[] timeArray = name.split("-");
282 if (timeArray.length == 3){ 286 if (timeArray.length == 3){
283 String fileStartTimeStr = dateFile.getName() + " " + timeArray[0]; 287 String fileStartTimeStr = dateFile.getName() + " " + timeArray[0];
@@ -289,12 +293,13 @@ public class VideoFileService { @@ -289,12 +293,13 @@ public class VideoFileService {
289 if (endTime != null) { 293 if (endTime != null) {
290 filterResult = filterResult && (formatter.parse(fileEndTimeStr).before(endTime) || (formatter.parse(fileEndTimeStr).after(endTime) && formatter.parse(fileStartTimeStr).before(endTime))); 294 filterResult = filterResult && (formatter.parse(fileEndTimeStr).before(endTime) || (formatter.parse(fileEndTimeStr).after(endTime) && formatter.parse(fileStartTimeStr).before(endTime)));
291 } 295 }
292 -  
293 } catch (ParseException e) { 296 } catch (ParseException e) {
294 logger.error("过滤视频文件时异常: {}-{}", name, e.getMessage()); 297 logger.error("过滤视频文件时异常: {}-{}", name, e.getMessage());
295 return false; 298 return false;
296 } 299 }
297 } 300 }
  301 + }else {
  302 + filterResult = false;
298 } 303 }
299 return filterResult; 304 return filterResult;
300 }); 305 });
@@ -399,7 +404,7 @@ public class VideoFileService { @@ -399,7 +404,7 @@ public class VideoFileService {
399 } 404 }
400 File[] dateFiles = streamFile.listFiles((File dir, String name)->{ 405 File[] dateFiles = streamFile.listFiles((File dir, String name)->{
401 File currentFile = new File(dir.getAbsolutePath() + File.separator + name); 406 File currentFile = new File(dir.getAbsolutePath() + File.separator + name);
402 - if (currentFile.isDirectory()){ 407 + if (!currentFile.isDirectory()){
403 return false; 408 return false;
404 } 409 }
405 Date date = null; 410 Date date = null;
@@ -411,7 +416,7 @@ public class VideoFileService { @@ -411,7 +416,7 @@ public class VideoFileService {
411 Calendar c = Calendar.getInstance(); 416 Calendar c = Calendar.getInstance();
412 c.setTime(date); 417 c.setTime(date);
413 int y = c.get(Calendar.YEAR); 418 int y = c.get(Calendar.YEAR);
414 - int m = c.get(Calendar.MONTH); 419 + int m = c.get(Calendar.MONTH) + 1;
415 if (year != null) { 420 if (year != null) {
416 if (month != null) { 421 if (month != null) {
417 return y == year && m == month; 422 return y == year && m == month;
src/main/java/top/panll/assist/utils/PageInfo.java
@@ -24,6 +24,7 @@ public class PageInfo&lt;T&gt; { @@ -24,6 +24,7 @@ public class PageInfo&lt;T&gt; {
24 } 24 }
25 25
26 public void startPage(int page, int count) { 26 public void startPage(int page, int count) {
  27 + if (count <= 0) count = 10;
27 if (page <= 0) page = 1; 28 if (page <= 0) page = 1;
28 this.pageNum = page; 29 this.pageNum = page;
29 this.pageSize = count; 30 this.pageSize = count;