|
|
@@ -18,6 +18,7 @@ import space.anyi.serve.mapper.SubmissionMapper;
|
|
|
import space.anyi.serve.service.ContestService;
|
|
|
import space.anyi.serve.service.ProblemService;
|
|
|
import space.anyi.serve.service.UserService;
|
|
|
+import space.anyi.serve.util.SecurityUtils;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.List;
|
|
|
@@ -139,6 +140,7 @@ public class ContestServiceImpl extends ServiceImpl<ContestMapper, Contest> impl
|
|
|
if (contest == null) {
|
|
|
throw new IllegalArgumentException("比赛不存在");
|
|
|
}
|
|
|
+ assertNotStarted(contest);
|
|
|
contest.setTitle(dto.getTitle());
|
|
|
contest.setDescription(dto.getDescription());
|
|
|
contest.setType(dto.getType());
|
|
|
@@ -154,6 +156,19 @@ public class ContestServiceImpl extends ServiceImpl<ContestMapper, Contest> impl
|
|
|
if (ids == null || ids.isEmpty()) {
|
|
|
return false;
|
|
|
}
|
|
|
+ String role = SecurityUtils.getCurrentRole();
|
|
|
+ Long userId = SecurityUtils.getCurrentUserId();
|
|
|
+ if (User.ROLE_COACH.equals(role)) {
|
|
|
+ for (Long id : ids) {
|
|
|
+ Contest contest = getById(id);
|
|
|
+ if (contest == null) {
|
|
|
+ throw new IllegalArgumentException("比赛不存在");
|
|
|
+ }
|
|
|
+ if (!Objects.equals(contest.getCreatedBy(), userId)) {
|
|
|
+ throw new IllegalArgumentException("教练只能删除自己创建的比赛");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
contestProblemMapper.delete(new LambdaQueryWrapper<ContestProblem>()
|
|
|
.in(ContestProblem::getContestId, ids));
|
|
|
contestRegistrationMapper.delete(new LambdaQueryWrapper<ContestRegistration>()
|
|
|
@@ -167,6 +182,7 @@ public class ContestServiceImpl extends ServiceImpl<ContestMapper, Contest> impl
|
|
|
if (contest == null) {
|
|
|
throw new IllegalArgumentException("比赛不存在");
|
|
|
}
|
|
|
+ assertNotStarted(contest);
|
|
|
Problem problem = problemService.getById(dto.getProblemId());
|
|
|
if (problem == null) {
|
|
|
throw new IllegalArgumentException("题目不存在");
|
|
|
@@ -181,6 +197,11 @@ public class ContestServiceImpl extends ServiceImpl<ContestMapper, Contest> impl
|
|
|
|
|
|
@Override
|
|
|
public Boolean updateProblem(Long contestId, ContestProblemDto dto) {
|
|
|
+ Contest contest = getById(contestId);
|
|
|
+ if (contest == null) {
|
|
|
+ throw new IllegalArgumentException("比赛不存在");
|
|
|
+ }
|
|
|
+ assertNotStarted(contest);
|
|
|
ContestProblem contestProblem = new ContestProblem();
|
|
|
contestProblem.setContestId(contestId);
|
|
|
contestProblem.setProblemId(dto.getProblemId());
|
|
|
@@ -193,6 +214,11 @@ public class ContestServiceImpl extends ServiceImpl<ContestMapper, Contest> impl
|
|
|
|
|
|
@Override
|
|
|
public Boolean removeProblem(Long contestId, Long problemId) {
|
|
|
+ Contest contest = getById(contestId);
|
|
|
+ if (contest == null) {
|
|
|
+ throw new IllegalArgumentException("比赛不存在");
|
|
|
+ }
|
|
|
+ assertNotStarted(contest);
|
|
|
return contestProblemMapper.delete(new LambdaQueryWrapper<ContestProblem>()
|
|
|
.eq(ContestProblem::getContestId, contestId)
|
|
|
.eq(ContestProblem::getProblemId, problemId)) > 0;
|
|
|
@@ -246,4 +272,10 @@ public class ContestServiceImpl extends ServiceImpl<ContestMapper, Contest> impl
|
|
|
updateById(contest);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private void assertNotStarted(Contest contest) {
|
|
|
+ if (!Contest.STATUS_PENDING.equals(contest.getStatus())) {
|
|
|
+ throw new IllegalArgumentException("比赛已开始,无法修改");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|