Browse Source

donateSearch

master
gsd 3 months ago
parent
commit
0c9d25891d
  1. 29
      src/main/java/app/controllers/user/DetailController.java
  2. 22
      src/main/java/app/entities/SearchFilter.java
  3. 12
      src/main/java/app/entities/db/DonateStat.java
  4. 21
      src/main/java/app/repositories/DonateStatRepository.java
  5. 3
      src/main/java/app/repositories/GametimeRepository.java

29
src/main/java/app/controllers/user/DetailController.java

@ -5,11 +5,17 @@ import app.annotations.interfaces.BurstUpdatePlayers;
import app.annotations.interfaces.CheckWebAccess; import app.annotations.interfaces.CheckWebAccess;
import app.annotations.interfaces.CollectStatistic; import app.annotations.interfaces.CollectStatistic;
import app.annotations.interfaces.WaitAfterNext; import app.annotations.interfaces.WaitAfterNext;
import app.entities.SearchFilter;
import app.entities.db.DonateStat;
import app.entities.other.SteamID; import app.entities.other.SteamID;
import app.repositories.DonateStatRepository;
import app.repositories.GametimeRepository;
import app.services.ProfileService; import app.services.ProfileService;
import app.utils.SteamIDConverter; import app.utils.SteamIDConverter;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -24,6 +30,12 @@ import java.util.HashMap;
public class DetailController { public class DetailController {
private ProfileService profileService; private ProfileService profileService;
@Autowired
private DonateStatRepository donateStatRepository;
@Autowired
private GametimeRepository gametimeRepository;
@Autowired @Autowired
public DetailController(ProfileService profileService) { public DetailController(ProfileService profileService) {
this.profileService = profileService; this.profileService = profileService;
@ -99,4 +111,21 @@ public class DetailController {
put("total", profileService.usertimeService.getTotalGametimeOnServer(steamID, srv)); put("total", profileService.usertimeService.getTotalGametimeOnServer(steamID, srv));
}}, HttpStatus.OK); }}, HttpStatus.OK);
} }
@PostMapping("/donate")
@CheckWebAccess(auth_method = AuthMethod.STEAM64)
@WaitAfterNext(order = "donatelist")
@CollectStatistic
public ResponseEntity<Page<DonateStat>> getDonatePage(Pageable pageable, @RequestBody(required = false) SearchFilter searchFilter) {
String ids = searchFilter.getAccountsSteam2(profileService);
Page<DonateStat> donates = donateStatRepository.getDonate(pageable,
ids.isEmpty(), ids,
searchFilter.getBeginUnixTime(),
searchFilter.getEndUnixTime());
donates.getContent().forEach((donateStat -> {
donateStat.setGametime(gametimeRepository.searchGametimeBySteam2(donateStat.getSteam2()));
}));
return new ResponseEntity<>(donates, HttpStatus.OK);
}
} }

22
src/main/java/app/entities/SearchFilter.java

@ -11,7 +11,7 @@ import java.util.List;
import java.util.Objects; import java.util.Objects;
@Setter @Setter
public abstract class SearchFilter { public class SearchFilter {
private List<String> accounts = null; private List<String> accounts = null;
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private LocalDateTime begin = null; private LocalDateTime begin = null;
@ -20,6 +20,11 @@ public abstract class SearchFilter {
private String serverId = null; private String serverId = null;
private Long utc = 0L; private Long utc = 0L;
/**
* Выдает список из ид 3 версии [U:1:127332962]
* @param profileService
* @return
*/
public List<Long> getAccounts(ProfileService profileService) { public List<Long> getAccounts(ProfileService profileService) {
if (accounts == null || accounts.isEmpty()) return new ArrayList<>(); if (accounts == null || accounts.isEmpty()) return new ArrayList<>();
@ -30,6 +35,21 @@ public abstract class SearchFilter {
.toList(); .toList();
} }
/**
* Выдает список из ид 2 версии STEAM_0:0:63666481
* @param profileService
* @return
*/
public String getAccountsSteam2(ProfileService profileService) {
if (accounts == null || accounts.isEmpty()) return "";
return String.join(",", accounts.stream()
.map(profileService::GetSteamIDFromAnyData)
.filter(Objects::nonNull)
.map(sId -> sId.steam2)
.toList());
}
public Long getBeginUnixTime() { public Long getBeginUnixTime() {
return begin == null ? null : (Timestamp.valueOf(begin).getTime()/1000) + utc*60; return begin == null ? null : (Timestamp.valueOf(begin).getTime()/1000) + utc*60;
} }

12
src/main/java/app/entities/db/DonateStat.java

@ -57,6 +57,10 @@ public class DonateStat {
@Column(name = "timestamp") @Column(name = "timestamp")
Timestamp timestamp; Timestamp timestamp;
@JsonIgnore
@Transient
private Gametime gametime;
public DonateStat(Object[] obj) { public DonateStat(Object[] obj) {
this.id = (int) obj[0]; this.id = (int) obj[0];
this.steam2 = String.valueOf(obj[1]); this.steam2 = String.valueOf(obj[1]);
@ -136,4 +140,12 @@ public class DonateStat {
public String getBeExtended() { public String getBeExtended() {
return extended?"Была продлена":""; return extended?"Была продлена":"";
} }
public String getAccountName() {
return gametime == null ? "" : gametime.getPlayer_name();
}
public Long getAccountId() {
return gametime == null ? null : gametime.getAccount_id();
}
} }

21
src/main/java/app/repositories/DonateStatRepository.java

@ -0,0 +1,21 @@
package app.repositories;
import app.entities.db.DonateStat;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
public interface DonateStatRepository extends PagingAndSortingRepository<DonateStat, Long> {
@Query(value = "select d from DonateStat d where " +
"(:account_ids_non_exists = true or position(d.steam2 in :account_ids) > 0) and " +
"(:begin_date is null or DATE_PART('EPOCH', d.timestamp) >= :begin_date) and " +
"(:end_date is null or :end_date >= DATE_PART('EPOCH', d.timestamp)) order by d.id desc")
Page<DonateStat> getDonate(Pageable pageable,
@Param(value = "account_ids_non_exists") Boolean account_ids_non_exists,
@Param(value = "account_ids") String account_ids,
@Param(value = "begin_date") Long begin_date,
@Param(value = "end_date") Long end_date);
}

3
src/main/java/app/repositories/GametimeRepository.java

@ -15,6 +15,9 @@ public interface GametimeRepository extends PagingAndSortingRepository<Gametime,
@Query(value = "select g from Gametime g where g.account_id = :account_id order by g.id desc limit 1") @Query(value = "select g from Gametime g where g.account_id = :account_id order by g.id desc limit 1")
Gametime searchGametimeByAccountId(@Param("account_id") Long account_id); Gametime searchGametimeByAccountId(@Param("account_id") Long account_id);
@Query(value = "select g from Gametime g where g.steam_id like :steam2 order by g.id desc limit 1")
Gametime searchGametimeBySteam2(@Param("steam2") String steam2);
@Query(value = "select g.steam_id from Gametime g where g.connect_ip in (select gg.connect_ip from Gametime gg where gg.account_id = :account_id and gg.connect_ip not like '10.%' group by gg.connect_ip, gg.id order by gg.id) group by g.steam_id") @Query(value = "select g.steam_id from Gametime g where g.connect_ip in (select gg.connect_ip from Gametime gg where gg.account_id = :account_id and gg.connect_ip not like '10.%' group by gg.connect_ip, gg.id order by gg.id) group by g.steam_id")
List<String> searchAccountsByAccountId(@Param("account_id") Long account_id); List<String> searchAccountsByAccountId(@Param("account_id") Long account_id);
} }

Loading…
Cancel
Save