dev add statistic rest
Test Workflow / test (push) Successful in 2s

This commit is contained in:
vladp
2026-04-15 17:41:33 +07:00
parent bb41898abf
commit b56fb63a37
@@ -34,19 +34,20 @@ public interface TariffInfoRepository extends JpaRepository<TariffInfo, String>
@Query(value = """
SELECT
COALESCE(t.tariff_name, 'NULL') as tariff_name,
t.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
WHERE (:activeOnly = false OR u2.is_active = true)
AND u2.personal_tariff_info_id IS NOT NULL
), 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
INNER JOIN tariff_info pti ON u.personal_tariff_info_id = pti.id
INNER 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)
""", nativeQuery = true)
List<Object[]> getTariffStatisticsNative(@Param("activeOnly") boolean activeOnly);
}