| | |
| | | import com.mindskip.xzs.base.RestResponse; |
| | | import com.mindskip.xzs.base.SystemCode; |
| | | import com.mindskip.xzs.domain.Question; |
| | | import com.mindskip.xzs.domain.QuestionSubject; |
| | | import com.mindskip.xzs.domain.Subject; |
| | | import com.mindskip.xzs.domain.TextContent; |
| | | import com.mindskip.xzs.domain.enums.QuestionSourceEnum; |
| | | import com.mindskip.xzs.domain.enums.QuestionStatusEnum; |
| | | import com.mindskip.xzs.domain.enums.QuestionTypeEnum; |
| | | import com.mindskip.xzs.domain.question.QuestionItemObject; |
| | | import com.mindskip.xzs.domain.question.QuestionObject; |
| | | import com.mindskip.xzs.domain.vo.DeptQuestionVO; |
| | | import com.mindskip.xzs.excel.CurrencyDataListener; |
| | | import com.mindskip.xzs.excel.SelectExcel; |
| | | import com.mindskip.xzs.repository.DepartmentMapper; |
| | | import com.mindskip.xzs.repository.DeptQuestionMapper; |
| | | import com.mindskip.xzs.repository.SubjectMapper; |
| | |
| | | import com.mindskip.xzs.vo.QuestionExportData; |
| | | import com.mindskip.xzs.vo.QuestionExportVO; |
| | | import com.mindskip.xzs.vo.QuestionImportVO; |
| | | import com.mindskip.xzs.vo.QuestionSubjectVO; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.validation.Valid; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.net.URLEncoder; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.*; |
| | | import java.util.function.Consumer; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @RestController("AdminQuestionController") |
| | |
| | | vm.setQuestionSubjects(questionSubjectService.getQuestion(vm.getId()).stream().map(e -> { |
| | | SubjectPageRequestVM subjectPageRequestVM = new SubjectPageRequestVM(); |
| | | subjectPageRequestVM.setId(e.getSubjectId()); |
| | | e.setSubName(subjectMapper.page(subjectPageRequestVM).get(0).getName()); |
| | | e.setSubName(subjectMapper.page(subjectPageRequestVM).stream().map(Subject::getName).collect(Collectors.joining(SPLIT))); |
| | | return e; |
| | | }).collect(Collectors.toList())); |
| | | // 查询题目所属部门 |
| | |
| | | |
| | | // 构建模板样例数据 |
| | | List<QuestionImportVO> data = new ArrayList<>(4); |
| | | EasyExcel.write(response.getOutputStream(), QuestionExportData.class) |
| | | QuestionImportVO questionImportVO = new QuestionImportVO(); |
| | | questionImportVO.setQuestionType("单选题"); |
| | | questionImportVO.setDifficult(2); |
| | | questionImportVO.setCorrect("B"); |
| | | questionImportVO.setScore("2"); |
| | | questionImportVO.setSubjectName("测试课目"); |
| | | questionImportVO.setAnalyze("B是对的"); |
| | | questionImportVO.setTitle("这是一道测试题目,使用该模板请删除或替换这道题"); |
| | | questionImportVO.setOptionA("选我"); |
| | | questionImportVO.setOptionB("选我"); |
| | | questionImportVO.setOptionC("选我"); |
| | | questionImportVO.setOptionD("选我"); |
| | | data.add(questionImportVO); |
| | | |
| | | // 查出所有的课目(excel下拉数据) |
| | | List<Subject> subjects = subjectMapper.allSubject(new ArrayList<>(), Boolean.TRUE); |
| | | List<String> subjectNameList = subjects.stream().map(Subject::getName).collect(Collectors.toList()); |
| | | |
| | | EasyExcel.write(response.getOutputStream(), QuestionImportVO.class) |
| | | .sheet("模板") |
| | | .registerWriteHandler(new SelectExcel(subjectNameList)) |
| | | // .registerWriteHandler(new FixedMergeCellStrategy(2, 4, Arrays.asList(1, 2, 3, 6, 7, 8, 9))) |
| | | .doWrite(data); |
| | | } |
| | | |
| | |
| | | * @param file |
| | | * @throws IOException |
| | | */ |
| | | // @PostMapping("/question/import") |
| | | // @Transactional(rollbackFor = Exception.class) |
| | | // public RestResponse importQuestion(@RequestPart("file") MultipartFile file) throws IOException { |
| | | // Consumer<List<QuestionImportVO>> consumer = (data) -> { |
| | | // // 题目的课目信息 |
| | | // List<QuestionSubject> questionSubjectsList = new ArrayList<>(48); |
| | | // for (int i = 0; i < data.size(); i++) { |
| | | // // 题目实体 |
| | | // Question question = new Question(); |
| | | // // 读取的题目 |
| | | // QuestionImportVO excelQuestion = data.get(i); |
| | | // |
| | | // // 如果是第一条完整数据,那么继续往后读取选项内容 |
| | | // if (excelQuestion.master()) { |
| | | // // 该题的选项 |
| | | // List<QuestionItemObject> options = new ArrayList<>(4); |
| | | // // 选项内容 |
| | | // QuestionItemObject option = new QuestionItemObject(); |
| | | // option.setPrefix(excelQuestion.getOptionName()); |
| | | // option.setContent(excelQuestion.getOptionValue()); |
| | | // options.add(option); |
| | | // int next = 1; |
| | | // // 继续往后读选项 |
| | | // while (Boolean.TRUE) { |
| | | // // 判断是否是最后一条 |
| | | // if (next + i == data.size()) { |
| | | // break; |
| | | // } |
| | | // QuestionImportVO nextQuestion = data.get(next + i); |
| | | // if (nextQuestion.master()) { |
| | | // break; |
| | | // } |
| | | // QuestionItemObject nextOption = new QuestionItemObject(); |
| | | // nextOption.setPrefix(nextQuestion.getOptionName()); |
| | | // nextOption.setContent(nextQuestion.getOptionValue()); |
| | | // options.add(nextOption); |
| | | // next++; |
| | | // } |
| | | // i += next; |
| | | // |
| | | // // 保存题目内容 |
| | | // 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()); |
| | | // textContentService.insert(textContent); |
| | | // |
| | | // // 保存题目信息 |
| | | // // 设置题型 |
| | | // question.setQuestionType(QuestionTypeEnum.get(excelQuestion.getQuestionType())); |
| | | // // 答案(多选需要用,分割保存字符串到数据库) |
| | | // String[] corrects = excelQuestion.getCorrect().split(SPLIT); |
| | | // if (corrects.length > 1) { |
| | | // question.setCorrect(Arrays.asList(corrects).stream().collect(Collectors.joining(","))); |
| | | // } else { |
| | | // question.setCorrect(excelQuestion.getCorrect()); |
| | | // } |
| | | // |
| | | // // 难度 |
| | | // question.setDifficult(excelQuestion.getDifficult()); |
| | | // // 分数 |
| | | // 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.insert(question); |
| | | // |
| | | // |
| | | // // 查出所有的课目 |
| | | // List<Subject> subjects = subjectMapper.allSubject(new ArrayList<>(), Boolean.TRUE); |
| | | // List<String> subjectNames = Arrays.asList(excelQuestion.getSubjectName().split(SPLIT)); |
| | | // List<Subject> targetSubject = subjects.stream() |
| | | // .filter(subject -> subjectNames.contains(subject.getName())) |
| | | // .collect(Collectors.toList()); |
| | | // if (CollectionUtils.isEmpty(targetSubject)) { |
| | | // // todo 记录这个错误 |
| | | // continue; |
| | | // } |
| | | // // 构建课目-题目信息 |
| | | // questionSubjectsList = targetSubject.stream().map(subject -> { |
| | | // QuestionSubject questionSubject = new QuestionSubject(); |
| | | // questionSubject.setQuestionId(question.getId()); |
| | | // questionSubject.setSubjectId(subject.getId()); |
| | | // questionSubject.setDeleted(0); |
| | | // return questionSubject; |
| | | // }).collect(Collectors.toList()); |
| | | // } |
| | | // System.out.println(question); |
| | | // } |
| | | // // 批量保存题目-课目信息 |
| | | // if (! CollectionUtils.isEmpty(questionSubjectsList)) { |
| | | // questionSubjectService.saves(questionSubjectsList); |
| | | // } |
| | | // }; |
| | | // EasyExcel.read(file.getInputStream(), QuestionImportVO.class, new CurrencyDataListener(consumer)).sheet("模板").doRead(); |
| | | // return RestResponse.ok(); |
| | | // } |
| | | |
| | | @PostMapping("/import") |
| | | public RestResponse importQuestion(@RequestPart("file") MultipartFile file) throws Exception { |
| | | List<QuestionEditVO> questionEditVOS = ExcelUtils.readMultipartFile(file, QuestionEditVO.class) |
| | | .stream().map(e -> { |
| | | e.setQuestionType(QuestionTypeEnum.get(e.getType())); |
| | | // e.setSubjectId(subjectMapper.getName(e.getSbNames()).getId()); |
| | | // e.setGradeLevel(departmentMapper.getName(e.getDepartment()).getId()); |
| | | return e; |
| | | }).collect(Collectors.toList()); |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public RestResponse importQuestion(@RequestPart("file") MultipartFile file) throws IOException { |
| | | Consumer<List<QuestionImportVO>> consumer = (data) -> { |
| | | // 题目的课目信息 |
| | | List<QuestionSubject> questionSubjectsList = new ArrayList<>(48); |
| | | for (int i = 0; i < data.size(); i++) { |
| | | |
| | | List<QuestionEditRequestVM> list = QuestionClassConvert.INSTANCE.QuestionEditVOListToQuestionEditRequestVMList(questionEditVOS); |
| | | // 题目实体 |
| | | Question question = new Question(); |
| | | // 读取的题目 |
| | | QuestionImportVO excelQuestion = data.get(i); |
| | | |
| | | List<QuestionEditItemVM> questionEditItemVMS = new ArrayList<>(); |
| | | QuestionEditItemVM questionEditItemVM = new QuestionEditItemVM(); |
| | | // 判断题干是否重复,重复不添加 |
| | | Integer questionId = questionService.countQuestionByTitle(excelQuestion.getTitle()); |
| | | if (Objects.isNull(questionId)) { |
| | | // 该题的选项 |
| | | List<QuestionItemObject> options = new ArrayList<>(4); |
| | | // 选项内容 |
| | | QuestionItemObject optionA = new QuestionItemObject(); |
| | | optionA.setPrefix("A"); |
| | | optionA.setContent(excelQuestion.getOptionA()); |
| | | options.add(optionA); |
| | | |
| | | //组装题目 |
| | | for (QuestionEditRequestVM vm : list) { |
| | | // 判断题干是否重复,重复不添加 |
| | | Integer num = questionService.countQuestionByTitle(vm.getTitle()); |
| | | if (num > 0) { |
| | | continue; |
| | | 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()); |
| | | textContentService.insert(textContent); |
| | | |
| | | // 保存题目信息 |
| | | // 设置题型 |
| | | question.setQuestionType(QuestionTypeEnum.get(excelQuestion.getQuestionType())); |
| | | // 答案(多选需要用,分割保存字符串到数据库) |
| | | String[] corrects = excelQuestion.getCorrect().split(SPLIT); |
| | | if (corrects.length > 1) { |
| | | question.setCorrect(Arrays.asList(corrects).stream().collect(Collectors.joining(","))); |
| | | } else { |
| | | question.setCorrect(excelQuestion.getCorrect()); |
| | | } |
| | | |
| | | // 难度 |
| | | 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.insert(question); |
| | | |
| | | |
| | | // 查出所有的课目 |
| | | List<Subject> subjects = subjectMapper.allSubject(new ArrayList<>(), Boolean.TRUE); |
| | | List<String> subjectNames = Arrays.asList(excelQuestion.getSubjectName().split(SPLIT)); |
| | | List<Subject> targetSubject = subjects.stream() |
| | | .filter(subject -> subjectNames.contains(subject.getName())) |
| | | .collect(Collectors.toList()); |
| | | if (CollectionUtils.isEmpty(targetSubject)) { |
| | | // todo 记录这个错误 |
| | | continue; |
| | | } |
| | | // 构建课目-题目信息 |
| | | questionSubjectsList = targetSubject.stream() |
| | | .filter(subject -> { |
| | | // 去重题目:题干+课目相同才算同一题 |
| | | List<QuestionSubjectVO> lists = questionService.countQuestionByTitleAndSubject(excelQuestion.getTitle(), subject.getId()); |
| | | return 0 == lists.size(); |
| | | }) |
| | | .map(subject -> { |
| | | QuestionSubject questionSubject = new QuestionSubject(); |
| | | questionSubject.setQuestionId(question.getId()); |
| | | questionSubject.setSubjectId(subject.getId()); |
| | | questionSubject.setDeleted(0); |
| | | return questionSubject; |
| | | }).collect(Collectors.toList()); |
| | | // 批量保存题目-课目信息 |
| | | if (! CollectionUtils.isEmpty(questionSubjectsList)) { |
| | | questionSubjectService.saves(questionSubjectsList); |
| | | } |
| | | } else { |
| | | // 查出所有的课目 |
| | | List<Subject> subjects = subjectMapper.allSubject(new ArrayList<>(), Boolean.TRUE); |
| | | List<String> subjectNames = Arrays.asList(excelQuestion.getSubjectName().split(SPLIT)); |
| | | List<Subject> targetSubject = subjects.stream() |
| | | .filter(subject -> subjectNames.contains(subject.getName())) |
| | | .collect(Collectors.toList()); |
| | | if (CollectionUtils.isEmpty(targetSubject)) { |
| | | // todo 记录这个错误 |
| | | continue; |
| | | } |
| | | // 构建课目-题目信息 |
| | | questionSubjectsList = targetSubject.stream() |
| | | .filter(subject -> { |
| | | // 去重题目:题干+课目相同才算同一题 |
| | | List<QuestionSubjectVO> lists = questionService.countQuestionByTitleAndSubject(excelQuestion.getTitle(), subject.getId()); |
| | | return 0 == lists.size(); |
| | | }) |
| | | .map(subject -> { |
| | | QuestionSubject questionSubject = new QuestionSubject(); |
| | | questionSubject.setQuestionId(questionId); |
| | | questionSubject.setSubjectId(subject.getId()); |
| | | questionSubject.setDeleted(0); |
| | | return questionSubject; |
| | | }).collect(Collectors.toList()); |
| | | // 批量保存题目-课目信息 |
| | | if (! CollectionUtils.isEmpty(questionSubjectsList)) { |
| | | questionSubjectService.saves(questionSubjectsList); |
| | | } |
| | | } |
| | | } |
| | | |
| | | questionEditItemVM.setPrefix("A"); |
| | | questionEditItemVM.setContent(vm.getA()); |
| | | |
| | | questionEditItemVMS.add(questionEditItemVM); |
| | | questionEditItemVM = new QuestionEditItemVM(); |
| | | questionEditItemVM.setPrefix("B"); |
| | | questionEditItemVM.setContent(vm.getB()); |
| | | questionEditItemVMS.add(questionEditItemVM); |
| | | if(!"".equals(vm.getC()) && vm.getC()!=null){ |
| | | questionEditItemVM = new QuestionEditItemVM(); |
| | | questionEditItemVM.setPrefix("C"); |
| | | questionEditItemVM.setContent(vm.getC()); |
| | | questionEditItemVMS.add(questionEditItemVM); |
| | | } |
| | | if(!"".equals(vm.getD()) && vm.getD()!=null){ |
| | | questionEditItemVM = new QuestionEditItemVM(); |
| | | questionEditItemVM.setPrefix("D"); |
| | | questionEditItemVM.setContent(vm.getD()); |
| | | questionEditItemVMS.add(questionEditItemVM); |
| | | } |
| | | vm.setItems(questionEditItemVMS); |
| | | // 清空前后的逗号,以免后续作答判断为错误 |
| | | String s = vm.getCorrect().replaceAll("^,+|,+$", ""); |
| | | if (Objects.equals(s, "正确")) s = "A"; |
| | | if (Objects.equals(s, "错误")) s = "B"; |
| | | vm.setCorrect(s); |
| | | List<String> str = Arrays.asList(s.split(SPLIT)); |
| | | |
| | | List<Subject> subjectList = subjectMapper.getNames(vm.getSbNames().split(SPLIT)); |
| | | |
| | | Integer[] arr =subjectList.stream() |
| | | .map(Subject::getId).toArray(Integer[]::new); |
| | | |
| | | vm.setSubjectIds(arr); |
| | | //多选 |
| | | if (str.size() > 1) { |
| | | vm.setCorrectArray(str); |
| | | vm.setCorrect(null); |
| | | } |
| | | vm.setScore(QuestionSourceEnum.fromType(vm.getQuestionType()).toString()); |
| | | vm.setDifficult(4); |
| | | |
| | | questionService.insertFullQuestion(vm, getCurrentUser().getId()); |
| | | questionEditItemVMS.clear(); |
| | | } |
| | | }; |
| | | EasyExcel.read(file.getInputStream(), QuestionImportVO.class, new CurrencyDataListener(consumer)).sheet("模板").doRead(); |
| | | return RestResponse.ok(); |
| | | } |
| | | |
| | | // @PostMapping("/import") |
| | | // public RestResponse importQuestion(@RequestPart("file") MultipartFile file) throws Exception { |
| | | // List<QuestionEditVO> questionEditVOS = ExcelUtils.readMultipartFile(file, QuestionEditVO.class) |
| | | // .stream().map(e -> { |
| | | // e.setQuestionType(QuestionTypeEnum.get(e.getType())); |
| | | //// e.setSubjectId(subjectMapper.getName(e.getSbNames()).getId()); |
| | | //// e.setGradeLevel(departmentMapper.getName(e.getDepartment()).getId()); |
| | | // return e; |
| | | // }).collect(Collectors.toList()); |
| | | // |
| | | // List<QuestionEditRequestVM> list = QuestionClassConvert.INSTANCE.QuestionEditVOListToQuestionEditRequestVMList(questionEditVOS); |
| | | // |
| | | // List<QuestionEditItemVM> questionEditItemVMS = new ArrayList<>(); |
| | | // QuestionEditItemVM questionEditItemVM = new QuestionEditItemVM(); |
| | | // |
| | | // //组装题目 |
| | | // for (QuestionEditRequestVM vm : list) { |
| | | // // 判断题干是否重复,重复不添加 |
| | | // Integer num = questionService.countQuestionByTitle(vm.getTitle()); |
| | | // if (num > 0) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // questionEditItemVM.setPrefix("A"); |
| | | // questionEditItemVM.setContent(vm.getA()); |
| | | // |
| | | // questionEditItemVMS.add(questionEditItemVM); |
| | | // questionEditItemVM = new QuestionEditItemVM(); |
| | | // questionEditItemVM.setPrefix("B"); |
| | | // questionEditItemVM.setContent(vm.getB()); |
| | | // questionEditItemVMS.add(questionEditItemVM); |
| | | // if(!"".equals(vm.getC()) && vm.getC()!=null){ |
| | | // questionEditItemVM = new QuestionEditItemVM(); |
| | | // questionEditItemVM.setPrefix("C"); |
| | | // questionEditItemVM.setContent(vm.getC()); |
| | | // questionEditItemVMS.add(questionEditItemVM); |
| | | // } |
| | | // if(!"".equals(vm.getD()) && vm.getD()!=null){ |
| | | // questionEditItemVM = new QuestionEditItemVM(); |
| | | // questionEditItemVM.setPrefix("D"); |
| | | // questionEditItemVM.setContent(vm.getD()); |
| | | // questionEditItemVMS.add(questionEditItemVM); |
| | | // } |
| | | // vm.setItems(questionEditItemVMS); |
| | | // // 清空前后的逗号,以免后续作答判断为错误 |
| | | // String s = vm.getCorrect().replaceAll("^,+|,+$", ""); |
| | | // if (Objects.equals(s, "正确")) s = "A"; |
| | | // if (Objects.equals(s, "错误")) s = "B"; |
| | | // vm.setCorrect(s); |
| | | // List<String> str = Arrays.asList(s.split(SPLIT)); |
| | | // |
| | | // List<Subject> subjectList = subjectMapper.getNames(vm.getSbNames().split(SPLIT)); |
| | | // |
| | | // Integer[] arr =subjectList.stream() |
| | | // .map(Subject::getId).toArray(Integer[]::new); |
| | | // |
| | | // vm.setSubjectIds(arr); |
| | | // //多选 |
| | | // if (str.size() > 1) { |
| | | // vm.setCorrectArray(str); |
| | | // vm.setCorrect(null); |
| | | // } |
| | | // vm.setScore(QuestionSourceEnum.fromType(vm.getQuestionType()).toString()); |
| | | // vm.setDifficult(4); |
| | | // |
| | | // questionService.insertFullQuestion(vm, getCurrentUser().getId()); |
| | | // questionEditItemVMS.clear(); |
| | | // } |
| | | // return RestResponse.ok(); |
| | | // } |
| | | |
| | | @PostMapping("/question/export") |
| | | public void exportQuestion(@RequestBody QuestionExportVO query, HttpServletResponse response) throws IOException { |
| | | // 查询导出数据 |
| | | List<QuestionExportData> exportData = questionService.exportData(query); |
| | | List<QuestionImportVO> exportData = questionService.exportData(query); |
| | | // 处理完善数据 |
| | | exportData.stream().forEach(question -> { |
| | | if (StringUtils.isNotBlank(question.getContent())) { |
| | | QuestionObject questionContent = JSON.parseObject(question.getContent(), QuestionObject.class); |
| | | if (StringUtils.isNotBlank(question.getQuestionContent())) { |
| | | QuestionObject questionContent = JSON.parseObject(question.getQuestionContent(), QuestionObject.class); |
| | | // 设置选项 |
| | | for (QuestionItemObject option : questionContent.getQuestionItemObjects()) { |
| | | String optionContent = option.getContent(); |
| | |
| | | question.setOptionD(optionContent); |
| | | } |
| | | } |
| | | question.setScore(BigDecimal.valueOf(Double.valueOf(question.getScore())).divide(BigDecimal.TEN).toString()); |
| | | // 设置题干、解析 |
| | | question.setAnalyze(questionContent.getAnalyze()); |
| | | question.setTitle(questionContent.getTitleContent()); |
| | | // 设置课目 |
| | | question.setSubject(question.getSubjectList().stream().collect(Collectors.joining(","))); |
| | | question.setSubjectName(question.getSubjectList().stream().collect(Collectors.joining(","))); |
| | | // 设置题型 |
| | | question.setQuestionType(QuestionTypeEnum.fromCode(Integer.valueOf(question.getQuestionType())).getName()); |
| | | } |
| | |
| | | String fileName = URLEncoder.encode("题目导出数据", "UTF-8").replaceAll("\\+", "%20"); |
| | | response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); |
| | | |
| | | |
| | | // 查出所有的课目(excel下拉数据) |
| | | EasyExcel.write(response.getOutputStream(), QuestionExportData.class) |
| | | List<Subject> subjects = subjectMapper.allSubject(new ArrayList<>(), Boolean.TRUE); |
| | | List<String> subjectNameList = subjects.stream().map(Subject::getName).collect(Collectors.toList()); |
| | | |
| | | // 查出所有的课目(excel下拉数据) |
| | | EasyExcel.write(response.getOutputStream(), QuestionImportVO.class) |
| | | .sheet("题目导出数据") |
| | | .registerWriteHandler(new SelectExcel(subjectNameList)) |
| | | .doWrite(exportData); |
| | | } |
| | | } |