added finance API methods

This commit is contained in:
2023-06-04 22:21:15 -04:00
parent b684b80ea9
commit ffaea04b86
5 changed files with 537 additions and 456 deletions

View File

@@ -111,10 +111,10 @@ public class EventApi {
@POST
@Path("/document/{documentId}/send")
@RolesAllowed(
Constants.EVENT_ROLE_PREFIX
+ "communicate"
)
@RolesAllowed(
Constants.EVENT_ROLE_PREFIX
+ "communicate"
)
@Produces(Constants.V1_JSON)
@Operation(
summary = "Sends the specified document.",
@@ -144,10 +144,10 @@ public class EventApi {
@POST
@Path("/document/{documentId}/sendTest/{personId}")
@RolesAllowed(
Constants.EVENT_ROLE_PREFIX
+ "communicate"
)
@RolesAllowed(
Constants.EVENT_ROLE_PREFIX
+ "communicate"
)
@Produces(Constants.V1_JSON)
@Operation(
summary = "Sends the specified document to the specified person.",

View File

@@ -15,6 +15,7 @@ import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.SecurityContext;
@@ -48,7 +49,7 @@ public class EventFinanceApi {
)
@Produces(Constants.V1_JSON)
@SecurityRequirement(name = "basic")
@Operation(summary = "Retrieves the balances of all participants in an event.")
@Operation(summary = "Retrieves the balances of all persons associated with an event.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "Success"),
@ApiResponse(responseCode = "401", description = "Not authenticated"),
@@ -56,8 +57,11 @@ public class EventFinanceApi {
@ApiResponse(responseCode = "404", description = "An event with the specified ID could not be found")
})
public List<Map<String, Object>> getBalanceByPersonsAsJson(@Context
SecurityContext securityContext) throws JsonProcessingException {
Map<Long, DataSet> personsBalances = this.eventFinanceService.getPersonsBalances(this.eventId);
SecurityContext securityContext, @QueryParam("minBalance")
Float minBalance, @QueryParam("maxBalance")
Float maxBalance) throws JsonProcessingException {
Map<Long, DataSet> personsBalances = this.eventFinanceService.getPersonsBalances(this.eventId, minBalance,
maxBalance);
List<Map<String, Object>> personsBalancesJson = new ArrayList<>(personsBalances.size());
for (DataSet personBalance : personsBalances.values()) {
@@ -80,7 +84,7 @@ public class EventFinanceApi {
)
@Produces("text/csv")
@SecurityRequirement(name = "basic")
@Operation(summary = "Retrieves the balances of all participants in an event.")
@Operation(summary = "Retrieves the balances of all persons associated with an event.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "Success"),
@ApiResponse(responseCode = "401", description = "Not authenticated"),
@@ -115,4 +119,68 @@ public class EventFinanceApi {
};
}
@GET
@Path("/balance/person/{personId}")
@RolesAllowed(
Constants.EVENT_ROLE_PREFIX
+ "member"
)
@Produces(Constants.V1_JSON)
@SecurityRequirement(name = "basic")
@Operation(summary = "Retrieves the balance of a person in an event.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "Success"),
@ApiResponse(responseCode = "401", description = "Not authenticated"),
@ApiResponse(responseCode = "403", description = "Authenticated, but not permitted"),
@ApiResponse(
responseCode = "404",
description = "An event or person with the specified IDs could not be found"
)
})
public Map<String, Object> getBalanceByPersonsAsJson(@Context
SecurityContext securityContext, @PathParam("personId")
long personId) throws JsonProcessingException {
DataSet personBalance = this.eventFinanceService.getPersonBalance(this.eventId, personId);
Map<String, Object> personBalanceJson = new HashMap<>(5);
personBalanceJson.put("personId", personBalance.getLong("personID"));
personBalanceJson.put("expense", personBalance.getFloat("expense"));
personBalanceJson.put("paid", personBalance.getFloat("paid"));
personBalanceJson.put("balance", personBalance.getFloat("balance"));
return personBalanceJson;
}
@GET
@Path("/series/balance/persons")
@RolesAllowed(
Constants.EVENT_ROLE_PREFIX
+ "member"
)
@Produces(Constants.V1_JSON)
@SecurityRequirement(name = "basic")
@Operation(summary = "Retrieves the cumulative balances of all persons associated with a series prior to an event.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "Success"),
@ApiResponse(responseCode = "401", description = "Not authenticated"),
@ApiResponse(responseCode = "403", description = "Authenticated, but not permitted"),
@ApiResponse(responseCode = "404", description = "An event with the specified ID could not be found")
})
public List<Map<String, Object>> getSeriesBalanceByPersonsAsJson(@Context
SecurityContext securityContext) throws JsonProcessingException {
Map<Long, DataSet> personsBalances = this.eventFinanceService.getSeriesPersonsPreviousBalances(this.eventId);
List<Map<String, Object>> personsBalancesJson = new ArrayList<>(personsBalances.size());
for (DataSet personBalance : personsBalances.values()) {
Map<String, Object> personBalanceJson = new HashMap<>(5);
personBalanceJson.put("personId", personBalance.getLong("personID"));
personBalanceJson.put("expense", personBalance.getFloat("expense"));
personBalanceJson.put("paid", personBalance.getFloat("paid"));
personBalanceJson.put("balance", personBalance.getFloat("balance"));
personsBalancesJson.add(personBalanceJson);
}
return personsBalancesJson;
}
}

View File

@@ -1,79 +1,81 @@
package com.poststats.golf.service;
import java.util.Map;
import com.brianlong.sql.DataSet;
import java.util.Map;
/**
* This service provides financial metadata about the event, series, associated
* people, or a combination of those.
*
* The balance metadata includes money `paid`, `expenses`, and `balance`. The
*
* The balance metadata includes money `paid`, `expenses`, and `balance`. The
* balance numerically consistent with the perspective of the person, not the
* event organizers. That means it is positive when the person paid more than
* event organizers. That means it is positive when the person paid more than
* they should owe and negative if they owe money.
*
*
* @author brian
*/
public interface EventFinanceService {
/**
* Computes and retrieves the person balances for those associated with the
* specified event.
*
* @param eventId The unique identifier of an event.
* @return A map of `personId` to balance metadata.
*/
Map<Long, DataSet> getPersonsBalances(long eventId);
/**
* Computes and retrieves the person balances for those associated with the
* specified event.
*
* @param eventId The unique identifier of an event.
* @param minBalance The minimum balance for returned balances; `0.01` for those that have paid more than they owe; `null` for no constraint.
* @param maxBalance The maximum balance for returned balances; `-0.01` for those that owe; `null` for no constraint.
* @return A map of `personId` to balance metadata.
*/
/**
* Computes and retrieves the person balances for those associated with the
* specified event.
*
* @param eventId The unique identifier of an event.
* @return A map of `personId` to balance metadata.
*/
Map<Long, DataSet> getPersonsBalances(long eventId);
/**
* Computes and retrieves the person balances for those associated with the
* specified event.
*
* @param eventId The unique identifier of an event.
* @param minBalance The minimum balance for returned balances; `0.01` for those
* that have paid more than they owe; `null` for no
* constraint.
* @param maxBalance The maximum balance for returned balances; `-0.01` for
* those that owe; `null` for no constraint.
* @return A map of `personId` to balance metadata.
*/
Map<Long, DataSet> getPersonsBalances(long eventId, Float minBalance, Float maxBalance);
/**
* Computes and retrieves the specified person's balance for the specified
* event.
*
* @param eventId The unique identifier of an event.
* @param personId The unique identifier of a person.
* @return Balance metadata.
*/
DataSet getPersonBalance(long eventId, long personId);
/**
* Computes and retrieves the specified person's balance for the specified
* event.
*
* @param eventId The unique identifier of an event.
* @param personId The unique identifier of a person.
* @return Balance metadata.
*/
DataSet getPersonBalance(long eventId, long personId);
/**
* Computes and retrieves all associated persons' cumulative balance for
* all events in the series before the specified event.
*
* @param eventId The unique identifier of an event.
* @return A map of `personId` to balance metadata.
*/
Map<Long, DataSet> getSeriesPersonsBalances(long eventId);
/**
* Computes and retrieves all associated persons' cumulative balance for all
* events in the series before the specified event.
*
* @param eventId The unique identifier of an event.
* @return A map of `personId` to balance metadata.
*/
Map<Long, DataSet> getSeriesPersonsPreviousBalances(long eventId);
/**
* Computes and retrieves the specified person's balances for all events in
* the specified series.
*
* @param seriesId The unique identifier of a series.
* @param personId The unique identifier of a person.
* @return A map of `eventId` to balance metadata.
*/
Map<Long, DataSet> getSeriesPersonBalances(int seriesId, long personId);
/**
* Computes and retrieves the specified person's balances for all events in the
* specified series.
*
* @param seriesId The unique identifier of a series.
* @param personId The unique identifier of a person.
* @return A map of `eventId` to balance metadata.
*/
Map<Long, DataSet> getSeriesPersonBalances(int seriesId, long personId);
/**
* Computes and retrieves the specified person's balances for all events in
* the series before the specified event.
*
* @param eventId The unique identifier of an event.
* @param personId The unique identifier of a person.
* @return A map of `eventId` to balance metadata.
*/
Map<Long, DataSet> getSeriesPersonPreviousBalances(long eventId, long personId);
/**
* Computes and retrieves the specified person's balances for all events in the
* series before the specified event.
*
* @param eventId The unique identifier of an event.
* @param personId The unique identifier of a person.
* @return A map of `eventId` to balance metadata.
*/
Map<Long, DataSet> getSeriesPersonPreviousBalances(long eventId, long personId);
}

View File

@@ -1,9 +1,5 @@
package com.poststats.golf.service.db;
import java.sql.SQLException;
import java.time.LocalDate;
import java.util.Map;
import com.brianlong.sql.DataSet;
import com.brianlong.sql.FlexPreparedStatement;
import com.brianlong.util.FlexMap;
@@ -14,20 +10,22 @@ import com.poststats.provider.NonTransactionalProvider;
import com.poststats.provider.Statement;
import com.poststats.provider.StatementProvider;
import com.poststats.service.ServiceException;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import java.sql.SQLException;
import java.time.LocalDate;
import java.util.Map;
@ApplicationScoped
public class EventFinanceServiceDAO implements EventFinanceService {
@Inject
private EventService eventService;
@Override
public Map<Long, DataSet> getPersonsBalances(long eventId) {
return this.getPersonsBalances(eventId, null, null);
}
@Inject
private EventService eventService;
@Override
public Map<Long, DataSet> getPersonsBalances(long eventId) {
return this.getPersonsBalances(eventId, null, null);
}
@Override
public Map<Long, DataSet> getPersonsBalances(long eventId, Float minBalance, Float maxBalance) {
@@ -36,8 +34,8 @@ public class EventFinanceServiceDAO implements EventFinanceService {
try {
for (int i = 1; i <= 5; i++)
fps.setIntegerU(i, eventId);
fps.setFloat(6, minBalance == null ? Float.NEGATIVE_INFINITY : minBalance);
fps.setFloat(7, maxBalance == null ? Float.POSITIVE_INFINITY : maxBalance);
fps.setFloat(6, minBalance == null ? -1e20f : minBalance);
fps.setFloat(7, maxBalance == null ? 1e20f : maxBalance);
return fps.executeQuery().getAllRows("personID", Long.class);
} finally {
fps.close();
@@ -47,124 +45,124 @@ public class EventFinanceServiceDAO implements EventFinanceService {
}
}
@Override
public DataSet getPersonBalance(long eventId, long personId) {
try {
FlexPreparedStatement fps = this.sqlSelectPersonBalances.buildPreparedStatement();
try {
for (int i = 1; i <= 10; i += 2) {
fps.setIntegerU(i, eventId);
fps.setIntegerU(i+1, personId);
}
return fps.executeQuery().getNextRow();
} finally {
fps.close();
}
} catch (SQLException se) {
throw new ServiceException(se);
}
}
@Override
public DataSet getPersonBalance(long eventId, long personId) {
try {
FlexPreparedStatement fps = this.sqlSelectPersonBalances.buildPreparedStatement();
try {
for (int i = 1; i <= 10; i += 2) {
fps.setIntegerU(i, eventId);
fps.setIntegerU(i + 1, personId);
}
return fps.executeQuery().getNextRow();
} finally {
fps.close();
}
} catch (SQLException se) {
throw new ServiceException(se);
}
}
@Override
public Map<Long, DataSet> getSeriesPersonsBalances(long eventId) {
FlexMap event = this.eventService.get(eventId);
int seriesId = event.getInteger("seriesID");
LocalDate liveline = event.getDate("liveline");
try {
FlexPreparedStatement fps = this.sqlSelectSeriesBalances.buildPreparedStatement();
try {
for (int i = 1; i <= 15; i += 3) {
fps.setSmallintU(i, seriesId);
fps.setIntegerU(i+1, eventId);
fps.setDate(i+2, liveline);
}
return fps.executeQuery().getAllRows("personID", Long.class);
} finally {
fps.close();
}
} catch (SQLException se) {
throw new ServiceException(se);
}
}
@Override
public Map<Long, DataSet> getSeriesPersonsPreviousBalances(long eventId) {
FlexMap event = this.eventService.get(eventId);
int seriesId = event.getInteger("seriesID");
LocalDate liveline = event.getDate("liveline");
@Override
public Map<Long, DataSet> getSeriesPersonBalances(int seriesId, long personId) {
return this.getSeriesPersonBalances(seriesId, null, null, personId);
}
try {
FlexPreparedStatement fps = this.sqlSelectSeriesBalances.buildPreparedStatement();
try {
for (int i = 1; i <= 15; i += 3) {
fps.setSmallintU(i, seriesId);
fps.setIntegerU(i + 1, eventId);
fps.setDate(i + 2, liveline);
}
return fps.executeQuery().getAllRows("personID", Long.class);
} finally {
fps.close();
}
} catch (SQLException se) {
throw new ServiceException(se);
}
}
@Override
public Map<Long, DataSet> getSeriesPersonPreviousBalances(long eventId, long personId) {
FlexMap event = this.eventService.get(eventId);
int seriesId = event.getInteger("seriesID");
LocalDate liveline = event.getDate("liveline");
return this.getSeriesPersonBalances(seriesId, eventId, liveline, personId);
}
private Map<Long, DataSet> getSeriesPersonBalances(int seriesId, Long eventId, LocalDate liveline, long personId) {
if (eventId == null)
eventId = -1L;
if (liveline == null)
liveline = LocalDate.now().plusYears(10L);
try {
FlexPreparedStatement fps = this.sqlSelectSeriesPersonEventBalances.buildPreparedStatement();
try {
for (int i = 1; i <= 20; i += 4) {
fps.setSmallintU(i, seriesId);
fps.setIntegerU(i+1, eventId);
fps.setDate(i+2, liveline);
fps.setIntegerU(i+3, personId);
}
return fps.executeQuery().getAllRows("personID", Long.class);
} finally {
fps.close();
}
} catch (SQLException se) {
throw new ServiceException(se);
}
}
@Override
public Map<Long, DataSet> getSeriesPersonBalances(int seriesId, long personId) {
return this.getSeriesPersonBalances(seriesId, null, null, personId);
}
@Inject
@NonTransactionalProvider
@GolfProvider
@Statement(
sql = "SELECT TT.personID, TT.epersonID, SUM(TT.expenses) expenses, SUM(TT.paid) paid, (SUM(TT.paid)-SUM(TT.expenses)) balance "
+ "FROM ("
+ " SELECT ALL EP.personID, EP.epersonID, IF(EB.projectedValue IS NULL, 0, EB.projectedValue) expenses, 0 paid "
+ " FROM ~g~.EventPerson EP "
+ " LEFT JOIN ~g~.EventBudget EB ON (EP.eventID=EB.eventID) "
+ " WHERE EP.eventID=? "
+ " UNION ALL "
+ " SELECT ALL EP.personID, EP.epersonID, EO.amount expenses, 0 paid "
+ " FROM ~g~.EventPerson EP "
+ " INNER JOIN ~g~.EventPersonOption EPO ON (EP.epersonID=EPO.epersonID) "
+ " INNER JOIN ~g~.EventOption EO ON (EPO.optionID=EO.optionID) "
+ " WHERE EP.eventID=? AND EPO.answer='Y' AND EO.amount IS NOT NULL AND EO.waive IS FALSE "
+ " UNION ALL "
+ " SELECT ALL EP.personID, EP.epersonID, EO.amount expenses, 0 paid "
+ " FROM ~g~.EventPerson EP "
+ " INNER JOIN ~g~.EventPersonOption EPO ON (EP.epersonID=EPO.epersonID) "
+ " INNER JOIN ~g~.EventOption EO ON (EPO.optionID=EO.optionID) "
+ " WHERE EP.eventID=? AND EPO.itemID IS NOT NULL "
+ " AND (EO.multiple IS FALSE OR EO.funded='option' OR EO.static IS NOT NULL) "
+ " AND EO.amount IS NOT NULL AND EO.waive IS FALSE "
+ " UNION ALL "
+ " SELECT ALL EP.personID, EP.epersonID, EOI.amount expenses, 0 paid "
+ " FROM ~g~.EventPerson EP "
+ " INNER JOIN ~g~.EventPersonOption EPO ON (EP.epersonID=EPO.epersonID) "
+ " INNER JOIN ~g~.EventOption EO ON (EPO.optionID=EO.optionID) "
+ " INNER JOIN ~g~.EventOptionItem EOI ON (EPO.itemID=EOI.itemID) "
+ " WHERE EP.eventID=? AND EO.waive IS FALSE AND EO.funded='selection' AND EOI.amount IS NOT NULL "
+ " UNION ALL "
+ " SELECT ALL EPP.personID, EP.epersonID, 0 expenses, EPP.amount paid "
+ " FROM ~g~.EventPersonPayment EPP "
+ " LEFT JOIN ~g~.EventPerson EP ON (EPP.eventID=EP.eventID AND EPP.personID=EP.personID) "
+ " WHERE EPP.eventID=?) TT "
+ "GROUP BY TT.personID "
+ "HAVING (SUM(TT.paid)-SUM(TT.expenses))>=? AND (SUM(TT.paid)-SUM(TT.expenses))<=? "
)
private StatementProvider sqlSelectBalances;
@Override
public Map<Long, DataSet> getSeriesPersonPreviousBalances(long eventId, long personId) {
FlexMap event = this.eventService.get(eventId);
int seriesId = event.getInteger("seriesID");
LocalDate liveline = event.getDate("liveline");
return this.getSeriesPersonBalances(seriesId, eventId, liveline, personId);
}
private Map<Long, DataSet> getSeriesPersonBalances(int seriesId, Long eventId, LocalDate liveline, long personId) {
if (eventId == null)
eventId = -1L;
if (liveline == null)
liveline = LocalDate.now().plusYears(10L);
try {
FlexPreparedStatement fps = this.sqlSelectSeriesPersonEventBalances.buildPreparedStatement();
try {
for (int i = 1; i <= 20; i += 4) {
fps.setSmallintU(i, seriesId);
fps.setIntegerU(i + 1, eventId);
fps.setDate(i + 2, liveline);
fps.setIntegerU(i + 3, personId);
}
return fps.executeQuery().getAllRows("personID", Long.class);
} finally {
fps.close();
}
} catch (SQLException se) {
throw new ServiceException(se);
}
}
@Inject
@NonTransactionalProvider
@GolfProvider
@Statement(
sql = "SELECT TT.personID, TT.epersonID, SUM(TT.expenses) expenses, SUM(TT.paid) paid, (SUM(TT.paid)-SUM(TT.expenses)) balance "
+ "FROM ("
+ " SELECT ALL EP.personID, EP.epersonID, IF(EB.projectedValue IS NULL, 0, EB.projectedValue) expenses, 0 paid "
+ " FROM ~g~.EventPerson EP "
+ " LEFT JOIN ~g~.EventBudget EB ON (EP.eventID=EB.eventID) "
+ " WHERE EP.eventID=? "
+ " UNION ALL "
+ " SELECT ALL EP.personID, EP.epersonID, EO.amount expenses, 0 paid "
+ " FROM ~g~.EventPerson EP "
+ " INNER JOIN ~g~.EventPersonOption EPO ON (EP.epersonID=EPO.epersonID) "
+ " INNER JOIN ~g~.EventOption EO ON (EPO.optionID=EO.optionID) "
+ " WHERE EP.eventID=? AND EPO.answer='Y' AND EO.amount IS NOT NULL AND EO.waive IS FALSE "
+ " UNION ALL "
+ " SELECT ALL EP.personID, EP.epersonID, EO.amount expenses, 0 paid "
+ " FROM ~g~.EventPerson EP "
+ " INNER JOIN ~g~.EventPersonOption EPO ON (EP.epersonID=EPO.epersonID) "
+ " INNER JOIN ~g~.EventOption EO ON (EPO.optionID=EO.optionID) "
+ " WHERE EP.eventID=? AND EPO.itemID IS NOT NULL "
+ " AND (EO.multiple IS FALSE OR EO.funded='option' OR EO.static IS NOT NULL) "
+ " AND EO.amount IS NOT NULL AND EO.waive IS FALSE "
+ " UNION ALL "
+ " SELECT ALL EP.personID, EP.epersonID, EOI.amount expenses, 0 paid "
+ " FROM ~g~.EventPerson EP "
+ " INNER JOIN ~g~.EventPersonOption EPO ON (EP.epersonID=EPO.epersonID) "
+ " INNER JOIN ~g~.EventOption EO ON (EPO.optionID=EO.optionID) "
+ " INNER JOIN ~g~.EventOptionItem EOI ON (EPO.itemID=EOI.itemID) "
+ " WHERE EP.eventID=? AND EO.waive IS FALSE AND EO.funded='selection' AND EOI.amount IS NOT NULL "
+ " UNION ALL "
+ " SELECT ALL EPP.personID, EP.epersonID, 0 expenses, EPP.amount paid "
+ " FROM ~g~.EventPersonPayment EPP "
+ " LEFT JOIN ~g~.EventPerson EP ON (EPP.eventID=EP.eventID AND EPP.personID=EP.personID) "
+ " WHERE EPP.eventID=?) TT "
+ "GROUP BY TT.personID "
+ "HAVING (SUM(TT.paid)-SUM(TT.expenses))>=? AND (SUM(TT.paid)-SUM(TT.expenses))<=? "
)
private StatementProvider sqlSelectBalances;
@Inject
@NonTransactionalProvider
@@ -205,96 +203,96 @@ public class EventFinanceServiceDAO implements EventFinanceService {
)
private StatementProvider sqlSelectPersonBalances;
@Inject
@NonTransactionalProvider
@GolfProvider
@Statement(
sql = "SELECT TT.personID, TT.epersonID, SUM(TT.expenses) expenses, SUM(TT.paid) paid, (SUM(TT.paid)-SUM(TT.expenses)) balance "
+ "FROM ("
+ " SELECT ALL EP.personID, EP.epersonID, IF(EB.projectedValue IS NULL, 0, EB.projectedValue) expenses, 0 paid "
+ " FROM ~g~.Event E "
+ " INNER JOIN ~g~.EventPerson EP ON (E.eventID=EP.eventID) "
+ " INNER JOIN ~g~.EventBudget EB ON (EP.eventID=EB.eventID) "
+ " WHERE E.seriesID=? AND E.eventID<>? AND E.liveline<? "
+ " UNION ALL "
+ " SELECT ALL EP.personID, EP.epersonID, EO.amount expenses, 0 paid "
+ " FROM ~g~.Event E "
+ " INNER JOIN ~g~.EventPerson EP ON (E.eventID=EP.eventID) "
+ " INNER JOIN ~g~.EventPersonOption EPO ON (EP.epersonID=EPO.epersonID) "
+ " INNER JOIN ~g~.EventOption EO ON (EPO.optionID=EO.optionID) "
+ " WHERE E.seriesID=? AND E.eventID<>? AND E.liveline<? AND EPO.answer='Y' AND EO.amount IS NOT NULL AND EO.waive IS FALSE "
+ " UNION ALL "
+ " SELECT ALL EP.personID, EP.epersonID, EO.amount expenses, 0 paid "
+ " FROM ~g~.Event E "
+ " INNER JOIN ~g~.EventPerson EP ON (E.eventID=EP.eventID) "
+ " INNER JOIN ~g~.EventPersonOption EPO ON (EP.epersonID=EPO.epersonID) "
+ " INNER JOIN ~g~.EventOption EO ON (EPO.optionID=EO.optionID) "
+ " WHERE E.seriesID=? AND E.eventID<>? AND E.liveline<? AND EPO.itemID IS NOT NULL "
+ " AND (EO.multiple IS FALSE OR EO.funded='option' OR EO.static IS NOT NULL) "
+ " AND EO.amount IS NOT NULL AND EO.waive IS FALSE "
+ " UNION ALL "
+ " SELECT ALL EP.personID, EP.epersonID, EOI.amount expenses, 0 paid "
+ " FROM ~g~.Event E "
+ " INNER JOIN ~g~.EventPerson EP ON (E.eventID=EP.eventID) "
+ " INNER JOIN ~g~.EventPersonOption EPO ON (EP.epersonID=EPO.epersonID) "
+ " INNER JOIN ~g~.EventOption EO ON (EPO.optionID=EO.optionID) "
+ " INNER JOIN ~g~.EventOptionItem EOI ON (EPO.itemID=EOI.itemID) "
+ " WHERE E.seriesID=? AND E.eventID<>? AND E.liveline<? AND EO.waive IS FALSE AND EO.funded='selection' AND EOI.amount IS NOT NULL "
+ " UNION ALL "
+ " SELECT ALL EPP.personID, EP.epersonID, 0 expenses, EPP.amount paid "
+ " FROM ~g~.Event E "
+ " INNER JOIN ~g~.EventPersonPayment EPP ON (E.eventID=EPP.eventID) "
+ " LEFT JOIN ~g~.EventPerson EP ON (EPP.eventID=EP.eventID AND EPP.personID=EP.personID) "
+ " WHERE E.seriesID=? AND E.eventID<>? AND E.liveline<?) TT "
+ "GROUP BY TT.personID"
)
private StatementProvider sqlSelectSeriesBalances;
@Inject
@NonTransactionalProvider
@GolfProvider
@Statement(
sql = "SELECT TT.personID, TT.epersonID, SUM(TT.expenses) expenses, SUM(TT.paid) paid, (SUM(TT.paid)-SUM(TT.expenses)) balance "
+ "FROM ("
+ " SELECT ALL EP.personID, EP.epersonID, IF(EB.projectedValue IS NULL, 0, EB.projectedValue) expenses, 0 paid "
+ " FROM ~g~.Event E "
+ " INNER JOIN ~g~.EventPerson EP ON (E.eventID=EP.eventID) "
+ " INNER JOIN ~g~.EventBudget EB ON (EP.eventID=EB.eventID) "
+ " WHERE E.seriesID=? AND E.eventID<>? AND E.liveline<? "
+ " UNION ALL "
+ " SELECT ALL EP.personID, EP.epersonID, EO.amount expenses, 0 paid "
+ " FROM ~g~.Event E "
+ " INNER JOIN ~g~.EventPerson EP ON (E.eventID=EP.eventID) "
+ " INNER JOIN ~g~.EventPersonOption EPO ON (EP.epersonID=EPO.epersonID) "
+ " INNER JOIN ~g~.EventOption EO ON (EPO.optionID=EO.optionID) "
+ " WHERE E.seriesID=? AND E.eventID<>? AND E.liveline<? AND EPO.answer='Y' AND EO.amount IS NOT NULL AND EO.waive IS FALSE "
+ " UNION ALL "
+ " SELECT ALL EP.personID, EP.epersonID, EO.amount expenses, 0 paid "
+ " FROM ~g~.Event E "
+ " INNER JOIN ~g~.EventPerson EP ON (E.eventID=EP.eventID) "
+ " INNER JOIN ~g~.EventPersonOption EPO ON (EP.epersonID=EPO.epersonID) "
+ " INNER JOIN ~g~.EventOption EO ON (EPO.optionID=EO.optionID) "
+ " WHERE E.seriesID=? AND E.eventID<>? AND E.liveline<? AND EPO.itemID IS NOT NULL "
+ " AND (EO.multiple IS FALSE OR EO.funded='option' OR EO.static IS NOT NULL) "
+ " AND EO.amount IS NOT NULL AND EO.waive IS FALSE "
+ " UNION ALL "
+ " SELECT ALL EP.personID, EP.epersonID, EOI.amount expenses, 0 paid "
+ " FROM ~g~.Event E "
+ " INNER JOIN ~g~.EventPerson EP ON (E.eventID=EP.eventID) "
+ " INNER JOIN ~g~.EventPersonOption EPO ON (EP.epersonID=EPO.epersonID) "
+ " INNER JOIN ~g~.EventOption EO ON (EPO.optionID=EO.optionID) "
+ " INNER JOIN ~g~.EventOptionItem EOI ON (EPO.itemID=EOI.itemID) "
+ " WHERE E.seriesID=? AND E.eventID<>? AND E.liveline<? AND EO.waive IS FALSE AND EO.funded='selection' AND EOI.amount IS NOT NULL "
+ " UNION ALL "
+ " SELECT ALL EPP.personID, EP.epersonID, 0 expenses, EPP.amount paid "
+ " FROM ~g~.Event E "
+ " INNER JOIN ~g~.EventPersonPayment EPP ON (E.eventID=EPP.eventID) "
+ " LEFT JOIN ~g~.EventPerson EP ON (EPP.eventID=EP.eventID AND EPP.personID=EP.personID) "
+ " WHERE E.seriesID=? AND E.eventID<>? AND E.liveline<?) TT "
+ "GROUP BY TT.personID"
)
private StatementProvider sqlSelectSeriesBalances;
@Inject
@NonTransactionalProvider
@GolfProvider
@Statement(
sql = "SELECT TT.eventID, TT.epersonID, SUM(TT.expenses) expenses, SUM(TT.paid) paid, (SUM(TT.paid)-SUM(TT.expenses)) balance "
+ "FROM ("
+ " SELECT ALL E.eventID, EP.epersonID, IF(EB.projectedValue IS NULL, 0, EB.projectedValue) expenses, 0 paid "
+ " FROM ~g~.Event E "
+ " INNER JOIN ~g~.EventPerson EP ON (E.eventID=EP.eventID) "
+ " INNER JOIN ~g~.EventBudget EB ON (EP.eventID=EB.eventID) "
+ " WHERE E.seriesID=? AND E.eventID<>? AND E.liveline<? AND EP.personID=? "
+ " UNION ALL "
+ " SELECT ALL E.eventID, EP.epersonID, EO.amount expenses, 0 paid "
+ " FROM ~g~.Event E "
+ " INNER JOIN ~g~.EventPerson EP ON (E.eventID=EP.eventID) "
+ " INNER JOIN ~g~.EventPersonOption EPO ON (EP.epersonID=EPO.epersonID) "
+ " INNER JOIN ~g~.EventOption EO ON (EPO.optionID=EO.optionID) "
+ " WHERE E.seriesID=? AND E.eventID<>? AND E.liveline<? AND EP.personID=? "
+ " AND EPO.answer='Y' AND EO.amount IS NOT NULL AND EO.waive IS FALSE "
+ " UNION ALL "
+ " SELECT ALL E.eventID, EP.epersonID, EO.amount expenses, 0 paid "
+ " FROM ~g~.Event E "
+ " INNER JOIN ~g~.EventPerson EP ON (E.eventID=EP.eventID) "
+ " INNER JOIN ~g~.EventPersonOption EPO ON (EP.epersonID=EPO.epersonID) "
+ " INNER JOIN ~g~.EventOption EO ON (EPO.optionID=EO.optionID) "
+ " WHERE E.seriesID=? AND E.eventID<>? AND E.liveline<? AND EP.personID=? AND EPO.itemID IS NOT NULL "
+ " AND (EO.multiple IS FALSE OR EO.funded='option' OR EO.static IS NOT NULL) "
+ " AND EO.amount IS NOT NULL AND EO.waive IS FALSE "
+ " UNION ALL "
+ " SELECT ALL E.eventID, EP.epersonID, EOI.amount expenses, 0 paid "
+ " FROM ~g~.Event E "
+ " INNER JOIN ~g~.EventPerson EP ON (E.eventID=EP.eventID) "
+ " INNER JOIN ~g~.EventPersonOption EPO ON (EP.epersonID=EPO.epersonID) "
+ " INNER JOIN ~g~.EventOption EO ON (EPO.optionID=EO.optionID) "
+ " INNER JOIN ~g~.EventOptionItem EOI ON (EPO.itemID=EOI.itemID) "
+ " WHERE E.seriesID=? AND E.eventID<>? AND E.liveline<? AND EP.personID=? "
+ " AND EO.waive IS FALSE AND EO.funded='selection' AND EOI.amount IS NOT NULL "
+ " UNION ALL "
+ " SELECT ALL E.eventID, EP.epersonID, 0 expenses, EPP.amount paid "
+ " FROM ~g~.Event E "
+ " INNER JOIN ~g~.EventPersonPayment EPP ON (E.eventID=EPP.eventID) "
+ " LEFT JOIN ~g~.EventPerson EP ON (EPP.eventID=EP.eventID AND EPP.personID=EP.personID) "
+ " WHERE E.seriesID=? AND E.eventID<>? AND E.liveline<? AND EPP.personID=?) TT "
+ "GROUP BY TT.eventID"
)
private StatementProvider sqlSelectSeriesPersonEventBalances;
@Inject
@NonTransactionalProvider
@GolfProvider
@Statement(
sql = "SELECT TT.eventID, TT.epersonID, SUM(TT.expenses) expenses, SUM(TT.paid) paid, (SUM(TT.paid)-SUM(TT.expenses)) balance "
+ "FROM ("
+ " SELECT ALL E.eventID, EP.epersonID, IF(EB.projectedValue IS NULL, 0, EB.projectedValue) expenses, 0 paid "
+ " FROM ~g~.Event E "
+ " INNER JOIN ~g~.EventPerson EP ON (E.eventID=EP.eventID) "
+ " INNER JOIN ~g~.EventBudget EB ON (EP.eventID=EB.eventID) "
+ " WHERE E.seriesID=? AND E.eventID<>? AND E.liveline<? AND EP.personID=? "
+ " UNION ALL "
+ " SELECT ALL E.eventID, EP.epersonID, EO.amount expenses, 0 paid "
+ " FROM ~g~.Event E "
+ " INNER JOIN ~g~.EventPerson EP ON (E.eventID=EP.eventID) "
+ " INNER JOIN ~g~.EventPersonOption EPO ON (EP.epersonID=EPO.epersonID) "
+ " INNER JOIN ~g~.EventOption EO ON (EPO.optionID=EO.optionID) "
+ " WHERE E.seriesID=? AND E.eventID<>? AND E.liveline<? AND EP.personID=? "
+ " AND EPO.answer='Y' AND EO.amount IS NOT NULL AND EO.waive IS FALSE "
+ " UNION ALL "
+ " SELECT ALL E.eventID, EP.epersonID, EO.amount expenses, 0 paid "
+ " FROM ~g~.Event E "
+ " INNER JOIN ~g~.EventPerson EP ON (E.eventID=EP.eventID) "
+ " INNER JOIN ~g~.EventPersonOption EPO ON (EP.epersonID=EPO.epersonID) "
+ " INNER JOIN ~g~.EventOption EO ON (EPO.optionID=EO.optionID) "
+ " WHERE E.seriesID=? AND E.eventID<>? AND E.liveline<? AND EP.personID=? AND EPO.itemID IS NOT NULL "
+ " AND (EO.multiple IS FALSE OR EO.funded='option' OR EO.static IS NOT NULL) "
+ " AND EO.amount IS NOT NULL AND EO.waive IS FALSE "
+ " UNION ALL "
+ " SELECT ALL E.eventID, EP.epersonID, EOI.amount expenses, 0 paid "
+ " FROM ~g~.Event E "
+ " INNER JOIN ~g~.EventPerson EP ON (E.eventID=EP.eventID) "
+ " INNER JOIN ~g~.EventPersonOption EPO ON (EP.epersonID=EPO.epersonID) "
+ " INNER JOIN ~g~.EventOption EO ON (EPO.optionID=EO.optionID) "
+ " INNER JOIN ~g~.EventOptionItem EOI ON (EPO.itemID=EOI.itemID) "
+ " WHERE E.seriesID=? AND E.eventID<>? AND E.liveline<? AND EP.personID=? "
+ " AND EO.waive IS FALSE AND EO.funded='selection' AND EOI.amount IS NOT NULL "
+ " UNION ALL "
+ " SELECT ALL E.eventID, EP.epersonID, 0 expenses, EPP.amount paid "
+ " FROM ~g~.Event E "
+ " INNER JOIN ~g~.EventPersonPayment EPP ON (E.eventID=EPP.eventID) "
+ " LEFT JOIN ~g~.EventPerson EP ON (EPP.eventID=EP.eventID AND EPP.personID=EP.personID) "
+ " WHERE E.seriesID=? AND E.eventID<>? AND E.liveline<? AND EPP.personID=?) TT "
+ "GROUP BY TT.eventID"
)
private StatementProvider sqlSelectSeriesPersonEventBalances;
}

View File

@@ -1,14 +1,5 @@
package com.poststats.golf.service.db;
import java.math.BigInteger;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.brianlong.sql.DataSet;
import com.brianlong.sql.FlexPreparedStatement;
import com.brianlong.util.FlexMap;
@@ -21,16 +12,23 @@ import com.poststats.provider.StatementProvider;
import com.poststats.service.ServiceException;
import com.poststats.service.db.CacheableServiceDAO;
import com.poststats.util.Contact;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.mail.MessagingException;
import java.math.BigInteger;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ApplicationScoped
public class EventPersonServiceDAO extends CacheableServiceDAO<BigInteger> implements EventPersonService {
@Inject
private EventFinanceService eventFinanceService;
@Inject
private EventFinanceService eventFinanceService;
@Override
public FlexMap get(long eventId, long personId) {
@@ -185,173 +183,188 @@ public class EventPersonServiceDAO extends CacheableServiceDAO<BigInteger> imple
+ "WHERE ECL.eventID=? AND ECL.listID=? "
)
private StatementProvider sqlSelectByListId;
public List<? extends FlexMap> getByAutolist(long eventId, String autolist) {
switch (autolist) {
case "balance":
Map<Long, DataSet> balances = this.eventFinanceService.getPersonsBalances(eventId, null, -0.01f);
return new ArrayList<>(balances.values());
default:
}
StatementProvider statementProvider = this.getStatementProviderByAutolist(autolist);
try {
FlexPreparedStatement fps = this.getStatementByAutolist(statementProvider, eventId, autolist);
try {
return fps.executeQuery().getAllRows();
} finally {
fps.close();
}
} catch (SQLException se) {
throw new ServiceException(se);
}
}
private StatementProvider getStatementProviderByAutolist(String autolist) {
switch (autolist) {
case "all":
return this.sqlSelectEventAllIds;
case "signed":
return this.sqlSelectEventParticipantIds;
case "unsigned":
return this.sqlSelectEventRumormillIds;
case "rookies":
return this.sqlSelectEventRookieIds;
case "rookies-refs":
return this.sqlSelectEventRookieReferralIds;
case "options":
return this.sqlSelectEventParticipantIdsWithUnansweredOptions;
default:
}
public List<? extends FlexMap> getByAutolist(long eventId, String autolist) {
switch (autolist) {
case "balance":
Map<Long, DataSet> balances = this.eventFinanceService.getPersonsBalances(eventId, null, -0.01f);
return new ArrayList<>(balances.values());
default:
}
if (autolist.startsWith("previous")) {
if (autolist.length() > "previous".length()) {
return this.sqlSelectRecentSeriesParticipantIds;
} else {
return this.sqlSelectSeriesParticipantIds;
}
} else {
throw new IllegalArgumentException();
}
}
StatementProvider statementProvider = this.getStatementProviderByAutolist(autolist);
try {
FlexPreparedStatement fps = this.getStatementByAutolist(statementProvider, eventId, autolist);
try {
return fps.executeQuery().getAllRows();
} finally {
fps.close();
}
} catch (SQLException se) {
throw new ServiceException(se);
}
}
private FlexPreparedStatement getStatementByAutolist(StatementProvider statementProvider, long eventId, String autolist) throws SQLException {
int weeks = -1;
if (autolist.startsWith("previous") && autolist.length() > "previous".length())
weeks = Integer.parseInt(autolist.substring("previous".length() + 1));
private StatementProvider getStatementProviderByAutolist(String autolist) {
switch (autolist) {
case "all":
return this.sqlSelectEventAllIds;
case "signed":
return this.sqlSelectEventParticipantIds;
case "unsigned":
return this.sqlSelectEventRumormillIds;
case "rookies":
return this.sqlSelectEventRookieIds;
case "rookies-refs":
return this.sqlSelectEventRookieReferralIds;
case "options":
return this.sqlSelectEventParticipantIdsWithUnansweredOptions;
default:
}
FlexPreparedStatement fps = statementProvider.buildPreparedStatement();
try {
int c = 1;
fps.setIntegerU(c++, eventId);
if (weeks >= 0) {
fps.setIntegerU(c++, eventId);
fps.setSmallintU(c++, weeks);
fps.setSmallintU(c++, weeks);
}
if (autolist.equals("all") || autolist.equals("rookies-refs") || autolist.startsWith("previous")) {
fps.setIntegerU(c++, eventId);
}
return fps;
} catch (SQLException se) {
fps.close();
throw se;
}
}
if (autolist.startsWith("previous")) {
if (autolist.length() > "previous".length()) {
return this.sqlSelectRecentSeriesParticipantIds;
} else {
return this.sqlSelectSeriesParticipantIds;
}
} else {
throw new IllegalArgumentException();
}
}
@Inject
@NonTransactionalProvider
@GolfProvider
@Statement(sql = "SELECT personID, epersonID FROM ~g~.EventPerson WHERE eventID=?")
private StatementProvider sqlSelectEventParticipantIds;
private FlexPreparedStatement getStatementByAutolist(StatementProvider statementProvider, long eventId,
String autolist) throws SQLException {
int weeks = -1;
if (autolist.startsWith("previous") && autolist.length() > "previous".length())
weeks = Integer.parseInt(autolist.substring("previous".length() + 1));
@Inject
@NonTransactionalProvider
@GolfProvider
@Statement(sql = "SELECT personID, NULL epersonID FROM ~g~.EventPersonContract WHERE eventID=?")
private StatementProvider sqlSelectEventRumormillIds;
FlexPreparedStatement fps = statementProvider.buildPreparedStatement();
try {
int c = 1;
fps.setIntegerU(c++, eventId);
if (weeks >= 0) {
fps.setIntegerU(c++, eventId);
fps.setSmallintU(c++, weeks);
fps.setSmallintU(c++, weeks);
}
if (autolist.equals("all") || autolist.equals("rookies-refs") || autolist.startsWith("previous")) {
fps.setIntegerU(c++, eventId);
}
@Inject
@NonTransactionalProvider
@GolfProvider
@Statement(sql = "SELECT personID, epersonID FROM ~g~.EventPerson WHERE eventID=? "
+ "UNION "
+ "SELECT personID, NULL epersonID FROM ~g~.EventPersonContract WHERE eventID=? ")
private StatementProvider sqlSelectEventAllIds;
return fps;
} catch (SQLException se) {
fps.close();
throw se;
}
}
@Inject
@NonTransactionalProvider
@GolfProvider
@Statement(sql = "SELECT DISTINCT EP.personID, EP.epersonID "
+ "FROM ~g~.EventPerson EP "
+ " LEFT JOIN ~g~.EventPerson EP2 ON (EP.eventID<>EP2.eventID AND EP.personID=EP2.personID) "
+ "WHERE EP.eventID=? AND EP2.epersonID IS NULL")
private StatementProvider sqlSelectEventRookieIds;
@Inject
@NonTransactionalProvider
@GolfProvider
@Statement(sql = "SELECT personID, epersonID FROM ~g~.EventPerson WHERE eventID=?")
private StatementProvider sqlSelectEventParticipantIds;
@Inject
@NonTransactionalProvider
@GolfProvider
@Statement(sql = "SELECT DISTINCT EP.personID "
+ "FROM ~g~.EventPerson EP "
+ " LEFT JOIN ~g~.EventPerson EP2 ON (EP.eventID<>EP2.eventID AND EP.personID=EP2.personID) "
+ "WHERE EP.eventID=? AND EP2.epersonID IS NULL "
+ "UNION "
+ "SELECT DISTINCT P.referralPersonID "
+ "FROM ~g~.EventPerson EP "
+ " LEFT JOIN ~g~.EventPerson EP2 ON (EP.eventID<>EP2.eventID AND EP.personID=EP2.personID) "
+ " INNER JOIN ~p~.Person P ON (EP.personID=P.personID) "
+ "WHERE EP.eventID=? AND EP2.epersonID IS NULL AND P.referralPersonID IS NOT NULL")
private StatementProvider sqlSelectEventRookieReferralIds;
@Inject
@NonTransactionalProvider
@GolfProvider
@Statement(sql = "SELECT personID, NULL epersonID FROM ~g~.EventPersonContract WHERE eventID=?")
private StatementProvider sqlSelectEventRumormillIds;
@Inject
@NonTransactionalProvider
@GolfProvider
@Statement(sql = "SELECT EP.personID, EP.epersonID "
+ "FROM ~g~.EventPerson EP "
+ " INNER JOIN ?TT? TT1 ON (EP.personID=TT1.personID) "
+ "WHERE EP.eventID=? "
+ "GROUP BY EP.personID HAVING SUM(TT1.balance) < 0 ")
private StatementProvider sqlSelectEventParticipantIdsWithBalance;
@Inject
@NonTransactionalProvider
@GolfProvider
@Statement(
sql = "SELECT personID, epersonID FROM ~g~.EventPerson WHERE eventID=? "
+ "UNION "
+ "SELECT personID, NULL epersonID FROM ~g~.EventPersonContract WHERE eventID=? "
)
private StatementProvider sqlSelectEventAllIds;
@Inject
@NonTransactionalProvider
@GolfProvider
@Statement(sql = "SELECT DISTINCT EP.personID, EP.epersonID "
+ "FROM ~g~.EventOption EO "
+ " INNER JOIN ~g~.EventPerson EP ON (EO.eventID=EP.eventID) "
+ " LEFT JOIN ~g~.EventPersonOption EPO ON (EO.optionID=EPO.optionID AND EP.epersonID=EPO.epersonID) "
+ "WHERE EO.eventID=? "
+ " AND (EO.liveline IS NULL OR EO.liveline<=CURRENT_DATE) "
+ " AND (EO.deadline IS NULL OR EO.deadline>=CURRENT_DATE) "
+ " AND EPO.optionID IS NULL ")
private StatementProvider sqlSelectEventParticipantIdsWithUnansweredOptions;
@Inject
@NonTransactionalProvider
@GolfProvider
@Statement(
sql = "SELECT DISTINCT EP.personID, EP.epersonID "
+ "FROM ~g~.EventPerson EP "
+ " LEFT JOIN ~g~.EventPerson EP2 ON (EP.eventID<>EP2.eventID AND EP.personID=EP2.personID) "
+ "WHERE EP.eventID=? AND EP2.epersonID IS NULL"
)
private StatementProvider sqlSelectEventRookieIds;
@Inject
@NonTransactionalProvider
@GolfProvider
@Statement(sql = "SELECT DISTINCT EP.personID "
+ "FROM ~g~.Event E "
+ " INNER JOIN ~g~.Event E2 ON (E.seriesID=E2.seriesID) "
+ " INNER JOIN ~g~.EventPerson EP ON (E2.eventID=EP.eventID) "
+ "WHERE E.eventID=? AND E2.eventID<>? "
+ "UNION DISTINCT "
+ "SELECT personID FROM ~g~.EventPersonContract WHERE eventID=? ")
private StatementProvider sqlSelectSeriesParticipantIds;
@Inject
@NonTransactionalProvider
@GolfProvider
@Statement(
sql = "SELECT DISTINCT EP.personID "
+ "FROM ~g~.EventPerson EP "
+ " LEFT JOIN ~g~.EventPerson EP2 ON (EP.eventID<>EP2.eventID AND EP.personID=EP2.personID) "
+ "WHERE EP.eventID=? AND EP2.epersonID IS NULL "
+ "UNION "
+ "SELECT DISTINCT P.referralPersonID "
+ "FROM ~g~.EventPerson EP "
+ " LEFT JOIN ~g~.EventPerson EP2 ON (EP.eventID<>EP2.eventID AND EP.personID=EP2.personID) "
+ " INNER JOIN ~p~.Person P ON (EP.personID=P.personID) "
+ "WHERE EP.eventID=? AND EP2.epersonID IS NULL AND P.referralPersonID IS NOT NULL"
)
private StatementProvider sqlSelectEventRookieReferralIds;
@Inject
@NonTransactionalProvider
@GolfProvider
@Statement(sql = "SELECT DISTINCT EP.personID "
+ "FROM ~g~.Event E "
+ " INNER JOIN ~g~.Event E2 ON (E.seriesID=E2.seriesID) "
+ " INNER JOIN ~g~.EventPerson EP ON (E2.eventID=EP.eventID) "
+ "WHERE E.eventID=? AND E2.eventID<>? "
+ " AND ((E2.deadline IS NOT NULL AND DATE_ADD(E2.deadline, INTERVAL ? WEEK)>=CURRENT_DATE) "
+ " OR (E2.liveline IS NOT NULL AND DATE_ADD(E2.liveline, INTERVAL ? WEEK)>=CURRENT_DATE)) "
+ "UNION DISTINCT "
+ "SELECT personID FROM ~g~.EventPersonContract WHERE eventID=? ")
private StatementProvider sqlSelectRecentSeriesParticipantIds;
@Inject
@NonTransactionalProvider
@GolfProvider
@Statement(
sql = "SELECT EP.personID, EP.epersonID "
+ "FROM ~g~.EventPerson EP "
+ " INNER JOIN ?TT? TT1 ON (EP.personID=TT1.personID) "
+ "WHERE EP.eventID=? "
+ "GROUP BY EP.personID HAVING SUM(TT1.balance) < 0 "
)
private StatementProvider sqlSelectEventParticipantIdsWithBalance;
@Inject
@NonTransactionalProvider
@GolfProvider
@Statement(
sql = "SELECT DISTINCT EP.personID, EP.epersonID "
+ "FROM ~g~.EventOption EO "
+ " INNER JOIN ~g~.EventPerson EP ON (EO.eventID=EP.eventID) "
+ " LEFT JOIN ~g~.EventPersonOption EPO ON (EO.optionID=EPO.optionID AND EP.epersonID=EPO.epersonID) "
+ "WHERE EO.eventID=? "
+ " AND (EO.liveline IS NULL OR EO.liveline<=CURRENT_DATE) "
+ " AND (EO.deadline IS NULL OR EO.deadline>=CURRENT_DATE) "
+ " AND EPO.optionID IS NULL "
)
private StatementProvider sqlSelectEventParticipantIdsWithUnansweredOptions;
@Inject
@NonTransactionalProvider
@GolfProvider
@Statement(
sql = "SELECT DISTINCT EP.personID "
+ "FROM ~g~.Event E "
+ " INNER JOIN ~g~.Event E2 ON (E.seriesID=E2.seriesID) "
+ " INNER JOIN ~g~.EventPerson EP ON (E2.eventID=EP.eventID) "
+ "WHERE E.eventID=? AND E2.eventID<>? "
+ "UNION DISTINCT "
+ "SELECT personID FROM ~g~.EventPersonContract WHERE eventID=? "
)
private StatementProvider sqlSelectSeriesParticipantIds;
@Inject
@NonTransactionalProvider
@GolfProvider
@Statement(
sql = "SELECT DISTINCT EP.personID "
+ "FROM ~g~.Event E "
+ " INNER JOIN ~g~.Event E2 ON (E.seriesID=E2.seriesID) "
+ " INNER JOIN ~g~.EventPerson EP ON (E2.eventID=EP.eventID) "
+ "WHERE E.eventID=? AND E2.eventID<>? "
+ " AND ((E2.deadline IS NOT NULL AND DATE_ADD(E2.deadline, INTERVAL ? WEEK)>=CURRENT_DATE) "
+ " OR (E2.liveline IS NOT NULL AND DATE_ADD(E2.liveline, INTERVAL ? WEEK)>=CURRENT_DATE)) "
+ "UNION DISTINCT "
+ "SELECT personID FROM ~g~.EventPersonContract WHERE eventID=? "
)
private StatementProvider sqlSelectRecentSeriesParticipantIds;
@Override
protected DataSet fetchOne(BigInteger epersonId) throws SQLException {