From 3ec909b27b3eba956aa9d00cc7a94c179bd04bbf Mon Sep 17 00:00:00 2001 From: 龚焕茏 <2842157468@qq.com> Date: 星期三, 03 七月 2024 18:29:31 +0800 Subject: [PATCH] feat:新增随机时间题目配置 --- src/main/java/com/mindskip/xzs/controller/admin/QuestionController.java | 437 ++++++++++++++++++++++++++++-------------------------- 1 files changed, 229 insertions(+), 208 deletions(-) diff --git a/src/main/java/com/mindskip/xzs/controller/admin/QuestionController.java b/src/main/java/com/mindskip/xzs/controller/admin/QuestionController.java index aca34d0..4fa6f0a 100644 --- a/src/main/java/com/mindskip/xzs/controller/admin/QuestionController.java +++ b/src/main/java/com/mindskip/xzs/controller/admin/QuestionController.java @@ -18,8 +18,10 @@ 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.*; import com.mindskip.xzs.repository.DepartmentMapper; +import com.mindskip.xzs.repository.DeptQuestionMapper; import com.mindskip.xzs.repository.SubjectMapper; import com.mindskip.xzs.service.*; import com.mindskip.xzs.utility.*; @@ -28,6 +30,7 @@ import com.mindskip.xzs.viewmodel.admin.education.SubjectPageRequestVM; import com.mindskip.xzs.viewmodel.admin.question.*; import com.github.pagehelper.PageInfo; +import com.mindskip.xzs.vo.QuestionExportData; import com.mindskip.xzs.vo.QuestionExportVO; import com.mindskip.xzs.vo.QuestionImportVO; import org.apache.commons.lang3.StringUtils; @@ -55,22 +58,20 @@ private final QuestionService questionService; private final TextContentService textContentService; - private final SubjectMapper subjectMapper; - private final DepartmentMapper departmentMapper; - private final QuestionSubjectService questionSubjectService; + private final DeptQuestionMapper deptQuestionMapper; - private static final String SPLIT = "銆�"; + private static final String SPLIT = ","; - @Autowired - public QuestionController(QuestionService questionService, TextContentService textContentService, SubjectMapper subjectMapper, DepartmentMapper departmentMapper, QuestionSubjectService questionSubjectService) { + public QuestionController(QuestionService questionService, TextContentService textContentService, SubjectMapper subjectMapper, DepartmentMapper departmentMapper, QuestionSubjectService questionSubjectService, DeptQuestionMapper deptQuestionMapper) { this.questionService = questionService; this.textContentService = textContentService; this.subjectMapper = subjectMapper; this.departmentMapper = departmentMapper; this.questionSubjectService = questionSubjectService; + this.deptQuestionMapper = deptQuestionMapper; } @RequestMapping(value = "/page", method = RequestMethod.POST) @@ -90,6 +91,9 @@ e.setSubName(subjectMapper.page(subjectPageRequestVM).get(0).getName()); return e; }).collect(Collectors.toList())); + // 鏌ヨ棰樼洰鎵�灞為儴闂� + String deptNames = deptQuestionMapper.deptByQuestionId(q.getId()).stream().map(DeptQuestionVO::getDeptName).collect(Collectors.joining("銆�")); + vm.setDeptNames(deptNames); return vm; }); return RestResponse.ok(page); @@ -156,104 +160,70 @@ // 鏋勫缓妯℃澘鏍蜂緥鏁版嵁 List<QuestionImportVO> data = new ArrayList<>(4); - QuestionImportVO questionImportVO = new QuestionImportVO(); - questionImportVO.setQuestionType("鍗曢�夐"); - questionImportVO.setDifficult(2); - questionImportVO.setCorrect("B"); - questionImportVO.setScore(2); - questionImportVO.setSubjectName("娴嬭瘯璇剧洰"); - questionImportVO.setAnalyze("B鏄鐨�"); - questionImportVO.setTitle("杩欐槸涓�閬撴祴璇曢鐩紝浣跨敤璇ユā鏉胯鍒犻櫎鎴栨浛鎹㈣繖閬撻"); - questionImportVO.setOptionName("A"); - questionImportVO.setOptionValue("閫夋垜"); - data.add(questionImportVO); - - QuestionImportVO questionImportVO1 = new QuestionImportVO(); - questionImportVO1.setOptionName("B"); - questionImportVO1.setOptionValue("閫塀"); - data.add(questionImportVO1); - - QuestionImportVO questionImportVO2 = new QuestionImportVO(); - questionImportVO2.setOptionName("C"); - questionImportVO2.setOptionValue("閫塁"); - data.add(questionImportVO2); - - QuestionImportVO questionImportVO3 = new QuestionImportVO(); - questionImportVO3.setOptionName("D"); - questionImportVO3.setOptionValue("閫塂"); - data.add(questionImportVO3); - - // 鏌ュ嚭鎵�鏈夌殑璇剧洰锛坋xcel涓嬫媺鏁版嵁锛� - List<Subject> subjects = subjectMapper.allSubject(); - List<String> subjectNameList = subjects.stream().map(Subject::getName).collect(Collectors.toList()); - - EasyExcel.write(response.getOutputStream(), QuestionImportVO.class) + EasyExcel.write(response.getOutputStream(), QuestionExportData.class) .sheet("妯℃澘") - .registerWriteHandler(new SelectExcel(subjectNameList)) - .registerWriteHandler(new FixedMergeCellStrategy(2, 4, Arrays.asList(0, 1, 2, 5, 6, 7, 8))) .doWrite(data); } - @GetMapping("/question/export") - public void importQuestion(QuestionExportVO query, HttpServletResponse response) throws IOException { - query.formartTime(); - // 鏌ヨ瀵煎嚭鏁版嵁 - List<QuestionImportVO> exportData = questionService.export(query); - // 鏋勫缓鏁版嵁 - List<QuestionImportVO> exportList = new ArrayList<>(exportData.size() * 4); - // 琛屽悎骞惰鍒� - List<RowItem> mergeRowList = new ArrayList<>(exportData.size()); - int j = 2; - for (QuestionImportVO 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) { - QuestionImportVO master = new QuestionImportVO(); - 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.setSubjectName(data.getSubjectList().stream().collect(Collectors.joining("銆�"))); - master.setCorrect(data.getCorrect().replaceAll(",", "銆�")); - BigDecimal score = BigDecimal.valueOf(master.getScore()); - master.setScore(score.divide(BigDecimal.TEN).intValue()); - exportList.add(master); - } else { - QuestionImportVO optionItem = new QuestionImportVO(); - 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鍙互闃叉涓枃涔辩爜 褰撶劧鍜宔asyexcel娌℃湁鍏崇郴 - String fileName = URLEncoder.encode("棰樼洰瀵煎嚭鏁版嵁", "UTF-8").replaceAll("\\+", "%20"); - response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); - - // 鏌ュ嚭鎵�鏈夌殑璇剧洰锛坋xcel涓嬫媺鏁版嵁锛� - List<Subject> subjects = subjectMapper.allSubject(); - List<String> subjectNameList = subjects.stream().map(Subject::getName).collect(Collectors.toList()); - EasyExcel.write(response.getOutputStream(), QuestionImportVO.class) - .sheet("棰樼洰瀵煎嚭鏁版嵁") - .registerWriteHandler(new SelectExcel(subjectNameList)) - .registerWriteHandler(new DynamicMergeCellStrategy(mergeRowList, Arrays.asList(0, 1, 2, 5, 6, 7, 8))) - .doWrite(exportList); - } +// @PostMapping("/question/export") +// public void exportQuestion(@RequestBody QuestionExportVO query, HttpServletResponse response) throws IOException { +// // 鏌ヨ瀵煎嚭鏁版嵁 +// List<QuestionImportVO> exportData = questionService.export(query); +// // 鏋勫缓鏁版嵁 +// List<QuestionImportVO> exportList = new ArrayList<>(exportData.size() * 4); +// // 琛屽悎骞惰鍒� +// List<RowItem> mergeRowList = new ArrayList<>(exportData.size()); +// int j = 2; +// for (QuestionImportVO 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) { +// QuestionImportVO master = new QuestionImportVO(); +// 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.setSubjectName(data.getSubjectList().stream().collect(Collectors.joining("銆�"))); +// master.setCorrect(data.getCorrect().replaceAll(",", "銆�")); +// BigDecimal score = BigDecimal.valueOf(master.getScore()); +// master.setScore(score.divide(BigDecimal.TEN).intValue()); +// exportList.add(master); +// } else { +// QuestionImportVO optionItem = new QuestionImportVO(); +// 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鍙互闃叉涓枃涔辩爜 褰撶劧鍜宔asyexcel娌℃湁鍏崇郴 +// String fileName = URLEncoder.encode("棰樼洰瀵煎嚭鏁版嵁", "UTF-8").replaceAll("\\+", "%20"); +// response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); +// +// // 鏌ュ嚭鎵�鏈夌殑璇剧洰锛坋xcel涓嬫媺鏁版嵁锛� +// 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 DynamicMergeCellStrategy(mergeRowList, Arrays.asList(0, 1, 2, 5, 6, 7, 8))) +// .doWrite(exportList); +// } /** * 棰樼洰瀵煎叆 @@ -262,114 +232,114 @@ * @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); - - // 濡傛灉鏄涓�鏉″畬鏁存暟鎹紝閭d箞缁х画寰�鍚庤鍙栭�夐」鍐呭 - 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(); - 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("/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); +// +// // 濡傛灉鏄涓�鏉″畬鏁存暟鎹紝閭d箞缁х画寰�鍚庤鍙栭�夐」鍐呭 +// 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 importUser(@RequestPart("file") MultipartFile file) throws Exception { + 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())); @@ -385,6 +355,12 @@ //缁勮棰樼洰 for (QuestionEditRequestVM vm : list) { + // 鍒ゆ柇棰樺共鏄惁閲嶅锛岄噸澶嶄笉娣诲姞 + Integer num = questionService.countQuestionByTitle(vm.getTitle()); + if (num > 0) { + continue; + } + questionEditItemVM.setPrefix("A"); questionEditItemVM.setContent(vm.getA()); @@ -406,9 +382,12 @@ questionEditItemVMS.add(questionEditItemVM); } vm.setItems(questionEditItemVMS); - List<String> str = Arrays.asList(vm.getCorrect().split(",")); + // 娓呯┖鍓嶅悗鐨勯�楀彿锛屼互鍏嶅悗缁綔绛斿垽鏂负閿欒 + String s = vm.getCorrect().replaceAll("^,+|,+$", ""); + vm.setCorrect(s); + List<String> str = Arrays.asList(s.split(SPLIT)); - List<Subject> subjectList = subjectMapper.getNames(vm.getSbNames().split(",")); + List<Subject> subjectList = subjectMapper.getNames(vm.getSbNames().split(SPLIT)); Integer[] arr =subjectList.stream() .map(Subject::getId).toArray(Integer[]::new); @@ -427,4 +406,46 @@ } return RestResponse.ok(); } + + @PostMapping("/question/export") + public void exportQuestion(@RequestBody QuestionExportVO query, HttpServletResponse response) throws IOException { + // 鏌ヨ瀵煎嚭鏁版嵁 + List<QuestionExportData> exportData = questionService.exportData(query); + // 澶勭悊瀹屽杽鏁版嵁 + exportData.stream().forEach(question -> { + if (StringUtils.isNotBlank(question.getContent())) { + QuestionObject questionContent = JSON.parseObject(question.getContent(), QuestionObject.class); + // 璁剧疆閫夐」 + for (QuestionItemObject option : questionContent.getQuestionItemObjects()) { + String optionContent = option.getContent(); + if ("A".equals(option.getPrefix())) { + question.setOptionA(optionContent); + } else if ("B".equals(option.getPrefix())) { + question.setOptionB(optionContent); + } else if ("C".equals(option.getPrefix())) { + question.setOptionC(optionContent); + } else if ("D".equals(option.getPrefix())) { + question.setOptionD(optionContent); + } + } + // 璁剧疆棰樺共銆佽В鏋� + question.setAnalyze(questionContent.getAnalyze()); + question.setTitle(questionContent.getTitleContent()); + // 璁剧疆璇剧洰 + question.setSubject(question.getSubjectList().stream().collect(Collectors.joining(","))); + // 璁剧疆棰樺瀷 + question.setQuestionType(QuestionTypeEnum.fromCode(Integer.valueOf(question.getQuestionType())).getName()); + } + }); + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + // 杩欓噷URLEncoder.encode鍙互闃叉涓枃涔辩爜 褰撶劧鍜宔asyexcel娌℃湁鍏崇郴 + String fileName = URLEncoder.encode("棰樼洰瀵煎嚭鏁版嵁", "UTF-8").replaceAll("\\+", "%20"); + response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); + + // 鏌ュ嚭鎵�鏈夌殑璇剧洰锛坋xcel涓嬫媺鏁版嵁锛� + EasyExcel.write(response.getOutputStream(), QuestionExportData.class) + .sheet("棰樼洰瀵煎嚭鏁版嵁") + .doWrite(exportData); + } } -- Gitblit v1.8.0