Browse Source

donatelo2

master
gsd 2 years ago
parent
commit
9f0945b297
  1. 14
      src/main/java/app/services/db/DonateService.java

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

@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
@ -30,29 +31,30 @@ public class DonateService {
public HashMap<String, Integer> getDonateStatistic(StatisticRange statisticRange) {
HashMap<String, Integer> map = new HashMap<>();
List<Object[]> steam = entityManager.createNativeQuery(
"SELECT SUM(REPLACE(REPLACE(substring_index(`reserved`,';',-2), 'metal=',''), ';','')) as r," +
" SUM(REPLACE(REPLACE(substring_index(`reserved`,';',1), 'keys=',''), ';','')) as k " +
"SELECT SUM(CAST(REPLACE(REPLACE(substring_index(`reserved`,';',-2), 'metal=',''), ';','') AS INT)) as r," +
" SUM(CAST(REPLACE(REPLACE(substring_index(`reserved`,';',1), 'keys=',''), ';','') as INT)) as k " +
"FROM `gived_vip` WHERE `givemethod` = ?1 AND `timestamp` > CAST(DATE_FORMAT(NOW() ,?2) as DATE)")
.setParameter(1, VipGiveMethod.STEAM.ordinal())
.setParameter(2, StatisticRange.cast(statisticRange))
.getResultList();
if(!steam.isEmpty()) {
System.out.println(steam.get(0));
//За то что ниже мне стыдно
map.put("metal", steam.get(0)[0]==null?0:Integer.parseInt(steam.get(0)[0].toString().replace(".0","")));
map.put("key", steam.get(0)[1]==null?0:Integer.parseInt(steam.get(0)[1].toString().replace(".0","")));
map.put("metal", steam.get(0)==null||steam.get(0)[0]==null?0: Integer.parseInt(steam.get(0)[0].toString()));
map.put("key", steam.get(0)==null||steam.get(0)[1]==null?0: Integer.parseInt(steam.get(0)[1].toString()));
} else {
map.put("metal", 0);
map.put("key", 0);
}
List<Object> qiwi = entityManager.createNativeQuery(
"SELECT SUM(REPLACE(REPLACE(substring_index(`reserved`,';',1), 'rub=',''), ';','')) as k " +
"SELECT SUM(CAST(REPLACE(REPLACE(substring_index(`reserved`,';',1), 'rub=',''), ';','') as INT)) as k " +
"FROM `gived_vip` WHERE `givemethod` = ?1 AND `timestamp` > CAST(DATE_FORMAT(NOW() ,?2) as DATE)")
.setParameter(1, VipGiveMethod.QIWI.ordinal())
.setParameter(2, StatisticRange.cast(statisticRange))
.getResultList();
if(!qiwi.isEmpty()) map.put("rub", qiwi.get(0)==null?0:Integer.parseInt(qiwi.get(0).toString().replace(".0","")));
if(!qiwi.isEmpty()) map.put("rub", qiwi.get(0)==null?0: Integer.parseInt(qiwi.get(0).toString()));
else map.put("rub", 0);
Long count = (Long) entityManager.createNativeQuery("SELECT COUNT(*) as count FROM `gived_vip` WHERE `givemethod` = ?1 AND `timestamp` > CAST(DATE_FORMAT(NOW() ,?2) as DATE)")

Loading…
Cancel
Save