diff --git a/src/main/java/club/joylink/rtss/controller/competition/question/QuestionBankController2.java b/src/main/java/club/joylink/rtss/controller/competition/question/QuestionBankController2.java new file mode 100644 index 000000000..72783c245 --- /dev/null +++ b/src/main/java/club/joylink/rtss/controller/competition/question/QuestionBankController2.java @@ -0,0 +1,120 @@ +package club.joylink.rtss.controller.competition.question; + + +import club.joylink.rtss.constants.Project; +import club.joylink.rtss.services.completition.question.IQuestionBankService; +import club.joylink.rtss.vo.AccountVO; +import club.joylink.rtss.vo.LoginUserInfoVO; +import club.joylink.rtss.vo.client.PageVO; +import club.joylink.rtss.vo.client.competition.TheoryQuestionCountVO; +import club.joylink.rtss.vo.client.question.QuestionOptionVO; +import club.joylink.rtss.vo.client.question.QuestionQueryVO; +import club.joylink.rtss.vo.client.question.QuestionVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + + +/** + *题库管理接口 + */ +@RestController +@RequestMapping(path = "/api/questionBank2") +public class QuestionBankController2 { + + @Autowired + private IQuestionBankService iQuestionBankService; + + /** + *分页查询题目 + */ + @GetMapping(path = "/questions/paging") + public PageVO pagingQueryQuestions(@RequestAttribute LoginUserInfoVO loginInfo, QuestionQueryVO queryVO) { + queryVO.setProjectCode(loginInfo.getProject().name()); + return iQuestionBankService.pagingQueryQuestions(queryVO); + } + + /** + *查询题目列表 + */ + @GetMapping(path = "/questions") + public List queryQuestions(@RequestAttribute LoginUserInfoVO loginInfo,QuestionQueryVO queryVO) { + queryVO.setProjectCode(loginInfo.getProject().name()); + return iQuestionBankService.queryQuestions(queryVO); + } + + /** + *获取题目信息 + */ + @GetMapping(path = "/questions/{questionId}") + public QuestionVO getQuestion(@PathVariable Long questionId) { + return iQuestionBankService.getQuestion(questionId); + } + + /** + *添加题目 + */ + @PostMapping(path = "/questions") + public void addQuestion(@Validated @RequestBody QuestionVO questionVO,@RequestAttribute LoginUserInfoVO loginInfo, + @RequestAttribute AccountVO user) { + questionVO.setProjectCode(loginInfo.getProject().name()); + iQuestionBankService.addQuestion(questionVO, user); + } + + /** + *导入项目或单位试题库 + */ + @PostMapping(path = "/questions/import") + public void importProjectQuestion(@Validated @RequestBody List questions, @RequestAttribute LoginUserInfoVO loginInfo, + @RequestAttribute AccountVO user, @RequestParam(required = false, name = "id") Long companyId) { + + iQuestionBankService.importProjectQuestion(questions, loginInfo.getProject().name(), companyId,user); + } + + /** + *更新题目 + */ + @PutMapping(path = "/questions/{questionId}") + public void updateQuestion(@PathVariable Long questionId, @RequestAttribute LoginUserInfoVO loginInfo,@RequestBody QuestionVO questionVO) { + questionVO.setProjectCode(loginInfo.getProject().name()); + iQuestionBankService.updateQuestion(questionId, questionVO); + } + + /** + *删除题目 + */ + @DeleteMapping(path = "/questions/{questionId}") + public void deleteQuestion(@PathVariable Long questionId) { + iQuestionBankService.deleteQuestion(questionId); + } + + /** + *根据题目查询选项 + */ + @GetMapping(path = "/questions/{questionId}/options") + public List getOptionsByQuestionId(@PathVariable Long questionId) { + return iQuestionBankService.getOptionsByQuestionId(questionId); + } + + /** + *根据题型获取题目数量 + */ + @GetMapping(path = "/number") + public Integer getNumberUnderKnowledgeAndType(@RequestAttribute LoginUserInfoVO loginInfo, String type, Long companyId) { + + return iQuestionBankService.getNumberWithType(type, loginInfo.getProject().name(), companyId); + } + + /** + *获取题型数量 + */ + @GetMapping(path = "/type/number") + public List getNumberUnderKnowledgeAndType(@RequestAttribute LoginUserInfoVO loginInfo, @RequestParam(required = false) Long companyId) { + + String projectCode = Project.isDefault(loginInfo.getProject()) ? null : loginInfo.getProject().name(); + return iQuestionBankService.countNumByType(projectCode, companyId); + } + +} diff --git a/src/main/java/club/joylink/rtss/services/completition/question/QuestionBankService.java b/src/main/java/club/joylink/rtss/services/completition/question/QuestionBankService.java index 8de1b1d51..2e9d3c4fc 100644 --- a/src/main/java/club/joylink/rtss/services/completition/question/QuestionBankService.java +++ b/src/main/java/club/joylink/rtss/services/completition/question/QuestionBankService.java @@ -151,13 +151,13 @@ public class QuestionBankService implements IQuestionBankService { @Transactional public void addQuestion(QuestionVO questionVO, AccountVO accountVO) { BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue( - (Objects.equals(BusinessConsts.TheoryType.select, questionVO.getType()) || - Objects.equals(BusinessConsts.TheoryType.judge, questionVO.getType())) && + (Objects.equals(BusinessConsts.TheoryType.select.name(), questionVO.getType()) || + Objects.equals(BusinessConsts.TheoryType.judge.name(), questionVO.getType())) && questionVO.getOptionList().stream().filter(QuestionOptionVO::getCorrect).count() == 1, "单选或判断题正确答案有且只有一个!"); - BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue( - (Objects.equals(BusinessConsts.TheoryType.fill, questionVO.getType()) || - Objects.equals(BusinessConsts.TheoryType.answer, questionVO.getType())) && + BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotTrue( + (Objects.equals(BusinessConsts.TheoryType.fill.name(), questionVO.getType()) || + Objects.equals(BusinessConsts.TheoryType.answer.name(), questionVO.getType())) && questionVO.getOptionList().stream().filter(op -> !op.getCorrect()).count() == 0, "填空或问答题不能有错误选项!"); RaceQuestion question = questionVO.convert2DB();