Browse Source

учет выдачи випок

master
gsd 2 years ago
parent
commit
6b226d46a5
  1. 2
      src/main/java/app/services/db/FreeVIPService.java
  2. 22
      src/main/java/app/services/db/PermitionService.java
  3. 34
      src/main/java/app/services/db/VIPService.java

2
src/main/java/app/services/db/FreeVIPService.java

@ -125,7 +125,7 @@ public class FreeVIPService{
if (test != true) { if (test != true) {
setGivedFreeVip(steamID, socialAuth); setGivedFreeVip(steamID, socialAuth);
vipService.addVIP(steamID, 86400, VipGiveMethod.FREE); vipService.addVIP(steamID, 86400, VipGiveMethod.FREE, null);
} }
return 1L; return 1L;
} }

22
src/main/java/app/services/db/PermitionService.java

@ -34,8 +34,8 @@ public class PermitionService {
} }
@Transactional @Transactional
public boolean addPermition(SteamID steamID, Integer amount, String flags, Integer immunity_level, String status, String comment) { public int addPermition(SteamID steamID, Integer amount, String flags, Integer immunity_level, String status, String comment) {
if (getPermition(steamID) != null) return true; if (getPermition(steamID) != null) return 0;
return entityManager.createNativeQuery("INSERT INTO `sm_admins` (`authtype`, `identity`, `password`, `flags`, `name`, `immunity`, `comment`, `status`, `reg_date`, `amount`)" + return entityManager.createNativeQuery("INSERT INTO `sm_admins` (`authtype`, `identity`, `password`, `flags`, `name`, `immunity`, `comment`, `status`, `reg_date`, `amount`)" +
" VALUES ('steam', ?1, NULL, ?2, '', ?3, ?4, ?5, CURRENT_TIMESTAMP, ?6)") " VALUES ('steam', ?1, NULL, ?2, '', ?3, ?4, ?5, CURRENT_TIMESTAMP, ?6)")
.setParameter(1, steamID.steam2) .setParameter(1, steamID.steam2)
@ -44,7 +44,7 @@ public class PermitionService {
.setParameter(4, comment) .setParameter(4, comment)
.setParameter(5, status) .setParameter(5, status)
.setParameter(6, amount) .setParameter(6, amount)
.executeUpdate() > 0; .executeUpdate();
} }
@Transactional @Transactional
@ -56,12 +56,22 @@ public class PermitionService {
.executeUpdate() > 0; .executeUpdate() > 0;
} }
public boolean addFreeVIP(SteamID steamID, Integer amount) { @Transactional
public int extendPermition(SteamID steamID, Integer amount, String status) {
return entityManager.createNativeQuery("UPDATE `sm_admins` SET `amount`=`amount`+?1, `reg_date`=`reg_date` WHERE `identity` LIKE ?2 AND `status` LIKE ?3")
.setParameter(1, amount)
.setParameter(2, steamID.steam2)
.setParameter(3, status)
.executeUpdate();
}
public int addFreeVIP(SteamID steamID, Integer amount) {
return addPermition(steamID, amount, "oat", 20, "VIP", "f13bot.FreeVIP"); return addPermition(steamID, amount, "oat", 20, "VIP", "f13bot.FreeVIP");
} }
public boolean addVIP(SteamID steamID, Integer amount) { public int addVIP(SteamID steamID, Integer amount) {
return addPermition(steamID, amount, "oa", 20, "VIP", "f13bot.User"); if (getPermition(steamID) == null) return addPermition(steamID, amount, "oa", 20, "VIP", "f13bot.User");
else return -1 * extendPermition(steamID, amount, "VIP");
} }
public boolean removeVIP(SteamID steamID) { public boolean removeVIP(SteamID steamID) {

34
src/main/java/app/services/db/VIPService.java

@ -3,6 +3,7 @@ package app.services.db;
import app.entities.VipGiveMethod; import app.entities.VipGiveMethod;
import app.entities.db.Permition; import app.entities.db.Permition;
import app.entities.other.SteamID; import app.entities.other.SteamID;
import app.services.ServerService;
import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext; import jakarta.persistence.PersistenceContext;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -27,11 +28,13 @@ public class VIPService {
String webhook_url; String webhook_url;
PermitionService permitionService; PermitionService permitionService;
ServerService serverService;
@Autowired @Autowired
public VIPService(PermitionService permitionService) { public VIPService(PermitionService permitionService,
ServerService serverService) {
this.restTemplate = new RestTemplate(); this.restTemplate = new RestTemplate();
this.permitionService = permitionService; this.permitionService = permitionService;
this.serverService = serverService;
} }
public List<Long> getUsersDiscordWithActiveVIP() { public List<Long> getUsersDiscordWithActiveVIP() {
@ -56,25 +59,46 @@ public class VIPService {
.executeUpdate(); .executeUpdate();
} }
@Transactional
public int regesterGiveVIP(SteamID steamID, int amount, VipGiveMethod vipGiveMethod, String extra, boolean extend) {
return entityManager.createNativeQuery("INSERT INTO `gived_vip` (`id`, `steam2`, `amount`, `timestamp`, `givemethod`, `reserved`, `extend`) VALUES (NULL, ?1, ?2, current_timestamp(), ?3, ?4, ?5)")
.setParameter(1, steamID.steam2)
.setParameter(2, amount)
.setParameter(3, vipGiveMethod.ordinal())
.setParameter(4, extra)
.setParameter(5, extend)
.executeUpdate();
}
public Permition CheckCurrentPermition(SteamID steamID) { public Permition CheckCurrentPermition(SteamID steamID) {
return permitionService.getPermition(steamID); return permitionService.getPermition(steamID);
} }
public void addVIP(SteamID steamID, int amount, VipGiveMethod vipGiveMethod) { public void addVIP(SteamID steamID, int amount, VipGiveMethod vipGiveMethod, String extra) {
int result = 0;
switch (vipGiveMethod){ switch (vipGiveMethod){
case FREE -> { case FREE -> {
permitionService.addFreeVIP(steamID, amount); permitionService.addFreeVIP(steamID, amount);
regesterGiveVIP(steamID, amount, vipGiveMethod, extra, false);
publishWebhook(steamID, amount, "Free", true); publishWebhook(steamID, amount, "Free", true);
} }
case QIWI -> { case QIWI -> {
permitionService.addVIP(steamID, amount); result = permitionService.addVIP(steamID, amount);
regesterGiveVIP(steamID, amount, vipGiveMethod, extra, result < 0);
publishWebhook(steamID, amount, "Qiwi", false); publishWebhook(steamID, amount, "Qiwi", false);
} }
case STEAM -> { case STEAM -> {
permitionService.addVIP(steamID, amount); result = permitionService.addVIP(steamID, amount);
regesterGiveVIP(steamID, amount, vipGiveMethod, extra, result < 0);
publishWebhook(steamID, amount, "Steam", false); publishWebhook(steamID, amount, "Steam", false);
} }
case MANUAL -> {
result = permitionService.addVIP(steamID, amount);
regesterGiveVIP(steamID, amount, vipGiveMethod, extra, result < 0);
publishWebhook(steamID, amount, "Admin", false);
}
} }
serverService.executeRCONOnAllServers("sm_reloadadmins");
} }
public void publishWebhook(SteamID steamID, int amount, String status, boolean free) { public void publishWebhook(SteamID steamID, int amount, String status, boolean free) {

Loading…
Cancel
Save