|
|
@@ -7,11 +7,15 @@ import java.sql.PreparedStatement;
|
|
|
import java.sql.ResultSet;
|
|
|
import java.sql.SQLException;
|
|
|
import java.text.DecimalFormat;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.AbstractMap;
|
|
|
import java.util.AbstractMap.SimpleEntry;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import org.eclipse.jetty.util.log.Log;
|
|
|
|
|
|
@@ -19,6 +23,7 @@ import com.google.common.base.Strings;
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
|
import mysql.Mysql;
|
|
|
+import objects.BetDTO;
|
|
|
import objects.Constants;
|
|
|
import objects.League;
|
|
|
import objects.OverUnder;
|
|
|
@@ -54,7 +59,8 @@ public class GuiMysql extends Mysql {
|
|
|
final ResultSet rs = stat.executeQuery();
|
|
|
|
|
|
while (rs.next()) {
|
|
|
- final SimpleEntry<Integer, String> entry = new SimpleEntry<>(rs.getInt(Constants.ID), rs.getString("name"));
|
|
|
+ final SimpleEntry<Integer, String> entry = new SimpleEntry<>(rs.getInt(Constants.ID),
|
|
|
+ rs.getString("name"));
|
|
|
sports.add(entry);
|
|
|
}
|
|
|
} catch (final SQLException e) {
|
|
|
@@ -73,7 +79,8 @@ public class GuiMysql extends Mysql {
|
|
|
final ResultSet rs = stat.executeQuery();
|
|
|
|
|
|
while (rs.next()) {
|
|
|
- final SimpleEntry<Integer, String> entry = new SimpleEntry<>(rs.getInt(Constants.ID), rs.getString("name"));
|
|
|
+ final SimpleEntry<Integer, String> entry = new SimpleEntry<>(rs.getInt(Constants.ID),
|
|
|
+ rs.getString("name"));
|
|
|
countries.add(entry);
|
|
|
}
|
|
|
} catch (final SQLException e) {
|
|
|
@@ -93,7 +100,8 @@ public class GuiMysql extends Mysql {
|
|
|
final ResultSet rs = stat.executeQuery();
|
|
|
|
|
|
while (rs.next()) {
|
|
|
- final SimpleEntry<Integer, String> entry = new SimpleEntry<>(rs.getInt(Constants.ID), rs.getString("name"));
|
|
|
+ final SimpleEntry<Integer, String> entry = new SimpleEntry<>(rs.getInt(Constants.ID),
|
|
|
+ rs.getString("name"));
|
|
|
leagues.add(entry);
|
|
|
}
|
|
|
} catch (final SQLException e) {
|
|
|
@@ -161,7 +169,7 @@ public class GuiMysql extends Mysql {
|
|
|
|
|
|
public List<Float> getAvgHomeScore(int teamId) {
|
|
|
final ArrayList<Float> returnValue = Lists.newArrayList();
|
|
|
- final String sql = "SELECT AVG(homeScore) as avgScored, AVG(awayScore) as avgConceded FROM SoccerResults WHERE homeScore != -1 && homeTeamId = ?";
|
|
|
+ final String sql = "SELECT AVG(homeScore) as avgScored, AVG(awayScore) as avgConceded FROM SoccerResults WHERE homeScore != -1 AND homeTeamId = ?";
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
stat.setInt(1, teamId);
|
|
|
|
|
|
@@ -179,9 +187,68 @@ public class GuiMysql extends Mysql {
|
|
|
return returnValue;
|
|
|
}
|
|
|
|
|
|
+ public List<Float> getAvgHomeScoreThisSeason(int teamId, int countryId, int leagueId) {
|
|
|
+ return getAvgHomeScoreThisSeason(teamId, countryId, leagueId, "");
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Float> getAvgHomeScoreThisSeason(int teamId, int countryId, int leagueId, String gameDate) {
|
|
|
+ final ArrayList<Float> returnValue = Lists.newArrayList();
|
|
|
+ final String sql = "SELECT AVG(homeScore) as avgScoredSeason, AVG(awayScore) as avgConcededSeason FROM SoccerResults WHERE homeScore != -1 AND homeTeamId = ? AND season = ? AND DATE(gameDate) < ? ORDER BY gameDate ASC";
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
+ stat.setInt(1, teamId);
|
|
|
+
|
|
|
+ if (Strings.isNullOrEmpty(gameDate)
|
|
|
+ || getSeasonFromDate(countryId, leagueId, gameDate).equals(getLastSeason(countryId, leagueId))) {
|
|
|
+ stat.setString(2, getLastSeason(countryId, leagueId));
|
|
|
+ } else {
|
|
|
+ String seasonFromDate = getSeasonFromDate(countryId, leagueId, gameDate);
|
|
|
+ stat.setString(2, seasonFromDate);
|
|
|
+ }
|
|
|
+ if (Strings.isNullOrEmpty(gameDate)) {
|
|
|
+ stat.setString(3, new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
|
|
|
+ } else {
|
|
|
+ stat.setString(3, gameDate);
|
|
|
+ }
|
|
|
+
|
|
|
+ final ResultSet rs = stat.executeQuery();
|
|
|
+
|
|
|
+ while (rs.next()) {
|
|
|
+ returnValue.add(rs.getFloat("avgScoredSeason"));
|
|
|
+ returnValue.add(rs.getFloat("avgConcededSeason"));
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (final SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return returnValue;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getSeasonFromDate(int countryId, int leagueId, String gameDate) {
|
|
|
+ String sql = "SELECT season FROM SoccerResults WHERE DATE(gameDate) = ? AND countryId = ? AND leagueId = ? LIMIT 1";
|
|
|
+ String returnValue = "";
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
+ if (Strings.isNullOrEmpty(gameDate)) {
|
|
|
+ stat.setString(1, new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
|
|
|
+ } else {
|
|
|
+ stat.setString(1, gameDate);
|
|
|
+ }
|
|
|
+ stat.setInt(2, countryId);
|
|
|
+ stat.setInt(3, leagueId);
|
|
|
+
|
|
|
+ ResultSet rs = stat.executeQuery();
|
|
|
+ while (rs.next()) {
|
|
|
+ returnValue = rs.getString("season");
|
|
|
+ }
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return returnValue;
|
|
|
+ }
|
|
|
+
|
|
|
public List<Float> getAvgAwayScore(int teamId) {
|
|
|
final ArrayList<Float> returnValue = Lists.newArrayList();
|
|
|
- final String sql = "SELECT AVG(homeScore) as avgConceded, AVG(awayScore) as avgScored FROM SoccerResults WHERE awayScore != -1 && awayTeamId = ?";
|
|
|
+ final String sql = "SELECT AVG(homeScore) as avgConceded, AVG(awayScore) as avgScored FROM SoccerResults WHERE awayScore != -1 AND awayTeamId = ?";
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
stat.setInt(1, teamId);
|
|
|
|
|
|
@@ -199,13 +266,48 @@ public class GuiMysql extends Mysql {
|
|
|
return returnValue;
|
|
|
}
|
|
|
|
|
|
+ public List<Float> getAvgAwayScoreThisSeason(int teamId, int countryId, int leagueId) {
|
|
|
+ return getAvgAwayScoreThisSeason(teamId, countryId, leagueId, "");
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Float> getAvgAwayScoreThisSeason(int teamId, int countryId, int leagueId, String gameDate) {
|
|
|
+ final ArrayList<Float> returnValue = Lists.newArrayList();
|
|
|
+ final String sql = "SELECT AVG(homeScore) as avgConcededSeason, AVG(awayScore) as avgScoredSeason FROM SoccerResults WHERE awayScore != -1 AND awayTeamId = ? AND season = ? AND DATE(gameDate) < ? ORDER BY gameDate ASC";
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
+ stat.setInt(1, teamId);
|
|
|
+ if (Strings.isNullOrEmpty(gameDate)
|
|
|
+ || getSeasonFromDate(countryId, leagueId, gameDate).equals(getLastSeason(countryId, leagueId))) {
|
|
|
+ stat.setString(2, getLastSeason(countryId, leagueId));
|
|
|
+ } else {
|
|
|
+ String seasonFromDate = getSeasonFromDate(countryId, leagueId, gameDate);
|
|
|
+ stat.setString(2, seasonFromDate);
|
|
|
+ }
|
|
|
+ if (Strings.isNullOrEmpty(gameDate)) {
|
|
|
+ stat.setString(3, new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
|
|
|
+ } else {
|
|
|
+ stat.setString(3, gameDate);
|
|
|
+ }
|
|
|
+
|
|
|
+ final ResultSet rs = stat.executeQuery();
|
|
|
+
|
|
|
+ while (rs.next()) {
|
|
|
+ returnValue.add(rs.getFloat("avgScoredSeason"));
|
|
|
+ returnValue.add(rs.getFloat("avgConcededSeason"));
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (final SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return returnValue;
|
|
|
+ }
|
|
|
+
|
|
|
public List<Float> getLeagueAvarages(int leagueId, int countryId) {
|
|
|
final ArrayList<Float> returnValue = Lists.newArrayList();
|
|
|
final String sql = "SELECT AVG(homeScore) avgHomeScore, AVG(awayScore) as avgAwayScore"
|
|
|
+ " FROM SoccerResults WHERE leagueId = ? AND countryId = ?";
|
|
|
|
|
|
- final String goalsSql = "SELECT (homeScore + awayScore) as totalGoals, count(*) as count FROM SoccerResults WHERE leagueId = ? AND countryId = ? AND season = ? GROUP BY totalGoals ORDER BY totalGoals asc";
|
|
|
- try (PreparedStatement stat = conn.prepareStatement(sql); PreparedStatement goalStmt = conn.prepareStatement(goalsSql)) {
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql);) {
|
|
|
stat.setInt(1, leagueId);
|
|
|
stat.setInt(2, countryId);
|
|
|
|
|
|
@@ -215,46 +317,106 @@ public class GuiMysql extends Mysql {
|
|
|
returnValue.add(rs.getFloat("avgAwayScore"));
|
|
|
}
|
|
|
|
|
|
+ } catch (final SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return returnValue;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<Integer, Integer> getGoalAvgThisSeason(int leagueId, int countryId) {
|
|
|
+ Map<Integer, Integer> returnValue = new HashMap<>();
|
|
|
+ final String goalsSql = "SELECT (homeScore + awayScore) as totalGoals, count(*) as count FROM SoccerResults WHERE leagueId = ? AND countryId = ? AND season = ? GROUP BY totalGoals ORDER BY totalGoals asc";
|
|
|
+ try (PreparedStatement goalStmt = conn.prepareStatement(goalsSql)) {
|
|
|
goalStmt.setInt(1, leagueId);
|
|
|
goalStmt.setInt(2, countryId);
|
|
|
goalStmt.setString(3, getLastSeason(countryId, leagueId));
|
|
|
|
|
|
final ResultSet goalRs = goalStmt.executeQuery();
|
|
|
+
|
|
|
while (goalRs.next()) {
|
|
|
- // TODO Not done!
|
|
|
- }
|
|
|
+ int tg = goalRs.getInt("totalGoals");
|
|
|
+ if (tg < 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ int numGoals = goalRs.getInt("count");
|
|
|
|
|
|
- } catch (final SQLException e) {
|
|
|
+ returnValue.put(tg, numGoals);
|
|
|
+ }
|
|
|
+ } catch (SQLException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
-
|
|
|
return returnValue;
|
|
|
}
|
|
|
|
|
|
public List<OverUnder> getStatsOverUnder(int leagueId) {
|
|
|
+ return getStatsOverUnder(leagueId, "");
|
|
|
+ }
|
|
|
|
|
|
- final DecimalFormat df = new DecimalFormat("##.##");
|
|
|
- df.setRoundingMode(RoundingMode.HALF_DOWN);
|
|
|
- final ArrayList<OverUnder> result = Lists.newArrayList();
|
|
|
+ private List<String> getAllSeasons(int leagueId) {
|
|
|
+ List<String> returnValue = new ArrayList<String>();
|
|
|
+ String sql = "SELECT distinct(season) FROM SoccerResults WHERE leagueId = ?";
|
|
|
|
|
|
- final String sql = "SELECT ((sHome.avgScored + sAway.avgConceded) - (sAway.avgScored + sHome.avgConceded)) as diff, (homeScore + awayScore) as numGoals "
|
|
|
- + "FROM SoccerResults "
|
|
|
- + "INNER JOIN (SELECT homeTeamId, AVG(homeScore) as avgScored, AVG(awayScore) as avgConceded FROM SoccerResults WHERE homeScore != -1 && homeTeamId = SoccerResults.homeTeamId GROUP BY homeTeamId) as sHome ON SoccerResults.homeTeamId = sHome.homeTeamId "
|
|
|
- + "INNER JOIN (SELECT awayTeamId, AVG(homeScore) as avgConceded, AVG(awayScore) as avgScored FROM SoccerResults WHERE awayScore != -1 && awayTeamId = SoccerResults.awayTeamId GROUP BY awayTeamId) as sAway ON SoccerResults.awayTeamId = sAway.awayTeamId "
|
|
|
- + "WHERE homeScore != -1 AND awayScore != -1 AND leagueId = ? " + "ORDER BY diff ASC";
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
stat.setInt(1, leagueId);
|
|
|
- final ResultSet rs = stat.executeQuery();
|
|
|
+
|
|
|
+ ResultSet rs = stat.executeQuery();
|
|
|
|
|
|
while (rs.next()) {
|
|
|
- final float diff = rs.getFloat("diff");
|
|
|
- final int numGoals = rs.getInt("numGoals");
|
|
|
- final Float formatted = round(BigDecimal.valueOf(diff), INCREMENT, RoundingMode.HALF_UP).floatValue();
|
|
|
+ returnValue.add(rs.getString("season"));
|
|
|
+ }
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return returnValue;
|
|
|
+ }
|
|
|
|
|
|
- final OverUnder entry = result.stream().filter(ou -> ou.getKey().compareTo(formatted) == 0).findFirst()
|
|
|
- .orElse(new OverUnder(formatted));
|
|
|
- entry.addGoalStat(numGoals);
|
|
|
- result.add(entry);
|
|
|
+ public List<OverUnder> getStatsOverUnder(int leagueId, String gameDate) {
|
|
|
+
|
|
|
+ final DecimalFormat df = new DecimalFormat("##.##");
|
|
|
+ df.setRoundingMode(RoundingMode.HALF_DOWN);
|
|
|
+ final ArrayList<OverUnder> result = Lists.newArrayList();
|
|
|
+
|
|
|
+ final String sql = "SELECT ((sHome.avgScored * sAway.avgConceded) + (sAway.avgScored * sHome.avgConceded)) as diff, (homeScore + awayScore) as numGoals "
|
|
|
+ + "FROM SoccerResults "
|
|
|
+ + "INNER JOIN (SELECT homeTeamId, AVG(homeScore) as avgScored, AVG(awayScore) as avgConceded FROM SoccerResults WHERE homeScore != -1 AND homeTeamId = SoccerResults.homeTeamId AND DATE(gameDate) < ? AND season = ? AND leagueId = ? GROUP BY homeTeamId) as sHome ON SoccerResults.homeTeamId = sHome.homeTeamId "
|
|
|
+ + "INNER JOIN (SELECT awayTeamId, AVG(homeScore) as avgConceded, AVG(awayScore) as avgScored FROM SoccerResults WHERE awayScore != -1 AND awayTeamId = SoccerResults.awayTeamId AND DATE(gameDate) < ? AND season = ? AND leagueId = ? GROUP BY awayTeamId) as sAway ON SoccerResults.awayTeamId = sAway.awayTeamId "
|
|
|
+ + "WHERE homeScore != -1 AND awayScore != -1 AND leagueId = ? AND DATE(gameDate) < ? AND season = ? "
|
|
|
+ + "ORDER BY diff ASC";
|
|
|
+ List<String> allSeasons = getAllSeasons(leagueId);
|
|
|
+
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
+ final String dateString;
|
|
|
+ if (Strings.isNullOrEmpty(gameDate)) {
|
|
|
+ dateString = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
|
|
+ } else {
|
|
|
+ dateString = gameDate;
|
|
|
+ }
|
|
|
+ for (String season : allSeasons) {
|
|
|
+ stat.setString(1, dateString);
|
|
|
+ stat.setString(2, season);
|
|
|
+ stat.setInt(3, leagueId);
|
|
|
+ stat.setString(4, dateString);
|
|
|
+ stat.setString(5, season);
|
|
|
+ stat.setInt(6, leagueId);
|
|
|
+
|
|
|
+ stat.setInt(7, leagueId);
|
|
|
+ stat.setString(8, dateString);
|
|
|
+ stat.setString(9, season);
|
|
|
+
|
|
|
+ final ResultSet rs = stat.executeQuery();
|
|
|
+
|
|
|
+ while (rs.next()) {
|
|
|
+ final float diff = rs.getFloat("diff");
|
|
|
+ final int numGoals = rs.getInt("numGoals");
|
|
|
+ final Float formatted = round(BigDecimal.valueOf(diff), INCREMENT, RoundingMode.HALF_UP)
|
|
|
+ .floatValue();
|
|
|
+
|
|
|
+ final OverUnder entry = result.stream().filter(ou -> ou.getKey().compareTo(formatted) == 0)
|
|
|
+ .findFirst().orElse(new OverUnder(formatted));
|
|
|
+ entry.addGoalStat(numGoals);
|
|
|
+ result.add(entry);
|
|
|
+ }
|
|
|
}
|
|
|
} catch (final SQLException e) {
|
|
|
e.printStackTrace();
|
|
|
@@ -300,8 +462,8 @@ public class GuiMysql extends Mysql {
|
|
|
final ResultSet rs = stat.executeQuery();
|
|
|
while (rs.next()) {
|
|
|
final TeamStanding ts = new TeamStanding(rs.getString("teamName"), rs.getInt("wins"), rs.getInt("lost"),
|
|
|
- rs.getInt("draws"), rs.getInt("score"), rs.getFloat(Constants.HOME_SCORE), rs.getFloat(Constants.AWAY_SCORE),
|
|
|
- rs.getFloat("goal_diff"));
|
|
|
+ rs.getInt("draws"), rs.getInt("score"), rs.getFloat(Constants.HOME_SCORE),
|
|
|
+ rs.getFloat(Constants.AWAY_SCORE), rs.getFloat("goal_diff"));
|
|
|
result.add(ts);
|
|
|
}
|
|
|
|
|
|
@@ -435,7 +597,7 @@ public class GuiMysql extends Mysql {
|
|
|
final ArrayList<SimpleEntry<Integer, String>> result = new ArrayList<>();
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
if (date.equals("")) {
|
|
|
- stat.setString(1, "DATE(NOW())");
|
|
|
+ stat.setString(1, new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
|
|
|
} else {
|
|
|
stat.setString(1, date);
|
|
|
}
|
|
|
@@ -463,7 +625,8 @@ public class GuiMysql extends Mysql {
|
|
|
final ResultSet rs = stat.executeQuery();
|
|
|
|
|
|
while (rs.next()) {
|
|
|
- final SimpleEntry<Integer, String> entry = new SimpleEntry<>(rs.getInt(Constants.ID), rs.getString("name"));
|
|
|
+ final SimpleEntry<Integer, String> entry = new SimpleEntry<>(rs.getInt(Constants.ID),
|
|
|
+ rs.getString("name"));
|
|
|
leagues.add(entry);
|
|
|
}
|
|
|
} catch (final SQLException e) {
|
|
|
@@ -472,18 +635,23 @@ public class GuiMysql extends Mysql {
|
|
|
return leagues;
|
|
|
}
|
|
|
|
|
|
- public List<SoccerMatch> getMatches(int sportId, Integer countryId, Integer leagueId, String date, String order) {
|
|
|
+ public List<SoccerMatch> getMatches(int sportId, Integer countryId, Integer leagueId, String date, String order,
|
|
|
+ boolean exactDate) {
|
|
|
final ArrayList<SoccerMatch> matches = Lists.newArrayList();
|
|
|
final String dateSql;
|
|
|
final String orderSql = " ORDER BY gameDate " + order;
|
|
|
if (date.equals("")) {
|
|
|
dateSql = "DATE(gameDate) = DATE(NOW()) ";
|
|
|
} else {
|
|
|
- dateSql = "DATE(gameDate) <= '" + date + "' ";
|
|
|
+ if (exactDate) {
|
|
|
+ dateSql = "DATE(gameDate) = '" + date + "' ";
|
|
|
+ } else {
|
|
|
+ dateSql = "DATE(gameDate) <= '" + date + "' ";
|
|
|
+ }
|
|
|
}
|
|
|
final String sql = "SELECT res.*, " + "hTeam.name as homeTeamName, aTeam.name as awayTeamName "
|
|
|
+ "FROM SoccerResults as res " + "Join Team as hTeam ON res.homeTeamId = hTeam.id "
|
|
|
- + "Join Team as aTeam ON res.awayTeam = aTeam.id " + "WHERE " + dateSql + "AND res.leagueId = ? "
|
|
|
+ + "Join Team as aTeam ON res.awayTeamId = aTeam.id " + "WHERE " + dateSql + "AND res.leagueId = ? "
|
|
|
+ "AND res.countryId = ? " + orderSql;
|
|
|
|
|
|
try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
@@ -649,4 +817,55 @@ public class GuiMysql extends Mysql {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public List<BetDTO> getBetSeries(boolean includeInactive) {
|
|
|
+ List<BetDTO> result = new ArrayList<>();
|
|
|
+ String sql = "SELECT ab.*, sr.gameDate as gameDate, sr.id as gameId, sr.homeScore as homeScore, sr.awayScore as awayScore, "
|
|
|
+ + "ht.name as homeTeam, aw.name as awayTeam " + "FROM ActiveBets ab "
|
|
|
+ + "INNER JOIN SoccerResults sr ON ab.gameId = sr.id " + "INNER JOIN Team ht ON sr.homeTeamId = ht.id "
|
|
|
+ + "INNER JOIN Team aw ON sr.awayTeamId = aw.id " + "WHERE done = ?";
|
|
|
+
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
+ stat.setBoolean(1, includeInactive);
|
|
|
+
|
|
|
+ ResultSet rs = stat.executeQuery();
|
|
|
+
|
|
|
+ while (rs.next()) {
|
|
|
+ BetDTO dto = new BetDTO();
|
|
|
+ dto.setHomeTeam(rs.getString("homeTeam"));
|
|
|
+ dto.setAwayTeam(rs.getString("awayTeam"));
|
|
|
+ dto.setBet(rs.getFloat("bet"));
|
|
|
+ dto.setBetType(rs.getString("betType"));
|
|
|
+ dto.setBetSeries(rs.getInt("series"));
|
|
|
+ dto.setGameId(rs.getInt("gameId"));
|
|
|
+ dto.setMatch(rs.getString("homeTeam"), rs.getString("awayTeam"));
|
|
|
+ dto.setOdds(rs.getFloat("odds"));
|
|
|
+ dto.setResult(rs.getInt("homeScore"), rs.getInt("AwayScore"));
|
|
|
+ dto.setGameDate(rs.getString("gameDate"));
|
|
|
+ dto.setWinAmount(rs.getFloat("odds") * rs.getFloat("bet"));
|
|
|
+ result.add(dto);
|
|
|
+ }
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addBetSeries(BetDTO bet) {
|
|
|
+ String sql = "INSERT INTO ActiveBets (series, gameId, betType, bet, odds, done) VALUES (?, ?, ?, ?, ?, ?)";
|
|
|
+
|
|
|
+ try (PreparedStatement stat = conn.prepareStatement(sql)) {
|
|
|
+ stat.setInt(1, bet.getBetSeries());
|
|
|
+ stat.setInt(2, bet.getGameId());
|
|
|
+ stat.setString(3, bet.getBetType());
|
|
|
+ stat.setFloat(4, bet.getBet());
|
|
|
+ stat.setFloat(5, bet.getOdds());
|
|
|
+ stat.setBoolean(6, false);
|
|
|
+
|
|
|
+ stat.execute();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|