From e7c9fcbd077aff4f64653787d89dd0c88fa2be32 Mon Sep 17 00:00:00 2001 From: wenyu441069198 <14186472+wenyu441069198@user.noreply.gitee.com> Date: Tue, 6 Aug 2024 20:52:06 +0800 Subject: [PATCH] =?UTF-8?q?=E8=82=96=E6=B5=B7=E5=8D=97=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E5=B0=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/report/ReportServiceImpl.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/teaching/backend/service/impl/report/ReportServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/report/ReportServiceImpl.java index e3ee1a3..dd42ddc 100644 --- a/src/main/java/com/teaching/backend/service/impl/report/ReportServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/report/ReportServiceImpl.java @@ -11,6 +11,7 @@ import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; @@ -24,7 +25,7 @@ public class ReportServiceImpl extends ServiceImpl impleme @Override public BrowseReportVO getBrowseStatistics() { //存放访问的前一天至前七天的每天对应的日期 - List dateList = new ArrayList<>(); + List dateList = new ArrayList<>(); //存放这个月访问的前一天至前七天的每天对应的浏览量 List ThisMonthBrowseList = new ArrayList<>(); //存放上个月访问的前一天至前七天的每天对应的浏览量 @@ -36,7 +37,9 @@ public class ReportServiceImpl extends ServiceImpl impleme // 获取前七天的日期 for (int i = 1; i <= 7; i++) { LocalDate day = end.minusDays(i); - dateList.add(day); + // 定义一个仅包含月日的格式化器 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM-dd"); + dateList.add(day.format(formatter)); //查询今天对应的浏览量 String browse = reportMapper.getBrowseByTime(day); @@ -47,6 +50,8 @@ public class ReportServiceImpl extends ServiceImpl impleme LocalDate lastMonth = lastMonthToday.minusDays(i); //查询上个月的今天对应的浏览量 String lastMonthBrowse = reportMapper.getBrowseByTime(lastMonth); + + LastMonthBrowseList.add(lastMonthBrowse); } @@ -62,7 +67,7 @@ public class ReportServiceImpl extends ServiceImpl impleme public boolean getReceptionBrowse() { //查询今日有无记录 List list = lambdaQuery().eq(Report::getCreateTime, LocalDate.now()).list(); - + if (list.size() > 0){ //有,给记录加一 update().setSql("page_view = page_view + 1").eq("create_time",LocalDate.now()).update();