日志统计
This commit is contained in:
@@ -3,8 +3,13 @@ package com.banben.modules.auth.service;
|
||||
import com.banben.common.PageResult;
|
||||
import com.banben.modules.auth.dto.LoginLogQuery;
|
||||
import com.banben.modules.auth.entity.LoginLog;
|
||||
import com.banben.modules.auth.vo.AccessDimensionItem;
|
||||
import com.banben.modules.auth.vo.AccessOverview;
|
||||
import com.banben.modules.auth.vo.AccessTrendPoint;
|
||||
import com.banben.modules.auth.vo.LoginLogSummary;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户登录日志服务。
|
||||
*/
|
||||
@@ -21,4 +26,13 @@ public interface LoginLogService {
|
||||
|
||||
/** 概览统计:总数 / 在线 / 今日登录。 */
|
||||
LoginLogSummary summary();
|
||||
|
||||
/** 网络访问概览:历史 / 本月 / 本周 / 今日 的人次与人数。 */
|
||||
AccessOverview accessOverview();
|
||||
|
||||
/** 网络访问趋势:按 小时/日/周/月/年 分桶统计。 */
|
||||
List<AccessTrendPoint> accessTrend(String granularity, String start, String end);
|
||||
|
||||
/** 网络访问维度统计:按 IP / 单位 / 账号 / 类型 分组。 */
|
||||
List<AccessDimensionItem> accessDimension(String dimension, String start, String end, int limit);
|
||||
}
|
||||
|
||||
@@ -8,14 +8,20 @@ import com.banben.modules.auth.dto.LoginLogQuery;
|
||||
import com.banben.modules.auth.entity.LoginLog;
|
||||
import com.banben.modules.auth.mapper.LoginLogMapper;
|
||||
import com.banben.modules.auth.service.LoginLogService;
|
||||
import com.banben.modules.auth.vo.AccessDimensionItem;
|
||||
import com.banben.modules.auth.vo.AccessOverview;
|
||||
import com.banben.modules.auth.vo.AccessTrendPoint;
|
||||
import com.banben.modules.auth.vo.LoginLogSummary;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 用户登录日志服务实现。
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.banben.modules.auth.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 网络访问维度统计项(按 IP / 单位 / 账号 / 类型)。
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "网络访问维度统计项")
|
||||
public class AccessDimensionItem {
|
||||
|
||||
@Schema(description = "维度值(IP / 单位 / 账号 / 在线状态)")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "访问人次")
|
||||
private long count;
|
||||
|
||||
@Schema(description = "访问人数(去重)")
|
||||
private long users;
|
||||
|
||||
public AccessDimensionItem() {
|
||||
}
|
||||
|
||||
public AccessDimensionItem(String name, long count, long users) {
|
||||
this.name = name;
|
||||
this.count = count;
|
||||
this.users = users;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.banben.modules.auth.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 网络访问统计概览。
|
||||
*
|
||||
* <p>人次 = 登录会话记录数;人数 = 去重用户数(按 user_id)。</p>
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "网络访问统计概览")
|
||||
public class AccessOverview {
|
||||
|
||||
@Schema(description = "历史访问人次")
|
||||
private long historyCount;
|
||||
|
||||
@Schema(description = "历史访问人数(去重)")
|
||||
private long historyUsers;
|
||||
|
||||
@Schema(description = "本月访问人次")
|
||||
private long monthCount;
|
||||
|
||||
@Schema(description = "本月访问人数(去重)")
|
||||
private long monthUsers;
|
||||
|
||||
@Schema(description = "本周访问人次")
|
||||
private long weekCount;
|
||||
|
||||
@Schema(description = "本周访问人数(去重)")
|
||||
private long weekUsers;
|
||||
|
||||
@Schema(description = "今日访问人次")
|
||||
private long todayCount;
|
||||
|
||||
@Schema(description = "今日访问人数(去重)")
|
||||
private long todayUsers;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.banben.modules.auth.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 网络访问趋势(按时间分桶)。
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "网络访问趋势(按时间分桶)")
|
||||
public class AccessTrendPoint {
|
||||
|
||||
@Schema(description = "时间桶,如 2026-11-04 08 / 2026-11 / 2026")
|
||||
private String bucket;
|
||||
|
||||
@Schema(description = "访问人次")
|
||||
private long count;
|
||||
|
||||
@Schema(description = "访问人数(去重)")
|
||||
private long users;
|
||||
|
||||
public AccessTrendPoint() {
|
||||
}
|
||||
|
||||
public AccessTrendPoint(String bucket, long count, long users) {
|
||||
this.bucket = bucket;
|
||||
this.count = count;
|
||||
this.users = users;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user