From 8b12eec0520cffd753513fa3a56af5f443778501 Mon Sep 17 00:00:00 2001 From: gsd Date: Sat, 14 Dec 2024 15:00:31 +0300 Subject: [PATCH] goty --- .../java/app/controllers/StatsController.java | 18 +++++++++++++++++- .../java/app/services/db/DonateService.java | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/main/java/app/controllers/StatsController.java b/src/main/java/app/controllers/StatsController.java index 5fe1ab7..335d2c1 100644 --- a/src/main/java/app/controllers/StatsController.java +++ b/src/main/java/app/controllers/StatsController.java @@ -2,8 +2,10 @@ package app.controllers; import app.annotations.enums.CollectStages; import app.annotations.interfaces.*; +import app.entities.StatisticRange; import app.entities.Stats; import app.services.ExternalServices; +import app.services.db.DonateService; import app.services.io.readers.ServersReader; import app.updates.OnlineUpdater; import app.utils.RealIPService; @@ -30,14 +32,17 @@ public class StatsController { private HashMap, HashMap, Long>> cache = new HashMap<>(); private ServersReader serversReader; private RealIPService realIPService; + private DonateService donateService; @Autowired - public StatsController(Stats stats, ExternalServices externalServices, OnlineUpdater onlineUpdater, ServersReader serversReader){ + public StatsController(Stats stats, ExternalServices externalServices, OnlineUpdater onlineUpdater, ServersReader serversReader, + DonateService donateService){ this.stats = stats; this.externalServices = externalServices; this.onlineUpdater = onlineUpdater; this.serversReader = serversReader; this.realIPService = new RealIPService(); + this.donateService = donateService; } @GetMapping @@ -120,4 +125,15 @@ public class StatsController { "connect " + route, "steam://connect/" + route ), HttpStatus.OK); } + + @GetMapping("/goty") + @WaitAfterNext(order = "goty") + public Map getGoty() { + //select message, count(*) as c from user_messages group by message order by c desc limit 15 - топ сообщений + //select weapon_name, count(*) as c from user_killfeed group by weapon_name order by c desc limit 10 - топ пушек + //select count(*) as c from user_killfeed where attacker_id != user_killfeed.victim_id - скок умерло карликов + return Map.of( + "topdonate", donateService.getTopSteamSheikh(StatisticRange.YEAR) + ); + } } diff --git a/src/main/java/app/services/db/DonateService.java b/src/main/java/app/services/db/DonateService.java index b34c1be..6ad1317 100644 --- a/src/main/java/app/services/db/DonateService.java +++ b/src/main/java/app/services/db/DonateService.java @@ -7,10 +7,13 @@ import app.entities.VipGiveMethod; import app.entities.db.DonateStat; import app.entities.other.SteamID; import jakarta.annotation.PostConstruct; +import lombok.Data; +import lombok.Getter; import org.apache.commons.lang3.tuple.Pair; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.ResultSetExtractor; import org.springframework.jdbc.core.RowMapper; @@ -146,4 +149,19 @@ public class DonateService { } //надо добавить шейхов GROUP BY steam2 ORDER BY r DESC + @Data + public static class DonateSheikh { + private String steam2; + private long r; + private long k; + } + + public List getTopSteamSheikh(StatisticRange statisticRange) { + return jdbcTemplate.query("SELECT steam2, SUM(CAST(REPLACE(REPLACE(split_part(reserved,';',-2), 'metal=',''), ';','') AS INT)) as r, " + + " SUM(CAST(REPLACE(REPLACE(split_part(reserved,';',1), 'keys=',''), ';','') as INT)) as k " + + "FROM gived_vip WHERE givemethod = ? AND timestamp > date_trunc(?,now())::DATE " + + "group by steam2 order by k desc limit ?", + new Object[]{VipGiveMethod.STEAM.ordinal(), StatisticRange.cast(statisticRange), 10}, + new BeanPropertyRowMapper<>(DonateSheikh.class)); + } }