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();