parent
c1da086cb0
commit
7437cf33ef
21 changed files with 326 additions and 20 deletions
@ -0,0 +1,47 @@ |
||||
package com.teaching.backend.controller.umsAdmin; |
||||
|
||||
import com.teaching.backend.common.CommonResult; |
||||
import com.teaching.backend.model.dto.report.ReportDTO; |
||||
import com.teaching.backend.model.vo.report.BrowseReportVO; |
||||
import com.teaching.backend.service.report.ReportService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
@RestController |
||||
@Api(tags = "ReportController") |
||||
@RequestMapping("/api/report") |
||||
@Slf4j |
||||
public class ReportController { |
||||
|
||||
@Autowired |
||||
private ReportService reportService; |
||||
|
||||
/** |
||||
* 浏览统计 |
||||
* @return |
||||
*/ |
||||
@GetMapping("/browseStatistics") |
||||
@ApiOperation("浏览统计") |
||||
public CommonResult<BrowseReportVO> browseStatistics(){ |
||||
return CommonResult.success(reportService.getBrowseStatistics()); |
||||
} |
||||
|
||||
/** |
||||
* 接收每日浏览量 |
||||
* @return |
||||
*/ |
||||
@PostMapping("/receptionBrowse") |
||||
@ApiOperation("接收每日浏览量") |
||||
public CommonResult receptionBrowse(@RequestBody ReportDTO reportDTO){ |
||||
|
||||
boolean receptionBrowse = reportService.getReceptionBrowse(reportDTO); |
||||
if (receptionBrowse == false){ |
||||
return CommonResult.failed(); |
||||
} |
||||
return CommonResult.success(receptionBrowse); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,13 @@ |
||||
package com.teaching.backend.controller.umsStudent; |
||||
|
||||
import io.swagger.annotations.Api; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
@RestController |
||||
@Api(tags = "UmsStudentController") |
||||
@RequestMapping("/api/student") |
||||
@Slf4j |
||||
public class UmsStudentController { |
||||
} |
@ -0,0 +1,14 @@ |
||||
package com.teaching.backend.mapper.report; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.teaching.backend.model.dto.report.ReportDTO; |
||||
import com.teaching.backend.model.entity.report.Report; |
||||
|
||||
import java.time.LocalDate; |
||||
|
||||
public interface ReportMapper extends BaseMapper<Report> { |
||||
|
||||
String getBrowseByTime(LocalDate day); |
||||
|
||||
boolean addTodayBrowse(ReportDTO reportDTO); |
||||
} |
@ -0,0 +1,21 @@ |
||||
package com.teaching.backend.model.dto.report; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.time.LocalDate; |
||||
|
||||
@Data |
||||
@TableName("report") |
||||
public class ReportDTO implements Serializable { |
||||
|
||||
//时间
|
||||
private LocalDate createTime; |
||||
|
||||
//浏览量
|
||||
private String pageView; |
||||
|
||||
} |
@ -0,0 +1,24 @@ |
||||
package com.teaching.backend.model.entity.report; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.time.LocalDate; |
||||
|
||||
@Data |
||||
@TableName("report") |
||||
public class Report implements Serializable { |
||||
//主键
|
||||
@TableId(type = IdType.AUTO) |
||||
private Long id; |
||||
|
||||
//时间
|
||||
private LocalDate createTime; |
||||
|
||||
//浏览量
|
||||
private String pageView; |
||||
|
||||
} |
@ -0,0 +1,20 @@ |
||||
package com.teaching.backend.model.vo.report; |
||||
|
||||
import lombok.Builder; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
@Data |
||||
@Builder |
||||
public class BrowseReportVO implements Serializable { |
||||
|
||||
//日期,以逗号分隔,例如:2022-10-01,2022-10-02,2022-10-03
|
||||
private String dateList; |
||||
|
||||
//本月浏览量,以逗号分隔,例如:200,210,220
|
||||
private String ThisMonthBrowseList; |
||||
|
||||
//上月浏览量,以逗号分隔,例如:20,21,10
|
||||
private String LastMonthBrowseList; |
||||
} |
@ -0,0 +1,73 @@ |
||||
package com.teaching.backend.service.impl.report; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import com.teaching.backend.mapper.report.ReportMapper; |
||||
import com.teaching.backend.model.dto.report.ReportDTO; |
||||
import com.teaching.backend.model.entity.report.Report; |
||||
import com.teaching.backend.model.vo.report.BrowseReportVO; |
||||
import com.teaching.backend.service.report.ReportService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.apache.commons.lang.StringUtils; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
||||
import java.time.LocalDate; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
@Service |
||||
@Slf4j |
||||
public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> implements ReportService { |
||||
|
||||
@Autowired |
||||
private ReportMapper reportMapper; |
||||
|
||||
@Override |
||||
public BrowseReportVO getBrowseStatistics() { |
||||
//存放访问的前一天至前七天的每天对应的日期
|
||||
List<LocalDate> dateList = new ArrayList<>(); |
||||
//存放这个月访问的前一天至前七天的每天对应的浏览量
|
||||
List<String> ThisMonthBrowseList = new ArrayList<>(); |
||||
//存放上个月访问的前一天至前七天的每天对应的浏览量
|
||||
List<String> LastMonthBrowseList = new ArrayList<>(); |
||||
|
||||
//获取今天的日期
|
||||
LocalDate end = LocalDate.now(); |
||||
|
||||
// 获取前七天的日期
|
||||
for (int i = 1; i <= 7; i++) { |
||||
LocalDate day = end.minusDays(i); |
||||
dateList.add(day); |
||||
|
||||
//查询今天对应的浏览量
|
||||
String browse = reportMapper.getBrowseByTime(day); |
||||
ThisMonthBrowseList.add(browse); |
||||
|
||||
//获取上个月的今天
|
||||
LocalDate lastMonthToday = end.minusMonths(1); |
||||
LocalDate lastMonth = lastMonthToday.minusDays(i); |
||||
//查询上个月的今天对应的浏览量
|
||||
String lastMonthBrowse = reportMapper.getBrowseByTime(lastMonth); |
||||
LastMonthBrowseList.add(lastMonthBrowse); |
||||
|
||||
} |
||||
return BrowseReportVO |
||||
.builder() |
||||
.dateList(StringUtils.join(dateList,",")) |
||||
.ThisMonthBrowseList(StringUtils.join(ThisMonthBrowseList,",")) |
||||
.LastMonthBrowseList(StringUtils.join(LastMonthBrowseList,",")) |
||||
.build(); |
||||
} |
||||
|
||||
@Override |
||||
public boolean getReceptionBrowse(ReportDTO reportDTO) { |
||||
if (reportDTO.getCreateTime() == null || reportDTO.getPageView() == null){ |
||||
return false; |
||||
} |
||||
boolean todayBrowse = reportMapper.addTodayBrowse(reportDTO); |
||||
if (todayBrowse == false){ |
||||
return false; |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
} |
@ -1,4 +1,4 @@ |
||||
package com.teaching.backend.service.umsAdmin.impl; |
||||
package com.teaching.backend.service.impl.umsAdmin; |
||||
|
||||
import cn.hutool.core.collection.CollUtil; |
||||
import cn.hutool.core.util.StrUtil; |
@ -0,0 +1,21 @@ |
||||
package com.teaching.backend.service.report; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import com.teaching.backend.model.dto.report.ReportDTO; |
||||
import com.teaching.backend.model.entity.report.Report; |
||||
import com.teaching.backend.model.vo.report.BrowseReportVO; |
||||
|
||||
public interface ReportService extends IService<Report> { |
||||
|
||||
/** |
||||
* 浏览统计 |
||||
* @return |
||||
*/ |
||||
BrowseReportVO getBrowseStatistics(); |
||||
|
||||
/** |
||||
* 接收每日浏览量 |
||||
* @return |
||||
*/ |
||||
boolean getReceptionBrowse(ReportDTO reportDTO); |
||||
} |
@ -0,0 +1,18 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
<mapper namespace="com.teaching.backend.mapper.report.ReportMapper"> |
||||
<insert id="addTodayBrowse" parameterType="com.teaching.backend.model.dto.report.ReportDTO"> |
||||
INSERT INTO report (create_time, page_view) |
||||
VALUES |
||||
(#{createTime}, #{pageView}) |
||||
</insert> |
||||
|
||||
<select id="getBrowseByTime" resultType="java.lang.String" parameterType="java.time.LocalDate"> |
||||
SELECT |
||||
r.page_view pageView |
||||
FROM |
||||
report r |
||||
WHERE |
||||
r.create_time = #{day} |
||||
</select> |
||||
</mapper> |
Loading…
Reference in new issue