|
@@ -10,8 +10,6 @@ import com.google.common.reflect.TypeToken;
|
|
|
import com.google.gson.Gson;
|
|
|
import com.itextpdf.text.DocumentException;
|
|
|
import com.qmth.boot.api.exception.ApiException;
|
|
|
-import com.qmth.teachcloud.common.bean.result.ExcelResult;
|
|
|
-import com.qmth.teachcloud.common.bean.vo.PrintPathVo;
|
|
|
import com.qmth.distributed.print.business.bean.dto.*;
|
|
|
import com.qmth.distributed.print.business.bean.examRule.CodeNameEnableValue;
|
|
|
import com.qmth.distributed.print.business.bean.examRule.FieldsDto;
|
|
@@ -30,7 +28,9 @@ import com.qmth.teachcloud.common.bean.dto.excel.*;
|
|
|
import com.qmth.teachcloud.common.bean.dto.excel.export.BasicStudentErrorExportDto;
|
|
|
import com.qmth.teachcloud.common.bean.dto.excel.export.SysUserErrorExportDto;
|
|
|
import com.qmth.teachcloud.common.bean.params.ArraysParams;
|
|
|
+import com.qmth.teachcloud.common.bean.result.ExcelResult;
|
|
|
import com.qmth.teachcloud.common.bean.vo.PaperInfoVo;
|
|
|
+import com.qmth.teachcloud.common.bean.vo.PrintPathVo;
|
|
|
import com.qmth.teachcloud.common.config.DictionaryConfig;
|
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
import com.qmth.teachcloud.common.entity.*;
|
|
@@ -39,14 +39,14 @@ import com.qmth.teachcloud.common.service.*;
|
|
|
import com.qmth.teachcloud.common.util.*;
|
|
|
import com.qmth.teachcloud.common.util.excel.ExcelError;
|
|
|
import com.qmth.teachcloud.mark.entity.MarkPaper;
|
|
|
-import com.qmth.teachcloud.mark.entity.MarkStudent;
|
|
|
+import com.qmth.teachcloud.mark.params.MarkQuestionParams;
|
|
|
import com.qmth.teachcloud.mark.service.MarkPaperService;
|
|
|
+import com.qmth.teachcloud.mark.service.MarkQuestionService;
|
|
|
import com.qmth.teachcloud.mark.service.MarkStudentService;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.apache.commons.lang3.time.DateUtils;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
@@ -71,7 +71,6 @@ import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
-import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
|
* @Description: 任务处理逻辑impl
|
|
@@ -151,6 +150,8 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
MarkPaperService markPaperService;
|
|
|
@Resource
|
|
|
MarkStudentService markStudentService;
|
|
|
+ @Resource
|
|
|
+ MarkQuestionService markQuestionService;
|
|
|
|
|
|
/**
|
|
|
* 创建pdf前置条件
|
|
@@ -2317,6 +2318,146 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> executeImportObjectiveStructLogic(Map<String, Object> map) throws Exception {
|
|
|
+ SysUser requestUser = (SysUser) map.get(SystemConstant.USER);
|
|
|
+ InputStream inputStream = (InputStream) map.get("inputStream");
|
|
|
+ Long examId = SystemConstant.convertIdToLong(String.valueOf(map.get("examId")));
|
|
|
+ Long schoolId = requestUser.getSchoolId();
|
|
|
+ BasicExam basicExam = basicExamService.getById(examId);
|
|
|
+ if (Objects.isNull(basicExam)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("考试不存在");
|
|
|
+ }
|
|
|
+ if (!ExamModelEnum.MODEL4.equals(basicExam.getExamModel())) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("仅针对模式4的考试可以导入");
|
|
|
+ }
|
|
|
+ // 课程编号名称校验
|
|
|
+ Map<String, String> courseCheckMap = basicCourseService.list(
|
|
|
+ new QueryWrapper<BasicCourse>().lambda().eq(BasicCourse::getSchoolId, schoolId)).stream()
|
|
|
+ .collect(Collectors.toMap(BasicCourse::getCode, BasicCourse::getName));
|
|
|
+ List<MarkPaper> markPaperList = markPaperService.list(
|
|
|
+ new QueryWrapper<MarkPaper>().lambda().eq(MarkPaper::getExamId, examId));
|
|
|
+ // 题号重复校验
|
|
|
+ Set<String> paperCheckSet = new HashSet<>();
|
|
|
+
|
|
|
+ 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();
|
|
|
+ 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]的数据异常 : ", paperNumber, mainNumber,
|
|
|
+ subNumber);
|
|
|
+ String questionKey = paperNumber + SystemConstant.HYPHEN + mainNumber + SystemConstant.HYPHEN + subNumber;
|
|
|
+ if (paperCheckSet.contains(questionKey)) {
|
|
|
+ logicErrorList.add("题号重复");
|
|
|
+ } else {
|
|
|
+ paperCheckSet.add(questionKey);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2.校验课程编号,课程名称,试卷在考试下是否存在
|
|
|
+ if (SystemConstant.strNotNull(courseCode) && SystemConstant.strNotNull(courseName) && SystemConstant.strNotNull(paperNumber)) {
|
|
|
+ if (!courseCheckMap.containsKey(courseCode)) {
|
|
|
+ logicErrorList.add("课程编号不存在");
|
|
|
+ } else if (!courseCheckMap.get(courseCode).equals(courseName)) {
|
|
|
+ logicErrorList.add("课程编号名称不匹配");
|
|
|
+ }
|
|
|
+ if (markPaperList.stream().noneMatch(m -> m.getPaperNumber().equals(paperNumber) && m.getCourseCode().equals(courseCode))) {
|
|
|
+ logicErrorList.add("试卷不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 3.客观题答案必须是OptionsEnum中的编号
|
|
|
+ if (SystemConstant.strNotNull(answer)) {
|
|
|
+ for (String s : answer.split("")) {
|
|
|
+ if (OptionsEnum.getByCode(s) == null) {
|
|
|
+ logicErrorList.add("客观题答案必须是[A-Z]中的大写英文字母");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4.判断答案是否符合题型
|
|
|
+ if (questionType != null && SystemConstant.strNotNull(answer)) {
|
|
|
+ //单选题的答案只能有一个
|
|
|
+ if (Objects.equals(QuestionType.SINGLE.getValue(), questionType)) {
|
|
|
+ if (answer.length() > 1) {
|
|
|
+ logicErrorList.add("单选题答案只能有一个");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断题的答案只能为A&B
|
|
|
+ if (Objects.equals(QuestionType.TRUE_OR_FALSE.getValue(), questionType)) {
|
|
|
+ if (!OptionsEnum.A.getCode().equals(answer) && !OptionsEnum.B.getCode().equals(answer)) {
|
|
|
+ logicErrorList.add("判断题答案只能为A&B");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 整理异常信息
|
|
|
+ if (CollectionUtils.isNotEmpty(logicErrorList)) {
|
|
|
+ errorMsg = 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);
|
|
|
+ markQuestion.setAnswer(answer);
|
|
|
+ markQuestion.setTotalScore(totalScore);
|
|
|
+ markQuestion.setObjectivePolicy(ObjectivePolicy.NONE);
|
|
|
+ markQuestion.setQuestionType(questionType);
|
|
|
+ markQuestionList.add(markQuestion);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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.remove(new QueryWrapper<MarkQuestion>().lambda().eq(MarkQuestion::getExamId, examId)
|
|
|
+ .eq(MarkQuestion::getPaperNumber, k).eq(MarkQuestion::getObjective, true));
|
|
|
+
|
|
|
+ MarkQuestionParams markQuestionParams = new MarkQuestionParams();
|
|
|
+ markQuestionParams.setQuestions(v);
|
|
|
+ markQuestionParams.setExamId(examId);
|
|
|
+ markQuestionParams.setPaperNumber(k);
|
|
|
+ try {
|
|
|
+ markQuestionService.saveQuestions(markQuestionParams);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(e.getMessage());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 验证机构是否存在
|
|
|
*
|