|
@@ -0,0 +1,266 @@
|
|
|
+package cn.com.qmth.examcloud.core.oe.admin.service.impl;
|
|
|
+
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.bean.CourseBean;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.base.utils.QuestionTypeUtil;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.dao.ExamRecordDataRepo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.dao.ExamRecordQuestionsRepo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.dao.ExamScoreRepo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.dao.ExamStudentRepo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.dao.entity.ExamQuestionEntity;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.dao.entity.ExamRecordDataEntity;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.dao.entity.ExamRecordPaperStructEntity;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.dao.entity.ExamRecordQuestionsEntity;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.dao.entity.ExamScoreEntity;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.dao.entity.ExamStudentEntity;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.dao.enums.ExamRecordStatus;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.service.ExamRecordPaperStructService;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.service.PracticeService;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.service.bean.PaperStructInfo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.service.bean.PracticeCourseInfo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.service.bean.PracticeDetailInfo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.service.bean.PracticeRecordInfo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.service.others.ExamCacheTransferHelper;
|
|
|
+import cn.com.qmth.examcloud.examwork.api.bean.ExamBean;
|
|
|
+import cn.com.qmth.examcloud.question.commons.core.paper.DefaultPaper;
|
|
|
+import cn.com.qmth.examcloud.question.commons.core.paper.DefaultQuestionGroup;
|
|
|
+import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author chenken
|
|
|
+ * @date 2018年9月7日 上午11:05:18
|
|
|
+ * @company QMTH
|
|
|
+ * @description PracticeServiceImpl.java
|
|
|
+ */
|
|
|
+@Service("practiceService")
|
|
|
+public class PracticeServiceImpl implements PracticeService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamStudentRepo examStudentRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamRecordDataRepo examRecordDataRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamScoreRepo examScoreRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamRecordQuestionsRepo examRecordQuestionsRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamRecordPaperStructService examRecordPaperStructService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<PracticeCourseInfo> queryPracticeCourseList(Long examId, Long studentId) {
|
|
|
+ if (examId == null || studentId == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<ExamStudentEntity> examStudentList = examStudentRepo.findByExamIdAndStudentId(examId, studentId);
|
|
|
+ if (examStudentList == null || examStudentList.size() == 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<PracticeCourseInfo> practiceCourseInfos = new ArrayList<PracticeCourseInfo>();
|
|
|
+ ExamBean examBean = ExamCacheTransferHelper.getCachedExam(examId,studentId);
|
|
|
+ for (ExamStudentEntity examStudent : examStudentList) {
|
|
|
+ practiceCourseInfos.add(buildPracticeCourseInfo(examStudent, examBean));
|
|
|
+ }
|
|
|
+ return practiceCourseInfos;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private PracticeCourseInfo buildPracticeCourseInfo(ExamStudentEntity examStudent, ExamBean examBean) {
|
|
|
+ PracticeCourseInfo practiceCourseInfo = new PracticeCourseInfo();
|
|
|
+ practiceCourseInfo.setExamStudentId(examStudent.getExamStudentId());
|
|
|
+ practiceCourseInfo.setCourseCode(examStudent.getCourseCode());
|
|
|
+
|
|
|
+ CourseBean courseBean = ExamCacheTransferHelper.getCachedCourse(examStudent.getCourseId());
|
|
|
+ practiceCourseInfo.setCourseName(courseBean.getName());
|
|
|
+ practiceCourseInfo.setStudentCode(examStudent.getStudentCode());
|
|
|
+ practiceCourseInfo.setStudentName(examStudent.getStudentName());
|
|
|
+
|
|
|
+ practiceCourseInfo.setExamId(examBean.getId());
|
|
|
+ practiceCourseInfo.setExamName(examBean.getName());
|
|
|
+ practiceCourseInfo.setExamType(examBean.getExamType());
|
|
|
+ practiceCourseInfo.setStartTime(examBean.getBeginTime());
|
|
|
+ practiceCourseInfo.setEndTime(examBean.getEndTime());
|
|
|
+
|
|
|
+ List<ExamRecordDataEntity> examRecordEntities = examRecordDataRepo.findByExamStudentId(examStudent.getExamStudentId());
|
|
|
+
|
|
|
+ int allExamRecordNums = 0;
|
|
|
+ List<ExamScoreEntity> examScoreEntities = new ArrayList<ExamScoreEntity>();
|
|
|
+ for (ExamRecordDataEntity examRecordData : examRecordEntities) {
|
|
|
+ if (examRecordData.getExamRecordStatus() != ExamRecordStatus.EXAM_ING) {
|
|
|
+ allExamRecordNums++;
|
|
|
+ ExamScoreEntity examScore = examScoreRepo.findByExamRecordDataId(examRecordData.getId());
|
|
|
+ examScoreEntities.add(examScore);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ double allObjectiveAccuracy = 0;//总正确率
|
|
|
+ double maxObjectiveAccuracy = 0;//最高客观题正确率
|
|
|
+ long recentObjectiveAccuracyId = 0;//最近ID
|
|
|
+ double recentObjectiveAccuracy = 0;//最近客观题正确率
|
|
|
+
|
|
|
+ for (ExamScoreEntity examScore : examScoreEntities) {
|
|
|
+ if (examScore != null) {
|
|
|
+ if (examScore.getObjectiveAccuracy() > maxObjectiveAccuracy) {
|
|
|
+ maxObjectiveAccuracy = examScore.getObjectiveAccuracy();
|
|
|
+ }
|
|
|
+ if (examScore.getId() > recentObjectiveAccuracyId) {//判断是否为最近的
|
|
|
+ recentObjectiveAccuracyId = examScore.getId();
|
|
|
+ recentObjectiveAccuracy = examScore.getObjectiveAccuracy();
|
|
|
+ }
|
|
|
+ allObjectiveAccuracy = allObjectiveAccuracy + examScore.getObjectiveAccuracy();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //平均正确率
|
|
|
+ double aveObjectiveAccuracy = 0D;
|
|
|
+ if (allExamRecordNums > 0) {
|
|
|
+ aveObjectiveAccuracy = Double.valueOf(new DecimalFormat("#.00").format(allObjectiveAccuracy / allExamRecordNums));
|
|
|
+ }
|
|
|
+ practiceCourseInfo.setAveObjectiveAccuracy(aveObjectiveAccuracy);
|
|
|
+ practiceCourseInfo.setMaxObjectiveAccuracy(maxObjectiveAccuracy);
|
|
|
+ practiceCourseInfo.setRecentObjectiveAccuracy(recentObjectiveAccuracy);
|
|
|
+ practiceCourseInfo.setPracticeCount(allExamRecordNums);//练习总次数
|
|
|
+ return practiceCourseInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<PracticeRecordInfo> queryPracticeRecordList(Long examStudentId) {
|
|
|
+ if (examStudentId == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<ExamRecordDataEntity> examRecordDataList = examRecordDataRepo.findByExamStudentId(examStudentId);
|
|
|
+ List<PracticeRecordInfo> practiceRecords = new ArrayList<PracticeRecordInfo>();
|
|
|
+ ExamStudentEntity examStudent = examStudentRepo.findByExamStudentId(examStudentId);
|
|
|
+ CourseBean courseBean = ExamCacheTransferHelper.getCachedCourse(examStudent.getCourseId());
|
|
|
+ for (ExamRecordDataEntity examRecordData : examRecordDataList) {
|
|
|
+ if (examRecordData.getExamRecordStatus() != ExamRecordStatus.EXAM_ING) {
|
|
|
+ practiceRecords.add(buildPracticeRecord(examRecordData, courseBean));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return practiceRecords;
|
|
|
+ }
|
|
|
+
|
|
|
+ private PracticeRecordInfo buildPracticeRecord(ExamRecordDataEntity examRecordData, CourseBean courseBean) {
|
|
|
+ PracticeRecordInfo practiceRecordInfo = new PracticeRecordInfo();
|
|
|
+
|
|
|
+ practiceRecordInfo.setId(examRecordData.getId());
|
|
|
+ practiceRecordInfo.setCourseCode(courseBean.getCode());
|
|
|
+ practiceRecordInfo.setCourseName(courseBean.getName());
|
|
|
+ practiceRecordInfo.setStartTime(examRecordData.getStartTime());
|
|
|
+ practiceRecordInfo.setEndTime(examRecordData.getEndTime());
|
|
|
+ practiceRecordInfo.setUsedExamTime(examRecordData.getUsedExamTime());
|
|
|
+
|
|
|
+ ExamScoreEntity examScoreEntity = examScoreRepo.findByExamRecordDataId(examRecordData.getId());
|
|
|
+ practiceRecordInfo.setObjectiveAccuracy(examScoreEntity.getObjectiveAccuracy());//客观题答对的比率
|
|
|
+ ExamRecordQuestionsEntity examRecordQuestions = examRecordQuestionsRepo.findByExamRecordDataId(examRecordData.getId());
|
|
|
+ List<ExamQuestionEntity> examQuestionEntities = examRecordQuestions.getExamQuestionEntities();
|
|
|
+ practiceRecordInfo = calculationExamQuestionSituationInfo(practiceRecordInfo, examQuestionEntities);
|
|
|
+
|
|
|
+ return practiceRecordInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算答题情况
|
|
|
+ *
|
|
|
+ * @param practiceRecordInfo
|
|
|
+ * @param examQuestionEntities
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private PracticeRecordInfo calculationExamQuestionSituationInfo(PracticeRecordInfo practiceRecordInfo, List<ExamQuestionEntity> examQuestionEntities) {
|
|
|
+ if (practiceRecordInfo == null) {
|
|
|
+ practiceRecordInfo = new PracticeRecordInfo();
|
|
|
+ }
|
|
|
+ int succQuestionNum = 0;//正确答题数
|
|
|
+ int failQuestionNum = 0;//错误答题数
|
|
|
+ int notAnsweredCount = 0;//未作答题数
|
|
|
+ for (ExamQuestionEntity examQuestionEntity : examQuestionEntities) {
|
|
|
+ if (examQuestionEntity.getIsAnswer() == null || !examQuestionEntity.getIsAnswer()) {
|
|
|
+ notAnsweredCount++;
|
|
|
+ } else {
|
|
|
+ //客观题判断正确错误
|
|
|
+ if (QuestionTypeUtil.isObjectiveQuestion(examQuestionEntity.getQuestionType())) {
|
|
|
+ if (examQuestionEntity.getCorrectAnswer() != null
|
|
|
+ && examQuestionEntity.getStudentAnswer() != null
|
|
|
+ && examQuestionEntity.getCorrectAnswer().equals(examQuestionEntity.getStudentAnswer())) {
|
|
|
+ succQuestionNum++;
|
|
|
+ } else {
|
|
|
+ failQuestionNum++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int objectiveQuestionsNum = 0;//客观题总数
|
|
|
+ for (ExamQuestionEntity examQuestionEntity : examQuestionEntities) {
|
|
|
+ if (QuestionTypeUtil.isObjectiveQuestion(examQuestionEntity.getQuestionType())) {
|
|
|
+ objectiveQuestionsNum++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ practiceRecordInfo.setObjectiveNum(objectiveQuestionsNum);
|
|
|
+ practiceRecordInfo.setSuccQuestionNum(succQuestionNum);
|
|
|
+ practiceRecordInfo.setFailQuestionNum(failQuestionNum);
|
|
|
+ practiceRecordInfo.setNotAnsweredCount(notAnsweredCount);
|
|
|
+ practiceRecordInfo.setTotalQuestionCount(examQuestionEntities.size());
|
|
|
+ return practiceRecordInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PracticeDetailInfo getPracticeDetailInfo(Long examRecordDataId) {
|
|
|
+ if (examRecordDataId == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ PracticeDetailInfo practiceDetailInfo = new PracticeDetailInfo();
|
|
|
+ //取出试卷结构
|
|
|
+ ExamRecordPaperStructEntity examRecordPaperStruct = examRecordPaperStructService.getExamRecordPaperStruct(examRecordDataId);
|
|
|
+ DefaultPaper defaultPaper = examRecordPaperStruct.getDefaultPaper();
|
|
|
+ List<PaperStructInfo> paperStructInfos = new ArrayList<PaperStructInfo>();
|
|
|
+ List<DefaultQuestionGroup> questionGroupList = defaultPaper.getQuestionGroupList();
|
|
|
+ //取出作答记录
|
|
|
+ ExamRecordQuestionsEntity examRecordQuestions = examRecordQuestionsRepo.findByExamRecordDataId(examRecordDataId);
|
|
|
+ List<ExamQuestionEntity> examQuestionEntities = examRecordQuestions.getExamQuestionEntities();
|
|
|
+ //遍历大题
|
|
|
+ int objectiveNum = 0;//各个大题中的客观题总数
|
|
|
+ int objectSuccessNum = 0;//各个大题中的客观题答对的总数量
|
|
|
+ for (int i = 0; i < questionGroupList.size(); i++) {
|
|
|
+ DefaultQuestionGroup defaultQuestionGroup = questionGroupList.get(i);
|
|
|
+ PaperStructInfo paperStructInfo = new PaperStructInfo();
|
|
|
+ paperStructInfo.setTitle(defaultQuestionGroup.getGroupName());//大题名称
|
|
|
+ paperStructInfo.setIndex(i + 1);//大题号
|
|
|
+ //使用大题号过滤
|
|
|
+ List<ExamQuestionEntity> examQuestionEntitiesOfMainQuestion = examQuestionEntities.stream().filter(o1 -> o1.getMainNumber().intValue() == paperStructInfo.getIndex()).collect(Collectors.toList());
|
|
|
+ //计算出作答情况
|
|
|
+ PracticeRecordInfo practiceRecordInfo = calculationExamQuestionSituationInfo(null, examQuestionEntitiesOfMainQuestion);
|
|
|
+
|
|
|
+ objectiveNum += practiceRecordInfo.getObjectiveNum();
|
|
|
+ objectSuccessNum += practiceRecordInfo.getSuccQuestionNum();
|
|
|
+
|
|
|
+ paperStructInfo.setQuestionCount(practiceRecordInfo.getTotalQuestionCount());
|
|
|
+ paperStructInfo.setSuccQuestionNum(practiceRecordInfo.getSuccQuestionNum());
|
|
|
+ paperStructInfo.setFailQuestionNum(practiceRecordInfo.getFailQuestionNum());
|
|
|
+ paperStructInfo.setNotAnsweredCount(practiceRecordInfo.getNotAnsweredCount());
|
|
|
+ paperStructInfos.add(paperStructInfo);
|
|
|
+ }
|
|
|
+ practiceDetailInfo.setPaperStructInfos(paperStructInfos);
|
|
|
+ ExamRecordDataEntity examRecordData = GlobalHelper.getEntity(examRecordDataRepo, examRecordDataId, ExamRecordDataEntity.class);
|
|
|
+ CourseBean courseBean = ExamCacheTransferHelper.getCachedCourse(examRecordData.getCourseId());
|
|
|
+ practiceDetailInfo.setCourseCode(courseBean.getCode());
|
|
|
+ practiceDetailInfo.setCourseName(courseBean.getName());
|
|
|
+ practiceDetailInfo.setId(examRecordDataId);
|
|
|
+
|
|
|
+ double objectiveAccuracy = 0;//客观题答题正确率
|
|
|
+ if (objectiveNum > 0) {
|
|
|
+ objectiveAccuracy = Double.valueOf(new DecimalFormat("#.00").format(objectSuccessNum * 100D / objectiveNum));
|
|
|
+ }
|
|
|
+ practiceDetailInfo.setObjectiveAccuracy(objectiveAccuracy);
|
|
|
+ return practiceDetailInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|