refactor: 重构访问统计接口
This commit is contained in:
@@ -53,11 +53,11 @@ public class LogController {
|
||||
return Result.success(data);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取统计数据")
|
||||
@Operation(summary = "获取访问统计")
|
||||
@GetMapping("/visit-stats")
|
||||
public Result<List<VisitStatsVO>> getVisitStats() {
|
||||
List<VisitStatsVO> list = logService.getVisitStats();
|
||||
return Result.success(list);
|
||||
public Result<VisitStatsVO> getVisitStats() {
|
||||
VisitStatsVO result = logService.getVisitStats();
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.youlai.boot.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.youlai.boot.system.model.bo.VisitCount;
|
||||
import com.youlai.boot.system.model.bo.VisitStatsBO;
|
||||
import com.youlai.boot.system.model.entity.Log;
|
||||
import com.youlai.boot.system.model.query.LogPageQuery;
|
||||
import com.youlai.boot.system.model.vo.LogPageVO;
|
||||
@@ -13,7 +14,7 @@ import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 系统日志 数据库访问层
|
||||
* 系统日志数据访问层
|
||||
*
|
||||
* @author Ray
|
||||
* @since 2.10.0
|
||||
@@ -23,10 +24,6 @@ public interface LogMapper extends BaseMapper<Log> {
|
||||
|
||||
/**
|
||||
* 获取日志分页列表
|
||||
*
|
||||
* @param page
|
||||
* @param queryParams
|
||||
* @return
|
||||
*/
|
||||
Page<LogPageVO> getLogPage(Page<LogPageVO> page, LogPageQuery queryParams);
|
||||
|
||||
@@ -35,7 +32,6 @@ public interface LogMapper extends BaseMapper<Log> {
|
||||
*
|
||||
* @param startDate 开始日期 yyyy-MM-dd
|
||||
* @param endDate 结束日期 yyyy-MM-dd
|
||||
* @return
|
||||
*/
|
||||
List<VisitCount> getPvCounts(String startDate, String endDate);
|
||||
|
||||
@@ -44,23 +40,18 @@ public interface LogMapper extends BaseMapper<Log> {
|
||||
*
|
||||
* @param startDate 开始日期 yyyy-MM-dd
|
||||
* @param endDate 结束日期 yyyy-MM-dd
|
||||
* @return
|
||||
*/
|
||||
List<VisitCount> getIpCounts(String startDate, String endDate);
|
||||
|
||||
/**
|
||||
* 获取浏览量(PV)统计数据
|
||||
*
|
||||
* @return
|
||||
* 获取浏览量(PV)统计
|
||||
*/
|
||||
VisitStatsVO getPvStats();
|
||||
VisitStatsBO getPvStats();
|
||||
|
||||
/**
|
||||
* 获取IP统计数据
|
||||
*
|
||||
* @return
|
||||
* 获取访问IP统计
|
||||
*/
|
||||
VisitStatsVO getIpStats();
|
||||
VisitStatsBO getUvStats();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.youlai.boot.system.model.bo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 访问量统计业务对象
|
||||
*
|
||||
* @author Ray.Hao
|
||||
* @since 2024/7/2
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class VisitStatsBO {
|
||||
|
||||
@Schema(description = "今日访问量 (PV)")
|
||||
private Integer todayCount;
|
||||
|
||||
@Schema(description = "累计访问量 ")
|
||||
private Integer totalCount;
|
||||
|
||||
@Schema(description = "页面访问量增长率")
|
||||
private BigDecimal growthRate;
|
||||
|
||||
}
|
||||
@@ -7,32 +7,32 @@ import lombok.Setter;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 访问量统计VO
|
||||
* 访问量统计视图对象
|
||||
*
|
||||
* @author Ray
|
||||
* @author Ray.Hao
|
||||
* @since 2024/7/2
|
||||
*/
|
||||
@Schema(description = "访问量统计VO")
|
||||
@Schema(description = "访问量统计视图对象")
|
||||
@Getter
|
||||
@Setter
|
||||
public class VisitStatsVO {
|
||||
|
||||
@Schema(description = "统计类型")
|
||||
private String type;
|
||||
@Schema(description = "今日独立访客数 (UV)")
|
||||
private Integer todayUvCount;
|
||||
|
||||
@Schema(description = "标题")
|
||||
private String title;
|
||||
@Schema(description = "累计独立访客数 (UV)")
|
||||
private Integer totalUvCount;
|
||||
|
||||
@Schema(description = "今日访问量")
|
||||
private Integer todayCount;
|
||||
@Schema(description = "独立访客增长率")
|
||||
private BigDecimal uvGrowthRate;
|
||||
|
||||
@Schema(description = "总访问量")
|
||||
private Integer totalCount;
|
||||
@Schema(description = "今日页面浏览量 (PV)")
|
||||
private Integer todayPvCount;
|
||||
|
||||
@Schema(description = "增长率")
|
||||
private BigDecimal growthRate;
|
||||
@Schema(description = "累计页面浏览量 (PV)")
|
||||
private Integer totalPvCount;
|
||||
|
||||
@Schema(description = "统计粒度标签")
|
||||
private String granularityLabel;
|
||||
@Schema(description = "页面浏览量增长率")
|
||||
private BigDecimal pvGrowthRate;
|
||||
|
||||
}
|
||||
|
||||
@@ -14,16 +14,13 @@ import java.util.List;
|
||||
/**
|
||||
* 系统日志 服务接口
|
||||
*
|
||||
* @author Ray
|
||||
* @author Ray.Hao
|
||||
* @since 2.10.0
|
||||
*/
|
||||
public interface LogService extends IService<Log> {
|
||||
|
||||
/**
|
||||
* 获取日志分页列表
|
||||
*
|
||||
* @param queryParams 查询参数
|
||||
* @return
|
||||
*/
|
||||
Page<LogPageVO> getLogPage(LogPageQuery queryParams);
|
||||
|
||||
@@ -33,15 +30,12 @@ public interface LogService extends IService<Log> {
|
||||
*
|
||||
* @param startDate 开始时间
|
||||
* @param endDate 结束时间
|
||||
* @return
|
||||
*/
|
||||
VisitTrendVO getVisitTrend(LocalDate startDate, LocalDate endDate);
|
||||
|
||||
/**
|
||||
* 获取访问统计
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<VisitStatsVO> getVisitStats();
|
||||
VisitStatsVO getVisitStats();
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.youlai.boot.system.mapper.LogMapper;
|
||||
import com.youlai.boot.system.model.bo.VisitCount;
|
||||
import com.youlai.boot.system.model.bo.VisitStatsBO;
|
||||
import com.youlai.boot.system.model.entity.Log;
|
||||
import com.youlai.boot.system.model.query.LogPageQuery;
|
||||
import com.youlai.boot.system.model.vo.LogPageVO;
|
||||
@@ -22,7 +23,7 @@ import java.util.stream.Collectors;
|
||||
/**
|
||||
* 系统日志 服务实现类
|
||||
*
|
||||
* @author Ray
|
||||
* @author Ray.Hao
|
||||
* @since 2.10.0
|
||||
*/
|
||||
@Service
|
||||
@@ -33,7 +34,7 @@ public class LogServiceImpl extends ServiceImpl<LogMapper, Log>
|
||||
* 获取日志分页列表
|
||||
*
|
||||
* @param queryParams 查询参数
|
||||
* @return
|
||||
* @return 日志分页列表
|
||||
*/
|
||||
@Override
|
||||
public Page<LogPageVO> getLogPage(LogPageQuery queryParams) {
|
||||
@@ -84,39 +85,29 @@ public class LogServiceImpl extends ServiceImpl<LogMapper, Log>
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取访问统计
|
||||
*
|
||||
* @return
|
||||
* 访问量统计
|
||||
*/
|
||||
@Override
|
||||
public List<VisitStatsVO> getVisitStats() {
|
||||
List<VisitStatsVO> list = new ArrayList<>();
|
||||
public VisitStatsVO getVisitStats() {
|
||||
VisitStatsVO result = new VisitStatsVO();
|
||||
|
||||
// 访问量
|
||||
VisitStatsVO pvStats = this.baseMapper.getPvStats();
|
||||
pvStats.setTitle("浏览量");
|
||||
pvStats.setType("pv");
|
||||
pvStats.setGranularityLabel("日");
|
||||
list.add(pvStats);
|
||||
// 访客数统计(UV)
|
||||
VisitStatsBO uvStats = this.baseMapper.getUvStats();
|
||||
if(uvStats!=null){
|
||||
result.setTodayUvCount(uvStats.getTodayCount());
|
||||
result.setTotalUvCount(uvStats.getTotalCount());
|
||||
result.setUvGrowthRate(uvStats.getGrowthRate());
|
||||
}
|
||||
|
||||
// 访客数
|
||||
VisitStatsVO uvStats = new VisitStatsVO();
|
||||
uvStats.setTitle("访客数");
|
||||
uvStats.setType("uv");
|
||||
uvStats.setTodayCount(100);
|
||||
uvStats.setTotalCount(2000);
|
||||
uvStats.setGrowthRate(BigDecimal.ZERO);
|
||||
uvStats.setGranularityLabel("日");
|
||||
list.add(uvStats);
|
||||
// 浏览量统计(PV)
|
||||
VisitStatsBO pvStats = this.baseMapper.getPvStats();
|
||||
if(pvStats!=null){
|
||||
result.setTodayPvCount(pvStats.getTodayCount());
|
||||
result.setTotalPvCount(pvStats.getTotalCount());
|
||||
result.setPvGrowthRate(pvStats.getGrowthRate());
|
||||
}
|
||||
|
||||
// IP数
|
||||
VisitStatsVO ipStats = this.baseMapper.getIpStats();
|
||||
ipStats.setTitle("IP数");
|
||||
ipStats.setType("ip");
|
||||
ipStats.setGranularityLabel("日");
|
||||
list.add(ipStats);
|
||||
|
||||
return list;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@
|
||||
</select>
|
||||
|
||||
<!-- 获取访问量(PV)统计数据 -->
|
||||
<select id="getPvStats" resultType="com.youlai.boot.system.model.vo.VisitStatsVO">
|
||||
<select id="getPvStats" resultType="com.youlai.boot.system.model.bo.VisitStatsBO">
|
||||
SELECT
|
||||
COUNT(CASE WHEN DATE(create_time) = CURDATE() THEN 1 END) AS todayCount,
|
||||
COUNT(*) AS totalCount,
|
||||
@@ -94,7 +94,7 @@
|
||||
</select>
|
||||
|
||||
<!-- 获取IP统计数据 -->
|
||||
<select id="getIpStats" resultType="com.youlai.boot.system.model.vo.VisitStatsVO">
|
||||
<select id="getUvStats" resultType="com.youlai.boot.system.model.bo.VisitStatsBO">
|
||||
SELECT
|
||||
COUNT(DISTINCT CASE WHEN DATE(create_time) = CURDATE() THEN ip END) AS todayCount,
|
||||
COUNT(DISTINCT ip) AS totalCount,
|
||||
|
||||
Reference in New Issue
Block a user