feat(solution): update solution fields
This commit is contained in:
parent
a27e311526
commit
d1d8566b98
5 changed files with 163 additions and 82 deletions
|
@ -317,44 +317,56 @@ func (r *ContestRepository) ListSolutions(ctx context.Context, filter models.Sol
|
|||
const op = "ContestRepository.ListSolutions"
|
||||
|
||||
baseQuery := `
|
||||
SELECT
|
||||
s.id,
|
||||
s.task_id,
|
||||
t.contest_id,
|
||||
s.participant_id,
|
||||
s.state,
|
||||
s.score,
|
||||
s.penalty,
|
||||
s.total_score,
|
||||
s.language,
|
||||
s.updated_at,
|
||||
s.created_at
|
||||
FROM solutions s
|
||||
LEFT JOIN tasks t ON s.task_id = t.id
|
||||
WHERE 1=1
|
||||
SELECT s.id,
|
||||
|
||||
s.participant_id,
|
||||
p2.name as participant_name,
|
||||
|
||||
s.state,
|
||||
s.score,
|
||||
s.penalty,
|
||||
s.time_stat,
|
||||
s.memory_stat,
|
||||
s.language,
|
||||
|
||||
s.task_id,
|
||||
t.position as task_position,
|
||||
p.title as task_title,
|
||||
|
||||
t.contest_id,
|
||||
c.title,
|
||||
|
||||
s.updated_at,
|
||||
s.created_at
|
||||
FROM solutions s
|
||||
LEFT JOIN tasks t ON s.task_id = t.id
|
||||
LEFT JOIN problems p ON t.problem_id = p.id
|
||||
LEFT JOIN contests c ON t.contest_id = c.id
|
||||
LEFT JOIN participants p2 on s.participant_id = p2.id
|
||||
WHERE 1=1
|
||||
`
|
||||
|
||||
var conditions []string
|
||||
var args []interface{}
|
||||
|
||||
if filter.ContestId != nil {
|
||||
conditions = append(conditions, "contest_id = ?")
|
||||
conditions = append(conditions, "s.contest_id = ?")
|
||||
args = append(args, *filter.ContestId)
|
||||
}
|
||||
if filter.ParticipantId != nil {
|
||||
conditions = append(conditions, "participant_id = ?")
|
||||
conditions = append(conditions, "s.participant_id = ?")
|
||||
args = append(args, *filter.ParticipantId)
|
||||
}
|
||||
if filter.TaskId != nil {
|
||||
conditions = append(conditions, "task_id = ?")
|
||||
conditions = append(conditions, "s.task_id = ?")
|
||||
args = append(args, *filter.TaskId)
|
||||
}
|
||||
if filter.Language != nil {
|
||||
conditions = append(conditions, "language = ?")
|
||||
conditions = append(conditions, "s.language = ?")
|
||||
args = append(args, *filter.Language)
|
||||
}
|
||||
if filter.State != nil {
|
||||
conditions = append(conditions, "state = ?")
|
||||
conditions = append(conditions, "s.state = ?")
|
||||
args = append(args, *filter.State)
|
||||
}
|
||||
|
||||
|
@ -462,42 +474,66 @@ ORDER BY t.position;
|
|||
|
||||
solutionsQuery = `
|
||||
WITH RankedSolutions AS (
|
||||
SELECT
|
||||
SELECT
|
||||
s.id,
|
||||
s.task_id,
|
||||
|
||||
s.participant_id,
|
||||
p2.name as participant_name,
|
||||
|
||||
s.state,
|
||||
s.score,
|
||||
s.penalty,
|
||||
s.total_score,
|
||||
s.time_stat,
|
||||
s.memory_stat,
|
||||
s.language,
|
||||
s.created_at,
|
||||
s.updated_at,
|
||||
|
||||
s.task_id,
|
||||
t.position as task_position,
|
||||
p.title as task_title,
|
||||
|
||||
t.contest_id,
|
||||
c.title as contest_title,
|
||||
|
||||
s.updated_at,
|
||||
s.created_at,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY s.participant_id, s.task_id
|
||||
ORDER BY
|
||||
PARTITION BY s.participant_id, s.task_id
|
||||
ORDER BY
|
||||
CASE WHEN s.state = 5 THEN 0 ELSE 1 END,
|
||||
s.created_at
|
||||
) as rn
|
||||
) as rn
|
||||
FROM solutions s
|
||||
JOIN tasks t ON s.task_id = t.id
|
||||
LEFT JOIN tasks t ON s.task_id = t.id
|
||||
LEFT JOIN problems p ON t.problem_id = p.id
|
||||
LEFT JOIN contests c ON t.contest_id = c.id
|
||||
LEFT JOIN participants p2 on s.participant_id = p2.id
|
||||
WHERE t.contest_id = ?
|
||||
)
|
||||
SELECT
|
||||
SELECT
|
||||
rs.id,
|
||||
rs.task_id,
|
||||
rs.contest_id,
|
||||
|
||||
rs.participant_id,
|
||||
rs.participant_name,
|
||||
|
||||
rs.state,
|
||||
rs.score,
|
||||
rs.penalty,
|
||||
rs.total_score,
|
||||
rs.time_stat,
|
||||
rs.memory_stat,
|
||||
rs.language,
|
||||
rs.created_at,
|
||||
rs.updated_at
|
||||
|
||||
rs.task_id,
|
||||
rs.task_position,
|
||||
rs.task_title,
|
||||
|
||||
rs.contest_id,
|
||||
rs.contest_title,
|
||||
|
||||
rs.updated_at,
|
||||
rs.created_at
|
||||
FROM RankedSolutions rs
|
||||
WHERE rs.rn = 1
|
||||
WHERE rs.rn = 1;
|
||||
|
||||
`
|
||||
|
||||
participantsQuery = `
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue