From 712b055518564353f0db7a4a2c97817e42431be1 Mon Sep 17 00:00:00 2001 From: gsd Date: Tue, 4 Feb 2025 18:52:23 +0300 Subject: [PATCH 1/4] kamaz fix --- src/main/java/app/services/db/PermitionService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/app/services/db/PermitionService.java b/src/main/java/app/services/db/PermitionService.java index f41e7f1..133b1e6 100644 --- a/src/main/java/app/services/db/PermitionService.java +++ b/src/main/java/app/services/db/PermitionService.java @@ -49,7 +49,7 @@ public class PermitionService { } public int extendPermition(SteamID steamID, Integer amount, String status) { - return jdbcTemplate.update("UPDATE sm_admins SET amount=amount+?, reg_date=reg_date WHERE identity LIKE ? AND status LIKE ?", + return jdbcTemplate.update("UPDATE sm_admins SET amount=amount+? WHERE identity LIKE ? AND status LIKE ?", amount, steamID.steam2, status); } From 831659200abd2606c2228f70e9de929aac9b1947 Mon Sep 17 00:00:00 2001 From: gsd Date: Tue, 4 Feb 2025 19:00:30 +0300 Subject: [PATCH 2/4] kamaz fix 2 --- src/main/java/app/services/db/PermitionService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/app/services/db/PermitionService.java b/src/main/java/app/services/db/PermitionService.java index 133b1e6..3416c69 100644 --- a/src/main/java/app/services/db/PermitionService.java +++ b/src/main/java/app/services/db/PermitionService.java @@ -48,9 +48,9 @@ public class PermitionService { steamID.steam2, status) > 0; } - public int extendPermition(SteamID steamID, Integer amount, String status) { - return jdbcTemplate.update("UPDATE sm_admins SET amount=amount+? WHERE identity LIKE ? AND status LIKE ?", - amount, steamID.steam2, status); + public int extendPermition(SteamID steamID, Integer amount, String status, Long previousTimestamp) { + return jdbcTemplate.update("UPDATE sm_admins SET amount=amount+?, reg_date = ? WHERE identity LIKE ? AND status LIKE ?", + amount, previousTimestamp, steamID.steam2, status); } public int addFreeVIP(SteamID steamID, Integer amount) { @@ -61,7 +61,7 @@ public class PermitionService { //лишняя проверка не будет лишним Permition permition = getPermition(steamID); if (permition == null) return addPermition(steamID, amount, "oa", 20, "VIP", "f13bot.User"); - else if (permition.getStatus().equals("VIP")) return -1 * extendPermition(steamID, amount, "VIP"); + else if (permition.getStatus().equals("VIP")) return -1 * extendPermition(steamID, amount, "VIP", permition.getU_timestamp()); else return 0; } From 953e3093713388d4a59d6c6ec6fb9de19b6d2113 Mon Sep 17 00:00:00 2001 From: gsd Date: Tue, 4 Feb 2025 19:04:26 +0300 Subject: [PATCH 3/4] kamaz fix 3 --- src/main/java/app/services/db/PermitionService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/app/services/db/PermitionService.java b/src/main/java/app/services/db/PermitionService.java index 3416c69..d143d00 100644 --- a/src/main/java/app/services/db/PermitionService.java +++ b/src/main/java/app/services/db/PermitionService.java @@ -11,6 +11,8 @@ import org.springframework.stereotype.Service; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Timestamp; +import java.time.Instant; import java.util.List; @Service @@ -50,7 +52,7 @@ public class PermitionService { public int extendPermition(SteamID steamID, Integer amount, String status, Long previousTimestamp) { return jdbcTemplate.update("UPDATE sm_admins SET amount=amount+?, reg_date = ? WHERE identity LIKE ? AND status LIKE ?", - amount, previousTimestamp, steamID.steam2, status); + amount, Timestamp.from(Instant.ofEpochSecond(previousTimestamp)), steamID.steam2, status); } public int addFreeVIP(SteamID steamID, Integer amount) { From d8051da5ee7d14a98de05b46546b6f8a4ade3cef Mon Sep 17 00:00:00 2001 From: gsd Date: Tue, 4 Feb 2025 19:14:15 +0300 Subject: [PATCH 4/4] kamaz fix 4 --- src/main/java/app/services/db/PermitionService.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/app/services/db/PermitionService.java b/src/main/java/app/services/db/PermitionService.java index d143d00..689a813 100644 --- a/src/main/java/app/services/db/PermitionService.java +++ b/src/main/java/app/services/db/PermitionService.java @@ -3,6 +3,8 @@ package app.services.db; import app.entities.db.AdminInfo; import app.entities.db.Permition; import app.entities.other.SteamID; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.jdbc.core.JdbcTemplate; @@ -22,6 +24,8 @@ public class PermitionService { @Qualifier("jt_rw") JdbcTemplate jdbcTemplate; + private final Logger logger = LoggerFactory.getLogger(PermitionService.class); + public Permition getPermition(SteamID steamID){ return jdbcTemplate.query("SELECT id, flags, immunity, status, amount, extract(epoch from reg_date) as utime FROM sm_admins WHERE identity LIKE ?", new Object[]{steamID.steam2}, @@ -40,19 +44,22 @@ public class PermitionService { public int addPermition(SteamID steamID, Integer amount, String flags, Integer immunity_level, String status, String comment) { if (getPermition(steamID) != null) return 0; + logger.info("Add new permition to {} with amount: {}", steamID.steam2, amount); return jdbcTemplate.update("INSERT INTO sm_admins (authtype, identity, password, flags, name, immunity, comment, status, reg_date, amount) VALUES ('steam', ?, NULL, ?, '', ?, ?, ?, CURRENT_TIMESTAMP, ?)", steamID.steam2, flags, immunity_level, comment, status, amount); } public boolean removePermition(SteamID steamID, String status) { if (getPermition(steamID) == null) return true; + logger.info("Remove permition with: {}", steamID.steam2); return jdbcTemplate.update("DELETE FROM sm_admins WHERE identity = ? AND status LIKE ?", steamID.steam2, status) > 0; } public int extendPermition(SteamID steamID, Integer amount, String status, Long previousTimestamp) { - return jdbcTemplate.update("UPDATE sm_admins SET amount=amount+?, reg_date = ? WHERE identity LIKE ? AND status LIKE ?", - amount, Timestamp.from(Instant.ofEpochSecond(previousTimestamp)), steamID.steam2, status); + logger.info("Extend permition to {} on amount {}", steamID.steam2, amount); + return jdbcTemplate.update("UPDATE sm_admins SET amount=amount+? WHERE identity LIKE ? AND status LIKE ?", + amount, steamID.steam2, status); } public int addFreeVIP(SteamID steamID, Integer amount) {