|
@@ -2,11 +2,11 @@ package com.qmth.distributed.print.business.templete.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.qmth.boot.tools.excel.ExcelReader;
|
|
|
import com.qmth.boot.tools.excel.enums.ExcelType;
|
|
|
import com.qmth.boot.tools.excel.model.DataMap;
|
|
|
import com.qmth.distributed.print.business.bean.dto.ObjectiveStructDto;
|
|
|
+import com.qmth.distributed.print.business.bean.dto.ObjectiveStructImportDto;
|
|
|
import com.qmth.distributed.print.business.bean.dto.SubjectiveStructDto;
|
|
|
import com.qmth.distributed.print.business.bean.dto.SubjectiveStructImportDto;
|
|
|
import com.qmth.distributed.print.business.bean.dto.importFile.BasicExamStudentImport;
|
|
@@ -19,19 +19,16 @@ import com.qmth.distributed.print.business.enums.PrintPlanStatusEnum;
|
|
|
import com.qmth.distributed.print.business.enums.RequiredFieldsEnum;
|
|
|
import com.qmth.distributed.print.business.service.*;
|
|
|
import com.qmth.distributed.print.business.templete.service.ImportLogicService;
|
|
|
-import com.qmth.teachcloud.common.bean.dto.mark.MarkUser;
|
|
|
import com.qmth.teachcloud.common.bean.examRule.CodeNameEnableDisabledValue;
|
|
|
import com.qmth.teachcloud.common.bean.examRule.CodeNameEnableValue;
|
|
|
-import com.qmth.teachcloud.common.bean.params.UserSaveParams;
|
|
|
-import com.qmth.teachcloud.common.bean.result.ExcelResult;
|
|
|
import com.qmth.teachcloud.common.bean.result.SysUserResult;
|
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
import com.qmth.teachcloud.common.entity.*;
|
|
|
import com.qmth.teachcloud.common.enums.*;
|
|
|
import com.qmth.teachcloud.common.service.*;
|
|
|
import com.qmth.teachcloud.common.util.ConvertUtil;
|
|
|
-import com.qmth.teachcloud.mark.bean.answerbatch.Paper;
|
|
|
import com.qmth.teachcloud.mark.entity.MarkPaper;
|
|
|
+import com.qmth.teachcloud.mark.entity.MarkQuestionAnswer;
|
|
|
import com.qmth.teachcloud.mark.entity.MarkUserQuestion;
|
|
|
import com.qmth.teachcloud.mark.service.MarkPaperService;
|
|
|
import com.qmth.teachcloud.mark.service.MarkQuestionAnswerService;
|
|
@@ -902,190 +899,210 @@ public class ImportLogicServiceImpl implements ImportLogicService {
|
|
|
throw ExceptionResultEnum.ERROR.exception("考试不存在");
|
|
|
}
|
|
|
if (!ExamModelEnum.MODEL4.equals(basicExam.getExamModel())) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("仅针对模式4的考试可以导入");
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("非模式4的考试,无法使用此功能");
|
|
|
}
|
|
|
- // 课程编号名称校验
|
|
|
- Map<String, Set<String>> courseCheckMap = basicCourseService.list(
|
|
|
- new QueryWrapper<BasicCourse>().lambda().eq(BasicCourse::getSchoolId, schoolId)).stream().collect(
|
|
|
- Collectors.toMap(BasicCourse::getCode, v -> new HashSet<>(Collections.singletonList(v.getName())), (Set<String> v1, Set<String> v2) -> {
|
|
|
- v1.addAll(v2);
|
|
|
- return v1;
|
|
|
- }));
|
|
|
|
|
|
List<MarkPaper> markPaperList = markPaperService.findMarkPaperListByExamId(examId);
|
|
|
- // 题号重复校验
|
|
|
- // 导入的客观题题号集合
|
|
|
- Set<String> questionNumberCheckSet = new HashSet<>();
|
|
|
- // 客观题选项个数在大题下一致性校验
|
|
|
- Map<String, Integer> questionOptionCountMap = new HashMap<>();
|
|
|
- // 该试卷已存在的主观题题号集合
|
|
|
- Set<String> dbSubjectiveQuestionNumberSet = markQuestionService.list(
|
|
|
- new QueryWrapper<MarkQuestion>().lambda().eq(MarkQuestion::getExamId, examId)
|
|
|
- .eq(MarkQuestion::getObjective, false)).stream()
|
|
|
- .map(e -> e.getPaperNumber() + SystemConstant.HYPHEN + e.getMainNumber() + SystemConstant.HYPHEN + e.getSubNumber()).collect(Collectors.toSet());
|
|
|
-
|
|
|
- ExcelResult<ObjectiveStructDto> excelResult = ConvertUtil.analyzeExcel(inputStream, ObjectiveStructDto.class,
|
|
|
- true, 0);
|
|
|
- List<ObjectiveStructDto> objectiveStructDtoList = excelResult.getDatasource();
|
|
|
- List<MarkQuestion> markQuestionList = new ArrayList<>();
|
|
|
- for (ObjectiveStructDto objectiveStructDto : objectiveStructDtoList) {
|
|
|
- List<String> logicErrorList = new ArrayList<>();
|
|
|
- // 公共异常提示
|
|
|
- String logicErrorCommonNotice = "";
|
|
|
-
|
|
|
- String courseCode = objectiveStructDto.getCourseCode();
|
|
|
- String courseName = objectiveStructDto.getCourseName();
|
|
|
- String paperNumber = objectiveStructDto.getPaperNumber();
|
|
|
- String mainTitle = objectiveStructDto.getMainTitle();
|
|
|
- Integer mainNumber = objectiveStructDto.getMainNumber();
|
|
|
- Integer subNumber = objectiveStructDto.getSubNumber();
|
|
|
- String answer = objectiveStructDto.getAnswer();
|
|
|
- Integer optionCount = objectiveStructDto.getOptionCount();
|
|
|
- Double totalScore = objectiveStructDto.getTotalScore();
|
|
|
- Integer questionType = objectiveStructDto.getQuestionType();
|
|
|
- String errorMsg = objectiveStructDto.getErrorMsg();
|
|
|
-
|
|
|
- // 1.题号重复校验
|
|
|
- if (SystemConstant.strNotNull(paperNumber) && mainNumber != null && subNumber != null) {
|
|
|
- logicErrorCommonNotice = String.format("课程代码为[%s],试卷编号为[%s],大题号为[%s],小题号为[%s]的数据异常 : ", courseCode,
|
|
|
- paperNumber, mainNumber, subNumber);
|
|
|
- String questionNumberKey =
|
|
|
- courseCode + SystemConstant.HYPHEN + paperNumber + SystemConstant.HYPHEN + mainNumber + SystemConstant.HYPHEN + subNumber;
|
|
|
- if (questionNumberCheckSet.contains(questionNumberKey)) {
|
|
|
- logicErrorList.add("excel中题号重复");
|
|
|
- } else {
|
|
|
- questionNumberCheckSet.add(questionNumberKey);
|
|
|
+ Map<String, MarkPaper> markPaperCourseMap = markPaperList.stream().collect(Collectors.toMap(MarkPaper::getCourseCode, Function.identity()));
|
|
|
+ Map<String, MarkPaper> markPaperPaperNumberMap = markPaperList.stream().collect(Collectors.toMap(MarkPaper::getPaperNumber, Function.identity()));
|
|
|
+
|
|
|
+ List<MarkQuestion> markQuestionList = markQuestionService.listByExamIdAndObjective(examId, true);
|
|
|
+ Set<String> objectivePaperNumberSet = markQuestionList.stream().map(MarkQuestion::getPaperNumber).collect(Collectors.toSet());
|
|
|
+
|
|
|
+ List<MarkQuestion> markQuestionList1 = markQuestionService.listByExamIdAndObjective(examId, false);
|
|
|
+ Set<String> subjectivePaperNumberSet = markQuestionList1.stream().map(m -> SystemConstant.mergeString(SystemConstant.HYPHEN, m.getPaperNumber(), m.getMainNumber(), m.getSubNumber())).collect(Collectors.toSet());
|
|
|
+
|
|
|
+ List<SysUserResult> sysUserList = sysUserService.listBySchoolId(schoolId);
|
|
|
+ Map<String, SysUserResult> sysUserMap = sysUserList.stream().collect(Collectors.toMap(SysUserResult::getLoginName, Function.identity()));
|
|
|
+
|
|
|
+ ExcelReader excelReader = ExcelReader.create(ExcelType.XLSX, inputStream, 0);
|
|
|
+ List<ObjectiveStructImportDto> objectiveStructImportDtoList = excelReader.getObjectList(ObjectiveStructImportDto.class);
|
|
|
+
|
|
|
+ // 课程下试卷编号map
|
|
|
+ Map<String, String> coursePaperNumberMap = new HashMap<>();
|
|
|
+ // 课程、试卷编号下大题号、小题号
|
|
|
+ Map<String, String> coursePaperQuestionMap = new HashMap<>();
|
|
|
+
|
|
|
+ List<MarkQuestion> markQuestions = new ArrayList<>();
|
|
|
+ List<MarkQuestionAnswer> markQuestionAnswers = new ArrayList<>();
|
|
|
+ boolean hasError = false;
|
|
|
+ List<ObjectiveStructDto> objectiveStructDtos = new ArrayList<>();
|
|
|
+ // 按课程+试卷编号分组
|
|
|
+ for (ObjectiveStructImportDto objectiveStructImportDto : objectiveStructImportDtoList) {
|
|
|
+ ObjectiveStructDto objectiveStructDto = new ObjectiveStructDto();
|
|
|
+ BeanUtils.copyProperties(objectiveStructImportDto, objectiveStructDto);
|
|
|
+ try {
|
|
|
+ List<String> errorList = new ArrayList<>();
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(objectiveStructDto.getCourseCode())) {
|
|
|
+ errorList.add("课程代码不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(objectiveStructDto.getCourseName())) {
|
|
|
+ errorList.add("课程名称不能为空");
|
|
|
}
|
|
|
- if (dbSubjectiveQuestionNumberSet.contains(questionNumberKey)) {
|
|
|
- logicErrorList.add("该题号已存在主观题中");
|
|
|
+ if (StringUtils.isBlank(objectiveStructDto.getPaperNumber())) {
|
|
|
+ errorList.add("试卷编号不能为空");
|
|
|
}
|
|
|
- String mainQuestionKey = paperNumber + SystemConstant.HYPHEN + mainNumber;
|
|
|
- if (questionOptionCountMap.containsKey(mainQuestionKey)) {
|
|
|
- if (!Objects.equals(questionOptionCountMap.get(mainQuestionKey), optionCount)) {
|
|
|
- logicErrorList.add("选项个数和该大题中的其他小题不一致");
|
|
|
- }
|
|
|
- } else {
|
|
|
- questionOptionCountMap.put(mainQuestionKey, optionCount);
|
|
|
+ String mainTitle = objectiveStructDto.getMainTitle();
|
|
|
+ if (StringUtils.isBlank(mainTitle)) {
|
|
|
+ errorList.add("大题名称不能为空");
|
|
|
+ }
|
|
|
+ Integer mainNumber = objectiveStructDto.getMainNumber();
|
|
|
+ if (mainNumber == null) {
|
|
|
+ errorList.add("大题号不能为空");
|
|
|
+ }
|
|
|
+ Integer subNumber = objectiveStructDto.getSubNumber();
|
|
|
+ if (subNumber == null) {
|
|
|
+ errorList.add("小题号不能为空");
|
|
|
+ }
|
|
|
+ String answer = objectiveStructDto.getAnswer();
|
|
|
+ if (StringUtils.isBlank(answer)) {
|
|
|
+ errorList.add("标答不能为空");
|
|
|
+ }
|
|
|
+ Integer optionCount = objectiveStructDto.getOptionCount();
|
|
|
+ if (optionCount == null) {
|
|
|
+ errorList.add("选项个数不能为空");
|
|
|
+ }
|
|
|
+ Double totalScore = objectiveStructDto.getTotalScore();
|
|
|
+ if (totalScore == null) {
|
|
|
+ errorList.add("小题满分不能为空");
|
|
|
+ }
|
|
|
+ Integer questionType = objectiveStructDto.getQuestionType();
|
|
|
+ if (questionType == null) {
|
|
|
+ errorList.add("题型不能为空");
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(errorList)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(String.join(";", errorList));
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- // 2.校验课程编号,课程名称,试卷在考试下是否存在
|
|
|
- if (SystemConstant.strNotNull(courseCode) && SystemConstant.strNotNull(courseName) && SystemConstant.strNotNull(paperNumber)) {
|
|
|
- if (!courseCheckMap.containsKey(courseCode)) {
|
|
|
- logicErrorList.add("课程编号不存在");
|
|
|
- } else if (!courseCheckMap.get(courseCode).contains(courseName)) {
|
|
|
- logicErrorList.add("课程编号名称不匹配");
|
|
|
+ // 检查选项个数和标答范围是否一对待
|
|
|
+ validObjectiveAnswer(answer, optionCount, questionType);
|
|
|
+
|
|
|
+ String courseCode = objectiveStructDto.getCourseCode().trim();
|
|
|
+ String courseName = objectiveStructDto.getCourseName().trim();
|
|
|
+ String paperNumber = objectiveStructDto.getPaperNumber().trim();
|
|
|
+
|
|
|
+ // 课程是否存在
|
|
|
+ if (!markPaperCourseMap.containsKey(courseCode)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("未查询到此课程");
|
|
|
+ } else {
|
|
|
+ MarkPaper markPaper = markPaperCourseMap.get(courseCode);
|
|
|
+ if (!courseName.equals(markPaper.getCourseName())) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("评卷设置中,课程名称为[" + markPaper.getCourseName() + "]");
|
|
|
+ }
|
|
|
+ objectiveStructDto.setCourseId(markPaper.getCourseId());
|
|
|
}
|
|
|
- if (markPaperList.stream().noneMatch(
|
|
|
- m -> m.getPaperNumber().equals(paperNumber) && m.getCourseCode().equals(courseCode) && m.getCourseName().equals(courseName))) {
|
|
|
- logicErrorList.add("考试课程中不存在该试卷,请先创建试卷");
|
|
|
+
|
|
|
+ // 试卷编号是否存在
|
|
|
+ if (!markPaperPaperNumberMap.containsKey(paperNumber)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("未查询到此试卷编号");
|
|
|
}
|
|
|
- }
|
|
|
- // 3.选项越界校验
|
|
|
- List<String> optionScope = new ArrayList<>();
|
|
|
- try {
|
|
|
- for (int j = 1; j <= optionCount; j++) {
|
|
|
- String code = OptionsEnum.getCodeByIndex(j);
|
|
|
- optionScope.add(code);
|
|
|
+
|
|
|
+ // 试卷编号是否设置了主观题
|
|
|
+ if (objectivePaperNumberSet.contains(paperNumber)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("该试卷编号下已经存在客观题试卷结构,不允许导入");
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception(e.getMessage());
|
|
|
- }
|
|
|
|
|
|
- // 答案选项越界校验
|
|
|
- List<String> answerList = Arrays.asList(answer.split(""));
|
|
|
- if (CollectionUtils.isNotEmpty(answerList)) {
|
|
|
- for (String cell : answerList) {
|
|
|
- String outOfBoundsException = String.format("答案[%s]错误。答案只能从[%s]中选择", cell, String.join("", optionScope));
|
|
|
- try {
|
|
|
- OptionsEnum optionsEnum = OptionsEnum.getByCode(cell);
|
|
|
- int optionIndex = optionsEnum.getIndex();
|
|
|
- if (optionIndex > optionCount) {
|
|
|
- // 答案选项超出范围
|
|
|
- logicErrorList.add(outOfBoundsException);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- logicErrorList.add(outOfBoundsException);
|
|
|
+ // 校验课程下试卷编号唯一
|
|
|
+ if (coursePaperNumberMap.containsKey(courseCode)) {
|
|
|
+ if (!paperNumber.equals(coursePaperNumberMap.get(courseCode))) {
|
|
|
+ errorList.add("课程存在不同试卷编号");
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(String.join(";", errorList));
|
|
|
}
|
|
|
+ } else {
|
|
|
+ coursePaperNumberMap.put(courseCode, paperNumber);
|
|
|
}
|
|
|
- } else {
|
|
|
- logicErrorList.add("答案必填");
|
|
|
- }
|
|
|
|
|
|
- // 4.判断答案是否符合题型
|
|
|
- if (questionType != null && SystemConstant.strNotNull(answer)) {
|
|
|
- switch (questionType) {
|
|
|
- case 1:
|
|
|
- if (answer.length() > 1) {
|
|
|
- logicErrorList.add("单选题答案只能有一个");
|
|
|
- }
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- break;
|
|
|
- case 3:
|
|
|
- if (optionCount != 2) {
|
|
|
- logicErrorList.add("判断题[选项个数]只能为2");
|
|
|
+ // 校验试卷编号唯一
|
|
|
+ if (coursePaperNumberMap.containsValue(paperNumber)) {
|
|
|
+ for (Map.Entry<String, String> entry : coursePaperNumberMap.entrySet()) {
|
|
|
+ if (entry.getValue().equals(paperNumber) && !courseCode.equals(entry.getKey())) {
|
|
|
+ errorList.add("试卷编号已被其它课程占用");
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(String.join(";", errorList));
|
|
|
}
|
|
|
- break;
|
|
|
- default:
|
|
|
- logicErrorList.add("[题型(1-单选,2-多选,3-判断)]必须从1、2、3中填写");
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- // 整理异常信息
|
|
|
- if (CollectionUtils.isNotEmpty(logicErrorList)) {
|
|
|
- if (SystemConstant.strNotNull(errorMsg)) {
|
|
|
- errorMsg = errorMsg + "、" + logicErrorCommonNotice + String.join("、", logicErrorList);
|
|
|
+ // 题号重复校验
|
|
|
+ String coursePaper = SystemConstant.mergeString(SystemConstant.HYPHEN, courseCode, paperNumber);
|
|
|
+ String questionNumber = SystemConstant.mergeString(SystemConstant.HYPHEN, mainNumber, subNumber);
|
|
|
+ if (coursePaperQuestionMap.containsKey(coursePaper)) {
|
|
|
+ if (questionNumber.equals(coursePaperQuestionMap.get(coursePaper))) {
|
|
|
+ errorList.add("存在相同大题号、小题号");
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(String.join(";", errorList));
|
|
|
+ }
|
|
|
} else {
|
|
|
- errorMsg = logicErrorCommonNotice + String.join("、", logicErrorList);
|
|
|
- }
|
|
|
- objectiveStructDto.setErrorMsg(errorMsg);
|
|
|
- } else {
|
|
|
- MarkQuestion markQuestion = new MarkQuestion();
|
|
|
- markQuestion.setExamId(examId);
|
|
|
- markQuestion.setPaperNumber(paperNumber);
|
|
|
- markQuestion.setPaperType(OptionsEnum.A.getCode());
|
|
|
- markQuestion.setObjective(true);
|
|
|
- markQuestion.setMainNumber(mainNumber);
|
|
|
- markQuestion.setSubNumber(subNumber);
|
|
|
- markQuestion.setMainTitle(mainTitle);
|
|
|
- // todo 2024-10-16
|
|
|
- markQuestion.setAnswer(answer);
|
|
|
- markQuestion.setOptionCount(optionCount);
|
|
|
- markQuestion.setTotalScore(totalScore);
|
|
|
- // todo 2024-10-16
|
|
|
-// markQuestion.setObjectivePolicy(ObjectivePolicy.NONE);
|
|
|
- markQuestion.setQuestionType(questionType);
|
|
|
- markQuestionList.add(markQuestion);
|
|
|
+ coursePaperQuestionMap.put(coursePaper, questionNumber);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 题号是否被主观题使用
|
|
|
+ if (subjectivePaperNumberSet.contains(SystemConstant.mergeString(SystemConstant.HYPHEN, paperNumber, mainNumber, subNumber))) {
|
|
|
+ errorList.add("大题号、小题号已被主观题使用");
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(String.join(";", errorList));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 组装数据
|
|
|
+ assembleObjectiveImportData(examId, objectiveStructDto, markQuestions, markQuestionAnswers, sysUserMap);
|
|
|
+ } catch (Exception e) {
|
|
|
+ hasError = true;
|
|
|
+ objectiveStructDto.setErrorMsg(e.getMessage());
|
|
|
+ } finally {
|
|
|
+ objectiveStructDtos.add(objectiveStructDto);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (objectiveStructDtoList.stream().anyMatch(e -> SystemConstant.strNotNull(e.getErrorMsg()))) {
|
|
|
- // 抛出excel解析异常
|
|
|
- throw ExceptionResultEnum.ERROR.exception(
|
|
|
- objectiveStructDtoList.stream().map(ObjectiveStructDto::getErrorMsg).filter(SystemConstant::strNotNull).collect(Collectors.joining(System.lineSeparator())));
|
|
|
- } else {
|
|
|
- // 保存客观题结构
|
|
|
- Map<String, List<MarkQuestion>> markQuestionMap = markQuestionList.stream().collect(Collectors.groupingBy(MarkQuestion::getPaperNumber));
|
|
|
- markQuestionMap.forEach((k, v) -> {
|
|
|
- // 优先删除该试卷编号下的客观题
|
|
|
- markQuestionService.deleteByExamIdAndPaperNumberAndObjective(examId, k, true);
|
|
|
- // 保存客观题
|
|
|
- markQuestionService.saveBatch(v);
|
|
|
- markQuestionService.updateMarkPaperScore(examId, k);
|
|
|
-
|
|
|
- // 增加客观题
|
|
|
- markQuestionAnswerService.deleteByExamIdAndPaperNumber(examId, k);
|
|
|
- markQuestionAnswerService.saveByMarkQuestion(examId, k, v, true);
|
|
|
- });
|
|
|
- // 更改试卷结构状态为已提交
|
|
|
- Set<String> paperNumberSet = markQuestionMap.keySet();
|
|
|
- if (CollectionUtils.isNotEmpty(paperNumberSet)) {
|
|
|
- markPaperService.update(new UpdateWrapper<MarkPaper>().lambda().eq(MarkPaper::getExamId, examId)
|
|
|
- .in(MarkPaper::getPaperNumber, paperNumberSet).set(MarkPaper::getQuestionStatus, true));
|
|
|
+ map.put(SystemConstant.ERROR_DATA_LIST, objectiveStructDtos);
|
|
|
+ map.put(SystemConstant.DATASOURCE, markQuestions);
|
|
|
+ map.put(SystemConstant.DATASOURCE1, markQuestionAnswers);
|
|
|
+ map.put(SystemConstant.DATA_COUNT, objectiveStructDtos.size());
|
|
|
+ map.put(SystemConstant.HAS_ERROR_DATA, hasError);
|
|
|
+
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void validObjectiveAnswer(String answer, Integer optionCount, Integer questionType) {
|
|
|
+ if (optionCount <= 0 || optionCount > 26) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("选项个数只能填1~26之间的整数");
|
|
|
+ }
|
|
|
+ // 选项可选范围
|
|
|
+ List<String> optionScope = OptionsEnum.scopeByOptionCount(optionCount);
|
|
|
+ String optionScopeString = String.join("", optionScope);
|
|
|
+ String[] answers = answer.split("");
|
|
|
+ // 单选题
|
|
|
+ if (questionType == 1) {
|
|
|
+ if (answers.length > 1) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("单选题有且仅有一个答案");
|
|
|
+ }
|
|
|
+ for (String s : answers) {
|
|
|
+ if (!optionScope.contains(s)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("答案只能从[" + optionScopeString + "]中选择一个");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- return map;
|
|
|
+ // 多选题
|
|
|
+ else if (questionType == 2) {
|
|
|
+ for (String s : answers) {
|
|
|
+ if (!optionScope.contains(s)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("答案只能从[" + optionScopeString + "]中选择一个或多个");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 判断题
|
|
|
+ else if (questionType == 3) {
|
|
|
+ if (optionCount != 2) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("判断题选项个数只能为2");
|
|
|
+ }
|
|
|
+ if (answers.length > 1) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("判断题有且仅有一个答案A或B,A代表正确,B代表错误");
|
|
|
+ }
|
|
|
+ for (String s : answers) {
|
|
|
+ if (!optionScope.contains(s)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("答案只能从[" + optionScopeString + "]中选择一个");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("题型只能从1、2、3中选择一个填写,1代表单选题,2代表多选题,3代表判断判断题");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
@@ -1148,6 +1165,9 @@ public class ImportLogicServiceImpl implements ImportLogicService {
|
|
|
if (StringUtils.isBlank(subjectiveStructDto.getPaperNumber())) {
|
|
|
errorList.add("试卷编号不能为空");
|
|
|
}
|
|
|
+ if (StringUtils.isBlank(subjectiveStructDto.getMainTitle())) {
|
|
|
+ errorList.add("大题名称不能为空");
|
|
|
+ }
|
|
|
Integer mainNumber = subjectiveStructDto.getMainNumber();
|
|
|
if (mainNumber == null) {
|
|
|
errorList.add("大题号不能为空");
|
|
@@ -1202,7 +1222,7 @@ public class ImportLogicServiceImpl implements ImportLogicService {
|
|
|
|
|
|
// 试卷编号是否设置了主观题
|
|
|
if (subjectivePaperNumberSet.contains(paperNumber)) {
|
|
|
- errorList.add("试卷编号设置了主观题");
|
|
|
+ errorList.add("该试卷编号下已经存在主观题试卷结构,不允许导入");
|
|
|
throw ExceptionResultEnum.ERROR.exception(String.join(";", errorList));
|
|
|
}
|
|
|
|
|
@@ -1263,6 +1283,39 @@ public class ImportLogicServiceImpl implements ImportLogicService {
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+ private void assembleObjectiveImportData(Long examId, ObjectiveStructDto objectiveStructDto, List<MarkQuestion> markQuestions, List<MarkQuestionAnswer> markQuestionAnswers, Map<String, SysUserResult> sysUserMap) {
|
|
|
+ MarkQuestion markQuestion = new MarkQuestion();
|
|
|
+ markQuestion.setId(SystemConstant.getDbUuid());
|
|
|
+ markQuestion.setExamId(examId);
|
|
|
+ markQuestion.setCourseId(objectiveStructDto.getCourseId());
|
|
|
+ markQuestion.setPaperNumber(objectiveStructDto.getPaperNumber());
|
|
|
+ markQuestion.setObjective(true);
|
|
|
+ markQuestion.setMainNumber(objectiveStructDto.getMainNumber());
|
|
|
+ markQuestion.setSubNumber(objectiveStructDto.getSubNumber());
|
|
|
+ markQuestion.setMainTitle(objectiveStructDto.getMainTitle());
|
|
|
+ markQuestion.setOptionCount(objectiveStructDto.getOptionCount());
|
|
|
+ markQuestion.setQuestionType(objectiveStructDto.getQuestionType());
|
|
|
+ markQuestion.setTotalScore(objectiveStructDto.getTotalScore());
|
|
|
+ markQuestions.add(markQuestion);
|
|
|
+
|
|
|
+ MarkPaper markPaper = markPaperService.getByExamIdAndPaperNumber(examId, objectiveStructDto.getPaperNumber());
|
|
|
+ String paperType = markPaper.getPaperType();
|
|
|
+ if (StringUtils.isNotBlank(paperType)) {
|
|
|
+ for (String type : paperType.split(SystemConstant.COMMA)) {
|
|
|
+ MarkQuestionAnswer markQuestionAnswer = new MarkQuestionAnswer();
|
|
|
+ markQuestionAnswer.setId(SystemConstant.getDbUuid());
|
|
|
+ markQuestionAnswer.setExamId(examId);
|
|
|
+ markQuestionAnswer.setPaperNumber(objectiveStructDto.getPaperNumber());
|
|
|
+ markQuestionAnswer.setPaperType(type);
|
|
|
+ markQuestionAnswer.setMainNumber(objectiveStructDto.getMainNumber());
|
|
|
+ markQuestionAnswer.setSubNumber(objectiveStructDto.getSubNumber());
|
|
|
+ markQuestionAnswer.setAnswer(objectiveStructDto.getAnswer());
|
|
|
+ markQuestionAnswer.setObjectivePolicy(ObjectivePolicy.NONE);
|
|
|
+ markQuestionAnswers.add(markQuestionAnswer);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void assembleSubjectiveImportData(Long examId, SubjectiveStructDto subjectiveStructDto, List<MarkQuestion> markQuestions, List<MarkUserQuestion> markUserQuestions, Map<String, SysUserResult> sysUserMap) {
|
|
|
MarkQuestion markQuestion = new MarkQuestion();
|
|
|
markQuestion.setId(SystemConstant.getDbUuid());
|