class ServerLogService {

    public QueryResult<ServerLog> query(int page, int size, ServerLog model) {
        File[] logFiles = logFileContent.listFiles(); // 所有日志文件
        int count = logFiles.length; // 日志文件个数
        int skipCount = (page - 1) * size; // 需要跳过的文件个数
        int totalPages = (int) Math.ceil(count / (double) size); // 日志文件总页数
        if (skipCount > count) {
            page = totalPages;
            skipCount = (page - 1) * size; // 修改需要跳过的文件个数
        }
        List<ServerLog> serverLogList = Stream.of(logFiles)
                .sorted(Comparator.comparing(FileUtil::lastModifiedTime, Comparator.reverseOrder()))
                .skip(skipCount)
                .limit(size)
                .map(logFile -> {
                    ServerLog serverLog = new ServerLog();
                    serverLog.setFileName(logFile.getName());
                    serverLog.setSize(logFile.length());
                    serverLog.setLastModifiedTime(FileUtil.lastModifiedTime(logFile));
                    try {
                        serverLog.setCanonicalPath(logFile.getCanonicalPath());
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    return serverLog;
                })
                .collect(Collectors.toList());
        return new QueryResult(serverLogList, count, page, totalPages);
    }

}