|
@@ -2,6 +2,7 @@ package com.qmth.cqb.genpaper.service;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.LinkedList;
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
@@ -10,10 +11,10 @@ import java.util.Set;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import com.qmth.cqb.genpaper.condition.Condition;
|
|
|
|
import com.qmth.cqb.genpaper.context.DetailContext;
|
|
import com.qmth.cqb.genpaper.context.DetailContext;
|
|
import com.qmth.cqb.genpaper.context.PaperContext;
|
|
import com.qmth.cqb.genpaper.context.PaperContext;
|
|
import com.qmth.cqb.genpaper.context.UnitContext;
|
|
import com.qmth.cqb.genpaper.context.UnitContext;
|
|
|
|
+import com.qmth.cqb.genpaper.model.GenPaperDto;
|
|
import com.qmth.cqb.paper.dao.PaperDetailRepo;
|
|
import com.qmth.cqb.paper.dao.PaperDetailRepo;
|
|
import com.qmth.cqb.paper.dao.PaperDetailUnitRepo;
|
|
import com.qmth.cqb.paper.dao.PaperDetailUnitRepo;
|
|
import com.qmth.cqb.paper.dao.PaperRepo;
|
|
import com.qmth.cqb.paper.dao.PaperRepo;
|
|
@@ -42,13 +43,103 @@ public class GenPaperService {
|
|
PaperStructRepo paperStructRepo;
|
|
PaperStructRepo paperStructRepo;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 按分数在选定的试卷中随机抽取题,组成一套新的试卷
|
|
|
|
|
|
+ * 精确组卷,根据设定试卷结构组卷
|
|
*
|
|
*
|
|
- * @param paperMap
|
|
|
|
- * key:指定的试卷Id,value:需要抽取的分数
|
|
|
|
- * @return 试卷
|
|
|
|
|
|
+ * @param paperIds
|
|
|
|
+ * 取题范围
|
|
|
|
+ * @param paperStruct
|
|
|
|
+ * 设定的试卷结构
|
|
|
|
+ * @param conditions
|
|
|
|
+ * 筛选条件
|
|
|
|
+ * @return
|
|
*/
|
|
*/
|
|
- public Paper genPaperByScore(Map<String, Double> paperMap, String paperName) {
|
|
|
|
|
|
+ public Map<String, Object> genPaper(GenPaperDto genPaperDto) {
|
|
|
|
+ String msg = "";
|
|
|
|
+ Map<String, Object> paperMsgMap = new HashMap<String, Object>();
|
|
|
|
+ LinkedList<Question> questions = new LinkedList<Question>();// 所有试题集合
|
|
|
|
+ PaperStruct paperStruct = paperStructRepo.findOne(genPaperDto.getPaperStructId());
|
|
|
|
+ PaperContext paperContext = new PaperContext(paperStruct, genPaperDto.getConditions());
|
|
|
|
+ List<UnitContext> unitContexts = new LinkedList<UnitContext>();
|
|
|
|
+ List<DetailContext> detailContexts = paperContext.getDetails();
|
|
|
|
+ for (DetailContext dc : detailContexts) {
|
|
|
|
+ unitContexts.addAll(dc.getUnits());
|
|
|
|
+ }
|
|
|
|
+ List<Paper> papers = (List<Paper>) paperRepo.findAll(genPaperDto.getPaperIds());
|
|
|
|
+ for (Paper oldPaper : papers) {
|
|
|
|
+ List<PaperDetailUnit> unitList = unitRepo.findByPaper(oldPaper);
|
|
|
|
+ for (PaperDetailUnit unit : unitList) {
|
|
|
|
+ questions.add(unit.getQuestion());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ Collections.shuffle(questions);
|
|
|
|
+ int maxLoopCount = questions.size() * 2;
|
|
|
|
+ int selectCount = 0;
|
|
|
|
+ int maxCount = unitContexts.size();
|
|
|
|
+ int loopCount = 0;
|
|
|
|
+ while (questions.size() > 0 && (selectCount < maxCount) && loopCount < maxLoopCount) {
|
|
|
|
+ Question question = questions.removeFirst();
|
|
|
|
+ boolean structTypeMatch = false;
|
|
|
|
+ boolean selected = false;
|
|
|
|
+ for (UnitContext uc : unitContexts) {
|
|
|
|
+ if (uc.getUnitStruct().getQuestionType() == question.getQuestionType() && !uc.finish()) {
|
|
|
|
+ structTypeMatch = true;
|
|
|
|
+ if (uc.check(question)) {
|
|
|
|
+ uc.select(question);
|
|
|
|
+ selected = true;
|
|
|
|
+ selectCount++;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (structTypeMatch && !selected) {
|
|
|
|
+ questions.addLast(question);
|
|
|
|
+ }
|
|
|
|
+ loopCount++;
|
|
|
|
+ }
|
|
|
|
+ Set<Question> quesSet = paperContext.getSelectQues();
|
|
|
|
+ if (quesSet.size() < unitContexts.size()) {
|
|
|
|
+ msg = "匹配的题源不足,请核查";
|
|
|
|
+ return paperMsgMap;
|
|
|
|
+ }
|
|
|
|
+ List<PaperDetail> paperDetails = new ArrayList<PaperDetail>();
|
|
|
|
+ List<PaperDetailUnit> paperDetailunits = new ArrayList<PaperDetailUnit>();
|
|
|
|
+ for (DetailContext dc : detailContexts) {
|
|
|
|
+ List<PaperDetailUnit> unitsTemp = new ArrayList<PaperDetailUnit>();
|
|
|
|
+ List<UnitContext> units = dc.getUnits();
|
|
|
|
+ for (UnitContext uc : units) {
|
|
|
|
+ for (Question ques : quesSet) {
|
|
|
|
+ if (uc.getUnitStruct().getQuestionType() == ques.getQuestionType()) {
|
|
|
|
+ PaperDetailUnit pdu = new PaperDetailUnit();
|
|
|
|
+ pdu.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
+ pdu.setQuestion(ques);
|
|
|
|
+ pdu.setQuestionType(ques.getQuestionType());
|
|
|
|
+ pdu.setScore(uc.getUnitStruct().getScore());
|
|
|
|
+ unitsTemp.add(pdu);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ paperDetails.add(this.constuctPaperDeatil(unitsTemp, dc.getDetailStruct().getNumber(),
|
|
|
|
+ dc.getDetailStruct().getName()));
|
|
|
|
+ paperDetailunits.addAll(unitsTemp);
|
|
|
|
+ }
|
|
|
|
+ Paper paper = this.constuctPaperByPaperDetails(paperDetails, genPaperDto);
|
|
|
|
+ this.persistentPaper(paperDetails, paperDetailunits, paper);
|
|
|
|
+ msg = "success";
|
|
|
|
+ paperMsgMap.put("paper", paper);
|
|
|
|
+ paperMsgMap.put("msg", msg);
|
|
|
|
+ return paperMsgMap;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 按分数在选定的试卷中随机抽取题,组成一套新的试卷
|
|
|
|
+ */
|
|
|
|
+ public Map<String, Object> genPaperByScore(GenPaperDto genPaperDto) {
|
|
|
|
+ String msg = "";
|
|
|
|
+ Map<String, Object> paperMsgMap = new HashMap<String, Object>();
|
|
|
|
+ Map<String, Double> paperMap = genPaperDto.getSimpleParams();
|
|
List<PaperDetailUnit> selectedUnits = new ArrayList<PaperDetailUnit>();// 选中的小题
|
|
List<PaperDetailUnit> selectedUnits = new ArrayList<PaperDetailUnit>();// 选中的小题
|
|
if (paperMap != null && paperMap.size() > 0) {
|
|
if (paperMap != null && paperMap.size() > 0) {
|
|
for (String paperId : paperMap.keySet()) {
|
|
for (String paperId : paperMap.keySet()) {
|
|
@@ -68,24 +159,27 @@ public class GenPaperService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- return this.constuctPaper(selectedUnits, paperName);
|
|
|
|
|
|
+ Paper paper = this.constuctPaper(selectedUnits, genPaperDto);
|
|
|
|
+ msg = "success";
|
|
|
|
+ paperMsgMap.put("paper", paper);
|
|
|
|
+ paperMsgMap.put("msg", msg);
|
|
|
|
+ return paperMsgMap;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 按每套试卷需要抽取的题目数量随机抽取题,组成一套新的试卷
|
|
* 按每套试卷需要抽取的题目数量随机抽取题,组成一套新的试卷
|
|
*
|
|
*
|
|
- * @param paperMap
|
|
|
|
- * key:指定的试卷Id,value:需要抽取试题数量
|
|
|
|
- * @param paperName
|
|
|
|
- * 试卷名称
|
|
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public Paper genPaperByQuestionNum(Map<String, Integer> paperMap, String paperName) {
|
|
|
|
|
|
+ public Map<String, Object> genPaperByQuestionNum(GenPaperDto genPaperDto) {
|
|
|
|
+ String msg = "";
|
|
|
|
+ Map<String, Object> paperMsgMap = new HashMap<String, Object>();
|
|
|
|
+ Map<String, Double> paperMap = genPaperDto.getSimpleParams();
|
|
List<PaperDetailUnit> selectedUnits = new ArrayList<PaperDetailUnit>();// 选中的小题
|
|
List<PaperDetailUnit> selectedUnits = new ArrayList<PaperDetailUnit>();// 选中的小题
|
|
if (paperMap != null && paperMap.size() > 0) {
|
|
if (paperMap != null && paperMap.size() > 0) {
|
|
for (String paperId : paperMap.keySet()) {
|
|
for (String paperId : paperMap.keySet()) {
|
|
- int unitNum = paperMap.get(paperId);
|
|
|
|
|
|
+ int unitNum = paperMap.get(paperId).intValue();
|
|
Paper oldPaper = paperRepo.findOne(paperId);
|
|
Paper oldPaper = paperRepo.findOne(paperId);
|
|
List<PaperDetailUnit> unitList = unitRepo.findByPaper(oldPaper);
|
|
List<PaperDetailUnit> unitList = unitRepo.findByPaper(oldPaper);
|
|
Collections.shuffle(unitList);// 随机乱序之后再取题
|
|
Collections.shuffle(unitList);// 随机乱序之后再取题
|
|
@@ -94,6 +188,10 @@ public class GenPaperService {
|
|
selectedUnits.add(unitList.get(i));
|
|
selectedUnits.add(unitList.get(i));
|
|
unitList.remove(i);
|
|
unitList.remove(i);
|
|
}
|
|
}
|
|
|
|
+ } else {
|
|
|
|
+ msg = "题源不足:需要抽取的题目数量要多于试卷中题目数量,请检查";
|
|
|
|
+ paperMsgMap.put("msg", msg);
|
|
|
|
+ return paperMsgMap;
|
|
}
|
|
}
|
|
for (PaperDetailUnit pdu : selectedUnits) {
|
|
for (PaperDetailUnit pdu : selectedUnits) {
|
|
if (pdu.getQuestionType().getId() == 6L && pdu.getQuestion().getSubQuestions().size() > 1) {// 假如是套题,要计算下面小题数量
|
|
if (pdu.getQuestionType().getId() == 6L && pdu.getQuestion().getSubQuestions().size() > 1) {// 假如是套题,要计算下面小题数量
|
|
@@ -106,10 +204,14 @@ public class GenPaperService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- return this.constuctPaper(selectedUnits, paperName);
|
|
|
|
|
|
+ Paper paper = this.constuctPaper(selectedUnits, genPaperDto);
|
|
|
|
+ msg = "success";
|
|
|
|
+ paperMsgMap.put("paper", paper);
|
|
|
|
+ paperMsgMap.put("msg", msg);
|
|
|
|
+ return paperMsgMap;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -149,7 +251,7 @@ public class GenPaperService {
|
|
* @param details
|
|
* @param details
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public Paper constuctPaperByPaperDetails(List<PaperDetail> details, String paperName) {
|
|
|
|
|
|
+ public Paper constuctPaperByPaperDetails(List<PaperDetail> details, GenPaperDto genPaperDto) {
|
|
Paper paper = new Paper();
|
|
Paper paper = new Paper();
|
|
if (details != null && details.size() > 0) {
|
|
if (details != null && details.size() > 0) {
|
|
Double score = 0d;
|
|
Double score = 0d;
|
|
@@ -157,10 +259,13 @@ public class GenPaperService {
|
|
score += pd.getScore();
|
|
score += pd.getScore();
|
|
|
|
|
|
}
|
|
}
|
|
- paper.setName(paperName);
|
|
|
|
|
|
+ paper.setName(genPaperDto.getPaperName());
|
|
|
|
+ paper.setCourseNo(genPaperDto.getCourseNo());
|
|
|
|
+ paper.setCourseName(genPaperDto.getCourseName());
|
|
|
|
+ paper.setCreator(genPaperDto.getCreator());
|
|
|
|
+ paper.setCreateTime(CommonUtils.getCurDateTime());
|
|
paper.setPaperDetailCount(details.size());
|
|
paper.setPaperDetailCount(details.size());
|
|
paper.setTotalScore(score);
|
|
paper.setTotalScore(score);
|
|
- paper.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
for (PaperDetail pdu : details) {
|
|
for (PaperDetail pdu : details) {
|
|
pdu.setPaper(paper);
|
|
pdu.setPaper(paper);
|
|
}
|
|
}
|
|
@@ -177,7 +282,7 @@ public class GenPaperService {
|
|
* @param quesName
|
|
* @param quesName
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public Paper constuctPaper(List<PaperDetailUnit> selectedUnits, String paperName) {
|
|
|
|
|
|
+ public Paper constuctPaper(List<PaperDetailUnit> selectedUnits, GenPaperDto genPaperDto) {
|
|
Paper paper = new Paper();
|
|
Paper paper = new Paper();
|
|
List<PaperDetailUnit> singUnits = new ArrayList<PaperDetailUnit>();
|
|
List<PaperDetailUnit> singUnits = new ArrayList<PaperDetailUnit>();
|
|
List<PaperDetailUnit> multipleUnits = new ArrayList<PaperDetailUnit>();
|
|
List<PaperDetailUnit> multipleUnits = new ArrayList<PaperDetailUnit>();
|
|
@@ -208,50 +313,72 @@ public class GenPaperService {
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- PaperDetail singPd = this.constuctPaperDeatil(singUnits, 1, QuesStructType.SINGLE_ANSWER_QUESTION.getName());
|
|
|
|
- PaperDetail multipePd = this.constuctPaperDeatil(multipleUnits, 2,
|
|
|
|
- QuesStructType.MULTIPLE_ANSWER_QUESTION.getName());
|
|
|
|
- PaperDetail boolPd = this.constuctPaperDeatil(boolUnits, 3, QuesStructType.BOOL_ANSWER_QUESTION.getName());
|
|
|
|
- PaperDetail blankPd = this.constuctPaperDeatil(blankUnits, 4, QuesStructType.FILL_BLANK_QUESTION.getName());
|
|
|
|
- PaperDetail textPd = this.constuctPaperDeatil(textUnits, 5, QuesStructType.TEXT_ANSWER_QUESTION.getName());
|
|
|
|
- PaperDetail nestPd = this.constuctPaperDeatil(nestUnits, 6, QuesStructType.NESTED_ANSWER_QUESTION.getName());
|
|
|
|
|
|
+ int detailNumber = 1;
|
|
|
|
+ PaperDetail singPd = null;
|
|
|
|
+ PaperDetail multipePd = null;
|
|
|
|
+ PaperDetail boolPd = null;
|
|
|
|
+ PaperDetail blankPd = null;
|
|
|
|
+ PaperDetail textPd = null;
|
|
|
|
+ PaperDetail nestPd = null;
|
|
|
|
+ if (singUnits != null && singUnits.size() > 0) {
|
|
|
|
+ singPd = this.constuctPaperDeatil(singUnits, detailNumber, QuesStructType.SINGLE_ANSWER_QUESTION.getName());
|
|
|
|
+ detailNumber++;
|
|
|
|
+ } else if (multipleUnits != null && multipleUnits.size() > 0) {
|
|
|
|
+ multipePd = this.constuctPaperDeatil(multipleUnits, detailNumber,
|
|
|
|
+ QuesStructType.MULTIPLE_ANSWER_QUESTION.getName());
|
|
|
|
+ detailNumber++;
|
|
|
|
+ } else if (boolUnits != null && boolUnits.size() > 0) {
|
|
|
|
+ boolPd = this.constuctPaperDeatil(boolUnits, detailNumber, QuesStructType.BOOL_ANSWER_QUESTION.getName());
|
|
|
|
+ detailNumber++;
|
|
|
|
+ } else if (blankUnits != null && blankUnits.size() > 0) {
|
|
|
|
+ blankPd = this.constuctPaperDeatil(blankUnits, detailNumber, QuesStructType.FILL_BLANK_QUESTION.getName());
|
|
|
|
+ detailNumber++;
|
|
|
|
+ } else if (textUnits != null && textUnits.size() > 0) {
|
|
|
|
+ textPd = this.constuctPaperDeatil(textUnits, detailNumber, QuesStructType.TEXT_ANSWER_QUESTION.getName());
|
|
|
|
+ detailNumber++;
|
|
|
|
+ } else if (nestUnits != null && nestUnits.size() > 0) {
|
|
|
|
+ nestPd = this.constuctPaperDeatil(nestUnits, detailNumber, QuesStructType.NESTED_ANSWER_QUESTION.getName());
|
|
|
|
+ }
|
|
selectedUnits.clear();
|
|
selectedUnits.clear();
|
|
List<PaperDetail> pds = new ArrayList<PaperDetail>();
|
|
List<PaperDetail> pds = new ArrayList<PaperDetail>();
|
|
int paperDetailCount = 0;// 大题数量
|
|
int paperDetailCount = 0;// 大题数量
|
|
Double totalScore = 0d;
|
|
Double totalScore = 0d;
|
|
- if (singPd.getUnitCount() > 0) {
|
|
|
|
|
|
+ if (singPd != null && singPd.getUnitCount() > 0) {
|
|
paperDetailCount = paperDetailCount + 1;
|
|
paperDetailCount = paperDetailCount + 1;
|
|
totalScore += singPd.getScore();
|
|
totalScore += singPd.getScore();
|
|
pds.add(singPd);
|
|
pds.add(singPd);
|
|
selectedUnits.addAll(singUnits);
|
|
selectedUnits.addAll(singUnits);
|
|
- } else if (multipePd.getUnitCount() > 0) {
|
|
|
|
|
|
+ } else if (multipePd != null && multipePd.getUnitCount() > 0) {
|
|
paperDetailCount = paperDetailCount + 1;
|
|
paperDetailCount = paperDetailCount + 1;
|
|
totalScore += singPd.getScore();
|
|
totalScore += singPd.getScore();
|
|
pds.add(multipePd);
|
|
pds.add(multipePd);
|
|
selectedUnits.addAll(multipleUnits);
|
|
selectedUnits.addAll(multipleUnits);
|
|
- } else if (boolPd.getUnitCount() > 0) {
|
|
|
|
|
|
+ } else if (boolPd != null && boolPd.getUnitCount() > 0) {
|
|
paperDetailCount = paperDetailCount + 1;
|
|
paperDetailCount = paperDetailCount + 1;
|
|
totalScore += singPd.getScore();
|
|
totalScore += singPd.getScore();
|
|
pds.add(boolPd);
|
|
pds.add(boolPd);
|
|
selectedUnits.addAll(boolUnits);
|
|
selectedUnits.addAll(boolUnits);
|
|
- } else if (blankPd.getUnitCount() > 0) {
|
|
|
|
|
|
+ } else if (blankPd != null && blankPd.getUnitCount() > 0) {
|
|
paperDetailCount = paperDetailCount + 1;
|
|
paperDetailCount = paperDetailCount + 1;
|
|
totalScore += singPd.getScore();
|
|
totalScore += singPd.getScore();
|
|
pds.add(blankPd);
|
|
pds.add(blankPd);
|
|
selectedUnits.addAll(blankUnits);
|
|
selectedUnits.addAll(blankUnits);
|
|
- } else if (textPd.getUnitCount() > 0) {
|
|
|
|
|
|
+ } else if (textPd != null && textPd.getUnitCount() > 0) {
|
|
paperDetailCount = paperDetailCount + 1;
|
|
paperDetailCount = paperDetailCount + 1;
|
|
totalScore += singPd.getScore();
|
|
totalScore += singPd.getScore();
|
|
pds.add(textPd);
|
|
pds.add(textPd);
|
|
selectedUnits.addAll(textUnits);
|
|
selectedUnits.addAll(textUnits);
|
|
- } else if (nestPd.getUnitCount() > 0) {
|
|
|
|
|
|
+ } else if (nestPd != null && nestPd.getUnitCount() > 0) {
|
|
paperDetailCount = nestPd.getUnitCount() + paperDetailCount;
|
|
paperDetailCount = nestPd.getUnitCount() + paperDetailCount;
|
|
totalScore += singPd.getScore();
|
|
totalScore += singPd.getScore();
|
|
pds.add(nestPd);
|
|
pds.add(nestPd);
|
|
selectedUnits.addAll(nestUnits);
|
|
selectedUnits.addAll(nestUnits);
|
|
}
|
|
}
|
|
-
|
|
|
|
- paper.setName(paperName);
|
|
|
|
|
|
+ paper.setName(genPaperDto.getPaperName());
|
|
|
|
+ paper.setCourseName(genPaperDto.getCourseName());
|
|
|
|
+ paper.setCourseNo(genPaperDto.getCourseNo());
|
|
|
|
+ paper.setCreator(genPaperDto.getCreator());
|
|
|
|
+ paper.setCreateTime(CommonUtils.getCurDateTime());
|
|
paper.setTotalScore(totalScore);
|
|
paper.setTotalScore(totalScore);
|
|
paper.setPaperDetailCount(paperDetailCount);
|
|
paper.setPaperDetailCount(paperDetailCount);
|
|
// 数据入库
|
|
// 数据入库
|
|
@@ -282,85 +409,4 @@ public class GenPaperService {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 精确组卷,根据设定试卷结构组卷
|
|
|
|
- *
|
|
|
|
- * @param paperIds
|
|
|
|
- * 取题范围
|
|
|
|
- * @param paperStruct
|
|
|
|
- * 设定的试卷结构
|
|
|
|
- * @param conditions
|
|
|
|
- * 筛选条件
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public Paper genPaper(List<String> paperIds, PaperStruct paperStruct, List<Condition> conditions) {
|
|
|
|
- LinkedList<Question> questions = new LinkedList<Question>();// 所有试题集合
|
|
|
|
- PaperContext paperContext = new PaperContext(paperStruct, conditions);
|
|
|
|
- List<UnitContext> unitContexts = new LinkedList<UnitContext>();
|
|
|
|
- List<DetailContext> detailContexts = paperContext.getDetails();
|
|
|
|
- for (DetailContext dc : detailContexts) {
|
|
|
|
- unitContexts.addAll(dc.getUnits());
|
|
|
|
- }
|
|
|
|
- List<Paper> papers = (List<Paper>) paperRepo.findAll(paperIds);
|
|
|
|
- for (Paper oldPaper : papers) {
|
|
|
|
- List<PaperDetailUnit> unitList = unitRepo.findByPaper(oldPaper);
|
|
|
|
- for (PaperDetailUnit unit : unitList) {
|
|
|
|
- questions.add(unit.getQuestion());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- Collections.shuffle(questions);
|
|
|
|
- int maxLoopCount = questions.size() * 2;
|
|
|
|
- int selectCount = 0;
|
|
|
|
- int maxCount = unitContexts.size();
|
|
|
|
- int loopCount = 0;
|
|
|
|
- while (questions.size() > 0 && (selectCount < maxCount) && loopCount < maxLoopCount) {
|
|
|
|
- Question question = questions.removeFirst();
|
|
|
|
- boolean structTypeMatch = false;
|
|
|
|
- boolean selected = false;
|
|
|
|
- for (UnitContext uc : unitContexts) {
|
|
|
|
- if (uc.getUnitStruct().getQuestionType() == question.getQuestionType() && !uc.finish()) {
|
|
|
|
- structTypeMatch = true;
|
|
|
|
- if (uc.check(question)) {
|
|
|
|
- uc.select(question);
|
|
|
|
- selected = true;
|
|
|
|
- selectCount++;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (structTypeMatch && !selected) {
|
|
|
|
- questions.addLast(question);
|
|
|
|
- }
|
|
|
|
- loopCount++;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Set<Question> quesSet = paperContext.getSelectQues();
|
|
|
|
- List<PaperDetail> paperDetails = new ArrayList<PaperDetail>();
|
|
|
|
- List<PaperDetailUnit> paperDetailunits = new ArrayList<PaperDetailUnit>();
|
|
|
|
- for (DetailContext dc : detailContexts) {
|
|
|
|
- List<PaperDetailUnit> unitsTemp = new ArrayList<PaperDetailUnit>();
|
|
|
|
- List<UnitContext> units = dc.getUnits();
|
|
|
|
- for (UnitContext uc : units) {
|
|
|
|
- for (Question ques : quesSet) {
|
|
|
|
- if (uc.getUnitStruct().getQuestionType() == ques.getQuestionType()) {
|
|
|
|
- PaperDetailUnit pdu = new PaperDetailUnit();
|
|
|
|
- pdu.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
- pdu.setQuestion(ques);
|
|
|
|
- pdu.setQuestionType(ques.getQuestionType());
|
|
|
|
- pdu.setScore(uc.getUnitStruct().getScore());
|
|
|
|
- unitsTemp.add(pdu);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- paperDetails.add(this.constuctPaperDeatil(unitsTemp, dc.getDetailStruct().getNumber(),
|
|
|
|
- dc.getDetailStruct().getName()));
|
|
|
|
- paperDetailunits.addAll(unitsTemp);
|
|
|
|
- }
|
|
|
|
- Paper paper = this.constuctPaperByPaperDetails(paperDetails, paperStruct.getName());
|
|
|
|
- this.persistentPaper(paperDetails, paperDetailunits, paper);
|
|
|
|
- return paper;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|