| | |
| | | package com.ycl.jxkg.service.impl; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.github.pagehelper.PageHelper; |
| | |
| | | import com.ycl.jxkg.context.WebContext; |
| | | import com.ycl.jxkg.domain.entity.ExamPaper; |
| | | import com.ycl.jxkg.domain.entity.Question; |
| | | import com.ycl.jxkg.domain.entity.Subject; |
| | | import com.ycl.jxkg.domain.exam.PaperFixQuestionDTO; |
| | | import com.ycl.jxkg.domain.exam.PaperQuestion; |
| | | import com.ycl.jxkg.domain.exam.PaperQuestionSettingDTO; |
| | | import com.ycl.jxkg.domain.exam.PaperSettingItem; |
| | | import com.ycl.jxkg.domain.form.ExamPaperForm; |
| | | import com.ycl.jxkg.domain.other.KeyValue; |
| | | import com.ycl.jxkg.domain.question.QuestionItemObject; |
| | | import com.ycl.jxkg.domain.question.QuestionObject; |
| | | import com.ycl.jxkg.domain.question.RandomQuestionDTO; |
| | | import com.ycl.jxkg.domain.vo.admin.exam.ExamPaperEditRequestVO; |
| | | import com.ycl.jxkg.domain.vo.admin.exam.ExamPaperPageRequestVO; |
| | | import com.ycl.jxkg.domain.vo.admin.exam.ExamPaperTitleItemVO; |
| | | import com.ycl.jxkg.domain.vo.admin.exam.ExamResponseVO; |
| | | import com.ycl.jxkg.domain.vo.admin.exam.*; |
| | | import com.ycl.jxkg.domain.vo.student.dashboard.PaperFilter; |
| | | import com.ycl.jxkg.domain.vo.student.dashboard.PaperInfo; |
| | | import com.ycl.jxkg.domain.vo.student.exam.ExamPaperPageVO; |
| | | import com.ycl.jxkg.enums.ExamPaperTypeEnum; |
| | | import com.ycl.jxkg.enums.QuestionTypeEnum; |
| | | import com.ycl.jxkg.enums.VisibilityEnum; |
| | | import com.ycl.jxkg.enums.general.StatusEnum; |
| | | import com.ycl.jxkg.excel.*; |
| | | import com.ycl.jxkg.mapper.ExamPaperMapper; |
| | | import com.ycl.jxkg.mapper.QuestionMapper; |
| | | import com.ycl.jxkg.service.ExamPaperService; |
| | |
| | | import com.ycl.jxkg.service.SubjectService; |
| | | import com.ycl.jxkg.service.TextContentService; |
| | | import com.ycl.jxkg.utils.DateTimeUtil; |
| | | import com.ycl.jxkg.utils.JsonUtil; |
| | | import com.ycl.jxkg.utils.PageInfoHelper; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.SneakyThrows; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.math.BigDecimal; |
| | | import java.net.URLEncoder; |
| | | import java.util.*; |
| | | import java.util.function.Consumer; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | |
| | | if (ExamPaperTypeEnum.Random.getCode().equals(form.getPaperType())) { |
| | | //校验题目数量 |
| | | List<PaperQuestionSettingDTO> questionSetting = form.getQuestionSetting(); |
| | | //题目配置里配的试卷类型 |
| | | List<Integer> types = questionSetting.stream().map(PaperQuestionSettingDTO::getQuestionType).collect(Collectors.toList()); |
| | | Map<Integer, List<Integer>> map = questionMapper.selectBySubject(form.getSubjectId(), types) |
| | | .stream().collect(Collectors.groupingBy(RandomQuestionDTO::getQuestionType, Collectors.mapping(RandomQuestionDTO::getQuestionId, Collectors.toList()))); |
| | | |
| | | for (PaperQuestionSettingDTO settingDTO : questionSetting) { |
| | | Integer num = settingDTO.getNum(); |
| | | Integer questionType = settingDTO.getQuestionType(); |
| | | //需要配置的题目数量为0则跳过 |
| | | if(num ==null || num ==0 )continue; |
| | | List<Integer> questions = map.get(questionType); |
| | | if(CollectionUtils.isEmpty(questions) || num > questions.size())return Result.fail(SystemCode.InnerError.getCode(), QuestionTypeEnum.fromCode(questionType).getName()+"题目数量不足"); |
| | | for (PaperSettingItem item : settingDTO.getSettingList()) { |
| | | Integer num = item.getNum(); |
| | | Integer difficult = item.getDifficult(); |
| | | //需要配置的题目数量为0则跳过 |
| | | if(num ==null || num ==0 )continue; |
| | | //前端默认数据为0,转换为null |
| | | if (0 == item.getDifficult()){ |
| | | difficult= null; |
| | | } |
| | | RandomQuestionDTO randomQuestionDTO = new RandomQuestionDTO(); |
| | | randomQuestionDTO.setQuestionType(questionType); |
| | | randomQuestionDTO.setSubjectId(item.getSubjectId()); |
| | | randomQuestionDTO.setDifficult(difficult); |
| | | Integer numInData = questionMapper.selectByDifAndSub(randomQuestionDTO); |
| | | if(num > numInData)return Result.fail(SystemCode.InnerError.getCode(), QuestionTypeEnum.fromCode(questionType).getName()+"难度为"+item.getDifficult()+"的题目数量不足"); |
| | | } |
| | | } |
| | | examPaper.setContent(JSON.toJSONString(form.getQuestionSetting())); |
| | | baseMapper.insert(examPaper); |
| | |
| | | return Result.ok(); |
| | | } else { |
| | | //随序试卷 |
| | | Integer subjectId = form.getSubjectId(); |
| | | //题目配置 |
| | | List<PaperQuestionSettingDTO> questionSetting = form.getQuestionSetting(); |
| | | //题目配置里配的试卷类型 |
| | | List<Integer> types = questionSetting.stream().map(PaperQuestionSettingDTO::getQuestionType).collect(Collectors.toList()); |
| | | if (CollectionUtils.isEmpty(types)) { |
| | | return Result.fail(SystemCode.InnerError.getCode(), "试卷题目类型不能为空"); |
| | | } |
| | | Map<Integer, List<Integer>> map = questionMapper.selectBySubject(subjectId, types) |
| | | .stream().collect(Collectors.groupingBy(RandomQuestionDTO::getQuestionType, Collectors.mapping(RandomQuestionDTO::getQuestionId, Collectors.toList()))); |
| | | List<PaperFixQuestionDTO> questionTitleList = new ArrayList<>(); |
| | | // 遍历map |
| | | for (Integer questionType : map.keySet()) { |
| | | //数据库里的这个类型的题目 |
| | | List<Integer> questionIdList = map.get(questionType); |
| | | Result result = createQuestion(questionSetting, questionTitleList, questionType, questionIdList,QuestionTypeEnum.fromCode(questionType).getCode()); |
| | | if (result != null) return result; |
| | | for (PaperQuestionSettingDTO settingDTO : questionSetting) { |
| | | List<PaperSettingItem> settingList = settingDTO.getSettingList(); |
| | | List<PaperQuestion> questionList = new ArrayList<>(); |
| | | for (PaperSettingItem item : settingList) { |
| | | Integer num = item.getNum(); |
| | | Integer difficult = item.getDifficult(); |
| | | //需要配置的题目数量为0则跳过 |
| | | if(num ==null || num ==0 )continue; |
| | | //前端默认数据为0,转换为null |
| | | if (0 == difficult){ |
| | | difficult = null; |
| | | } |
| | | List<Question> questions = questionMapper.getRandomQuestion(item.getSubjectId(), settingDTO.getQuestionType(), difficult, item.getNum()); |
| | | if (CollectionUtils.isEmpty(questions) || item.getNum() > questions.size()) { |
| | | return Result.fail(SystemCode.InnerError.getCode(), QuestionTypeEnum.fromCode(settingDTO.getQuestionType()).getName()+"难度为:"+item.getDifficult()+"的题目数量不足"); |
| | | } |
| | | //转换数据 |
| | | convert(questionList, item, questions); |
| | | } |
| | | PaperFixQuestionDTO dto = new PaperFixQuestionDTO(); |
| | | dto.setTitle(settingDTO.getTitle()); |
| | | dto.setQuestionType(settingDTO.getQuestionType()); |
| | | dto.setQuestionList(questionList); |
| | | questionTitleList.add(dto); |
| | | } |
| | | examPaper.setContent(JSON.toJSONString(questionTitleList)); |
| | | baseMapper.insert(examPaper); |
| | | return Result.ok(); |
| | | } |
| | | } |
| | | //生成题目 |
| | | private Result createQuestion(List<PaperQuestionSettingDTO> questionSetting, List<PaperFixQuestionDTO> questionTitleList, Integer questionType, List<Integer> questionIdList , Integer questionEnumCode) { |
| | | if (questionType.equals(questionEnumCode)) { |
| | | //循环找到对应题目 |
| | | PaperQuestionSettingDTO settingDTO = new PaperQuestionSettingDTO(); |
| | | for (PaperQuestionSettingDTO dto : questionSetting) { |
| | | if (dto.getQuestionType().equals(questionType)) { |
| | | settingDTO = dto; |
| | | } |
| | | }// 需要生成的题目数量 |
| | | Integer num = settingDTO.getNum(); |
| | | if(num ==null || num ==0 ){ |
| | | //题目配置此类型数量为0,跳过,不生成题目。 |
| | | return null; |
| | | //转换数据 |
| | | private void convert(List<PaperQuestion> questionList, PaperSettingItem item, List<Question> questions) { |
| | | for (Question question : questions) { |
| | | PaperQuestion paperQuestion = new PaperQuestion(); |
| | | BeanUtils.copyProperties(question,paperQuestion); |
| | | paperQuestion.setScore(item.getScore()); |
| | | //转换 |
| | | QuestionObject questionObject = JSONObject.parseObject(question.getContent(), QuestionObject.class); |
| | | if(questionObject != null){ |
| | | paperQuestion.setItems(questionObject.getQuestionItemObjects()); |
| | | paperQuestion.setAnalyze(questionObject.getAnalyze()); |
| | | paperQuestion.setTitle(questionObject.getTitleContent()); |
| | | } |
| | | if (CollectionUtils.isEmpty(questionIdList) || num > questionIdList.size()) { |
| | | return Result.fail(SystemCode.InnerError.getCode(), QuestionTypeEnum.fromCode(questionType).getName()+"题目数量不足"); |
| | | } |
| | | |
| | | // 使用Random类生成不重复的随机索引 |
| | | Set<Integer> indexes = new HashSet<>(); |
| | | Random random = new Random(); |
| | | while (indexes.size() < num) { |
| | | int index = random.nextInt(questionIdList.size()); |
| | | indexes.add(index); |
| | | } |
| | | // 根据索引获取题目 |
| | | List<Integer> questionIds = new ArrayList<>(); |
| | | for (int index : indexes) { |
| | | questionIds.add(questionIdList.get(index)); |
| | | } |
| | | QueryWrapper<Question> wrapper = new QueryWrapper<>(); |
| | | wrapper.in("id",questionIds); |
| | | List<Question> questions = questionMapper.selectList(wrapper); |
| | | List<PaperQuestion> questionList = new ArrayList<>(); |
| | | for (Question question : questions) { |
| | | PaperQuestion paperQuestion = new PaperQuestion(); |
| | | BeanUtils.copyProperties(question,paperQuestion); |
| | | paperQuestion.setScore(settingDTO.getScore()); |
| | | //转换 |
| | | QuestionObject questionObject = JSONObject.parseObject(question.getContent(), QuestionObject.class); |
| | | if(questionObject != null){ |
| | | paperQuestion.setItems(questionObject.getQuestionItemObjects()); |
| | | paperQuestion.setAnalyze(questionObject.getAnalyze()); |
| | | paperQuestion.setTitle(questionObject.getTitleContent()); |
| | | } |
| | | questionList.add(paperQuestion); |
| | | } |
| | | PaperFixQuestionDTO dto = new PaperFixQuestionDTO(); |
| | | dto.setTitle(settingDTO.getTitle()); |
| | | dto.setQuestionType(questionType); |
| | | dto.setQuestionList(questionList); |
| | | questionTitleList.add(dto); |
| | | questionList.add(paperQuestion); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public Result updateExamPaper(ExamPaperForm form) { |
| | |
| | | |
| | | @Override |
| | | public PageInfo<ExamResponseVO> page(ExamPaperPageRequestVO requestVM) { |
| | | //TODO: 数据权限 |
| | | requestVM.setCreateUser(webContext.getCurrentUser().getId()); |
| | | PageInfo<ExamPaper> page = PageHelper.startPage(requestVM.getPageIndex(), requestVM.getPageSize(), "id desc").doSelectPageInfo(() -> |
| | | examPaperMapper.page(requestVM)); |
| | | PageInfo<ExamResponseVO> pageVO = PageInfoHelper.copyMap(page, e -> { |
| | |
| | | }); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | @SneakyThrows |
| | | public void importTemplate(HttpServletResponse response) { |
| | | String fileName = URLEncoder.encode("试卷导入模板", "UTF-8").replaceAll("\\+", "%20"); |
| | | response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); |
| | | |
| | | // 构建模板样例数据 |
| | | List<ExamPaperImportVO> data = new ArrayList<>(8); |
| | | ExamPaperImportVO questionImportVO = new ExamPaperImportVO(); |
| | | questionImportVO.setLabel("标题1"); |
| | | questionImportVO.setSubject("语文"); |
| | | questionImportVO.setQuestionType("单选题"); |
| | | questionImportVO.setDifficult(2); |
| | | questionImportVO.setCorrect("A"); |
| | | questionImportVO.setScore(2); |
| | | questionImportVO.setAnalyze("A是对的"); |
| | | questionImportVO.setTitle("这是一道测试题目,使用该模板请删除或替换这道题"); |
| | | questionImportVO.setOptionName("A"); |
| | | questionImportVO.setOptionValue("选我"); |
| | | data.add(questionImportVO); |
| | | |
| | | ExamPaperImportVO questionImport1 = new ExamPaperImportVO(); |
| | | questionImport1.setOptionName("B"); |
| | | questionImport1.setOptionValue("选B"); |
| | | data.add(questionImport1); |
| | | |
| | | ExamPaperImportVO questionImport2 = new ExamPaperImportVO(); |
| | | questionImport2.setOptionName("C"); |
| | | questionImport2.setOptionValue("选C"); |
| | | data.add(questionImport2); |
| | | |
| | | ExamPaperImportVO questionImport3 = new ExamPaperImportVO(); |
| | | questionImport3.setOptionName("D"); |
| | | questionImport3.setOptionValue("选D"); |
| | | data.add(questionImport3); |
| | | |
| | | // 查出所有的课目(excel下拉数据) |
| | | List<Subject> subjects = subjectService.list(); |
| | | List<String> subjectNameList = subjects.stream().map(Subject::getName).collect(Collectors.toList()); |
| | | EasyExcel.write(response.getOutputStream(), ExamPaperImportVO.class) |
| | | .sheet("模板") |
| | | .registerWriteHandler(new PaperSelectExcel(subjectNameList)) |
| | | .registerWriteHandler(new FixedMergeCellStrategy(2, 4, Arrays.asList(2, 3, 6, 7, 8, 9))) |
| | | .registerWriteHandler(new FixedMergeCellStrategy(2, 20, Arrays.asList(0, 1))) |
| | | .doWrite(data); |
| | | } |
| | | |
| | | @Override |
| | | @SneakyThrows |
| | | public void export(QuestionExportVO query, HttpServletResponse response) { |
| | | // 查询导出数据 |
| | | List<ExamPaperImportVO> exportData = questionService.export(query); |
| | | // 构建数据 |
| | | List<ExamPaperImportVO> exportList = new ArrayList<>(exportData.size() * 4); |
| | | // 行合并规则 |
| | | List<RowItem> mergeRowList = new ArrayList<>(exportData.size()); |
| | | int j = 2; |
| | | for (ExamPaperImportVO data : exportData) { |
| | | QuestionObject questionContent = JSON.parseObject(data.getQuestionContent(), QuestionObject.class); |
| | | |
| | | RowItem rowItem = new RowItem(); |
| | | rowItem.setStart(j); |
| | | int end = j + questionContent.getQuestionItemObjects().size() - 1; |
| | | rowItem.setEnd(end); |
| | | mergeRowList.add(rowItem); |
| | | j = end + 1; |
| | | int i = 0; |
| | | for (QuestionItemObject option : questionContent.getQuestionItemObjects()) { |
| | | if (i == 0) { |
| | | ExamPaperImportVO master = new ExamPaperImportVO(); |
| | | BeanUtils.copyProperties(data, master); |
| | | if (org.springframework.util.StringUtils.hasText(data.getQuestionType())) { |
| | | master.setQuestionType(QuestionTypeEnum.fromCode(Integer.valueOf(data.getQuestionType())).getName()); |
| | | } |
| | | master.setOptionName(option.getPrefix()); |
| | | master.setOptionValue(option.getContent()); |
| | | master.setTitle(questionContent.getTitleContent()); |
| | | master.setAnalyze(questionContent.getAnalyze()); |
| | | master.setCorrect(data.getCorrect().replaceAll(",", "、")); |
| | | BigDecimal score = BigDecimal.valueOf(master.getScore()); |
| | | master.setScore(score.divide(BigDecimal.TEN).intValue()); |
| | | exportList.add(master); |
| | | } else { |
| | | ExamPaperImportVO optionItem = new ExamPaperImportVO(); |
| | | optionItem.setOptionName(option.getPrefix()); |
| | | optionItem.setOptionValue(option.getContent()); |
| | | exportList.add(optionItem); |
| | | } |
| | | i++; |
| | | } |
| | | } |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 |
| | | String fileName = URLEncoder.encode("题目导出数据", "UTF-8").replaceAll("\\+", "%20"); |
| | | response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); |
| | | |
| | | // 查出所有的课目(excel下拉数据) |
| | | List<Subject> subjects = subjectService.list(); |
| | | List<String> subjectNameList = subjects.stream().map(Subject::getName).collect(Collectors.toList()); |
| | | EasyExcel.write(response.getOutputStream(), ExamPaperImportVO.class) |
| | | .sheet("题目导出数据") |
| | | .registerWriteHandler(new SelectExcel(subjectNameList)) |
| | | .registerWriteHandler(new DynamicMergeCellStrategy(mergeRowList, Arrays.asList(0, 1, 2, 5, 6, 7, 8))) |
| | | .doWrite(exportList); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | @SneakyThrows |
| | | public Result importPaper(MultipartFile file, ExamPaperForm form) { |
| | | List<Subject> subjects = subjectService.list(); |
| | | List<Integer> questionNum = new ArrayList<>(); |
| | | List<Integer> totalScore = new ArrayList<>(); |
| | | // 拿到试卷 |
| | | ExamPaper examPaper = ExamPaperForm.getEntityByForm(form, null); |
| | | // 题目集合用于批量保存 |
| | | ArrayList<Question> questions = new ArrayList<>(); |
| | | // 一张试卷多个标题 |
| | | ArrayList<PaperFixQuestionDTO> list = new ArrayList<>(); |
| | | |
| | | Consumer<List<ExamPaperImportVO>> consumer = (data) -> { |
| | | // 循环每一行 |
| | | for (int i = 0; i < data.size(); i++) { |
| | | // 读取的题目 |
| | | ExamPaperImportVO excelQuestion = data.get(i); |
| | | String questionType = excelQuestion.getQuestionType(); |
| | | String label = excelQuestion.getLabel(); |
| | | // 判断是否标题 |
| | | if (excelQuestion.master()) { |
| | | // 一个标题多个题目 |
| | | ArrayList<PaperQuestion> paperQuestions = new ArrayList<>(); |
| | | // 循环题目 |
| | | while (Boolean.TRUE) { |
| | | // 更新读取的题目 |
| | | excelQuestion = data.get(i); |
| | | // 判断是否题目 |
| | | if (excelQuestion.intact()) { |
| | | Question question = new Question(); |
| | | totalScore.add(excelQuestion.getScore()); |
| | | // 该题的选项 |
| | | List<QuestionItemObject> options = new ArrayList<>(8); |
| | | // 选项内容 |
| | | QuestionItemObject option = new QuestionItemObject(); |
| | | option.setPrefix(excelQuestion.getOptionName()); |
| | | option.setContent(excelQuestion.getOptionValue()); |
| | | options.add(option); |
| | | // 循环选项 |
| | | while (Boolean.TRUE) { |
| | | // 判断是否是最后一条 |
| | | if (i + 1 == data.size()) { |
| | | break; |
| | | } |
| | | ExamPaperImportVO nextQuestion = data.get(1 + i); |
| | | if (nextQuestion.intact()) { |
| | | break; |
| | | } |
| | | QuestionItemObject nextOption = new QuestionItemObject(); |
| | | nextOption.setPrefix(nextQuestion.getOptionName()); |
| | | nextOption.setContent(nextQuestion.getOptionValue()); |
| | | options.add(nextOption); |
| | | i++; |
| | | } |
| | | // 保存题目内容 |
| | | QuestionObject questionObject = new QuestionObject(); |
| | | questionObject.setQuestionItemObjects(options); |
| | | questionObject.setAnalyze(excelQuestion.getAnalyze()); |
| | | questionObject.setTitleContent(excelQuestion.getTitle()); |
| | | questionObject.setCorrect(excelQuestion.getCorrect()); |
| | | question.setTitle(excelQuestion.getTitle()); |
| | | question.setContent(JSON.toJSONString(questionObject)); |
| | | question.setQuestionType(QuestionTypeEnum.get(excelQuestion.getQuestionType())); |
| | | // 答案(多选需要用、分割保存字符串到数据库) |
| | | String[] corrects = excelQuestion.getCorrect().split("、"); |
| | | if (corrects.length > 1) { |
| | | question.setCorrect(String.join(",", corrects)); |
| | | } else { |
| | | question.setCorrect(excelQuestion.getCorrect()); |
| | | } |
| | | // 难度 |
| | | question.setDifficult(excelQuestion.getDifficult()); |
| | | // 创建人 |
| | | question.setCreateUser(2); |
| | | question.setStatus(StatusEnum.ENABLE); |
| | | question.setCreateTime(new Date()); |
| | | question.setDeleted(0); |
| | | question.setQuestionType(QuestionTypeEnum.get(questionType)); |
| | | // 根据科目名称获取id |
| | | ExamPaperImportVO finalExcelQuestion = excelQuestion; |
| | | question.setSubjectId(subjects.stream().filter(subject -> subject.getName().equals(finalExcelQuestion.getSubject())).findFirst().get().getId()); |
| | | questions.add(question); |
| | | |
| | | PaperQuestion paperQuestion = new PaperQuestion(); |
| | | BeanUtils.copyProperties(question, paperQuestion); |
| | | paperQuestion.setItems(options); |
| | | paperQuestion.setAnalyze(excelQuestion.getAnalyze()); |
| | | paperQuestion.setScore(BigDecimal.valueOf(excelQuestion.getScore())); |
| | | paperQuestions.add(paperQuestion); |
| | | } |
| | | // 下一条数据是标题 |
| | | if (i + 1 == data.size() || data.get(i + 1).master()) { |
| | | break; |
| | | } |
| | | i++; |
| | | } |
| | | // 组装试卷内容 |
| | | PaperFixQuestionDTO paperFixQuestionDTO = new PaperFixQuestionDTO(); |
| | | paperFixQuestionDTO.setTitle(label); |
| | | paperFixQuestionDTO.setQuestionType(QuestionTypeEnum.get(questionType)); |
| | | paperFixQuestionDTO.setQuestionList(paperQuestions); |
| | | questionNum.add(paperQuestions.size()); |
| | | list.add(paperFixQuestionDTO); |
| | | } |
| | | } |
| | | }; |
| | | EasyExcel.read(file.getInputStream(), ExamPaperImportVO.class, new CurrencyDataListener(consumer)).sheet("模板").doRead(); |
| | | // 保存题目 |
| | | questionService.saveBatch(questions); |
| | | // 保存试卷 |
| | | examPaper.setContent(JSON.toJSONString(list)); |
| | | examPaper.setVisibility(VisibilityEnum.fromCode(form.getVisibility()).getName()); |
| | | examPaper.setCreateUser(2); |
| | | examPaper.setCreateTime(new Date()); |
| | | Integer score = totalScore.stream().reduce(Integer::sum).orElse(0); |
| | | Integer num = questionNum.stream().reduce(Integer::sum).orElse(0); |
| | | examPaper.setScore(new BigDecimal(score)); |
| | | examPaper.setNum(num); |
| | | examPaperMapper.insert(examPaper); |
| | | return Result.ok(); |
| | | } |
| | | } |