|
|
@ -3,6 +3,7 @@ package app.services.db; |
|
|
import app.entities.SearchFilter; |
|
|
import app.entities.SearchFilter; |
|
|
import app.entities.db.period.PerPeriodStatistic; |
|
|
import app.entities.db.period.PerPeriodStatistic; |
|
|
import app.services.ProfileService; |
|
|
import app.services.ProfileService; |
|
|
|
|
|
import app.services.io.readers.GeoIP; |
|
|
import com.fasterxml.jackson.annotation.JsonIgnore; |
|
|
import com.fasterxml.jackson.annotation.JsonIgnore; |
|
|
import lombok.Data; |
|
|
import lombok.Data; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.Logger; |
|
|
@ -17,6 +18,7 @@ import org.springframework.scheduling.annotation.Scheduled; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
@Service |
|
|
@Service |
|
|
public class GraphService { |
|
|
public class GraphService { |
|
|
@ -26,6 +28,9 @@ public class GraphService { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private NamedParameterJdbcTemplate namedParameterJdbcTemplate; |
|
|
private NamedParameterJdbcTemplate namedParameterJdbcTemplate; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private GeoIP geoIP; |
|
|
|
|
|
|
|
|
private final static Logger logger = LoggerFactory.getLogger(GraphService.class); |
|
|
private final static Logger logger = LoggerFactory.getLogger(GraphService.class); |
|
|
|
|
|
|
|
|
@Scheduled(cron = "@hourly") |
|
|
@Scheduled(cron = "@hourly") |
|
|
@ -95,6 +100,33 @@ public class GraphService { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Data |
|
|
|
|
|
public static class CountryCityPerPeriodStatistic extends PerPeriodStatistic { |
|
|
|
|
|
private String connect_ip; |
|
|
|
|
|
private String countryAndCity; |
|
|
|
|
|
|
|
|
|
|
|
@JsonIgnore |
|
|
|
|
|
@Override |
|
|
|
|
|
public String getSrv_id() { |
|
|
|
|
|
return super.getSrv_id(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@JsonIgnore |
|
|
|
|
|
@Override |
|
|
|
|
|
public Long getValue() { |
|
|
|
|
|
return super.getValue(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@JsonIgnore |
|
|
|
|
|
public String getConnect_ip() { |
|
|
|
|
|
return connect_ip; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void fillCountryAndCity(GeoIP geoIP) { |
|
|
|
|
|
this.countryAndCity = geoIP.GetCountry(connect_ip) + "/" + geoIP.GetCity(countryAndCity); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Cacheable(value = "graphs.vip", key = "#searchFilter.cacheKey") |
|
|
@Cacheable(value = "graphs.vip", key = "#searchFilter.cacheKey") |
|
|
public List<VipPerPeriodStatistic> getVipOnPeriod(SearchFilter searchFilter) { |
|
|
public List<VipPerPeriodStatistic> getVipOnPeriod(SearchFilter searchFilter) { |
|
|
final String sql = "select date_trunc(:delta, timestamp) AS ts, :delta as period, count(*) as value, givemethod, amount from gived_vip " + |
|
|
final String sql = "select date_trunc(:delta, timestamp) AS ts, :delta as period, count(*) as value, givemethod, amount from gived_vip " + |
|
|
@ -111,4 +143,27 @@ public class GraphService { |
|
|
|
|
|
|
|
|
return namedParameterJdbcTemplate.query(sql, map, new BeanPropertyRowMapper(VipPerPeriodStatistic.class)); |
|
|
return namedParameterJdbcTemplate.query(sql, map, new BeanPropertyRowMapper(VipPerPeriodStatistic.class)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public List<CountryCityPerPeriodStatistic> getDoxingOnPeriod(SearchFilter searchFilter) { |
|
|
|
|
|
final String sql = "\n" + |
|
|
|
|
|
"select date_trunc(:delta, timestamp) AS ts, :delta as period, connect_ip from user_connections " + |
|
|
|
|
|
"where timestamp between :begindate and :enddate " + |
|
|
|
|
|
//" and migration_id is null " +
|
|
|
|
|
|
" and connect_duration = 0 " + |
|
|
|
|
|
" and account_id in (:account_ids) " + |
|
|
|
|
|
"group by ts, connect_ip"; |
|
|
|
|
|
|
|
|
|
|
|
MapSqlParameterSource map = new MapSqlParameterSource(); |
|
|
|
|
|
map.addValue("delta", searchFilter.getMaybePeriod()); |
|
|
|
|
|
String profiles = searchFilter.getAccountsSteam2(profileService); |
|
|
|
|
|
//map.addValue("account_ids_empty", profiles.isEmpty());
|
|
|
|
|
|
map.addValue("account_ids", profiles.isEmpty() ? "0" : profiles); |
|
|
|
|
|
map.addValue("begindate", searchFilter.getBeginTime()); |
|
|
|
|
|
map.addValue("enddate", searchFilter.getEndTime()); |
|
|
|
|
|
|
|
|
|
|
|
return namedParameterJdbcTemplate.query(sql, map, new BeanPropertyRowMapper<>(CountryCityPerPeriodStatistic.class)) |
|
|
|
|
|
.stream() |
|
|
|
|
|
.peek(d -> d.fillCountryAndCity(geoIP)) |
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|