|
@@ -0,0 +1,275 @@
|
|
|
+package cn.com.qmth.dp.examcloud.oe.modules.marking_item_change;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import javax.transaction.Transactional;
|
|
|
+
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+
|
|
|
+import cn.com.qmth.dp.examcloud.oe.bean.MarkItemBean;
|
|
|
+import cn.com.qmth.dp.examcloud.oe.dao.MarkItemRepo;
|
|
|
+import cn.com.qmth.dp.examcloud.oe.dao.MarkRangeRepo;
|
|
|
+import cn.com.qmth.dp.examcloud.oe.dao.MarkWorkRepo;
|
|
|
+import cn.com.qmth.dp.examcloud.oe.dao.PaperDetailRepo;
|
|
|
+import cn.com.qmth.dp.examcloud.oe.dao.PaperDetailUnitRepo;
|
|
|
+import cn.com.qmth.dp.examcloud.oe.dao.PaperRepo;
|
|
|
+import cn.com.qmth.dp.examcloud.oe.entity.marking.MarkItemEntity;
|
|
|
+import cn.com.qmth.dp.examcloud.oe.entity.marking.MarkRangeEntity;
|
|
|
+import cn.com.qmth.dp.examcloud.oe.entity.marking.MarkWorkEntity;
|
|
|
+import cn.com.qmth.dp.examcloud.oe.entity.question.Paper;
|
|
|
+import cn.com.qmth.dp.examcloud.oe.entity.question.PaperDetail;
|
|
|
+import cn.com.qmth.dp.examcloud.oe.entity.question.PaperDetailUnit;
|
|
|
+import cn.com.qmth.dp.examcloud.oe.entity.question.Question;
|
|
|
+import cn.com.qmth.dp.examcloud.oe.enums.question.QuesStructType;
|
|
|
+import cn.com.qmth.dp.examcloud.oe.util.Model;
|
|
|
+import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
+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.question.commons.core.paper.DefaultQuestionStructureWrapper;
|
|
|
+import cn.com.qmth.examcloud.question.commons.core.paper.DefaultQuestionUnitWrapper;
|
|
|
+import cn.com.qmth.examcloud.question.commons.core.question.QuestionType;
|
|
|
+import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 修改评卷任务给分板
|
|
|
+ *
|
|
|
+ * @author chenken
|
|
|
+ *
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class MarkingItemChangeService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ MongoTemplate mongoTemplate;
|
|
|
+ @Autowired
|
|
|
+ PaperRepo paperRepo;
|
|
|
+ @Autowired
|
|
|
+ private PaperDetailRepo paperDetailRepo;
|
|
|
+ @Autowired
|
|
|
+ private PaperDetailUnitRepo paperDetailUnitRepo;
|
|
|
+ @Autowired
|
|
|
+ private MarkWorkRepo markWorkRepo;
|
|
|
+ @Autowired
|
|
|
+ private MarkItemRepo markItemRepo;
|
|
|
+ @Autowired
|
|
|
+ private MarkRangeRepo markRangeRepo;
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void start() {
|
|
|
+ System.out.println("*******************start");
|
|
|
+ List<String> basePaperIds = new ArrayList<>();
|
|
|
+ basePaperIds.add("60c18496c68d4c45f68ef951");
|
|
|
+ basePaperIds.add("60c18495c68d4c45f68ef7af");
|
|
|
+
|
|
|
+ Long workId = 1479L;
|
|
|
+
|
|
|
+ for (String basePaperId : basePaperIds) {
|
|
|
+ List<MarkItemBean> markItems = new ArrayList<MarkItemBean>();
|
|
|
+ DefaultPaper defaultPaper = getBaseDefaultPaper(basePaperId);
|
|
|
+ List<DefaultQuestionGroup> defaultQuestionGroupList = defaultPaper.getQuestionGroupList();
|
|
|
+ // 大题号
|
|
|
+ int mainNumber = 1;
|
|
|
+ // 每个小题在试卷中的位置
|
|
|
+ int order = 0;
|
|
|
+ for (DefaultQuestionGroup defaultQuestionGroup : defaultQuestionGroupList) {
|
|
|
+ List<DefaultQuestionStructureWrapper> defaultQuestionStructureWrapperList = defaultQuestionGroup
|
|
|
+ .getQuestionWrapperList();
|
|
|
+ // 小题号
|
|
|
+ int subNumber = 1;
|
|
|
+ for (DefaultQuestionStructureWrapper defaultQuestionStructureWrapper : defaultQuestionStructureWrapperList) {
|
|
|
+ List<DefaultQuestionUnitWrapper> defaultQuestionUnitWrapperList = defaultQuestionStructureWrapper
|
|
|
+ .getQuestionUnitWrapperList();
|
|
|
+ for (DefaultQuestionUnitWrapper defaultQuestionUnitWrapper : defaultQuestionUnitWrapperList) {
|
|
|
+ order++;
|
|
|
+ if ("FILL_UP".equals(defaultQuestionUnitWrapper.getQuestionType().toString())
|
|
|
+ || "ESSAY".equals(defaultQuestionUnitWrapper.getQuestionType().toString())) {
|
|
|
+ MarkItemBean markItem = new MarkItemBean(basePaperId, mainNumber, subNumber,
|
|
|
+ defaultQuestionUnitWrapper.getQuestionScore(), 0.5, order,
|
|
|
+ defaultQuestionStructureWrapper.getQuestionId());
|
|
|
+ markItems.add(markItem);
|
|
|
+ }
|
|
|
+ subNumber++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mainNumber++;
|
|
|
+ }
|
|
|
+ saveMarkWorkItem(workId,markItems,basePaperId);
|
|
|
+ }
|
|
|
+ System.out.println("*******************finish");
|
|
|
+ }
|
|
|
+ private void saveMarkWorkItem(Long workId,List<MarkItemBean> markItemBeanList,String basePaperId) {
|
|
|
+ if(null != workId && CollectionUtils.isNotEmpty(markItemBeanList)){
|
|
|
+ List<MarkRangeEntity> rs=markRangeRepo.findByWorkIdAndBasePaperId(workId, basePaperId);
|
|
|
+ MarkWorkEntity work = GlobalHelper.getEntity(markWorkRepo, workId, MarkWorkEntity.class);
|
|
|
+ if(work == null){
|
|
|
+ throw new StatusException("Q-020560", "work null");
|
|
|
+ }
|
|
|
+ List<MarkItemEntity> markItems = Lists.newArrayList();
|
|
|
+ for(MarkItemBean bean : markItemBeanList){
|
|
|
+ MarkItemEntity entity = new MarkItemEntity(bean.getBasePaperId(),bean.getMainNumber(),bean.getSubNumber(),bean.getMaxScore()
|
|
|
+ ,bean.getScoreInterval(),bean.getOrders(),bean.getQuestionId());
|
|
|
+ entity.setWorkId(workId);
|
|
|
+ entity.setMarkRangeId(rs.get(0).getId());
|
|
|
+ markItems.add(entity);
|
|
|
+ }
|
|
|
+ markItemRepo.deleteByWorkIdPaperId(workId, basePaperId);
|
|
|
+ for (MarkItemEntity markItem : markItems) {
|
|
|
+ markItemRepo.save(markItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private DefaultPaper getBaseDefaultPaper(String paperId) {
|
|
|
+ Paper basePaper = Model.of(paperRepo.findById(paperId));
|
|
|
+ if (basePaper == null) {
|
|
|
+ throw new StatusException("Q-020560", "该考试和课程下调卷规则中试卷不存在,请重新制定调卷规则");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建试卷结构
|
|
|
+ DefaultPaper defaultPaper = this.buildDefaultByBasePaper(basePaper, null, null, null);
|
|
|
+ return defaultPaper;
|
|
|
+ }
|
|
|
+ private boolean checkIsAllQbjectiveQuestion(List<PaperDetailUnit> paperDetailUnits) {
|
|
|
+ for (PaperDetailUnit paperDetailUnit : paperDetailUnits) {
|
|
|
+ Question question = paperDetailUnit.getQuestion();
|
|
|
+ //填空或问答
|
|
|
+ if (question.getQuestionType() == QuesStructType.FILL_BLANK_QUESTION
|
|
|
+ || question.getQuestionType() == QuesStructType.TEXT_ANSWER_QUESTION) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (question.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
|
|
|
+ List<Question> subQuestions = question.getSubQuestions();
|
|
|
+ for (Question subQuestion : subQuestions) {
|
|
|
+ if (subQuestion.getQuestionType() == QuesStructType.FILL_BLANK_QUESTION
|
|
|
+ || subQuestion.getQuestionType() == QuesStructType.TEXT_ANSWER_QUESTION) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ private DefaultPaper buildDefaultByBasePaper(Paper basePaper, Long examId, String courseCode, String groupCode) {
|
|
|
+
|
|
|
+ // 获取大题
|
|
|
+ List<PaperDetail> paperDetails = paperDetailRepo.findByPaper(basePaper);
|
|
|
+
|
|
|
+ // 排序大题
|
|
|
+ Collections.sort(paperDetails);
|
|
|
+
|
|
|
+ // 将小题全部取出来,只取一次,减少对数据库的查询
|
|
|
+ List<PaperDetailUnit> allPaperDetailUnits = paperDetailUnitRepo.findByPaper(basePaper);
|
|
|
+ boolean fullyObjective = checkIsAllQbjectiveQuestion(allPaperDetailUnits);
|
|
|
+
|
|
|
+ // 根据大题id将小题归类
|
|
|
+ Map<String, List<PaperDetailUnit>> pduMap = allPaperDetailUnits.stream()
|
|
|
+ .collect(Collectors.groupingBy(PaperDetailUnit::getDetailId));
|
|
|
+
|
|
|
+
|
|
|
+ // 生成新的分组集合
|
|
|
+ List<DefaultQuestionGroup> questionGroupList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < paperDetails.size(); i++) {
|
|
|
+ PaperDetail paperDetail = paperDetails.get(i);
|
|
|
+ DefaultQuestionGroup defaultQuestionGroup = new DefaultQuestionGroup();
|
|
|
+ defaultQuestionGroup.setGroupName(paperDetail.getName());
|
|
|
+ defaultQuestionGroup.setGroupScore(paperDetail.getScore());
|
|
|
+
|
|
|
+ // 获取原小题的集合
|
|
|
+ List<PaperDetailUnit> paperDetailUnits = pduMap.get(paperDetail.getId());
|
|
|
+ if (CollectionUtils.isEmpty(paperDetailUnits)) {
|
|
|
+ throw new StatusException("500", "考试试卷有误,请联系老师!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 按题号顺序排序
|
|
|
+ Collections.sort(paperDetailUnits);
|
|
|
+
|
|
|
+ // 生成新的题包装器集合
|
|
|
+ List<DefaultQuestionStructureWrapper> questionWrapperList = new ArrayList<>();
|
|
|
+ for (int j = 0; j < paperDetailUnits.size(); j++) {
|
|
|
+ PaperDetailUnit paperDetailUnit = paperDetailUnits.get(j);
|
|
|
+ DefaultQuestionStructureWrapper defaultQuestionStructureWrapper = new DefaultQuestionStructureWrapper();
|
|
|
+ defaultQuestionStructureWrapper.setQuestionId(paperDetailUnit.getQuestion().getId());
|
|
|
+ defaultQuestionStructureWrapper.setVersion("1.0");
|
|
|
+ defaultQuestionStructureWrapper.setQuestionScore(paperDetailUnit.getScore());
|
|
|
+ defaultQuestionStructureWrapper.setTimeLimit(paperDetailUnit.getTimeLimit());
|
|
|
+
|
|
|
+
|
|
|
+ // 生成新的题单元包装器
|
|
|
+ List<DefaultQuestionUnitWrapper> defaultQuestionUnitWrappers = new ArrayList<>();
|
|
|
+ if (paperDetailUnit.getQuestion().getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
|
|
|
+ List<Question> subQuesList = paperDetailUnit.getQuestion().getSubQuestions();
|
|
|
+ List<Double> scoreList = paperDetailUnit.getSubScoreList();
|
|
|
+ if (subQuesList != null && subQuesList.size() > 0) {
|
|
|
+ for (int k = 0; k < subQuesList.size(); k++) {
|
|
|
+ DefaultQuestionUnitWrapper defaultQuestionUnitWrapper = buildQuesUnitWrapper(
|
|
|
+ subQuesList.get(k), scoreList.get(k));
|
|
|
+ defaultQuestionUnitWrappers.add(defaultQuestionUnitWrapper);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ DefaultQuestionUnitWrapper defaultQuestionUnitWrapper = buildQuesUnitWrapper(
|
|
|
+ paperDetailUnit.getQuestion(), paperDetailUnit.getScore());
|
|
|
+ defaultQuestionUnitWrappers.add(defaultQuestionUnitWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ defaultQuestionStructureWrapper.setQuestionUnitWrapperList(defaultQuestionUnitWrappers);
|
|
|
+ questionWrapperList.add(defaultQuestionStructureWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ defaultQuestionGroup.setQuestionWrapperList(questionWrapperList);
|
|
|
+ questionGroupList.add(defaultQuestionGroup);
|
|
|
+ }
|
|
|
+
|
|
|
+ DefaultPaper defaultPaper = new DefaultPaper();
|
|
|
+ defaultPaper.setName(basePaper.getName());
|
|
|
+ defaultPaper.setQuestionGroupList(questionGroupList);
|
|
|
+ defaultPaper.setFullyObjective(fullyObjective);
|
|
|
+
|
|
|
+ return defaultPaper;
|
|
|
+ }
|
|
|
+ private DefaultQuestionUnitWrapper buildQuesUnitWrapper(Question question, Double score) {
|
|
|
+ Integer[] optionPermutation = null;
|
|
|
+ if (question.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION || question.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
|
|
|
+ int length = question.getQuesOptions().size();
|
|
|
+ optionPermutation = new Integer[length];
|
|
|
+
|
|
|
+ for (int i = 0; i < length; i++) {
|
|
|
+ optionPermutation[i] = i;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ DefaultQuestionUnitWrapper defaultQuestionUnitWrapper = new DefaultQuestionUnitWrapper();
|
|
|
+ defaultQuestionUnitWrapper.setOptionPermutation(optionPermutation);
|
|
|
+ defaultQuestionUnitWrapper.setQuestionScore(score);
|
|
|
+ defaultQuestionUnitWrapper.setQuestionType(getByOldType(question.getQuestionType()));
|
|
|
+ defaultQuestionUnitWrapper.setAnswerType(question.getAnswerType());//作答类型
|
|
|
+ return defaultQuestionUnitWrapper;
|
|
|
+ }
|
|
|
+ private QuestionType getByOldType(QuesStructType quesStructType) {
|
|
|
+ if (quesStructType == QuesStructType.BOOL_ANSWER_QUESTION) {
|
|
|
+ return QuestionType.TRUE_OR_FALSE;
|
|
|
+ }
|
|
|
+ if (quesStructType == QuesStructType.FILL_BLANK_QUESTION) {
|
|
|
+ return QuestionType.FILL_UP;
|
|
|
+ }
|
|
|
+ if (quesStructType == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
|
|
|
+ return QuestionType.MULTIPLE_CHOICE;
|
|
|
+ }
|
|
|
+ if (quesStructType == QuesStructType.SINGLE_ANSWER_QUESTION) {
|
|
|
+ return QuestionType.SINGLE_CHOICE;
|
|
|
+ }
|
|
|
+ if (quesStructType == QuesStructType.TEXT_ANSWER_QUESTION) {
|
|
|
+ return QuestionType.ESSAY;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|