Browse Source

posgres support 2

master
gsd 6 months ago
parent
commit
36bf0fce3a
  1. 17
      src/main/java/app/entities/DonateStatistic.java
  2. 7
      src/main/java/app/entities/StatisticRange.java
  3. 28
      src/main/java/app/services/db/DonateService.java
  4. 2
      src/main/java/app/updates/CountriesUpdater.java
  5. 8
      src/main/java/app/updates/UniqueUpdater.java

17
src/main/java/app/entities/DonateStatistic.java

@ -22,24 +22,17 @@ public class DonateStatistic {
Long count;
String reserved;
Integer amount;
//sub
public DonateStatistic(Object[] raw) {
giveMethod = VipGiveMethod.values()[(int) raw[0]];
count = ((Long) raw[1]);
reserved = raw[2]==null?"": (String) raw[2];
amount = (int) raw[3];
}
public DonateStatistic(ResultSet rs) throws SQLException {
giveMethod = VipGiveMethod.values()[rs.getInt("givemethod")];
count = rs.getLong("count");
reserved = rs.getString("reserved");
try {
reserved = rs.getString("reserved");
} catch (Exception e) {
reserved = "";
}
amount = rs.getInt("amount");
}
public DonateStatistic(Object o) {
this((Object[]) o);
}
public DonateStatistic() {}
}

7
src/main/java/app/entities/StatisticRange.java

@ -4,11 +4,6 @@ public enum StatisticRange {
DAY, MONTH, YEAR;
public static String cast(StatisticRange statisticRange) {
switch (statisticRange) {
case DAY: return "%Y-%m-%d";
case MONTH: return "%Y-%m-01";
case YEAR: return "%Y-01-01";
default: return "";
}
return statisticRange.name();
}
}

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

@ -39,9 +39,9 @@ public class DonateService {
//KEY, METAL
public Pair<Integer, Integer> getSummarySteamDonateValue(StatisticRange statisticRange) {
return jdbcTemplate.query("SELECT SUM(CAST(REPLACE(REPLACE(substring_index(reserved,';',-2), 'metal=',''), ';','') AS INT)) as r," +
" 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)",
return jdbcTemplate.query("SELECT 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",
new Object[]{VipGiveMethod.STEAM.ordinal(), StatisticRange.cast(statisticRange)},
(rs, n) -> Pair.of(
Optional.of(rs.getInt("k")).orElse(0),
@ -51,29 +51,29 @@ public class DonateService {
}
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)",
return jdbcTemplate.query("SELECT SUM(CAST(REPLACE(REPLACE(split_part(reserved,';',1), 'rub=',''), ';','') as INT)) as k " +
"FROM gived_vip WHERE givemethod = ? AND timestamp > date_trunc(?,now())::DATE",
new Object[]{ VipGiveMethod.QIWI.ordinal(), StatisticRange.cast(statisticRange)},
(rs, n) -> rs.getInt("k")).stream().findFirst().orElse(0);
}
public Integer getSummaryDonationAlertsDonateValue(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)",
return jdbcTemplate.query("SELECT SUM(CAST(REPLACE(REPLACE(split_part(reserved,';',1), 'rub=',''), ';','') as INT)) as k " +
"FROM gived_vip WHERE givemethod = ? AND timestamp > date_trunc(?,now())::DATE",
new Object[]{ VipGiveMethod.DONATIONALERTS.ordinal(), StatisticRange.cast(statisticRange)},
(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)",
return jdbcTemplate.query("SELECT COUNT(*) as count FROM gived_vip WHERE givemethod = ? AND timestamp > date_trunc(?,now())::DATE",
new Object[]{ VipGiveMethod.FREE.ordinal(), StatisticRange.cast(statisticRange) },
(rs, n) -> rs.getLong("count"))
.stream().findFirst().orElse(0L);
}
public HashMap getGivedVipStatistic(StatisticRange statisticRange) {
List<DonateStatistic> donateStatistics = jdbcTemplate.query("SELECT givemethod,COUNT(*) as count,reserved, amount FROM gived_vip WHERE givemethod IN (0,1,2,6) AND timestamp > CAST(DATE_FORMAT(NOW() ,?) as DATE) GROUP BY givemethod, amount",
List<DonateStatistic> donateStatistics = jdbcTemplate.query("SELECT givemethod,COUNT(*) as count, amount FROM gived_vip WHERE givemethod IN (0,1,2,6) AND timestamp > date_trunc(?,now())::DATE GROUP BY givemethod, amount",
new Object[]{StatisticRange.cast(statisticRange)},
(rs, n) -> new DonateStatistic(rs));
@ -136,9 +136,13 @@ public class DonateService {
@PostConstruct
public void UpdateStatistic() {
//stats.getDonate().put("day", getDonateStatistic(StatisticRange.DAY));
//stats.getDonate().put("month", getDonateStatistic(StatisticRange.MONTH));
//stats.getDonate().put("year", getDonateStatistic(StatisticRange.YEAR));
try {
stats.getDonate().put("day", getDonateStatistic(StatisticRange.DAY));
stats.getDonate().put("month", getDonateStatistic(StatisticRange.MONTH));
stats.getDonate().put("year", getDonateStatistic(StatisticRange.YEAR));
} catch (Exception err) {
err.printStackTrace();
}
}
//надо добавить шейхов GROUP BY steam2 ORDER BY r DESC

2
src/main/java/app/updates/CountriesUpdater.java

@ -31,7 +31,7 @@ public class CountriesUpdater extends BaseUpdater{
@Value("${backend.updates.countries}")
private boolean update;
private final String countries_in_current_year = "SELECT DISTINCT connect_ip FROM %s.user_connections WHERE connection_type LIKE 'connect' AND timestamp > CAST(DATE_FORMAT(NOW() ,'%%Y-01-01') as DATE) UNION\n";
private final String countries_in_current_year = "SELECT DISTINCT connect_ip FROM %s.user_connections WHERE connection_type LIKE 'connect' AND timestamp > date_trunc('YEAR',now())::DATE UNION\n";
@Autowired
public CountriesUpdater(Stats stats,

8
src/main/java/app/updates/UniqueUpdater.java

@ -24,10 +24,10 @@ public class UniqueUpdater extends BaseUpdater{
@Qualifier("jt_ro")
private JdbcTemplate jdbcTemplate;
private final String query_total = "SELECT DISTINCT account_id FROM %s.user_connections WHERE connection_type LIKE \"disconnect\" AND connect_duration > 300 UNION\n";
private final String query_day = "SELECT DISTINCT account_id FROM %s.user_connections WHERE connection_type LIKE \"disconnect\" AND connect_duration > 300 AND timestamp > CAST(DATE_FORMAT(NOW() ,'%%Y-%%m-%%d') as DATE) UNION\n";
private final String query_month = "SELECT DISTINCT account_id FROM %s.user_connections WHERE connection_type LIKE \"disconnect\" AND connect_duration > 300 AND timestamp > CAST(DATE_FORMAT(NOW() ,'%%Y-%%m-01') as DATE) UNION\n";
private final String query_year = "SELECT DISTINCT account_id FROM %s.user_connections WHERE connection_type LIKE \"disconnect\" AND connect_duration > 300 AND timestamp > CAST(DATE_FORMAT(NOW() ,'%%Y-01-01') as DATE) UNION\n";
private final String query_total = "SELECT DISTINCT account_id FROM %s.user_connections WHERE connection_type LIKE 'disconnect' AND connect_duration > 300 UNION\n";
private final String query_day = "SELECT DISTINCT account_id FROM %s.user_connections WHERE connection_type LIKE 'disconnect' AND connect_duration > 300 AND timestamp > date_trunc('DAY',now())::DATE UNION\n";
private final String query_month = "SELECT DISTINCT account_id FROM %s.user_connections WHERE connection_type LIKE 'disconnect' AND connect_duration > 300 AND timestamp > date_trunc('MONTH',now())::DATE UNION\n";
private final String query_year = "SELECT DISTINCT account_id FROM %s.user_connections WHERE connection_type LIKE 'disconnect' AND connect_duration > 300 AND timestamp > date_trunc('YEAR',now())::DATE UNION\n";
private final Logger logger = LoggerFactory.getLogger(UniqueUpdater.class);

Loading…
Cancel
Save