Added basic statistics service #11
This commit is contained in:
parent
b725458a8a
commit
4e40f0bdd8
@ -10,7 +10,8 @@ import org.springframework.stereotype.Repository;
|
||||
import java.time.Instant;
|
||||
|
||||
@Repository
|
||||
public interface ChatMessageRepository extends JpaRepository<ChatMessage, Long> {
|
||||
public interface ChatMessageRepository
|
||||
extends JpaRepository<ChatMessage, Long> {
|
||||
@Query("select m from ChatMessage m join fetch m.messageCipher mc join fetch m.toUser tu join fetch m.fromUser fu "
|
||||
+ "where (tu.userName = ?1 or tu.userName = ?2) and "
|
||||
+ "(fu.userName = ?1 or fu.userName = ?2) order by m.messageTime asc")
|
||||
@ -19,10 +20,18 @@ public interface ChatMessageRepository extends JpaRepository<ChatMessage, Long>
|
||||
@Query("select m from ChatMessage m join fetch m.messageCipher mc join fetch m.toUser tu join fetch m.fromUser fu "
|
||||
+ "where (tu.userName = ?1 or tu.userName = ?2) and "
|
||||
+ "(fu.userName = ?1 or fu.userName = ?2) and (m.messageTime > ?3) order by m.messageTime asc")
|
||||
public List<ChatMessage> getNewMessages(String fromUser, String toUser, Instant lastMessageTime);
|
||||
public List<ChatMessage> getNewMessages(String fromUser, String toUser,
|
||||
Instant lastMessageTime);
|
||||
|
||||
@Query("select m from ChatMessage m join fetch m.messageCipher mc join fetch m.toUser tu join fetch m.fromUser fu "
|
||||
+ "where (tu.userName = ?1 or tu.userName = ?2) and "
|
||||
+ "(fu.userName = ?1 or fu.userName = ?2) order by m.messageTime desc")
|
||||
public List<ChatMessage> getAllMessages(String fromUser, String toUser, PageRequest pageRequest);
|
||||
public List<ChatMessage> getAllMessages(String fromUser, String toUser,
|
||||
PageRequest pageRequest);
|
||||
|
||||
@Query("select count(c) from ChatMessage c")
|
||||
public Long totalMessages();
|
||||
|
||||
@Query("select count(c) from ChatMessage c where c.messageTime=?1")
|
||||
public Long messagesOnDate(Instant date);
|
||||
}
|
@ -15,4 +15,7 @@ public interface UserRepository extends JpaRepository<ChatUser, Long> {
|
||||
|
||||
@Query("select cu.userName from ChatUser cu where cu.userName != ?1")
|
||||
public List<String> findAllOtherUserNames(String userName);
|
||||
|
||||
@Query("select count(u) from ChatUser u")
|
||||
public Long totalUsers();
|
||||
}
|
||||
|
@ -8,10 +8,14 @@ import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface UserSessionRepository extends JpaRepository<UserSession, Long> {
|
||||
public interface UserSessionRepository
|
||||
extends JpaRepository<UserSession, Long> {
|
||||
@Query("select us from UserSession us join fetch us.user where us.user.userName = ?1 ")
|
||||
public UserSession findByUserName(String userName);
|
||||
|
||||
|
||||
@Query("select us from UserSession us join fetch us.user")
|
||||
public List<UserSession> findAllUserSessions();
|
||||
|
||||
@Query("select count(us) from UserSession us where us.online=true")
|
||||
public Long totalOnlineUsers();
|
||||
}
|
||||
|
34
src/main/java/org/ros/chatto/service/StatisticsService.java
Normal file
34
src/main/java/org/ros/chatto/service/StatisticsService.java
Normal file
@ -0,0 +1,34 @@
|
||||
package org.ros.chatto.service;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import org.ros.chatto.repository.ChatMessageRepository;
|
||||
import org.ros.chatto.repository.UserRepository;
|
||||
import org.ros.chatto.repository.UserSessionRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class StatisticsService {
|
||||
private final ChatMessageRepository chatMessageRepository;
|
||||
private final UserRepository userRepo;
|
||||
private final UserSessionRepository userSessionRepo;
|
||||
|
||||
public Long totalMessage() {
|
||||
return chatMessageRepository.totalMessages();
|
||||
}
|
||||
|
||||
public Long totalUsers() {
|
||||
return userRepo.totalUsers();
|
||||
}
|
||||
|
||||
public Long totalUsersOnline() {
|
||||
return userSessionRepo.totalOnlineUsers();
|
||||
}
|
||||
|
||||
public Long messagesOnDay(Instant date) {
|
||||
return chatMessageRepository.messagesOnDate(date);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user