From f106675dc64082365ffb4142df687041ff11b610 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Sun, 3 Nov 2024 14:37:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=8E=86=E5=8F=B2=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E7=9A=84=E6=9F=A5=E7=9C=8B=EF=BC=8C=E8=BF=87=E6=BB=A4?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/service/bean/LogFileInfo.java | 13 +- .../iot/vmp/service/impl/LogServiceImpl.java | 59 +++-- .../iot/vmp/vmanager/log/LogController.java | 9 + .../components/dialog/operationsFoShowLog.vue | 155 +++++++++++++ .../components/operationsForHistoryLog.vue | 218 +++++++----------- .../src/components/operationsForRealLog.vue | 153 +----------- 6 files changed, 282 insertions(+), 325 deletions(-) create mode 100755 web_src/src/components/dialog/operationsFoShowLog.vue diff --git a/src/main/java/com/genersoft/iot/vmp/service/bean/LogFileInfo.java b/src/main/java/com/genersoft/iot/vmp/service/bean/LogFileInfo.java index e71046e4..c73cff3e 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/bean/LogFileInfo.java +++ b/src/main/java/com/genersoft/iot/vmp/service/bean/LogFileInfo.java @@ -6,15 +6,8 @@ import lombok.Data; public class LogFileInfo { private String fileName; - private String startTime; - private String endTime; - - public static LogFileInfo getInstance(String fileName, String startTime, String endTime) { - LogFileInfo logFileInfo = new LogFileInfo(); - logFileInfo.setFileName(fileName); - logFileInfo.setStartTime(startTime); - logFileInfo.setEndTime(endTime); - return logFileInfo; - } + private Long fileSize; + private Long startTime; + private Long endTime; } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/LogServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/LogServiceImpl.java index ed9db4c4..3aad0035 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/LogServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/LogServiceImpl.java @@ -9,17 +9,12 @@ import com.genersoft.iot.vmp.utils.DateUtil; import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.input.ReversedLinesFileReader; -import org.apache.commons.lang3.ObjectUtils; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import java.io.*; import java.nio.charset.Charset; -import java.nio.file.Files; -import java.nio.file.attribute.BasicFileAttributes; -import java.nio.file.attribute.FileTime; import java.util.ArrayList; -import java.util.Collections; import java.util.List; @Service @@ -37,33 +32,36 @@ public class LogServiceImpl implements ILogService { if (files == null || files.length == 0) { return result; } + + // 读取文件创建时间作为开始时间,修改时间为结束时间 + Long startTimestamp = null; + if (startTime != null) { + startTimestamp = DateUtil.yyyy_MM_dd_HH_mm_ssToTimestampMs(startTime); + } + Long endTimestamp = null; + if (endTime != null) { + endTimestamp = DateUtil.yyyy_MM_dd_HH_mm_ssToTimestampMs(endTime); + } for (File file : files) { LogFileInfo logFileInfo = new LogFileInfo(); logFileInfo.setFileName(file.getName()); + logFileInfo.setFileSize(file.length()); if (query != null && !file.getName().contains(query)) { continue; } - // 读取文件创建时间作为开始时间,修改时间为结束时间 - - Long startTimestamp = null; - if (startTime != null) { - startTimestamp = DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(startTime); - } - Long endTimestamp = null; - if (startTime != null) { - endTimestamp = DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(endTime); - } try { - String[] fileAttributes = getFileAttributes(file); + Long[] fileAttributes = getFileAttributes(file); if (fileAttributes == null) { continue; } - logFileInfo.setStartTime(fileAttributes[0]); - logFileInfo.setEndTime(fileAttributes[1]); - if (startTimestamp != null && startTimestamp > DateUtil.yyyy_MM_dd_HH_mm_ssToTimestampMs(fileAttributes[0])) { + long startTimestampForFile = fileAttributes[0]; + long endTimestampForFile = fileAttributes[1]; + logFileInfo.setStartTime(startTimestampForFile); + logFileInfo.setEndTime(endTimestampForFile); + if (startTimestamp != null && startTimestamp > startTimestampForFile) { continue; } - if (endTimestamp != null && endTimestamp < DateUtil.yyyy_MM_dd_HH_mm_ssToTimestampMs(fileAttributes[1])) { + if (endTimestamp != null && endTimestamp < endTimestampForFile) { continue; } } catch (IOException e) { @@ -73,6 +71,7 @@ public class LogServiceImpl implements ILogService { result.add(logFileInfo); } + result.sort((o1, o2) -> o2.getStartTime().compareTo(o1.getStartTime())); return result; } @@ -83,7 +82,7 @@ public class LogServiceImpl implements ILogService { return rollingFile.getParentFile(); } - String[] getFileAttributes(File file) throws IOException { + Long[] getFileAttributes(File file) throws IOException { BufferedReader bufferedReader = new BufferedReader(new FileReader(file)); String startLine = bufferedReader.readLine(); if (startLine== null) { @@ -91,15 +90,15 @@ public class LogServiceImpl implements ILogService { } String startTime = startLine.substring(0, 19); - - String lastLine = ""; - try (ReversedLinesFileReader reversedLinesReader = new ReversedLinesFileReader(file, Charset.defaultCharset())) { - lastLine = reversedLinesReader.readLine(); - } catch (Exception e) { - log.error("file read error, msg:{}", e.getMessage(), e); - } - String endTime = lastLine.substring(0, 19); - return new String[]{startTime, endTime}; + // 最后一行的开头不一定是时间 +// String lastLine = ""; +// try (ReversedLinesFileReader reversedLinesReader = new ReversedLinesFileReader(file, Charset.defaultCharset())) { +// lastLine = reversedLinesReader.readLine(); +// } catch (Exception e) { +// log.error("file read error, msg:{}", e.getMessage(), e); +// } +// String endTime = lastLine.substring(0, 19); + return new Long[]{DateUtil.yyyy_MM_dd_HH_mm_ssToTimestampMs(startTime), file.lastModified()}; } @Override diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java index b0d02eae..050a0c5c 100755 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java @@ -62,6 +62,15 @@ public class LogController { public List queryList(@RequestParam(required = false) String query, @RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime ) { + if (ObjectUtils.isEmpty(query)) { + query = null; + } + if (ObjectUtils.isEmpty(startTime)) { + startTime = null; + } + if (ObjectUtils.isEmpty(endTime)) { + endTime = null; + } return logService.queryList(query, startTime, endTime); } diff --git a/web_src/src/components/dialog/operationsFoShowLog.vue b/web_src/src/components/dialog/operationsFoShowLog.vue new file mode 100755 index 00000000..8ebbfd20 --- /dev/null +++ b/web_src/src/components/dialog/operationsFoShowLog.vue @@ -0,0 +1,155 @@ + + + diff --git a/web_src/src/components/operationsForHistoryLog.vue b/web_src/src/components/operationsForHistoryLog.vue index 5efb6b6d..d16d2564 100755 --- a/web_src/src/components/operationsForHistoryLog.vue +++ b/web_src/src/components/operationsForHistoryLog.vue @@ -2,43 +2,48 @@
- + - + - + + - - - - - - - - - - + :visible.sync="showLog" + width="90%"> +
@@ -93,28 +80,27 @@ diff --git a/web_src/src/components/operationsForRealLog.vue b/web_src/src/components/operationsForRealLog.vue index 52d4d2ea..30fa750e 100755 --- a/web_src/src/components/operationsForRealLog.vue +++ b/web_src/src/components/operationsForRealLog.vue @@ -1,175 +1,38 @@ - -