diff --git a/servers/boe-server-all/src/main/java/com/xboe/module/exam/api/ExamQuestionApi.java b/servers/boe-server-all/src/main/java/com/xboe/module/exam/api/ExamQuestionApi.java index fbc64aff..7c0beb6e 100644 --- a/servers/boe-server-all/src/main/java/com/xboe/module/exam/api/ExamQuestionApi.java +++ b/servers/boe-server-all/src/main/java/com/xboe/module/exam/api/ExamQuestionApi.java @@ -166,118 +166,231 @@ public class ExamQuestionApi extends ApiBaseController { return badRequest("请上传正确的试题文件"); } //获取表头 - Row row = sheetAt.getRow(2); + Row row ; //从第二行开始获取数据 List examQuestions1 = new ArrayList<>(); QuestionDto questionDto = new QuestionDto(); + if(sheetAt.getRow(1).getCell(0).getStringCellValue().equals("标题(*)")){ + row = sheetAt.getRow(1); + for (int i = 2;i examOptions = new ArrayList<>(); - for (int j=7;j<=13;j++) { + List examOptions = new ArrayList<>(); + for (int j=7;j<=13;j++) { - if(row1.getCell(j)!=null) { - ExamOption examOption = new ExamOption(); + if(row1.getCell(j)!=null) { + ExamOption examOption = new ExamOption(); // 截取表头 - String substring = row.getCell(j).getStringCellValue().substring(3, 4); - if (row1.getCell(6).getStringCellValue().contains(substring)) { + String substring = row.getCell(j).getStringCellValue().substring(3, 4); + if (row1.getCell(6).getStringCellValue().contains(substring)) { - examOption.setIsAnswer(true); - examOption.setScore(Float.valueOf(row1.getCell(4).getStringCellValue())); - } else { - examOption.setIsAnswer(false); - } - if (examOption.getIsAnswer()) { - examOption.setScore(Float.valueOf(row1.getCell(4).getStringCellValue())); - } + examOption.setIsAnswer(true); + examOption.setScore(Float.valueOf(row1.getCell(4).getStringCellValue())); + } else { + examOption.setIsAnswer(false); + } + if (examOption.getIsAnswer()) { + examOption.setScore(Float.valueOf(row1.getCell(4).getStringCellValue())); + } - examOption.setOptions(row.getCell(j).getStringCellValue()); + examOption.setOptions(row.getCell(j).getStringCellValue()); - Cell cell2 = row1.getCell(j); - cell2.setCellType(CellType.STRING); - examOption.setContent(cell2.getStringCellValue()); + Cell cell2 = row1.getCell(j); + cell2.setCellType(CellType.STRING); + examOption.setContent(cell2.getStringCellValue()); - if (examOption != null && StringUtil.isNotBlank(examOption.getContent())) { - examOptions.add(examOption); + if (examOption != null && StringUtil.isNotBlank(examOption.getContent())) { + examOptions.add(examOption); + } } } - } - examQuestion.setOptionList(examOptions); - examQuestions1.add(examQuestion); - } - //多选 多选的默认分存的是最大分 - else{ - String stringCellValue = row1.getCell(4).getStringCellValue(); - String[] strings = stringCellValue.split(","); + examQuestion.setOptionList(examOptions); + examQuestions1.add(examQuestion); + } + //多选 多选的默认分存的是最大分 + else{ + String stringCellValue = row1.getCell(4).getStringCellValue(); + String[] strings = stringCellValue.split(","); // String[] strings = new String[stringCellValue.length()]; - String max=strings[0]; - for (int j=0;j examOptions = new ArrayList<>(); - //A - for (int j=7;j<=13;j++){ - if(row1.getCell(j)!=null && StringUtil.isNotBlank(row1.getCell(j).getStringCellValue())){ - ExamOption examOption=new ExamOption(); - examOption.setOptions(row.getCell(j).getStringCellValue()); - examOption.setContent(row1.getCell(j).getStringCellValue()); - examOption.setIsAnswer(true); - examOption.setScore(Float.valueOf(strings[j-7])); - if(examOption!=null && StringUtil.isNotBlank(examOption.getContent())){ - examOptions.add(examOption); + String max=strings[0]; + for (int j=0;j examOptions = new ArrayList<>(); + //A + for (int j=7;j<=13;j++){ + if(row1.getCell(j)!=null && StringUtil.isNotBlank(row1.getCell(j).getStringCellValue())){ + ExamOption examOption=new ExamOption(); + examOption.setOptions(row.getCell(j).getStringCellValue()); + examOption.setContent(row1.getCell(j).getStringCellValue()); + examOption.setIsAnswer(true); + examOption.setScore(Float.valueOf(strings[j-7])); + if(examOption!=null && StringUtil.isNotBlank(examOption.getContent())){ + examOptions.add(examOption); + } + + } + } + examQuestion.setOptionList(examOptions); + examQuestions1.add(examQuestion); + } + } + }else { + row = sheetAt.getRow(2); + for (int i = 3;i examOptions = new ArrayList<>(); + for (int j=7;j<=13;j++) { + + if(row1.getCell(j)!=null) { + ExamOption examOption = new ExamOption(); +// 截取表头 + String substring = row.getCell(j).getStringCellValue().substring(3, 4); + if (row1.getCell(6).getStringCellValue().contains(substring)) { + + examOption.setIsAnswer(true); + examOption.setScore(Float.valueOf(row1.getCell(4).getStringCellValue())); + } else { + examOption.setIsAnswer(false); + } + if (examOption.getIsAnswer()) { + examOption.setScore(Float.valueOf(row1.getCell(4).getStringCellValue())); + } + + examOption.setOptions(row.getCell(j).getStringCellValue()); + + Cell cell2 = row1.getCell(j); + cell2.setCellType(CellType.STRING); + examOption.setContent(cell2.getStringCellValue()); + + if (examOption != null && StringUtil.isNotBlank(examOption.getContent())) { + examOptions.add(examOption); + } + } + } + + examQuestion.setOptionList(examOptions); + examQuestions1.add(examQuestion); + } + //多选 多选的默认分存的是最大分 + else{ + String stringCellValue = row1.getCell(4).getStringCellValue(); + String[] strings = stringCellValue.split(","); +// String[] strings = new String[stringCellValue.length()]; + String max=strings[0]; + for (int j=0;j examOptions = new ArrayList<>(); + //A + for (int j=7;j<=13;j++){ + if(row1.getCell(j)!=null && StringUtil.isNotBlank(row1.getCell(j).getStringCellValue())){ + ExamOption examOption=new ExamOption(); + examOption.setOptions(row.getCell(j).getStringCellValue()); + examOption.setContent(row1.getCell(j).getStringCellValue()); + examOption.setIsAnswer(true); + examOption.setScore(Float.valueOf(strings[j-7])); + if(examOption!=null && StringUtil.isNotBlank(examOption.getContent())){ + examOptions.add(examOption); + } + + } + } + examQuestion.setOptionList(examOptions); + examQuestions1.add(examQuestion); } - examQuestion.setOptionList(examOptions); - examQuestions1.add(examQuestion); } } //判断题 只存在试题表中