From df52db18eb307709145bef8d95df2e9f3c68099a Mon Sep 17 00:00:00 2001 From: Himit_ZH <372347736@qq.com> Date: Sun, 28 Nov 2021 20:39:40 +0800 Subject: [PATCH] fix update problem bug --- .../hoj/service/problem/impl/ProblemServiceImpl.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/service/problem/impl/ProblemServiceImpl.java b/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/service/problem/impl/ProblemServiceImpl.java index 0e8a83d6..14caf0a5 100644 --- a/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/service/problem/impl/ProblemServiceImpl.java +++ b/hoj-springboot/DataBackup/src/main/java/top/hcode/hoj/service/problem/impl/ProblemServiceImpl.java @@ -98,15 +98,16 @@ public class ProblemServiceImpl extends ServiceImpl impl String problemId = problem.getProblemId().toUpperCase(); QueryWrapper problemQueryWrapper = new QueryWrapper<>(); problemQueryWrapper.eq("problem_id", problemId); - int existedProblem = problemMapper.selectCount(problemQueryWrapper); - - if (existedProblem > 0) { - throw new RuntimeException("The problem_id [" + problemId + "] already exists. Do not reuse it!"); - } + Problem existedProblem = problemMapper.selectOne(problemQueryWrapper); problem.setProblemId(problem.getProblemId().toUpperCase()); // 后面许多表的更新或删除需要用到题目id long pid = problemDto.getProblem().getId(); + + if (existedProblem != null && existedProblem.getId() != pid) { + throw new RuntimeException("The problem_id [" + problemId + "] already exists. Do not reuse it!"); + } + Map map = new HashMap<>(); map.put("pid", pid); //查询出原来题目的关联表数据