| | |
| | | // 保存题目信息 |
| | | // 设置题型 |
| | | question.setQuestionType(QuestionTypeEnum.get(excelQuestion.getQuestionType())); |
| | | // 答案去掉空格 |
| | | String rightAnswer = excelQuestion.getCorrect().replaceAll("\\s+", ""); |
| | | // 答案(多选需要用,分割保存字符串到数据库) |
| | | String[] corrects = excelQuestion.getCorrect().split(SPLIT); |
| | | String[] corrects = rightAnswer.split(SPLIT); |
| | | if (corrects.length > 1) { |
| | | question.setCorrect(Arrays.asList(corrects).stream().collect(Collectors.joining(","))); |
| | | } else { |
| | | question.setCorrect(excelQuestion.getCorrect()); |
| | | question.setCorrect(rightAnswer); |
| | | } |
| | | |
| | | // 难度 |
| | |
| | | questionSubjectService.saves(questionSubjectsList); |
| | | } |
| | | } else { |
| | | question.setId(questionId); |
| | | this.updateQuestion(question, excelQuestion); |
| | | List<String> subjectNames = Arrays.asList(excelQuestion.getSubjectName().split(SPLIT)); |
| | | List<Subject> subjects = subjectNames.stream().map(name -> { |
| | | // 判断课目是否存在于数据库,如果不存在则自动新增课目 |
| | |
| | | // 构建课目-题目信息 |
| | | questionSubjectsList = subjects.stream() |
| | | .filter(subject -> { |
| | | // 去重题目:题干+课目相同才算同一题 |
| | | // 去重题目:题干+课目相同才算同一题(题干相同:但有新增的课目时才做保存) |
| | | List<QuestionSubjectVO> lists = questionService.countQuestionByTitleAndSubject(excelQuestion.getTitle(), subject.getId()); |
| | | return 0 == lists.size(); |
| | | }) |
| | |
| | | return RestResponse.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 导入时,如果题干重复,那么更新题目信息(该方法不会更新题目的题库信息) |
| | | * |
| | | * @param question |
| | | * @param excelQuestion |
| | | */ |
| | | private void updateQuestion(Question question, QuestionImportVO excelQuestion) { |
| | | Question question1 = questionService.selectById(question.getId()); |
| | | // 该题的选项 |
| | | List<QuestionItemObject> options = new ArrayList<>(4); |
| | | // 选项内容 |
| | | QuestionItemObject optionA = new QuestionItemObject(); |
| | | optionA.setPrefix("A"); |
| | | optionA.setContent(excelQuestion.getOptionA()); |
| | | options.add(optionA); |
| | | |
| | | QuestionItemObject optionB = new QuestionItemObject(); |
| | | optionB.setPrefix("B"); |
| | | optionB.setContent(excelQuestion.getOptionB()); |
| | | options.add(optionB); |
| | | |
| | | if (StringUtils.isNotBlank(excelQuestion.getOptionC())) { |
| | | QuestionItemObject optionC = new QuestionItemObject(); |
| | | optionC.setPrefix("C"); |
| | | optionC.setContent(excelQuestion.getOptionC()); |
| | | options.add(optionC); |
| | | } |
| | | if (StringUtils.isNotBlank(excelQuestion.getOptionD())) { |
| | | QuestionItemObject optionD = new QuestionItemObject(); |
| | | optionD.setPrefix("D"); |
| | | optionD.setContent(excelQuestion.getOptionD()); |
| | | options.add(optionD); |
| | | } |
| | | |
| | | // 更新题目内容 |
| | | QuestionObject questionObject = new QuestionObject(); |
| | | questionObject.setQuestionItemObjects(options); |
| | | questionObject.setAnalyze(excelQuestion.getAnalyze()); |
| | | questionObject.setTitleContent(excelQuestion.getTitle()); |
| | | questionObject.setCorrect(excelQuestion.getCorrect()); |
| | | |
| | | TextContent textContent = new TextContent(); |
| | | textContent.setContent(JSON.toJSONString(questionObject)); |
| | | textContent.setCreateTime(new Date()); |
| | | textContent.setId(question1.getInfoTextContentId()); |
| | | textContentService.updateByIdFilter(textContent); |
| | | |
| | | // 保存题目信息 |
| | | // 设置题型 |
| | | question.setQuestionType(QuestionTypeEnum.get(excelQuestion.getQuestionType())); |
| | | // 答案去掉空格 |
| | | String rightAnswer = excelQuestion.getCorrect().replaceAll("\\s+", ""); |
| | | // 答案(多选需要用,分割保存字符串到数据库) |
| | | String[] corrects = rightAnswer.split(SPLIT); |
| | | if (corrects.length > 1) { |
| | | question.setCorrect(Arrays.asList(corrects).stream().collect(Collectors.joining(","))); |
| | | } else { |
| | | question.setCorrect(rightAnswer); |
| | | } |
| | | |
| | | // 难度 |
| | | question.setDifficult(excelQuestion.getDifficult()); |
| | | // 分数 |
| | | if (StringUtils.isBlank(excelQuestion.getScore())) { |
| | | question.setScore(ExamUtil.scoreFromVM(QuestionSourceEnum.fromType(question.getQuestionType()) + "")); |
| | | } else { |
| | | question.setScore(ExamUtil.scoreFromVM(String.valueOf(excelQuestion.getScore()))); |
| | | } |
| | | // 创建人 |
| | | question.setCreateUser(1); |
| | | question.setStatus(QuestionStatusEnum.OK.getCode()); |
| | | question.setCreateTime(new Date()); |
| | | question.setDeleted(Boolean.FALSE); |
| | | // question.setInfoTextContentId(textContent.getId()); |
| | | questionService.updateByIdFilter(question); |
| | | |
| | | } |
| | | |
| | | // @PostMapping("/import") |
| | | // public RestResponse importQuestion(@RequestPart("file") MultipartFile file) throws Exception { |
| | | // List<QuestionEditVO> questionEditVOS = ExcelUtils.readMultipartFile(file, QuestionEditVO.class) |