From 9f0945b29748725ae28341d5f741ddd4bb5fba03 Mon Sep 17 00:00:00 2001 From: gsd Date: Thu, 23 Mar 2023 22:35:35 +0300 Subject: [PATCH] donatelo2 --- src/main/java/app/services/db/DonateService.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/app/services/db/DonateService.java b/src/main/java/app/services/db/DonateService.java index 46160f7..8d484ad 100644 --- a/src/main/java/app/services/db/DonateService.java +++ b/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 getDonateStatistic(StatisticRange statisticRange) { HashMap map = new HashMap<>(); List 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 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)")