From be299098cb1f78ce771542710a686378f78ffde1 Mon Sep 17 00:00:00 2001 From: gsd Date: Thu, 9 Mar 2023 21:38:28 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=B0=20=D1=8F=20=D1=82=D1=83=D1=82=20?= =?UTF-8?q?=D0=BE=D0=B1=D0=BE=D1=81=D1=80=D0=B0=D0=BB=D1=81=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/user/ProfileController.java | 5 ++-- src/main/java/app/entities/SocialAuth.java | 4 +-- .../java/app/services/db/FreeVIPService.java | 28 ++++++++++++++----- .../app/services/db/PermitionService.java | 2 +- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/main/java/app/controllers/user/ProfileController.java b/src/main/java/app/controllers/user/ProfileController.java index bc917c9..f580e54 100644 --- a/src/main/java/app/controllers/user/ProfileController.java +++ b/src/main/java/app/controllers/user/ProfileController.java @@ -52,12 +52,13 @@ public class ProfileController { @CheckWebAccess public ResponseEntity GetFreeVIP(HttpServletRequest request, @CookieValue(value = "steam64", defaultValue = "") String steam64, - @RequestBody(required = false) SocialAuth socialAuth) { + @RequestBody(required = false) SocialAuth socialAuth, + @RequestParam(required = false, defaultValue = "false") Boolean test) { //return new ResponseEntity<>(freeVIPService.) //1.get social //2.get steam2discord //3.так уж и быть випка без анального зонда - return new ResponseEntity(freeVIPService.addFreeVIP(SteamIDConverter.getSteamID(steam64), socialAuth), HttpStatus.OK); + return new ResponseEntity(freeVIPService.addFreeVIP(SteamIDConverter.getSteamID(steam64), socialAuth, test), HttpStatus.OK); } @PostMapping("/report") diff --git a/src/main/java/app/entities/SocialAuth.java b/src/main/java/app/entities/SocialAuth.java index 911c603..e64e23c 100644 --- a/src/main/java/app/entities/SocialAuth.java +++ b/src/main/java/app/entities/SocialAuth.java @@ -4,8 +4,8 @@ import lombok.Data; @Data public class SocialAuth { - protected long vk_id = 0; - protected long discord_id = 0; + public long vk_id = 0; + public long discord_id = 0; public boolean haveAny() { return vk_id != 0 || discord_id != 0; diff --git a/src/main/java/app/services/db/FreeVIPService.java b/src/main/java/app/services/db/FreeVIPService.java index 9746cb0..7990505 100644 --- a/src/main/java/app/services/db/FreeVIPService.java +++ b/src/main/java/app/services/db/FreeVIPService.java @@ -55,7 +55,10 @@ public class FreeVIPService { } public Long getLastGivedFreeVIP(SocialAuth socialAuth) { - if (socialAuth.getVk_id() != 0) { + if (socialAuth == null) { + return 0L; + } + else if (socialAuth.getVk_id() != 0) { return (Long) entityManager.createNativeQuery("SELECT UNIX_TIMESTAMP(`date`) as u_time FROM free_vip WHERE vk_id = ?1 ORDER BY `date` DESC") .setParameter(1, socialAuth.getVk_id()) .getResultStream().map(u_time -> Long.valueOf((String) u_time)).findFirst().orElse(0L); @@ -70,7 +73,7 @@ public class FreeVIPService { @Transactional public boolean setGivedFreeVip(SteamID steamID, SocialAuth socialAuth) { - if (!socialAuth.haveAny()) return false; + if (socialAuth == null) socialAuth = new SocialAuth(); return entityManager.createNativeQuery("INSERT INTO `free_vip` (`id`, `steam3`, `vk_id`, `discord_id`, `date`) VALUES (NULL, ?1, ?2, ?3, current_timestamp())") .setParameter(1, steamID.steam2) .setParameter(2, socialAuth.getVk_id()) @@ -78,7 +81,7 @@ public class FreeVIPService { .executeUpdate() > 0; } - public Long addFreeVIP(SteamID steamID, SocialAuth socialAuth) { + public Long addFreeVIP(SteamID steamID, SocialAuth socialAuth, Boolean test) { /* 0 - права уже есть 1 - права выданы @@ -106,16 +109,27 @@ public class FreeVIPService { BigDecimal total_usertime = BigDecimal.valueOf(0); for (Map.Entry> stringServerEntry : usertimeService.getPlayerUsertime(steamID).entrySet()) { for (Map.Entry stringBigDecimalEntry : stringServerEntry.getValue().entrySet()) { - total_usertime.add(stringBigDecimalEntry.getValue()); + total_usertime = total_usertime.add(stringBigDecimalEntry.getValue()); + if (test) { + System.out.printf("%s - %d\n", stringBigDecimalEntry.getKey(), stringBigDecimalEntry.getValue().longValue()); + } } } + + if (test) { + System.out.printf("Total: %d", total_usertime.longValue()); + } + if (total_usertime.longValue() < need_usertime) { //4.недостаточно наиграл return -1 * (need_usertime - total_usertime.longValue()); } - setGivedFreeVip(steamID, socialAuth); - permitionService.addFreeVIP(steamID, 86400); - publishWebhook(steamID, 86400, "Free"); + + if (test != true) { + setGivedFreeVip(steamID, socialAuth); + permitionService.addFreeVIP(steamID, 86400); + publishWebhook(steamID, 86400, "Free"); + } return 1L; } diff --git a/src/main/java/app/services/db/PermitionService.java b/src/main/java/app/services/db/PermitionService.java index 605fc4c..8bcee13 100644 --- a/src/main/java/app/services/db/PermitionService.java +++ b/src/main/java/app/services/db/PermitionService.java @@ -42,7 +42,7 @@ public class PermitionService { .setParameter(3, immunity_level) .setParameter(4, comment) .setParameter(5, status) - .setParameter(6, immunity_level) + .setParameter(6, amount) .executeUpdate() > 0; }