feat: add stat service

This commit is contained in:
Tim
2025-08-12 09:31:27 +08:00
parent 5a5d5add23
commit 08a2678bd5
7 changed files with 228 additions and 9 deletions

View File

@@ -32,4 +32,8 @@ public interface CommentRepository extends JpaRepository<Comment, Long> {
long countByAuthor_Id(Long userId);
@org.springframework.data.jpa.repository.Query("SELECT FUNCTION('date', c.createdAt) AS d, COUNT(c) AS c FROM Comment c " +
"WHERE c.createdAt >= :start AND c.createdAt < :end GROUP BY d ORDER BY d")
java.util.List<Object[]> countDailyRange(@org.springframework.data.repository.query.Param("start") java.time.LocalDateTime start,
@org.springframework.data.repository.query.Param("end") java.time.LocalDateTime end);
}

View File

@@ -95,4 +95,9 @@ public interface PostRepository extends JpaRepository<Post, Long> {
long countDistinctByTags_Id(Long tagId);
long countByAuthor_Id(Long userId);
@Query("SELECT FUNCTION('date', p.createdAt) AS d, COUNT(p) AS c FROM Post p " +
"WHERE p.createdAt >= :start AND p.createdAt < :end GROUP BY d ORDER BY d")
java.util.List<Object[]> countDailyRange(@Param("start") LocalDateTime start,
@Param("end") LocalDateTime end);
}

View File

@@ -1,6 +1,8 @@
package com.openisle.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import com.openisle.model.User;
import java.time.LocalDateTime;
import java.util.Optional;
@@ -12,4 +14,9 @@ public interface UserRepository extends JpaRepository<User, Long> {
java.util.List<User> findByRole(com.openisle.model.Role role);
long countByExperienceGreaterThanEqual(int experience);
long countByCreatedAtBefore(LocalDateTime createdAt);
@Query("SELECT FUNCTION('date', u.createdAt) AS d, COUNT(u) AS c FROM User u " +
"WHERE u.createdAt >= :start AND u.createdAt < :end GROUP BY d ORDER BY d")
java.util.List<Object[]> countDailyRange(@Param("start") LocalDateTime start,
@Param("end") LocalDateTime end);
}