From 2cd78f623c60c9000d52c777450b95bcd02a9fd5 Mon Sep 17 00:00:00 2001 From: gsd Date: Wed, 21 Feb 2024 20:05:52 +0300 Subject: [PATCH] jdbc migrate clean up --- src/main/java/app/services/db/DBService.java | 16 +-- .../java/app/services/db/DetectService.java | 28 +----- .../app/services/db/DiscordAuthService.java | 15 +-- .../java/app/services/db/DonateService.java | 43 ++------ .../java/app/services/db/FreeVIPService.java | 39 ++------ .../java/app/services/db/KillfeedService.java | 97 ++++--------------- .../java/app/services/db/MessageService.java | 38 ++------ .../java/app/services/db/NicknameService.java | 8 +- .../app/services/db/PermitionService.java | 22 +---- .../java/app/services/db/UsertimeService.java | 53 +++------- src/main/java/app/services/db/VIPService.java | 21 +--- .../java/app/updates/BanCountUpdater.java | 7 +- .../java/app/updates/CountriesUpdater.java | 7 +- src/main/java/app/updates/UniqueUpdater.java | 14 +-- .../java/app/updates/VipCountUpdater.java | 14 +-- 15 files changed, 83 insertions(+), 339 deletions(-) diff --git a/src/main/java/app/services/db/DBService.java b/src/main/java/app/services/db/DBService.java index 4d9a4f2..7fcfeb6 100644 --- a/src/main/java/app/services/db/DBService.java +++ b/src/main/java/app/services/db/DBService.java @@ -28,21 +28,13 @@ public class DBService { public Long getMainServerTime() { return jdbcTemplate_rw.query("SELECT UNIX_TIMESTAMP() as u", - new RowMapper() { - @Override - public Long mapRow(ResultSet rs, int rowNum) throws SQLException { - return rs.getLong("u"); - } - }).stream().findFirst().orElse(0L); + (rs, n) -> rs.getLong("u")) + .stream().findFirst().orElse(0L); } public Long getReplicaServerTime() { return jdbcTemplate_rw.query("SELECT UNIX_TIMESTAMP() as u", - new RowMapper() { - @Override - public Long mapRow(ResultSet rs, int rowNum) throws SQLException { - return rs.getLong("u"); - } - }).stream().findFirst().orElse(0L); + (rs, n) -> rs.getLong("u")) + .stream().findFirst().orElse(0L); } } diff --git a/src/main/java/app/services/db/DetectService.java b/src/main/java/app/services/db/DetectService.java index 9c621b8..d7934bc 100644 --- a/src/main/java/app/services/db/DetectService.java +++ b/src/main/java/app/services/db/DetectService.java @@ -42,12 +42,7 @@ public class DetectService { for (Map.Entry stringServerEntry : stats.getServers().entrySet()) { founded_steamid.addAll(jdbcTemplate_ro.query("SELECT `steam_id` FROM `" + stringServerEntry.getValue().getDb() + "`." + "`user_connections` WHERE `connect_ip` in (SELECT `connect_ip` FROM `" + stringServerEntry.getValue().getDb() + "`." + "`user_connections` WHERE `steam_id` LIKE ? AND `connect_ip` NOT LIKE '10.%' GROUP BY `connect_ip` ORDER BY `id` DESC) GROUP BY `steam_id`", new Object[]{steamID.steam2}, - new RowMapper() { - @Override - public String mapRow(ResultSet rs, int rowNum) throws SQLException { - return rs.getString("steam_id"); - } - })); + (rs, n) -> rs.getString("steam_id"))); } //SELECT `steam_id` FROM `tf2.facti13.five`.`user_connections` WHERE `connect_ip` in (SELECT `connect_ip` FROM `tf2.facti13.five`.`user_connections` WHERE `steam_id` LIKE 'STEAM_0:0:63666481' AND `connect_ip` NOT LIKE '10.%' GROUP BY `connect_ip` ORDER BY `id` DESC) GROUP BY `steam_id`; return founded_steamid.stream().distinct().map(SteamIDConverter::getSteamID).filter(Objects::nonNull).toList(); @@ -69,18 +64,8 @@ public class DetectService { String sql = "SELECT `steam_id` FROM `"+stringServerEntry.getValue().getDb()+"`."+"`user_connections` WHERE `connect_ip` in (SELECT `connect_ip` FROM `" + stringServerEntry.getValue().getDb() + "`." +"`user_connections` WHERE `steam_id` LIKE ? AND `connect_ip` NOT LIKE '10.%' GROUP BY `connect_ip` ORDER BY `id` DESC) GROUP BY `steam_id`"; switch (em_selector.get()) { - case 0:return jdbcTemplate_ro.query(sql, new Object[]{steamID.steam2}, new RowMapper() { - @Override - public String mapRow(ResultSet rs, int rowNum) throws SQLException { - return rs.getString("steam_id"); - } - }); - case 1:return jdbcTemplate_rw.query(sql, new Object[]{steamID.steam2}, new RowMapper() { - @Override - public String mapRow(ResultSet rs, int rowNum) throws SQLException { - return rs.getString("steam_id"); - } - }); + case 0:return jdbcTemplate_ro.query(sql, new Object[]{steamID.steam2}, (rs, n) -> rs.getString("steam_id")); + case 1:return jdbcTemplate_rw.query(sql, new Object[]{steamID.steam2}, (rs, n) -> rs.getString("steam_id")); default: return new ArrayList<>(); } }); @@ -98,12 +83,7 @@ public class DetectService { public List> getAttachedDiscordAccountPerSteam(SteamID steamID) { return jdbcTemplate_ro.query("SELECT `discord_id`, UNIX_TIMESTAMP(`timestamp`) as utime, `active` FROM `steam2discord` WHERE `steam_id` LIKE ? GROUP BY `discord_id`", new Object[]{ steamID.steam2 }, - new RowMapper>() { - @Override - public Map mapRow(ResultSet rs, int rowNum) throws SQLException { - return Map.of("discord_id", rs.getObject("discord_id"), "utime", rs.getObject("utime"), "active", rs.getObject("active")); - } - }); + (rs, n) -> Map.of("discord_id", rs.getObject("discord_id"), "utime", rs.getObject("utime"), "active", rs.getObject("active"))); } //SELECT CONCAT(SUBSTRING_INDEX(connect_ip,'.', 1),'.',SUBSTRING_INDEX(SUBSTRING_INDEX(connect_ip,'.', 2),'.',-1),'.',SUBSTRING_INDEX(SUBSTRING_INDEX(connect_ip,'.', 3),'.',-1),'.','%') FROM `all_users_con_2` WHERE `steam_id` LIKE 'STEAM_0:1:768781968'; } diff --git a/src/main/java/app/services/db/DiscordAuthService.java b/src/main/java/app/services/db/DiscordAuthService.java index 918ae3c..b9242e2 100644 --- a/src/main/java/app/services/db/DiscordAuthService.java +++ b/src/main/java/app/services/db/DiscordAuthService.java @@ -32,12 +32,8 @@ public class DiscordAuthService { public String getDiscordIDofSteamID(SteamID steamID) { return jdbcTemplate.query("SELECT discord_id FROM steam2discord WHERE steam_id = ? AND active = 1 LIMIT 1", new Object[]{ steamID.steam2 }, - new RowMapper() { - @Override - public String mapRow(ResultSet rs, int numRow) throws SQLException { - return rs.getString("discord_id"); - } - }).stream().findFirst().orElse(null); + (rs, n) -> rs.getString("discord_id")) + .stream().findFirst().orElse(null); } public boolean setSteamIDofDiscordID(SteamID steamID, String discord_id) { @@ -54,12 +50,7 @@ public class DiscordAuthService { String inSql = String.join(",", Collections.nCopies(discord_accounts.size(), "?")); return jdbcTemplate.query("SELECT `discord_id` FROM `steam2discord` WHERE `active` = 1 AND `discord_id` in (" + inSql + ")", discord_accounts.toArray(), - new RowMapper() { - @Override - public String mapRow(ResultSet rs, int rowNum) throws SQLException { - return rs.getString("discord_id"); - } - }); + (rs, n) -> rs.getString("discord_id")); } public HashMap> getProcessing_accounts() { diff --git a/src/main/java/app/services/db/DonateService.java b/src/main/java/app/services/db/DonateService.java index f48d241..ac4ea54 100644 --- a/src/main/java/app/services/db/DonateService.java +++ b/src/main/java/app/services/db/DonateService.java @@ -43,50 +43,32 @@ public class DonateService { " SUM(CAST(REPLACE(REPLACE(substring_index(`reserved`,';',1), 'keys=',''), ';','') as INT)) as k " + "FROM `gived_vip` WHERE `givemethod` = ? AND `timestamp` > CAST(DATE_FORMAT(NOW() ,?) as DATE)", new Object[]{VipGiveMethod.STEAM.ordinal(), StatisticRange.cast(statisticRange)}, - new RowMapper>() { - @Override - public Pair mapRow(ResultSet rs, int numRow) throws SQLException { - return Pair.of( - Optional.of(rs.getInt("k")).orElse(0), - Optional.of(rs.getInt("r")).orElse(0) - ); - } - }).stream().findFirst().orElse(Pair.of(0,0)); + (rs, n) -> Pair.of( + Optional.of(rs.getInt("k")).orElse(0), + Optional.of(rs.getInt("r")).orElse(0) + )) + .stream().findFirst().orElse(Pair.of(0,0)); } public Integer getSummaryQiwiDonateValue(StatisticRange statisticRange) { return jdbcTemplate.query("SELECT SUM(CAST(REPLACE(REPLACE(substring_index(`reserved`,';',1), 'rub=',''), ';','') as INT)) as k " + "FROM `gived_vip` WHERE `givemethod` = ? AND `timestamp` > CAST(DATE_FORMAT(NOW() ,?) as DATE)", new Object[]{ VipGiveMethod.QIWI.ordinal(), StatisticRange.cast(statisticRange)}, - new RowMapper() { - @Override - public Integer mapRow(ResultSet rs, int numRow) throws SQLException { - return rs.getInt("k"); - } - }).stream().findFirst().orElse(0); + (rs, n) -> rs.getInt("k")).stream().findFirst().orElse(0); } //no need if use getGivedVipStatistic public Long getSummaryGivedFreeVip(StatisticRange statisticRange) { return jdbcTemplate.query("SELECT COUNT(*) as count FROM `gived_vip` WHERE `givemethod` = ? AND `timestamp` > CAST(DATE_FORMAT(NOW() ,?) as DATE)", new Object[]{ VipGiveMethod.FREE.ordinal(), StatisticRange.cast(statisticRange) }, - new RowMapper() { - @Override - public Long mapRow(ResultSet rs, int numRow) throws SQLException { - return rs.getLong("count"); - } - }).stream().findFirst().orElse(0L); + (rs, n) -> rs.getLong("count")) + .stream().findFirst().orElse(0L); } public HashMap getGivedVipStatistic(StatisticRange statisticRange) { List donateStatistics = jdbcTemplate.query("SELECT `givemethod`,COUNT(*) as count,`reserved`, `amount` FROM `gived_vip` WHERE `givemethod` IN (0,1,2) AND `timestamp` > CAST(DATE_FORMAT(NOW() ,?) as DATE) GROUP BY `givemethod`, `amount`", new Object[]{StatisticRange.cast(statisticRange)}, - new RowMapper() { - @Override - public DonateStatistic mapRow(ResultSet rs, int rowNum) throws SQLException { - return new DonateStatistic(rs); - } - }); + (rs, n) -> new DonateStatistic(rs)); HashMap map = new HashMap<>(); map.put("steam", new HashMap<>()); @@ -118,12 +100,7 @@ public class DonateService { public List getDonateStatistic(SteamID steamID) { return jdbcTemplate.query("SELECT *, UNIX_TIMESTAMP(`timestamp`) as utime FROM `gived_vip` WHERE `steam2` LIKE ?", new Object[]{steamID.steam2}, - new RowMapper() { - @Override - public DonateStat mapRow(ResultSet rs, int rowNum) throws SQLException { - return new DonateStat(rs); - } - }); + (rs, n) -> new DonateStat(rs)); } public HashMap getDonateStatistic(StatisticRange statisticRange) { diff --git a/src/main/java/app/services/db/FreeVIPService.java b/src/main/java/app/services/db/FreeVIPService.java index 7496482..73495cf 100644 --- a/src/main/java/app/services/db/FreeVIPService.java +++ b/src/main/java/app/services/db/FreeVIPService.java @@ -35,34 +35,21 @@ public class FreeVIPService{ public Long getDBServerUTime() { return jdbcTemplate.query("SELECT UNIX_TIMESTAMP(NOW()) as c", - new RowMapper() { - @Override - public Long mapRow(ResultSet rs, int numRow) throws SQLException { - return rs.getLong("c"); - } - }).stream().findFirst().orElse(0L); + (rs, n) -> rs.getLong("c")) + .stream().findFirst().orElse(0L); } public List getSocial(SteamID steamID) { return jdbcTemplate.query("SELECT id, steam3, vk_id, discord_id, date FROM free_vip WHERE steam3 = ? ORDER BY `free_vip`.`date` DESC", new Object[]{steamID.steam2}, - new RowMapper() { - @Override - public FreeVIP mapRow(ResultSet rs, int rowNum) throws SQLException { - return new FreeVIP(rs); - } - }); + (rs, n) -> new FreeVIP(rs)); } public Long getLastGivedFreeVIP(SteamID steamID) { return jdbcTemplate.query("SELECT UNIX_TIMESTAMP(`date`) as u_time FROM free_vip WHERE steam3 LIKE ? ORDER BY `date` DESC", new Object[]{ steamID.steam2 }, - new RowMapper() { - @Override - public Long mapRow(ResultSet rs, int rowNum) throws SQLException { - return rs.getLong("u_time"); - } - }).stream().findFirst().orElse(0L); + (rs, n) -> rs.getLong("u_time")) + .stream().findFirst().orElse(0L); } public Long getLastGivedFreeVIP(SocialAuth socialAuth) { @@ -72,21 +59,13 @@ public class FreeVIPService{ else if (socialAuth.getVk_id() != 0) { return jdbcTemplate.query("SELECT UNIX_TIMESTAMP(`date`) as u_time FROM free_vip WHERE vk_id = ? ORDER BY `date` DESC", new Object[]{ socialAuth.getVk_id() }, - new RowMapper() { - @Override - public Long mapRow(ResultSet rs, int numRow) throws SQLException { - return rs.getLong("u_time"); - } - }).stream().findFirst().orElse(0L); + (rs, n) -> rs.getLong("u_time")) + .stream().findFirst().orElse(0L); } else if (socialAuth.getDiscord_id() != 0) { return jdbcTemplate.query("SELECT UNIX_TIMESTAMP(`date`) as u_time FROM free_vip WHERE discord_id = ? ORDER BY `date` DESC", new Object[]{ socialAuth.getDiscord_id() }, - new RowMapper() { - @Override - public Long mapRow(ResultSet rs, int numRow) throws SQLException { - return rs.getLong("u_time"); - } - }).stream().findFirst().orElse(0L); + (rs, n) -> rs.getLong("u_time")) + .stream().findFirst().orElse(0L); } else { return 0L; } diff --git a/src/main/java/app/services/db/KillfeedService.java b/src/main/java/app/services/db/KillfeedService.java index d73b0f9..092d596 100644 --- a/src/main/java/app/services/db/KillfeedService.java +++ b/src/main/java/app/services/db/KillfeedService.java @@ -32,78 +32,47 @@ public class KillfeedService { public Long getKills(SteamID steamID, String server_id) { return jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE `attacker_id` = ? AND `attacker_id` != `victim_id` AND `server_id` like ?", new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?'%':server_id }, - new RowMapper() { - @Override - public Long mapRow(ResultSet rs, int numRow) throws SQLException { - return rs.getLong("c"); - } - }).stream().findFirst().orElse(0L); + (rs, n) -> rs.getLong("c")) + .stream().findFirst().orElse(0L); } public List getTopKills(String server_id) { return jdbcTemplate.query("SELECT `attacker_id`, count(*) as c, `server_id` FROM `user_killfeed` WHERE `victim_id` != `attacker_id` AND `attacker_id` != 0 AND `server_id` LIKE ? GROUP BY `attacker_id` ORDER BY `c` DESC LIMIT 10", new Object[]{server_id == null || server_id.isEmpty() ? '%' : server_id}, - new RowMapper() { - @Override - public TopInFeed mapRow(ResultSet rs, int rowNum) throws SQLException { - return new TopInFeed(rs).setNicknames(nicknameService); - } - }); + (rs, n) -> new TopInFeed(rs).setNicknames(nicknameService)); } public Long getDeads(SteamID steamID, String server_id) { return jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE `victim_id` = ? AND `attacker_id` != `victim_id` AND `server_id` like ?", new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?'%':server_id }, - new RowMapper() { - @Override - public Long mapRow(ResultSet rs, int numRow) throws SQLException { - return rs.getLong("rs"); - } - }).stream().findFirst().orElse(0L); + (rs, n) -> rs.getLong("c")) + .stream().findFirst().orElse(0L); } public List getTopDeads(String server_id) { return jdbcTemplate.query("SELECT `victim_id`, count(`id`) as c, `server_id` FROM `user_killfeed` WHERE `victim_id` != `attacker_id` AND `victim_id` != 0 AND `server_id` LIKE ? GROUP BY `victim_id` ORDER BY `c` DESC LIMIT 10", new Object[]{ server_id == null || server_id.isEmpty() ? '%' : server_id}, - new RowMapper() { - @Override - public TopInFeed mapRow(ResultSet rs, int rowNum) throws SQLException { - return new TopInFeed(rs).setNicknames(nicknameService); - } - }); + (rs, n) -> new TopInFeed(rs).setNicknames(nicknameService)); } public Long getSuicides(SteamID steamID, String server_id) { return jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE `victim_id` = ? AND `attacker_id` = `victim_id` AND `server_id` like ?", new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?'%':server_id }, - new RowMapper() { - @Override - public Long mapRow(ResultSet rs, int rowNum) throws SQLException { - return rs.getLong("c"); - } - }).stream().findFirst().orElse(0L); + (rs, n) -> rs.getLong("c")) + .stream().findFirst().orElse(0L); } public Long getAssists(SteamID steamID, String server_id) { return jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE `assister_id` = ? AND `server_id` like ?", new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?'%':server_id}, - new RowMapper() { - @Override - public Long mapRow(ResultSet rs, int rowNum) throws SQLException { - return rs.getLong("c"); - } - }).stream().findFirst().orElse(0L); + (rs, n) -> rs.getLong("c")) + .stream().findFirst().orElse(0L); } public Map getPopulateWeapons(SteamID steamID, String server_id, int offset, int limit) { List result = jdbcTemplate.query("SELECT COUNT(u.`weapon_index`) as c, i.`name`, u.`server_id`, u.`weapon_classname` FROM `user_killfeed` as u INNER JOIN `tf2idb`.`tf2idb_item` as i ON u.`weapon_index` = i.`id` WHERE u.`attacker_id` = ? AND `attacker_id` != `victim_id` AND u.server_id like ? GROUP BY u.`weapon_index` DESC ORDER BY `c` DESC LIMIT ? OFFSET ?", new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?'%':server_id, limit, offset }, - new RowMapper() { - @Override - public HypeWeapons mapRow(ResultSet rs, int rowNum) throws SQLException { - return new HypeWeapons(rs); - } - }); + (rs, n) -> new HypeWeapons(rs)); /*Long count = (Long) createNativeQuery("SELECT COUNT(`weapon_index`) FROM `user_killfeed` WHERE `attacker_id` = ? AND server_id like ? GROUP BY `weapon_index`") .setParameter(1, steamID.account_id) @@ -115,21 +84,12 @@ public class KillfeedService { public Map getKills(SteamID steamID, String server_id, int offset, int limit) { List result = jdbcTemplate.query("SELECT -1, u.victim_id, u.assister_id, u.utime, i.name, u.server_id, u.weapon_classname FROM `user_killfeed` as u INNER JOIN `tf2idb`.`tf2idb_item` as i ON u.`weapon_index` = i.`id` WHERE u.`attacker_id` = ? AND u.`attacker_id` != u.`victim_id` AND u.`server_id` like ? ORDER BY u.`id` DESC LIMIT ? OFFSET ?", new Object[]{steamID.account_id, server_id == null || server_id.isEmpty() ? '%' : server_id, limit, offset}, - new RowMapper() { - @Override - public KillsInFeed mapRow(ResultSet rs, int rowNum) throws SQLException { - return new KillsInFeed(rs).setNicknames(nicknameService); - } - }); + (rs, n) -> new KillsInFeed(rs).setNicknames(nicknameService)); Long count = jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE `attacker_id` = ? AND `attacker_id` != `victim_id` AND `server_id` like ?", new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?'%':server_id }, - new RowMapper() { - @Override - public Long mapRow(ResultSet rs, int rowNum) throws SQLException { - return rs.getLong("c"); - } - }).stream().findFirst().orElse(0L); + (rs, n) -> rs.getLong("c")) + .stream().findFirst().orElse(0L); return Map.of("result", result, "count", count, "type", FeedType.KILL.ordinal()); } @@ -137,21 +97,11 @@ public class KillfeedService { public Map getDeads(SteamID steamID, String server_id, int offset, int limit) { List result = jdbcTemplate.query("SELECT u.attacker_id, -1, u.assister_id, u.utime, i.name, u.server_id, u.weapon_classname FROM `user_killfeed` as u INNER JOIN `tf2idb`.`tf2idb_item` as i ON u.`weapon_index` = i.`id` WHERE u.`victim_id` = ? AND u.`attacker_id` != u.`victim_id` AND u.`server_id` like ? ORDER BY u.`id` DESC LIMIT ? OFFSET ?", new Object[]{steamID.account_id, server_id == null || server_id.isEmpty() ? '%' : server_id, limit, offset}, - new RowMapper() { - @Override - public KillsInFeed mapRow(ResultSet rs, int rowNum) throws SQLException { - return new KillsInFeed(rs).setNicknames(nicknameService); - } - }); + (rs, n) -> new KillsInFeed(rs).setNicknames(nicknameService)); Long count = jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE `victim_id` = ? AND `attacker_id` != `victim_id` AND `server_id` like ?", new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?'%':server_id }, - new RowMapper() { - @Override - public Long mapRow(ResultSet rs, int numRow) throws SQLException { - return rs.getLong("c"); - } - }).stream().findFirst().orElse(0L); + (rs, n) -> rs.getLong("c")).stream().findFirst().orElse(0L); return Map.of("result", result, "count", count, "type", FeedType.DEAD.ordinal()); } @@ -159,21 +109,12 @@ public class KillfeedService { public Map getAssists(SteamID steamID, String server_id, int offset, int limit) { List result = jdbcTemplate.query("SELECT u.attacker_id, u.victim_id, -1, u.utime, i.name, u.server_id, u.weapon_classname FROM `user_killfeed` as u INNER JOIN `tf2idb`.`tf2idb_item` as i ON u.`weapon_index` = i.`id` WHERE u.`assister_id` = ? AND u.`server_id` like ? ORDER BY u.`id` DESC LIMIT ? OFFSET ?", new Object[]{steamID.account_id, server_id == null || server_id.isEmpty() ? '%' : server_id, limit, offset}, - new RowMapper() { - @Override - public KillsInFeed mapRow(ResultSet rs, int rowNum) throws SQLException { - return new KillsInFeed(rs).setNicknames(nicknameService); - } - }); + (rs, n) -> new KillsInFeed(rs).setNicknames(nicknameService)); Long count = jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE `assister_id` = ? AND `server_id` like ?", new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?'%':server_id }, - new RowMapper() { - @Override - public Long mapRow(ResultSet rs, int rowNum) throws SQLException { - return rs.getLong("c"); - } - }).stream().findFirst().orElse(0L); + (rs, n) -> rs.getLong("c")) + .stream().findFirst().orElse(0L); return Map.of("result", result, "count", count, "type", FeedType.ASSIST.ordinal()); } diff --git a/src/main/java/app/services/db/MessageService.java b/src/main/java/app/services/db/MessageService.java index 565c932..aa54671 100644 --- a/src/main/java/app/services/db/MessageService.java +++ b/src/main/java/app/services/db/MessageService.java @@ -33,21 +33,12 @@ public class MessageService { public Map getAllMessages(String server_id, String filter, int offset, int limit) { List result = jdbcTemplate.query("SELECT `account_id`,`utime`,`message`,`server_id` FROM `user_messages` WHERE `server_id` like ? AND `message` LIKE ? ORDER BY `user_messages`.`id` DESC LIMIT ? OFFSET ?", new Object[]{ server_id == null || server_id.isEmpty() ? "%" : server_id, filter == null || filter.isEmpty() ? "%" : "%" + filter + "%", limit, offset}, - new RowMapper() { - @Override - public Message mapRow(ResultSet rs, int rowNum) throws SQLException { - return new Message(rs).setAccount_name(nicknameService); - } - }); + (rs, n) -> new Message(rs)); Long count = jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_messages` WHERE `server_id` like ? AND `message` LIKE ?", new Object[]{ server_id==null||server_id.isEmpty()?"%":server_id, filter==null||filter.isEmpty()?"%":"%" + filter + "%" }, - new RowMapper() { - @Override - public Long mapRow(ResultSet rs, int rowNum) throws SQLException { - return rs.getLong("c"); - } - }).stream().findFirst().orElse(0L); + (rs, n) -> rs.getLong("c")) + .stream().findFirst().orElse(0L); return Map.of("result", result, "count", count); } @@ -55,21 +46,12 @@ public class MessageService { public Map getAccountMessages(SteamID steamID, String server_id, String filter, int offset, int limit) { List result = jdbcTemplate.query("SELECT `account_id`,`utime`,`message`,`server_id` FROM `user_messages` WHERE `account_id` = ? AND `server_id` like ? AND `message` LIKE ? ORDER BY `user_messages`.`id` DESC LIMIT ? OFFSET ?", new Object[]{steamID.account_id, server_id == null || server_id.isEmpty() ? "%" : server_id, filter == null || filter.isEmpty() ? "%" : "%" + filter + "%", limit, offset}, - new RowMapper() { - @Override - public Message mapRow(ResultSet rs, int rowNum) throws SQLException { - return new Message(rs); - } - }); + (rs, n) -> new Message(rs)); Long count = jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_messages` WHERE `account_id` = ? AND `server_id` like ? AND `message` LIKE ?", new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id, filter==null||filter.isEmpty()?"%":"%" + filter + "%"}, - new RowMapper() { - @Override - public Long mapRow(ResultSet rs, int rowNum) throws SQLException { - return rs.getLong("c"); - } - }).stream().findFirst().orElse(0L); + (rs, n) -> rs.getLong("c")) + .stream().findFirst().orElse(0L); return Map.of("result", result, "count", count); } @@ -77,12 +59,8 @@ public class MessageService { public Long getMessageCount(SteamID steamID, String server_id) { return jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_messages` WHERE `account_id` = ? AND `server_id` like ?", new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id }, - new RowMapper() { - @Override - public Long mapRow(ResultSet rs, int rowNum) throws SQLException { - return rs.getLong("c"); - } - }).stream().findFirst().orElse(0L); + (rs, n) -> rs.getLong("c")) + .stream().findFirst().orElse(0L); } /* diff --git a/src/main/java/app/services/db/NicknameService.java b/src/main/java/app/services/db/NicknameService.java index 90acfc1..20e093f 100644 --- a/src/main/java/app/services/db/NicknameService.java +++ b/src/main/java/app/services/db/NicknameService.java @@ -46,11 +46,7 @@ public class NicknameService { private String grabNicknameFromDb(int account_id, String db) { return jdbcTemplate.query("SELECT `player_name` FROM `"+db+"`.`user_connections` WHERE `account_id` = ? ORDER BY `user_connections`.`id` DESC LIMIT 1;", new Object[]{ account_id }, - new RowMapper() { - @Override - public String mapRow(ResultSet rs, int num) throws SQLException { - return rs.getString("player_name"); - } - }).stream().findFirst().orElse("Unknown"); + (rs, n) -> rs.getString("player_name")) + .stream().findFirst().orElse("Unknown"); } } diff --git a/src/main/java/app/services/db/PermitionService.java b/src/main/java/app/services/db/PermitionService.java index 15c6f28..bbe4b0e 100644 --- a/src/main/java/app/services/db/PermitionService.java +++ b/src/main/java/app/services/db/PermitionService.java @@ -23,12 +23,8 @@ public class PermitionService { public Permition getPermition(SteamID steamID){ return jdbcTemplate.query("SELECT id, flags, immunity, status, amount, UNIX_TIMESTAMP(`reg_date`) as utime as u_timestamp FROM sm_admins WHERE `identity` LIKE ?", new Object[]{steamID.steam2}, - new RowMapper() { - @Override - public Permition mapRow(ResultSet resultSet, int num) throws SQLException { - return new Permition(resultSet); - } - }).stream().findFirst().orElse(null); + (rs, n) -> new Permition(rs)) + .stream().findFirst().orElse(null); } public boolean CheckMorePowerfull(SteamID user_1, SteamID user_2) { @@ -78,22 +74,12 @@ public class PermitionService { //Так слушай меня ваня, ты ебанько ибо перепутал тут steam2 и steam3, d в бд steam3 хотя по факту там 2 List result = jdbcTemplate.query("SELECT id, vk_id, discord_id, discord_name, steam3, permition FROM bot_admins WHERE steam3 LIKE ?", new Object[]{steamID.steam2}, - new RowMapper() { - @Override - public AdminInfo mapRow(ResultSet resultSet, int num) throws SQLException { - return new AdminInfo(resultSet); - } - }); + (rs, n) -> new AdminInfo(rs)); //fix если модератор снят делаем бан пельменю if(result.isEmpty()) result = jdbcTemplate.query("SELECT id, vk_id, discord_id, discord_name, steam3, permition FROM bot_admins WHERE steam3 LIKE ?", new Object[]{"STEAM_0:0:90763498"}, - new RowMapper() { - @Override - public AdminInfo mapRow(ResultSet resultSet, int num) throws SQLException { - return new AdminInfo(resultSet); - } - }); + (rs, n) -> new AdminInfo(rs)); return result.stream().findFirst().orElse(null); } diff --git a/src/main/java/app/services/db/UsertimeService.java b/src/main/java/app/services/db/UsertimeService.java index 3e2f375..04cd557 100644 --- a/src/main/java/app/services/db/UsertimeService.java +++ b/src/main/java/app/services/db/UsertimeService.java @@ -88,44 +88,26 @@ public class UsertimeService { public Timestamp getLastplay(String db, SteamID steamID, String map) { return jdbcTemplate.query("select timestamp from `"+db+"`.`user_connections` WHERE map LIKE ? and connection_type LIKE ? AND account_id = ? ORDER BY `user_connections`.`id` DESC LIMIT 1", new Object[]{ map, "disconnect", steamID.account_id}, - new RowMapper() { - @Override - public Timestamp mapRow(ResultSet rs, int rowNum) throws SQLException { - return rs.getTimestamp("timestamp"); - } - }).stream().findFirst().orElse(null); + (rs, n) -> rs.getTimestamp("timestamp")) + .stream().findFirst().orElse(null); } public BigDecimal getTotalPlaytime(String db, SteamID steamID, String map) { return jdbcTemplate.query("select sum(connect_duration) as total from `"+db+"`.`user_connections` WHERE map LIKE ? and connection_type LIKE ? AND account_id = ?", new Object[]{ map, "disconnect", steamID.account_id }, - new RowMapper(){ - @Override - public BigDecimal mapRow(ResultSet rs, int rowNum) throws SQLException { - return rs.getBigDecimal("total"); - } - }).stream().findFirst().orElse(null); + (rs, n) -> rs.getBigDecimal("total")) + .stream().findFirst().orElse(null); } public List getMap(String db, int limit) { return jdbcTemplate.query("select distinct `map` from `"+db+"`.`user_connections` WHERE 1 ORDER BY `user_connections`.`id` DESC LIMIT ?", new Object[]{ limit }, - new RowMapper() { - @Override - public String mapRow(ResultSet rs, int rowNum) throws SQLException { - return rs.getString("map"); - } - }); + (rs, n) -> rs.getString("map")); } public List getMaps(String db) { return jdbcTemplate.query("select distinct `map` from `"+db+"`.`user_connections`", - new RowMapper() { - @Override - public String mapRow(ResultSet rs, int rowNum) throws SQLException { - return rs.getString("map"); - } - }); + (rs, n) -> rs.getString("map")); } public SteamID getSteamOnUsername(String username) { @@ -133,12 +115,8 @@ public class UsertimeService { for (Map.Entry stringServerEntry : stats.getServers().entrySet()) { steamID = jdbcTemplate.query("SELECT account_id FROM `"+stringServerEntry.getValue().getDb()+"`.`user_connections` WHERE player_name LIKE ? ORDER BY `id` DESC LIMIT 1", new Object[]{ username }, - new RowMapper() { - @Override - public SteamID mapRow(ResultSet rs, int rowNum) throws SQLException { - return SteamIDConverter.getSteamID("[U:1:%d]".formatted(rs.getInt("account_id"))); - } - }).stream().findFirst().orElse(null); + (rs, n) -> SteamIDConverter.getSteamID("[U:1:%d]".formatted(rs.getInt("account_id")))) + .stream().findFirst().orElse(null); if (steamID != null) return steamID; } return null; @@ -150,12 +128,7 @@ public class UsertimeService { return jdbcTemplate.query("SELECT * FROM `" + db + "`.`user_connections` WHERE account_id = ? AND connection_type LIKE ? ORDER BY `" + db + "`.`user_connections`.`id` DESC LIMIT ? OFFSET ?", new Object[]{steamID.account_id, "disconnect", limit, offset}, - new RowMapper() { - @Override - public Gametime mapRow(ResultSet rs, int rowNum) throws SQLException { - return new Gametime(rs); - } - }); + (rs, n) -> new Gametime(rs)); } public Long getTotalGametimeOnServer(SteamID steamID, String server) { @@ -163,11 +136,7 @@ public class UsertimeService { if (db == null) return 0L; return jdbcTemplate.query("SELECT count(id) as c FROM `"+db+"`.`user_connections` WHERE account_id = ? AND connection_type LIKE ?", new Object[]{ steamID.account_id, "disconnect" }, - new RowMapper() { - @Override - public Long mapRow(ResultSet rs, int rowNum) throws SQLException { - return rs.getLong("с"); - } - }).stream().findFirst().orElse(0L); + (rs, n) -> rs.getLong("с")) + .stream().findFirst().orElse(0L); } } diff --git a/src/main/java/app/services/db/VIPService.java b/src/main/java/app/services/db/VIPService.java index ee9162c..fcf59e9 100644 --- a/src/main/java/app/services/db/VIPService.java +++ b/src/main/java/app/services/db/VIPService.java @@ -49,36 +49,21 @@ public class VIPService { public List getUsersDiscordWithActiveVIP() { return jdbcTemplate.query("SELECT `discord_id` FROM `sm_admins` INNER JOIN `steam2discord` ON `sm_admins`.`status` LIKE ? AND (`sm_admins`.`comment` LIKE ? OR `sm_admins`.`comment` LIKE ?) AND `sm_admins`.`identity` = `steam2discord`.`steam_id`", new Object[]{"VIP", "Donate.User", "f13bot.User"}, - new RowMapper() { - @Override - public Long mapRow(ResultSet rs, int rowNum) throws SQLException { - return rs.getLong("discord_id"); - } - }); + (rs, n) -> rs.getLong("discord_id")); } // Список ид из дискорда кто имеет бесплатную випку public List getUsersDiscordWithActiveFreeVIP() { return jdbcTemplate.query("SELECT `discord_id` FROM `sm_admins` INNER JOIN `steam2discord` ON `sm_admins`.`status` LIKE ? AND `sm_admins`.`comment` LIKE ? AND `sm_admins`.`identity` = `steam2discord`.`steam_id`", new Object[]{"VIP", "f13bot.FreeVIP"}, - new RowMapper() { - @Override - public Long mapRow(ResultSet rs, int rowNum) throws SQLException { - return rs.getLong("discord_id"); - } - }); + (rs, n) -> rs.getLong("discord_id")); } // Транзакция, проверка и удаление випок подшедших к концу public int removeEndedVIPs() { List steamid2remove = jdbcTemplate.query("SELECT `identity` FROM `sm_admins` WHERE NOT UNIX_TIMESTAMP(`reg_date`) LIKE 0 AND `amount` NOT LIKE 0 AND `status` LIKE ? AND ((unix_timestamp(now()) - UNIX_TIMESTAMP(`reg_date`)) > `amount`)", new Object[]{"VIP"}, - new RowMapper() { - @Override - public SteamID mapRow(ResultSet rs, int rowNum) throws SQLException { - return SteamIDConverter.getSteamID(rs.getString("identity")); - } - }); + (rs, n) -> SteamIDConverter.getSteamID(rs.getString("identity"))); int removed_vips = jdbcTemplate.update("DELETE FROM `sm_admins` WHERE NOT UNIX_TIMESTAMP(`reg_date`) LIKE 0 AND `amount` NOT LIKE 0 AND `status` LIKE ? AND ((unix_timestamp(now()) - UNIX_TIMESTAMP(`reg_date`)) > `amount`)", "VIP"); diff --git a/src/main/java/app/updates/BanCountUpdater.java b/src/main/java/app/updates/BanCountUpdater.java index 28aa569..db4586f 100644 --- a/src/main/java/app/updates/BanCountUpdater.java +++ b/src/main/java/app/updates/BanCountUpdater.java @@ -41,12 +41,7 @@ public class BanCountUpdater extends BaseUpdater{ public boolean UpdateBanCount(){ logger.info("Update current ban count"); - long ban_count = jdbcTemplate.query("SELECT COUNT(*) as count FROM `light_bans` WHERE active = 1", new RowMapper() { - @Override - public Long mapRow(ResultSet rs, int numRow) throws SQLException { - return rs.getLong("count"); - } - }).stream().findFirst().orElse(0L); + long ban_count = jdbcTemplate.query("SELECT COUNT(*) as count FROM `light_bans` WHERE active = 1", (rs, n) -> rs.getLong("count")).stream().findFirst().orElse(0L); stats.setBan_count(ban_count); stats.getUpdates().merge("ban_count", Instant.now().getEpochSecond(), (x, y) -> y); return true; diff --git a/src/main/java/app/updates/CountriesUpdater.java b/src/main/java/app/updates/CountriesUpdater.java index 2648444..50a0831 100644 --- a/src/main/java/app/updates/CountriesUpdater.java +++ b/src/main/java/app/updates/CountriesUpdater.java @@ -61,12 +61,7 @@ public class CountriesUpdater extends BaseUpdater{ query += countries_in_current_year.formatted(stringServerEntry.getValue().getDb()); } query = query.substring(0, query.length()-7) + ";"; - jdbcTemplate.query(query, new RowMapper() { - @Override - public String mapRow(ResultSet rs, int rowNum) throws SQLException { - return rs.getString("connect_ip"); - } - }).forEach(ip -> { + jdbcTemplate.query(query, (rs, n) -> rs.getString("connect_ip")).forEach(ip -> { try { stats.getCountries().merge(geoIP.GetCountry(ip), 1, (x, y) -> x+y); } catch (UnknownHostException e) { diff --git a/src/main/java/app/updates/UniqueUpdater.java b/src/main/java/app/updates/UniqueUpdater.java index cc7778d..49655ad 100644 --- a/src/main/java/app/updates/UniqueUpdater.java +++ b/src/main/java/app/updates/UniqueUpdater.java @@ -63,12 +63,7 @@ public class UniqueUpdater extends BaseUpdater{ public Long getServerUniqueFromQuery(String query, String db) { query = String.format(query, db); query = "SELECT COUNT(*) as count FROM (" + query.substring(0, query.length()-7) + ") x;"; - return jdbcTemplate.query(query, new RowMapper() { - @Override - public Long mapRow(ResultSet rs, int numRow) throws SQLException { - return rs.getLong("count"); - } - }).stream().findFirst().orElse(0L); + return jdbcTemplate.query(query, (rs, n) -> rs.getLong("count")).stream().findFirst().orElse(0L); } public Long getServerUniqueFromQuery(String query) { @@ -77,12 +72,7 @@ public class UniqueUpdater extends BaseUpdater{ final_query += query.formatted(server.getDb()); } final_query = final_query.substring(0, final_query.length()-7) + ") x;"; - return jdbcTemplate.query(final_query, new RowMapper() { - @Override - public Long mapRow(ResultSet rs, int numRow) throws SQLException { - return rs.getLong("count"); - } - }).stream().findFirst().orElse(0L); + return jdbcTemplate.query(final_query, (rs, n) -> rs.getLong("count")).stream().findFirst().orElse(0L); } /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/main/java/app/updates/VipCountUpdater.java b/src/main/java/app/updates/VipCountUpdater.java index 845207a..2606d00 100644 --- a/src/main/java/app/updates/VipCountUpdater.java +++ b/src/main/java/app/updates/VipCountUpdater.java @@ -56,12 +56,7 @@ public class VipCountUpdater extends BaseUpdater{ public boolean UpdateVIPCount() { logger.info("Update current active VIP profiles"); Long count = jdbcTemplate.query("SELECT COUNT(*) as count FROM `sm_admins` WHERE `status` LIKE 'VIP' AND (`comment` LIKE 'Donate.User' OR `comment` LIKE 'f13bot.User')", - new RowMapper() { - @Override - public Long mapRow(ResultSet rs, int numRow) throws SQLException { - return rs.getLong("count"); - } - }).stream().findFirst().orElse(0L); + (rs, n) -> rs.getLong("count")).stream().findFirst().orElse(0L); stats.setVip_players(count); stats.getUpdates().merge("vip_count", Instant.now().getEpochSecond(), (x, y) -> y); return true; @@ -70,12 +65,7 @@ public class VipCountUpdater extends BaseUpdater{ public boolean UpdateFreeVIPCount() { logger.info("Update current active FreeVIP profiles"); Long count = jdbcTemplate.query("SELECT COUNT(*) as count FROM `sm_admins` WHERE `status` LIKE 'VIP' AND `comment` LIKE 'f13bot.FreeVIP'", - new RowMapper() { - @Override - public Long mapRow(ResultSet rs, int numRow) throws SQLException { - return rs.getLong("count"); - } - }).stream().findFirst().orElse(0L); + (rs, n) -> rs.getLong("count")).stream().findFirst().orElse(0L); stats.setFreevip_players(count); stats.getUpdates().merge("freevip_count", Instant.now().getEpochSecond(), (x, y) -> y); return true;