diff --git a/src/main/java/app/services/db/PermitionService.java b/src/main/java/app/services/db/PermitionService.java index f41e7f1..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; @@ -11,6 +13,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 @@ -20,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}, @@ -38,18 +44,21 @@ 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) { - return jdbcTemplate.update("UPDATE sm_admins SET amount=amount+?, reg_date=reg_date WHERE identity LIKE ? AND status LIKE ?", + public int extendPermition(SteamID steamID, Integer amount, String status, Long previousTimestamp) { + 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); } @@ -61,7 +70,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; }