use of org.apache.ibatis.annotations.Param in project judge by zjnu-acm.
the class BestSubmissionsBuilder method bestSubmissions.
public static String bestSubmissions(@Param("form") BestSubmissionForm form, @Param("pageable") Pageable pageable) {
Long contestId = form.getContestId();
long problemId = form.getProblemId();
Set<String> dejaVu = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
Sort sort = Optional.ofNullable(pageable.getSort()).map(s -> s.and(DEFAULT_SORT)).orElse(DEFAULT_SORT);
Sort.Order[] orders = StreamSupport.stream(sort.spliterator(), false).filter(order -> ALLOW_COLUMNS.contains(order.getProperty()) && dejaVu.add(order.getProperty())).toArray(Sort.Order[]::new);
final int length = orders.length;
log.debug("{}", Arrays.asList(orders));
StringBuilder sb = new StringBuilder("select " + SubmissionMapper.LIST_COLUMNS + " from solution s where problem_id=").append(problemId).append(" and score=100 ");
if (contestId != null) {
sb.append("and contest_id=").append(contestId).append(' ');
}
for (int i = length - 1; i >= 0; --i) {
sb.append("and(user_id");
for (int j = 0; j <= i; ++j) {
sb.append(',').append(orders[j].getProperty());
}
sb.append(")in(select user_id");
for (int j = 0; j < i; ++j) {
sb.append(',').append(orders[j].getProperty());
}
sb.append(',').append(orders[i].isAscending() ? "min" : "max").append("(").append(orders[i].getProperty()).append(")").append(orders[i].getProperty()).append(" from solution where problem_id=").append(problemId).append(" and score=100 ");
if (contestId != null) {
sb.append("and contest_id=").append(contestId).append(' ');
}
}
for (int i = 0; i < length; ++i) {
sb.append("group by user_id)");
}
if (length > 0) {
sb.append(" order by ");
for (int i = 0; i < length; ++i) {
if (i > 0) {
sb.append(",");
}
sb.append(orders[i].getProperty());
if (!orders[i].isAscending()) {
sb.append(" desc");
}
}
}
return sb.append(" limit ").append(pageable.getOffset()).append(",").append(pageable.getPageSize()).toString();
}
Aggregations