Browse Source

jdbc migrate clean up fix

master
gsd 1 year ago
parent
commit
148674065b
  1. 44
      src/main/java/app/services/ProfileService.java
  2. 28
      src/main/java/app/services/db/KillfeedService.java
  3. 7
      src/main/java/app/services/db/UsertimeService.java

44
src/main/java/app/services/ProfileService.java

@ -80,96 +80,133 @@ public class ProfileService {
callables.add(() -> {
try {
long start_time = Instant.now().toEpochMilli();
profile.setPlay_on(statsService.searchPlayer(steamID));
long end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("play_on", (double) end_time / 1000);
} catch (Exception err) {
err.printStackTrace();
}
return null;
});
if(requests.contains("steam_data")){
callables.add(() -> {
try {
long start_time = Instant.now().toEpochMilli();
profile.setSteam_data(steamWebApi.getSteamData(steamID.steam64));
long end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("steam_data", (double) end_time / 1000);
} catch (Exception err) {
err.printStackTrace();
}
return null;
});
}
if(requests.contains("lastplay")){
callables.add(() -> {
try {
long start_time = Instant.now().toEpochMilli();
profile.setLastplay(usertimeService.getPlayerLastplay(steamID));
long end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("lastplay", (double) end_time / 1000);
} catch (Exception err) {
err.printStackTrace();
}
return null;
});
}
if(requests.contains("usertime")){
callables.add(() -> {
try {
long start_time = Instant.now().toEpochMilli();
profile.setGametime(usertimeService.getPlayerUsertime(steamID));
long end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("usertime", (double) end_time / 1000);
} catch (Exception err) {
err.printStackTrace();
}
return null;
});
}
//if(requests.contains("permition")){
callables.add(() -> {
try {
long start_time = Instant.now().toEpochMilli();
profile.setPermition(permitionService.getPermition(steamID));
long end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("permition", (double) end_time / 1000);
} catch (Exception err) {
err.printStackTrace();
}
return null;
});
//}
//if(requests.contains("ban")){
callables.add(() -> {
try {
long start_time = Instant.now().toEpochMilli();
profile.setBan(banService.getBan(steamID));
long end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("ban", (double) end_time / 1000);
} catch (Exception err) {
err.printStackTrace();
}
return null;
});
//}
if(requests.contains("attached_discord")){
callables.add(() -> {
try {
long start_time = Instant.now().toEpochMilli();
profile.setAttached_discords(detectService.getAttachedDiscordAccountPerSteam(steamID));
long end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("attached_discord", (double) end_time / 1000);
} catch (Exception err) {
err.printStackTrace();
}
return null;
});
}
if(requests.contains("donates")){
callables.add(() -> {
try {
long start_time = Instant.now().toEpochMilli();
profile.setDonates(donateService.getDonateStatistic(steamID));
long end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("donates", (double) end_time / 1000);
} catch (Exception err) {
err.printStackTrace();
}
return null;
});
}
if(requests.contains("ban_list")){
callables.add(() -> {
try {
long start_time = Instant.now().toEpochMilli();
profile.setBan_list(banService.getBans(steamID));
long end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("ban_list", (double) end_time / 1000);
} catch (Exception err) {
err.printStackTrace();
}
return null;
});
}
//if(requests.contains("killfeed")){
callables.add(() -> {
try {
long start_time = Instant.now().toEpochMilli();
profile.setKillfeed((new Killfeed())
.setKills(killfeedService.getKills(steamID, null))
@ -178,16 +215,23 @@ public class ProfileService {
.setSuicides(killfeedService.getSuicides(steamID, null)));
long end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("killfeed", (double) end_time / 1000);
} catch (Exception err) {
err.printStackTrace();
}
return null;
});
//}
//if(requests.contains("messages")){
callables.add(() -> {
try {
long start_time = Instant.now().toEpochMilli();
profile.setMessages(messageService.getMessageCount(steamID, null));
long end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("messages", (double) end_time / 1000);
} catch (Exception err) {
err.printStackTrace();
}
return null;
});
//}

28
src/main/java/app/services/db/KillfeedService.java

@ -31,63 +31,63 @@ 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 Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id },
(rs, n) -> rs.getLong("c"))
.stream().findFirst().orElse(0L);
}
public List<TopInFeed> 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 Object[]{server_id == null || server_id.isEmpty() ? "%" : server_id},
(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 Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id },
(rs, n) -> rs.getLong("c"))
.stream().findFirst().orElse(0L);
}
public List<TopInFeed> 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 Object[]{ server_id == null || server_id.isEmpty() ? "%" : server_id},
(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 Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id },
(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 Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id},
(rs, n) -> rs.getLong("c"))
.stream().findFirst().orElse(0L);
}
public Map getPopulateWeapons(SteamID steamID, String server_id, int offset, int limit) {
List<HypeWeapons> 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 Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id, limit, offset },
(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)
.setParameter(2, server_id==null||server_id.isEmpty()?'%':server_id)
.setParameter(2, server_id==null||server_id.isEmpty()?"%":server_id)
.getSingleResult();*/
return Map.of("result", result, "count", -1);
}
public Map getKills(SteamID steamID, String server_id, int offset, int limit) {
List<KillsInFeed> 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 Object[]{steamID.account_id, server_id == null || server_id.isEmpty() ? "%" : server_id, limit, offset},
(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 Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id },
(rs, n) -> rs.getLong("c"))
.stream().findFirst().orElse(0L);
@ -96,11 +96,11 @@ public class KillfeedService {
public Map getDeads(SteamID steamID, String server_id, int offset, int limit) {
List<KillsInFeed> 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 Object[]{steamID.account_id, server_id == null || server_id.isEmpty() ? "%" : server_id, limit, offset},
(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 Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id },
(rs, n) -> rs.getLong("c")).stream().findFirst().orElse(0L);
return Map.of("result", result, "count", count, "type", FeedType.DEAD.ordinal());
@ -108,11 +108,11 @@ public class KillfeedService {
public Map getAssists(SteamID steamID, String server_id, int offset, int limit) {
List<KillsInFeed> 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 Object[]{steamID.account_id, server_id == null || server_id.isEmpty() ? "%" : server_id, limit, offset},
(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 Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id },
(rs, n) -> rs.getLong("c"))
.stream().findFirst().orElse(0L);

7
src/main/java/app/services/db/UsertimeService.java

@ -93,10 +93,11 @@ public class UsertimeService {
}
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 = ?",
List<BigDecimal> l = 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 },
(rs, n) -> rs.getBigDecimal("total"))
.stream().findFirst().orElse(null);
(rs, n) -> rs.getBigDecimal("total"));
//optional if has error
return l.size() > 0?l.get(0):null;
}
public List<String> getMap(String db, int limit) {

Loading…
Cancel
Save