|
@@ -16,56 +16,48 @@ public interface UserEventRepository extends JpaRepository<UserEvent, Long>,
|
|
|
|
|
|
|
|
/** 总数 */
|
|
/** 总数 */
|
|
|
@Query("SELECT COUNT(e) FROM UserEvent e " +
|
|
@Query("SELECT COUNT(e) FROM UserEvent e " +
|
|
|
- "WHERE (:startTime IS NULL OR e.createdAt >= :startTime) " +
|
|
|
|
|
- "AND (:endTime IS NULL OR e.createdAt < :endTime)")
|
|
|
|
|
|
|
+ "WHERE e.createdAt >= :startTime AND e.createdAt < :endTime")
|
|
|
long countTotal(@Param("startTime") Instant startTime, @Param("endTime") Instant endTime);
|
|
long countTotal(@Param("startTime") Instant startTime, @Param("endTime") Instant endTime);
|
|
|
|
|
|
|
|
/** 去重活跃用户数 */
|
|
/** 去重活跃用户数 */
|
|
|
@Query("SELECT COUNT(DISTINCT e.userKey) FROM UserEvent e " +
|
|
@Query("SELECT COUNT(DISTINCT e.userKey) FROM UserEvent e " +
|
|
|
- "WHERE (:startTime IS NULL OR e.createdAt >= :startTime) " +
|
|
|
|
|
- "AND (:endTime IS NULL OR e.createdAt < :endTime)")
|
|
|
|
|
|
|
+ "WHERE e.createdAt >= :startTime AND e.createdAt < :endTime")
|
|
|
long countDistinctUsers(@Param("startTime") Instant startTime, @Param("endTime") Instant endTime);
|
|
long countDistinctUsers(@Param("startTime") Instant startTime, @Param("endTime") Instant endTime);
|
|
|
|
|
|
|
|
/** 按类型统计数量 */
|
|
/** 按类型统计数量 */
|
|
|
@Query("SELECT COUNT(e) FROM UserEvent e " +
|
|
@Query("SELECT COUNT(e) FROM UserEvent e " +
|
|
|
"WHERE e.eventType = :eventType " +
|
|
"WHERE e.eventType = :eventType " +
|
|
|
- "AND (:startTime IS NULL OR e.createdAt >= :startTime) " +
|
|
|
|
|
- "AND (:endTime IS NULL OR e.createdAt < :endTime)")
|
|
|
|
|
|
|
+ "AND e.createdAt >= :startTime AND e.createdAt < :endTime")
|
|
|
long countByType(@Param("eventType") String eventType,
|
|
long countByType(@Param("eventType") String eventType,
|
|
|
@Param("startTime") Instant startTime, @Param("endTime") Instant endTime);
|
|
@Param("startTime") Instant startTime, @Param("endTime") Instant endTime);
|
|
|
|
|
|
|
|
/** 按 IP 分组统计 */
|
|
/** 按 IP 分组统计 */
|
|
|
@Query("SELECT e.ip as key, COUNT(e) as cnt FROM UserEvent e " +
|
|
@Query("SELECT e.ip as key, COUNT(e) as cnt FROM UserEvent e " +
|
|
|
- "WHERE (:startTime IS NULL OR e.createdAt >= :startTime) " +
|
|
|
|
|
- "AND (:endTime IS NULL OR e.createdAt < :endTime) " +
|
|
|
|
|
|
|
+ "WHERE e.createdAt >= :startTime AND e.createdAt < :endTime " +
|
|
|
"GROUP BY e.ip ORDER BY cnt DESC")
|
|
"GROUP BY e.ip ORDER BY cnt DESC")
|
|
|
List<Object[]> countByIp(@Param("startTime") Instant startTime, @Param("endTime") Instant endTime);
|
|
List<Object[]> countByIp(@Param("startTime") Instant startTime, @Param("endTime") Instant endTime);
|
|
|
|
|
|
|
|
/** 按 page_url 分组统计 */
|
|
/** 按 page_url 分组统计 */
|
|
|
@Query("SELECT e.pageUrl as key, COUNT(e) as cnt FROM UserEvent e " +
|
|
@Query("SELECT e.pageUrl as key, COUNT(e) as cnt FROM UserEvent e " +
|
|
|
- "WHERE (:startTime IS NULL OR e.createdAt >= :startTime) " +
|
|
|
|
|
- "AND (:endTime IS NULL OR e.createdAt < :endTime) " +
|
|
|
|
|
|
|
+ "WHERE e.createdAt >= :startTime AND e.createdAt < :endTime " +
|
|
|
"GROUP BY e.pageUrl ORDER BY cnt DESC")
|
|
"GROUP BY e.pageUrl ORDER BY cnt DESC")
|
|
|
List<Object[]> countByPageUrl(@Param("startTime") Instant startTime, @Param("endTime") Instant endTime);
|
|
List<Object[]> countByPageUrl(@Param("startTime") Instant startTime, @Param("endTime") Instant endTime);
|
|
|
|
|
|
|
|
/** 按 event_type 分组统计 */
|
|
/** 按 event_type 分组统计 */
|
|
|
@Query("SELECT e.eventType as key, COUNT(e) as cnt FROM UserEvent e " +
|
|
@Query("SELECT e.eventType as key, COUNT(e) as cnt FROM UserEvent e " +
|
|
|
- "WHERE (:startTime IS NULL OR e.createdAt >= :startTime) " +
|
|
|
|
|
- "AND (:endTime IS NULL OR e.createdAt < :endTime) " +
|
|
|
|
|
|
|
+ "WHERE e.createdAt >= :startTime AND e.createdAt < :endTime " +
|
|
|
"GROUP BY e.eventType ORDER BY cnt DESC")
|
|
"GROUP BY e.eventType ORDER BY cnt DESC")
|
|
|
List<Object[]> countByEventType(@Param("startTime") Instant startTime, @Param("endTime") Instant endTime);
|
|
List<Object[]> countByEventType(@Param("startTime") Instant startTime, @Param("endTime") Instant endTime);
|
|
|
|
|
|
|
|
/** 按 user_key 分组统计(去重用户) */
|
|
/** 按 user_key 分组统计(去重用户) */
|
|
|
@Query("SELECT e.userKey as key, COUNT(e) as cnt FROM UserEvent e " +
|
|
@Query("SELECT e.userKey as key, COUNT(e) as cnt FROM UserEvent e " +
|
|
|
- "WHERE (:startTime IS NULL OR e.createdAt >= :startTime) " +
|
|
|
|
|
- "AND (:endTime IS NULL OR e.createdAt < :endTime) " +
|
|
|
|
|
|
|
+ "WHERE e.createdAt >= :startTime AND e.createdAt < :endTime " +
|
|
|
"GROUP BY e.userKey ORDER BY cnt DESC")
|
|
"GROUP BY e.userKey ORDER BY cnt DESC")
|
|
|
List<Object[]> countByUserKey(@Param("startTime") Instant startTime, @Param("endTime") Instant endTime);
|
|
List<Object[]> countByUserKey(@Param("startTime") Instant startTime, @Param("endTime") Instant endTime);
|
|
|
|
|
|
|
|
/** 用户+IP 混合维度:每个用户关联的 IP 列表 */
|
|
/** 用户+IP 混合维度:每个用户关联的 IP 列表 */
|
|
|
@Query("SELECT e.userKey, e.ip, COUNT(e) as cnt FROM UserEvent e " +
|
|
@Query("SELECT e.userKey, e.ip, COUNT(e) as cnt FROM UserEvent e " +
|
|
|
- "WHERE (:startTime IS NULL OR e.createdAt >= :startTime) " +
|
|
|
|
|
- "AND (:endTime IS NULL OR e.createdAt < :endTime) " +
|
|
|
|
|
|
|
+ "WHERE e.createdAt >= :startTime AND e.createdAt < :endTime " +
|
|
|
"GROUP BY e.userKey, e.ip ORDER BY e.userKey, cnt DESC")
|
|
"GROUP BY e.userKey, e.ip ORDER BY e.userKey, cnt DESC")
|
|
|
List<Object[]> countByUserIp(@Param("startTime") Instant startTime, @Param("endTime") Instant endTime);
|
|
List<Object[]> countByUserIp(@Param("startTime") Instant startTime, @Param("endTime") Instant endTime);
|
|
|
}
|
|
}
|