@@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import ru.soune.nocopy.dto.statistic.UserFilesStatisticResponse;
|
||||
import ru.soune.nocopy.entity.file.FileEntity;
|
||||
import ru.soune.nocopy.entity.file.FileStatus;
|
||||
import ru.soune.nocopy.entity.file.ProtectionStatus;
|
||||
@@ -95,4 +96,24 @@ public interface FileEntityRepository extends JpaRepository<FileEntity, String>
|
||||
Long sumFileSize(
|
||||
@Param("userIds") List<Long> userIds,
|
||||
@Param("statuses") List<FileStatus> statuses);
|
||||
|
||||
@Query("""
|
||||
SELECT new ru.soune.nocopy.dto.statistic.UserFilesStatisticResponse(
|
||||
u.fullName,
|
||||
u.Id,
|
||||
CAST(COUNT(f.id) AS int),
|
||||
COALESCE(SUM(f.fileSize), 0L)
|
||||
)
|
||||
FROM FileEntity f
|
||||
JOIN User u ON f.userId = u.Id
|
||||
WHERE
|
||||
(:mimeType IS NULL OR :mimeType = '' OR f.mimeType LIKE CONCAT(:mimeType, '%'))
|
||||
GROUP BY u.Id, u.fullName
|
||||
ORDER BY COUNT(f.id) DESC
|
||||
LIMIT :topUsers
|
||||
""")
|
||||
List<UserFilesStatisticResponse> findTopUsers(
|
||||
@Param("topUsers") int topUsers,
|
||||
@Param("mimeType") String mimeType
|
||||
);
|
||||
}
|
||||
|
||||
@@ -13,4 +13,40 @@ import java.util.List;
|
||||
public interface TariffInfoRepository extends JpaRepository<TariffInfo, String> {
|
||||
@Query("SELECT t FROM TariffInfo t WHERE t.autoRenewal = true AND t.endTariff <= :date")
|
||||
List<TariffInfo> findForAutoRenewal(@Param("date") LocalDateTime date);
|
||||
|
||||
@Query("""
|
||||
SELECT COUNT(u.Id)
|
||||
FROM User u
|
||||
WHERE (:activeOnly = false OR u.isActive = true)
|
||||
AND (:companyOnly = false OR u.company IS NOT NULL)
|
||||
""")
|
||||
Long getTotalUsersCount(
|
||||
@Param("activeOnly") boolean activeOnly,
|
||||
@Param("companyOnly") boolean companyOnly
|
||||
);
|
||||
|
||||
@Query("""
|
||||
SELECT COUNT(u.Id)
|
||||
FROM User u
|
||||
WHERE (:activeOnly = false OR u.isActive = true)
|
||||
""")
|
||||
Long getTotalUsersCount(@Param("activeOnly") boolean activeOnly);
|
||||
|
||||
@Query(value = """
|
||||
SELECT
|
||||
COALESCE(t.tariff_name, 'NULL') as tariff_name,
|
||||
COUNT(u.id) as user_count,
|
||||
(COUNT(u.id) * 100.0) / NULLIF(
|
||||
(SELECT COUNT(*) FROM users u2
|
||||
WHERE :activeOnly = false OR u2.is_active = true
|
||||
), 0
|
||||
) as usage_percent
|
||||
FROM users u
|
||||
LEFT JOIN tariff_info pti ON u.personal_tariff_info_id = pti.id
|
||||
LEFT JOIN tariff t ON pti.tariff_id = t.id
|
||||
WHERE :activeOnly = false OR u.is_active = true
|
||||
GROUP BY t.id, t.tariff_name
|
||||
ORDER BY user_count DESC
|
||||
""", nativeQuery = true)
|
||||
List<Object[]> getTariffStatisticsNative(@Param("activeOnly") boolean activeOnly);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user