From 84f6656e7d4d019ac66fdcf6b902f6a55a2195c8 Mon Sep 17 00:00:00 2001 From: Unique-Jerry <10902054+unique-jerry@user.noreply.gitee.com> Date: Tue, 24 Oct 2023 15:33:01 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=98=E7=9B=AE=E5=8A=9F=E8=83=BD=E5=AE=8C?= =?UTF-8?q?=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/QuestionController.java | 71 +++++++++++++++++ .../service/QuestionService.java | 31 ++++++++ .../service/impl/QuestionServiceImpl.java | 79 ++++++++++++++++++- 3 files changed, 180 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/yzdx/AiInterviewer/controller/QuestionController.java b/src/main/java/com/yzdx/AiInterviewer/controller/QuestionController.java index 5e91bde..7052969 100644 --- a/src/main/java/com/yzdx/AiInterviewer/controller/QuestionController.java +++ b/src/main/java/com/yzdx/AiInterviewer/controller/QuestionController.java @@ -127,7 +127,78 @@ public class QuestionController { List questionDtoList= questionService.getQuestionList(encoding); return R.success(questionDtoList); } + + + /** + * 添加题目 + * @param addQuestionInfo 添加题目信息 + * + * */ + @PostMapping("add_question") + public R addQuestion(@RequestBody Map addQuestionInfo){ + String title=(String)addQuestionInfo.get("title"); + Integer bankId=(Integer) addQuestionInfo.get("bankId"); + String details=(String)addQuestionInfo.get("details"); + String promote=(String)addQuestionInfo.get("promote"); + String encoding=(String)addQuestionInfo.get("encoding"); + Integer userId=(Integer) addQuestionInfo.get("userId"); + + Integer rows = questionService.addQuestion(title, bankId, details, promote, encoding, userId); + + if(rows==0){ + return R.error("添加失败,请检查输入!"); + } + if(rows==-2){ + return R.error("题目标题已存在,请检查是否要添加该题目"); + } + return R.success("添加成功!"); + } + + /** + * 修改题目 + * @param addQuestionInfo 修改题目信息 + * + * */ + @PostMapping("update_question") + public R updateQuestion(@RequestBody Map addQuestionInfo){ + Integer id=(Integer) addQuestionInfo.get("id"); + String title=(String)addQuestionInfo.get("title"); + Integer bankId=(Integer) addQuestionInfo.get("bankId"); + String details=(String)addQuestionInfo.get("details"); + String promote=(String)addQuestionInfo.get("promote"); + String encoding=(String)addQuestionInfo.get("encoding"); + Integer userId=(Integer) addQuestionInfo.get("userId"); + + Integer rows = questionService.updateQuestion(id,title, bankId, details, promote, encoding, userId); + + if(rows==0){ + return R.error("修改失败,请检查输入!"); + } + if(rows==-2){ + return R.error("题目标题已存在,请检查是否要修改该题目"); + } + return R.success("修改成功!"); + } + + /** + *删除题目 + * @param id 删除题目的id + * */ + @GetMapping("/del_question") + public R deleteQuestion(Integer id){ + + Integer rows=questionService.deleteQuestion(id); + + if(rows==-2||rows==0){ + return R.error("删除失败,请联系管理员"); + } + return R.success("删除成功!"); + } + + + } + diff --git a/src/main/java/com/yzdx/AiInterviewer/service/QuestionService.java b/src/main/java/com/yzdx/AiInterviewer/service/QuestionService.java index fe0b597..1f6e86c 100644 --- a/src/main/java/com/yzdx/AiInterviewer/service/QuestionService.java +++ b/src/main/java/com/yzdx/AiInterviewer/service/QuestionService.java @@ -14,4 +14,35 @@ public interface QuestionService extends IService { * @return 题目列表 * */ List getQuestionList(String encoding); + + /** + * 增加题目 + * @param encoding 公司编码 + * @param bankId 题库类型id + * @param details 题目详情 + * @param promote 题目promote + * @param title 题目标题 + * @param userId 用户id + * @return 改变的行数 + * */ + Integer addQuestion(String title,Integer bankId,String details,String promote,String encoding,Integer userId); + /** + * 修改题目 + * @param id 题目ID + * @param encoding 公司编码 + * @param bankId 题库类型id + * @param details 题目详情 + * @param promote 题目promote + * @param title 题目标题 + * @param userId 用户id + * @return 改变的行数 + * */ + Integer updateQuestion(Integer id,String title,Integer bankId,String details,String promote,String encoding,Integer userId); + + /** + * 删除题目 + * @param id 删除题目的id + * @return 改变的行数 + * */ + Integer deleteQuestion(Integer id); } diff --git a/src/main/java/com/yzdx/AiInterviewer/service/impl/QuestionServiceImpl.java b/src/main/java/com/yzdx/AiInterviewer/service/impl/QuestionServiceImpl.java index ce08a93..8baa8d1 100644 --- a/src/main/java/com/yzdx/AiInterviewer/service/impl/QuestionServiceImpl.java +++ b/src/main/java/com/yzdx/AiInterviewer/service/impl/QuestionServiceImpl.java @@ -10,6 +10,7 @@ import com.yzdx.AiInterviewer.mapper.QuestionBankMapper; import com.yzdx.AiInterviewer.mapper.QuestionMapper; import com.yzdx.AiInterviewer.mapper.UserMapper; import com.yzdx.AiInterviewer.service.QuestionService; +import com.yzdx.AiInterviewer.utiles.TimeUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -37,12 +38,13 @@ public class QuestionServiceImpl extends ServiceImpl i List questionDtoList =new ArrayList<>(); - QuestionDto questionDto=new QuestionDto(); + QuestionBank findQuestionBank=new QuestionBank(); for (Question question:questionList) { + QuestionDto questionDto=new QuestionDto(); questionDto.setId(question.getId()); questionDto.setTitle(question.getTitle()); questionDto.setDetails(question.getDetails()); @@ -80,4 +82,79 @@ public class QuestionServiceImpl extends ServiceImpl i return questionDtoList; } + + @Override + public Integer addQuestion(String title, Integer bankId, String details, String promote, String encoding, Integer userId) { + //判断题目标题是否重复 + Question question=new Question(); + question.setTitle(title); + question.setBankId(bankId); + question.setDetails(details); + question.setPromote(promote); + question.setCompanyEncoding(encoding); + question.setCreateUser(userId); + question.setCreateTime(TimeUtil.getTime()); + question.setUpdateTime(TimeUtil.getTime()); + question.setUpdateUser(userId); + + LambdaQueryWrapper questionLambdaQueryWrapper=new LambdaQueryWrapper<>(); + + questionLambdaQueryWrapper + .eq(Question::getTitle,question.getTitle()) + .eq(Question::getBankId,question.getBankId()) + .eq(Question::getCompanyEncoding,question.getCompanyEncoding()); + + Question selectQuestion = questionMapper.selectOne(questionLambdaQueryWrapper); + + if(selectQuestion!=null){ + return -2; + } + + Integer rows = questionMapper.insert(question); + + return rows; + } + + @Override + public Integer updateQuestion(Integer id,String title, Integer bankId, String details, String promote, String encoding, Integer userId) { + //判断题目标题是否重复 + Question question=new Question(); + question.setId(id); + question.setTitle(title); + question.setBankId(bankId); + question.setDetails(details); + question.setPromote(promote); + question.setCompanyEncoding(encoding); + question.setUpdateTime(TimeUtil.getTime()); + question.setUpdateUser(userId); + LambdaQueryWrapper questionLambdaQueryWrapper=new LambdaQueryWrapper<>(); + questionLambdaQueryWrapper + .eq(Question::getTitle,question.getTitle()) + .eq(Question::getBankId,question.getBankId()) + .eq(Question::getCompanyEncoding,question.getCompanyEncoding()); + + Question selectQuestion = questionMapper.selectOne(questionLambdaQueryWrapper); + + if(selectQuestion!=null){ + return -2; + } + Integer rows = questionMapper.updateById(question); + + return rows; + + } + + @Override + public Integer deleteQuestion(Integer id) { + + LambdaQueryWrapper queryWrapper=new LambdaQueryWrapper<>(); + + queryWrapper.eq(Question::getId,id); + + if(questionMapper.selectOne(queryWrapper)==null){ + return -2; + } + Integer rows = questionMapper.delete(queryWrapper); + return rows; + } }