|
@@ -27,6 +27,7 @@ import com.qmth.cqb.paper.model.Paper;
|
|
import com.qmth.cqb.paper.model.PaperDetail;
|
|
import com.qmth.cqb.paper.model.PaperDetail;
|
|
import com.qmth.cqb.paper.model.PaperDetailUnit;
|
|
import com.qmth.cqb.paper.model.PaperDetailUnit;
|
|
import com.qmth.cqb.paper.model.PaperStruct;
|
|
import com.qmth.cqb.paper.model.PaperStruct;
|
|
|
|
+import com.qmth.cqb.question.model.QuesProperty;
|
|
import com.qmth.cqb.question.model.Question;
|
|
import com.qmth.cqb.question.model.Question;
|
|
import com.qmth.cqb.utils.BeanCopierUtil;
|
|
import com.qmth.cqb.utils.BeanCopierUtil;
|
|
import com.qmth.cqb.utils.CombinationUtils;
|
|
import com.qmth.cqb.utils.CombinationUtils;
|
|
@@ -146,7 +147,7 @@ public class GenPaperService {
|
|
private boolean checkQuesType(UnitContext uc,Question question){
|
|
private boolean checkQuesType(UnitContext uc,Question question){
|
|
List<String> quesNames = uc.getUnitStruct().getQuesNames();
|
|
List<String> quesNames = uc.getUnitStruct().getQuesNames();
|
|
if(quesNames != null && quesNames.size() > 0){
|
|
if(quesNames != null && quesNames.size() > 0){
|
|
- if(quesNames.contains(question.getQuesName()) && !uc.finish()){
|
|
|
|
|
|
+ if(quesNames.contains(question.getQuesName()) && !uc.finish() && uc.getUnitStruct().getQuestionType().name().equals(question.getQuestionType().name())){
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -456,4 +457,137 @@ public class GenPaperService {
|
|
return chooseNestNum;
|
|
return chooseNestNum;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 蓝图组卷,根据设定试卷结构组卷
|
|
|
|
+ * @param genPaperDto
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
+ public Map<String, Object> genBluePaper(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.findByPaperOrderByNumber(oldPaper);
|
|
|
|
+ for (PaperDetailUnit unit : unitList) {
|
|
|
|
+ Question question = unit.getQuestion();
|
|
|
|
+ question.setQuesName(unit.getPaperDetail().getName());
|
|
|
|
+ question.setPropertyGroup(bulidPropertyGroup(question));
|
|
|
|
+ questions.add(question);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ 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 (checkBlueQuesType(uc,question)) {
|
|
|
|
+ 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 = "匹配的题源不足,请核查";
|
|
|
|
+ paperMsgMap.put("msg", msg);
|
|
|
|
+ return paperMsgMap;
|
|
|
|
+ }
|
|
|
|
+ List<Object> list = paperContext.build(paperStruct);
|
|
|
|
+ if (list != null && list.size() == 3) {
|
|
|
|
+ Paper paper = (Paper) list.get(0);
|
|
|
|
+ List<PaperDetail> paperDetails = (List<PaperDetail>) list.get(1);
|
|
|
|
+ List<PaperDetailUnit> paperDetailunits = (List<PaperDetailUnit>) list.get(2);
|
|
|
|
+ // 补全paper属性
|
|
|
|
+ paper.setName(genPaperDto.getPaperName());
|
|
|
|
+ paper.setCourseNo(genPaperDto.getCourseNo());
|
|
|
|
+ paper.setCourseName(genPaperDto.getCourseName());
|
|
|
|
+ Course course = courseRepo.findFirstByCodeAndOrgId(genPaperDto.getCourseNo(),genPaperDto.getOrgId());
|
|
|
|
+ paper.setCourse(course);
|
|
|
|
+ paper.setCreator(genPaperDto.getCreator());
|
|
|
|
+ paper.setOrgId(genPaperDto.getOrgId());
|
|
|
|
+ paper.setLevel(genPaperDto.getLevel());
|
|
|
|
+ paper.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
+ paper.setUnitCount(this.getTotalQuesNum(paperDetailunits));
|
|
|
|
+ paper.setPaperType(PaperType.GENERATE);
|
|
|
|
+ // 数据入库
|
|
|
|
+ paper = this.persistentPaper(paperDetailunits, paperDetails, paper);
|
|
|
|
+ msg = "success";
|
|
|
|
+ paperMsgMap.put("paper", paper);
|
|
|
|
+ paperMsgMap.put("msg", msg);
|
|
|
|
+ }
|
|
|
|
+ return paperMsgMap;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 构建试题属性组合
|
|
|
|
+ * @param question
|
|
|
|
+ */
|
|
|
|
+ private List<String> bulidPropertyGroup(Question question) {
|
|
|
|
+ String propertyGroup = null;
|
|
|
|
+ List<String> propertyGroups = new ArrayList<String>();
|
|
|
|
+ //获取试题关联的多组属性
|
|
|
|
+ List<QuesProperty> quesProperties = question.getQuesProperties();
|
|
|
|
+ if(quesProperties!=null && quesProperties.size()>0){
|
|
|
|
+ for(QuesProperty quesProperty:quesProperties){
|
|
|
|
+ if(quesProperty.getSecondProperty() != null){
|
|
|
|
+ //有一级 和 二级
|
|
|
|
+ propertyGroup = String.valueOf(quesProperty.getFirstProperty().getId()) + "-" +
|
|
|
|
+ String.valueOf(quesProperty.getSecondProperty().getId()) + "-" +
|
|
|
|
+ String.valueOf(question.getPublicity()) + "-" + question.getDifficulty();
|
|
|
|
+ propertyGroups.add(propertyGroup);
|
|
|
|
+ }else {
|
|
|
|
+ //有一级 无 二级
|
|
|
|
+ propertyGroup = String.valueOf(quesProperty.getFirstProperty().getId()) + "-" +
|
|
|
|
+ String.valueOf(question.getPublicity()) + "-" + question.getDifficulty();
|
|
|
|
+ propertyGroups.add(propertyGroup);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return propertyGroups;
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 校验来源大题名称,题型结构,属性,公开度,难度
|
|
|
|
+ * @param uc
|
|
|
|
+ * @param question
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private boolean checkBlueQuesType(UnitContext uc,Question question){
|
|
|
|
+ List<String> quesNames = uc.getUnitStruct().getQuesNames();
|
|
|
|
+ if(quesNames != null && quesNames.size() > 0){
|
|
|
|
+ if(quesNames.contains(question.getQuesName()) && !uc.finish() && uc.getUnitStruct().getQuestionType().name().equals(question.getQuestionType().name())){
|
|
|
|
+ if(question.getPropertyGroup().contains(uc.getUnitStruct().getPropertyGroup())){
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|