Browse Source

donate stats

master
gsd 1 year ago
parent
commit
44cdef579d
  1. 8
      src/main/java/app/controllers/user/DetailController.java
  2. 2
      src/main/java/app/entities/PlayerProfile.java
  3. 13
      src/main/java/app/entities/VipGiveMethod.java
  4. 86
      src/main/java/app/entities/db/DonateStat.java
  5. 15
      src/main/java/app/services/ProfileService.java
  6. 10
      src/main/java/app/services/db/DonateService.java

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

@ -48,6 +48,14 @@ public class DetailController {
return new ResponseEntity<>(profileService.GetSteamIDFromAnyData(any), HttpStatus.OK);
}
@GetMapping("/steam/web")
@CheckWebAccess(auth_method = AuthMethod.STEAM64)
@WaitAfterNext
public ResponseEntity<SteamID> GetSteam4Web(HttpServletRequest request,
@RequestParam String any) {
return new ResponseEntity<>(profileService.GetSteamIDFromAnyData(any), HttpStatus.OK);
}
@PostMapping("/steam")
@CheckWebAccess(auth_method = AuthMethod.SECRET_KEY)
public ResponseEntity<SteamID> GetSteamOnHashMap(HttpServletRequest request,

2
src/main/java/app/entities/PlayerProfile.java

@ -1,6 +1,7 @@
package app.entities;
import app.entities.db.Ban;
import app.entities.db.DonateStat;
import app.entities.db.Permition;
import app.entities.other.SteamID;
import app.entities.server.PlayOn;
@ -22,4 +23,5 @@ public class PlayerProfile {
SteamID steamids;
PlayOn play_on;
List attached_discords;
List<DonateStat> donates;
}

13
src/main/java/app/entities/VipGiveMethod.java

@ -1,5 +1,16 @@
package app.entities;
public enum VipGiveMethod {
FREE, STEAM, QIWI, MANUAL, AFTERTIME
FREE("Бесплатно"),
STEAM("Steam"),
QIWI("Qiwi"),
MANUAL("Админ"),
AFTERTIME("Убрана"),
TOTAL("Итого");
String human_name;
VipGiveMethod(String human_name) {
this.human_name = human_name;
}
}

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

@ -0,0 +1,86 @@
package app.entities.db;
import app.entities.DonateStatistic;
import app.entities.VipGiveMethod;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Data;
import java.util.List;
@Data
public class DonateStat {
@JsonIgnore
int id;
@JsonIgnore
String steam2;
int amount;
@JsonIgnore
VipGiveMethod giveMethod;
@JsonIgnore
String reserved;
@JsonIgnore
boolean extended;
int utime;
public DonateStat(Object[] obj) {
this.id = (int) obj[0];
this.steam2 = String.valueOf(obj[1]);
this.amount = (int) obj[2];
this.giveMethod = (VipGiveMethod) obj[4];
this.reserved = String.valueOf(obj[5]);
this.utime = (int) obj[6];
}
public DonateStat(Integer rubles, Integer keys, Integer refs) {
//потом бля
}
@JsonValue
public Integer getRubles() {
if (this.giveMethod == VipGiveMethod.QIWI) return Integer.valueOf(this.reserved.split(";")[0].split("=")[1]);
return 0;
}
@JsonValue
public Integer getKeys() {
if (this.giveMethod == VipGiveMethod.STEAM) return Integer.valueOf(this.reserved.split(";")[0].split("=")[1]);
return 0;
}
@JsonValue
public Integer getRefs() {
if (this.giveMethod == VipGiveMethod.STEAM) return Integer.valueOf(this.reserved.split(";")[1].split("=")[1]);
return 0;
}
@JsonValue
public String getStatus() {
switch (this.giveMethod) {
case FREE -> {
return "Получен бесплатно";
}
case QIWI -> {
return "Оплачено Qiwi: " + getRubles().toString() + " рублей";
}
case STEAM -> {
return "Оплачено инвентарём: "
+ (getKeys() > 0?getKeys().toString() + " ключ":"")
+ (getRefs() > 0?getRefs().toString() + " рефов":"");
}
case MANUAL -> {
return "Выдана админом";
}
case AFTERTIME -> {
return "Снята";
}
}
return "Неизвестно";
}
@JsonValue
public String getHasExtended() {
return extended?"Была продлена":"";
}
}

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

@ -24,6 +24,8 @@ public class ProfileService {
BanService banService;
DiscordAuthService discordAuthService;
DetectService detectService;
DonateService donateService;
@Autowired
public ProfileService(SteamWebApi steamWebApi,
UsertimeService usertimeService,
@ -31,7 +33,8 @@ public class ProfileService {
StatsService statsService,
BanService banService,
DiscordAuthService discordAuthService,
DetectService detectService) {
DetectService detectService,
DonateService donateService) {
this.steamWebApi = steamWebApi;
this.usertimeService = usertimeService;
this.permitionService = permitionService;
@ -39,6 +42,7 @@ public class ProfileService {
this.banService = banService;
this.discordAuthService = discordAuthService;
this.detectService = detectService;
this.donateService = donateService;
}
public PlayerProfile GetProfile(SteamID steamID, List<String> requests) {
@ -110,11 +114,18 @@ public class ProfileService {
profile.getResponse_time().put("attached_discord", Double.valueOf(end_time) / 1000);
}
if(requests.contains("donates")){
start_time = Instant.now().toEpochMilli();
profile.setDonates(donateService.getDonateStatistic(steamID));
end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("donates", Double.valueOf(end_time) / 1000);
}
return profile;
}
public PlayerProfile GetProfile(String steam64) {
return GetProfile(steam64, List.of("steam_data,lastplay,usertime,permition,ban,attached_discord".split(",")));
return GetProfile(steam64, List.of("steam_data,lastplay,usertime,permition,ban,attached_discord,donates".split(",")));
}
public PlayerProfile GetProfile(String steam64, String requests) {

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

@ -4,6 +4,8 @@ import app.entities.DonateStatistic;
import app.entities.StatisticRange;
import app.entities.Stats;
import app.entities.VipGiveMethod;
import app.entities.db.DonateStat;
import app.entities.other.SteamID;
import jakarta.annotation.PostConstruct;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
@ -103,6 +105,12 @@ public class DonateService {
return map;
}
public List<DonateStat> getDonateStatistic(SteamID steamID) {
return entityManager.createNativeQuery("SELECT *, UNIX_TIMESTAMP(`timestamp`) as utime FROM `gived_vip` WHERE `steam2` LIKE ?1")
.setParameter(1, steamID.steam2)
.getResultStream().map(obj -> new DonateStat((Object[]) obj)).toList();
}
public HashMap getDonateStatistic(StatisticRange statisticRange) {
Pair<Integer, Integer> summary_steam = getSummarySteamDonateValue(statisticRange);
Integer summary_qiwi = getSummaryQiwiDonateValue(statisticRange);
@ -123,4 +131,6 @@ public class DonateService {
stats.getDonate().put("month", getDonateStatistic(StatisticRange.MONTH));
stats.getDonate().put("year", getDonateStatistic(StatisticRange.YEAR));
}
//надо добавить шейхов GROUP BY `steam2` ORDER BY `r` DESC
}

Loading…
Cancel
Save