Skip to content

Commit

Permalink
fix: solution achievement multi results logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamerblue committed Nov 9, 2024
1 parent 0e61df3 commit 23e4ced
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions src/app/solution/solution.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1897,7 +1897,7 @@ export default class SolutionService {
},
);
}
if (redundant.userId) {
if (redundant.userId && redundant.problemId) {
// 更新用户成就
switch (result) {
case ESolutionResult.AC: {
Expand Down Expand Up @@ -1979,6 +1979,37 @@ export default class SolutionService {
);
}
}

// 不同提交结果数量
const uniqResultsRes = await this.model.findAll({
attributes: [[sequelizeFn('DISTINCT', sequelizeCol('result')), 'result']],
where: {
userId: redundant.userId,
problemId: redundant.problemId,
},
});
const uniqResults = uniqResultsRes
.map((d: any) => d.result)
.filter(
(r) =>
![
ESolutionResult.WT,
ESolutionResult.JG,
ESolutionResult.RPD,
ESolutionResult.CNL,
ESolutionResult.SE,
].includes(r),
);
if (uniqResults.length >= 5) {
this.userAchievementService.addUserAchievementAndPush(
redundant.userId,
EAchievementKey.SolveWithMultiResults,
);
}
} else {
this.ctx.logger.warn(
`[updateJudgeFinish] redundant data incomplete. judgeInfoId: ${judgeInfoId}, solutionId: ${solutionId}, judgerId: ${judgerId}`,
);
}

// 设置异步定时任务来更新计数
Expand Down Expand Up @@ -2205,15 +2236,9 @@ export default class SolutionService {
ESolutionResult.JG,
ESolutionResult.RPD,
ESolutionResult.CNL,
ESolutionResult.SE,
].includes(s.result),
);
const results = new Set(allSolutionsOfProblem.map((d) => d.result));
if (results.size >= 5) {
this.userAchievementService.addUserAchievementAndPush(
userId,
EAchievementKey.SolveWithMultiResults,
);
}
let solutionCountBeforeAC = 0;
for (const { result } of allSolutionsOfProblem) {
if (result === ESolutionResult.AC) {
Expand Down

0 comments on commit 23e4ced

Please sign in to comment.