diff --git a/src/main/java/com/rymcu/forest/mapper/DashboardMapper.java b/src/main/java/com/rymcu/forest/mapper/DashboardMapper.java index 40550d7..73f1cbf 100644 --- a/src/main/java/com/rymcu/forest/mapper/DashboardMapper.java +++ b/src/main/java/com/rymcu/forest/mapper/DashboardMapper.java @@ -54,13 +54,13 @@ public interface DashboardMapper { List selectLastThirtyDaysArticleData(); /** - * 获取最近 30 天文章数据 + * 获取最近 30 天用户数据 * @return */ List selectLastThirtyDaysUserData(); /** - * 获取最近 30 天文章数据 + * 获取最近 30 天流量数据 * @return */ List selectLastThirtyDaysVisitData(); @@ -100,4 +100,16 @@ public interface DashboardMapper { * @return */ List selectNewArticles(); + + /** + * 获取最近 30 天访客数据 + * @return + */ + List selectLastThirtyDaysVisitIpData(); + + /** + * 获取历史 1 年访客数据 + * @return + */ + List selectHistoryVisitIpData(); } diff --git a/src/main/java/com/rymcu/forest/service/impl/DashboardServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/DashboardServiceImpl.java index 293e085..8c6bf0c 100644 --- a/src/main/java/com/rymcu/forest/service/impl/DashboardServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/DashboardServiceImpl.java @@ -40,20 +40,22 @@ public class DashboardServiceImpl implements DashboardService { @Override public Map lastThirtyDaysData() { - Map map = new HashMap(4); + Map map = new HashMap(5); ArrayList dates = new ArrayList(30); ArrayList articleData = new ArrayList(30); ArrayList userData = new ArrayList(30); ArrayList visitData = new ArrayList(30); + ArrayList visitIpData = new ArrayList(30); List articles = dashboardMapper.selectLastThirtyDaysArticleData(); List users = dashboardMapper.selectLastThirtyDaysUserData(); List visits = dashboardMapper.selectLastThirtyDaysVisitData(); + List visitIps = dashboardMapper.selectLastThirtyDaysVisitIpData(); LocalDate now = LocalDate.now().plusDays(1); LocalDate localDate = LocalDate.now().plusDays(-29); while (now.isAfter(localDate)) { String date = localDate.toString(); dates.add(date); - articles.forEach(article->{ + articles.forEach(article -> { if (date.equals(article.getLabel())) { articleData.add(article.getValue()); return; @@ -63,7 +65,7 @@ public class DashboardServiceImpl implements DashboardService { articleData.add(0); } - users.forEach(user->{ + users.forEach(user -> { if (date.equals(user.getLabel())) { userData.add(user.getValue()); return; @@ -73,7 +75,7 @@ public class DashboardServiceImpl implements DashboardService { userData.add(0); } - visits.forEach(visit->{ + visits.forEach(visit -> { if (date.equals(visit.getLabel())) { visitData.add(visit.getValue()); return; @@ -83,34 +85,47 @@ public class DashboardServiceImpl implements DashboardService { visitData.add(0); } + visitIps.forEach(visitIp -> { + if (date.equals(visitIp.getLabel())) { + visitIpData.add(visitIp.getValue()); + return; + } + }); + if (visitIpData.size() < dates.size()) { + visitIpData.add(0); + } + localDate = localDate.plusDays(1); } map.put("dates", dates); map.put("articles", articleData); map.put("users", userData); map.put("visits", visitData); + map.put("visitIps", visitIpData); return map; } @Override public Map history() { - Map map = new HashMap(4); + Map map = new HashMap(5); ArrayList dates = new ArrayList(30); ArrayList articleData = new ArrayList(30); ArrayList userData = new ArrayList(30); ArrayList visitData = new ArrayList(30); + ArrayList visitIpData = new ArrayList(30); List articles = dashboardMapper.selectHistoryArticleData(); List users = dashboardMapper.selectHistoryUserData(); List visits = dashboardMapper.selectHistoryVisitData(); + List visitIps = dashboardMapper.selectHistoryVisitIpData(); LocalDate now = LocalDate.now().plusMonths(1); LocalDate localDate = LocalDate.now().plusYears(-1).plusMonths(1); while (now.getYear() >= localDate.getYear()) { if (now.getYear() == localDate.getYear()) { - if (now.getMonthValue() > localDate.getMonthValue()){ + if (now.getMonthValue() > localDate.getMonthValue()) { String date = localDate.getYear() + "-" + (localDate.getMonthValue() < 10 ? "0" + localDate.getMonthValue() : localDate.getMonthValue()); dates.add(date); - articles.forEach(article->{ + articles.forEach(article -> { if (date.equals(article.getLabel())) { articleData.add(article.getValue()); return; @@ -120,7 +135,7 @@ public class DashboardServiceImpl implements DashboardService { articleData.add(0); } - users.forEach(user->{ + users.forEach(user -> { if (date.equals(user.getLabel())) { userData.add(user.getValue()); return; @@ -130,7 +145,7 @@ public class DashboardServiceImpl implements DashboardService { userData.add(0); } - visits.forEach(visit->{ + visits.forEach(visit -> { if (date.equals(visit.getLabel())) { visitData.add(visit.getValue()); return; @@ -139,12 +154,22 @@ public class DashboardServiceImpl implements DashboardService { if (visitData.size() < dates.size()) { visitData.add(0); } + + visitIps.forEach(visitIp -> { + if (date.equals(visitIp.getLabel())) { + visitIpData.add(visitIp.getValue()); + return; + } + }); + if (visitIpData.size() < dates.size()) { + visitIpData.add(0); + } } } else { String date = localDate.getYear() + "-" + (localDate.getMonthValue() < 10 ? "0" + localDate.getMonthValue() : localDate.getMonthValue()); dates.add(date); - articles.forEach(article->{ + articles.forEach(article -> { if (date.equals(article.getLabel())) { articleData.add(article.getValue()); return; @@ -154,7 +179,7 @@ public class DashboardServiceImpl implements DashboardService { articleData.add(0); } - users.forEach(user->{ + users.forEach(user -> { if (date.equals(user.getLabel())) { userData.add(user.getValue()); return; @@ -164,7 +189,7 @@ public class DashboardServiceImpl implements DashboardService { userData.add(0); } - visits.forEach(visit->{ + visits.forEach(visit -> { if (date.equals(visit.getLabel())) { visitData.add(visit.getValue()); return; @@ -173,6 +198,16 @@ public class DashboardServiceImpl implements DashboardService { if (visitData.size() < dates.size()) { visitData.add(0); } + + visitIps.forEach(visitIp -> { + if (date.equals(visitIp.getLabel())) { + visitIpData.add(visitIp.getValue()); + return; + } + }); + if (visitIpData.size() < dates.size()) { + visitIpData.add(0); + } } localDate = localDate.plusMonths(1); @@ -181,6 +216,7 @@ public class DashboardServiceImpl implements DashboardService { map.put("articles", articleData); map.put("users", userData); map.put("visits", visitData); + map.put("visitIps", visitIpData); return map; } diff --git a/src/main/java/mapper/DashboardMapper.xml b/src/main/java/mapper/DashboardMapper.xml index e0da515..8ce6df1 100644 --- a/src/main/java/mapper/DashboardMapper.xml +++ b/src/main/java/mapper/DashboardMapper.xml @@ -109,7 +109,7 @@ + + \ No newline at end of file