|
@@ -211,59 +211,13 @@ public class QuestionFlowService {
|
|
|
return true;
|
|
|
});
|
|
|
nextCallback.put(PaperModule.EXAMINATION, (question, report, lastQuestion)->{
|
|
|
- JSONObject setting = report.getSetting();
|
|
|
- JSONArray order = setting.getJSONArray("order");
|
|
|
- String stage = setting.getString("stage");
|
|
|
- JSONObject time = setting.getJSONObject("time");
|
|
|
- JSONObject number = setting.getJSONObject("number");
|
|
|
- time.put(stage, time.getIntValue(stage)+ question.getUserTime());
|
|
|
- Integer totalNumber = toolsService.examinationSubjectNumber(stage);
|
|
|
- // 判断数量是否已经完成
|
|
|
- if (number.getIntValue(stage) >= totalNumber){
|
|
|
- // 进入下一阶段
|
|
|
- int index = order.indexOf(stage);
|
|
|
- if (index == order.size() - 1){
|
|
|
- // 完成所有阶段,结束考试
|
|
|
- return false;
|
|
|
- }
|
|
|
- stage = order.getString(index + 1);
|
|
|
- setting.put("stage", stage);
|
|
|
- }
|
|
|
- // 获取本阶段完成数,剩余题目数
|
|
|
- Integer subnumber = number.getIntValue(stage);
|
|
|
- Integer surplus = totalNumber - subnumber;
|
|
|
- QuestionSubject subject = QuestionSubject.ValueOf(stage);
|
|
|
- List<String> questionTypes = QuestionType.FromSubject(subject);
|
|
|
- List<UserQuestion> userQuestionList = userQuestionService.listByReportAndType(report.getUserId(), report.getId(), questionTypes);
|
|
|
- Collection ids = Transform.getIds(userQuestionList, UserQuestion.class, "questionNoId");
|
|
|
- // 根据设置出题
|
|
|
- Integer questionNoId = 0;
|
|
|
ExaminationPaper paper = examinationPaperService.get(report.getOriginId());
|
|
|
- if (paper.getIsAdapt() > 0 && QuestionSubject.SupportAdapt(subject)){
|
|
|
- switch(subject){
|
|
|
- case VERBAL:
|
|
|
- questionNoId = verbalCompute(paper, setting, subnumber, ids, userQuestionList);
|
|
|
- break;
|
|
|
- case QUANT:
|
|
|
- questionNoId = quantCompute(paper, setting, subnumber, ids, userQuestionList);
|
|
|
- break;
|
|
|
- default:
|
|
|
- throw new ParameterException("模考出题流程错误:"+subject.key+"不支持适应性判断");
|
|
|
- }
|
|
|
- }else{
|
|
|
- questionNoId = randomCompute(subject, paper, questionTypes, setting, subnumber, ids, userQuestionList);
|
|
|
- }
|
|
|
- if (questionNoId == 0) {
|
|
|
- throw new ParameterException("模考出题流程错误:题目生成错误");
|
|
|
+ if (!examinationCompute(paper, report, lastQuestion, question)){
|
|
|
+ return false;
|
|
|
}
|
|
|
- QuestionNoRelation relation = questionNoService.getWithRelation(questionNoId);
|
|
|
- question.setQuestionNoId(relation.getId());
|
|
|
- question.setQuestionId(relation.getQuestionId());
|
|
|
- question.setQuestionType(relation.getQuestion().getQuestionType());
|
|
|
- question.setTime(toolsService.computerTime(relation));
|
|
|
|
|
|
// 保存report: 更新setting
|
|
|
- userReportService.edit(UserReport.builder().id(report.getId()).setting(setting).build());
|
|
|
+ userReportService.edit(UserReport.builder().id(report.getId()).setting(report.getSetting()).build());
|
|
|
return true;
|
|
|
});
|
|
|
|
|
@@ -381,18 +335,14 @@ public class QuestionFlowService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- InitPaper callback = makePaperCallback.get(module);
|
|
|
+ UserPaper paper = userPaperService.newByPaper(userId, origin, PaperModule.WithQuestion(module), 0);
|
|
|
+ paper.setQuestionNumber(questionNoIds.size());
|
|
|
+ paper.setQuestionNoIds(questionNoIds.toArray(new Integer[0]));
|
|
|
|
|
|
- UserPaper paper = UserPaper.builder()
|
|
|
- .userId(userId)
|
|
|
- .paperOrigin(origin.key)
|
|
|
- .paperModule(module.key)
|
|
|
- .questionNoIds(questionNoIds.toArray(new Integer[0]))
|
|
|
- .questionNumber(questionNoIds.size())
|
|
|
- .originId(0)
|
|
|
- .build();
|
|
|
+ InitPaper callback = makePaperCallback.get(module);
|
|
|
callback.callback(paper, 0);
|
|
|
paper = userPaperService.add(paper);
|
|
|
+
|
|
|
// 绑定关系,用于下次处理过滤
|
|
|
userPaperQuestionService.addOrigin(userId, paper.getId(), questionOrigin, module, questionNoIds);
|
|
|
return paper;
|
|
@@ -421,7 +371,14 @@ public class QuestionFlowService {
|
|
|
@Transactional
|
|
|
public UserPaper paper(Integer userId, PaperOrigin origin, Integer paperId){
|
|
|
PaperModule module = PaperModule.WithOrigin(origin);
|
|
|
- return userPaperService.getByPaper(userId, origin, module, paperId, initPaperCallback.get(module));
|
|
|
+ UserPaper paper = userPaperService.getByPaper(userId, origin, paperId);
|
|
|
+ if (paper == null){
|
|
|
+ paper = userPaperService.newByPaper(userId, origin, module, paperId);
|
|
|
+ InitPaper callback = initPaperCallback.get(module);
|
|
|
+ callback.callback(paper, paperId);
|
|
|
+ paper = userPaperService.add(paper);
|
|
|
+ }
|
|
|
+ return paper;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -441,10 +398,14 @@ public class QuestionFlowService {
|
|
|
paper.setIsReset(0);
|
|
|
userPaperService.edit(paper);
|
|
|
}else if(setting == null){
|
|
|
+ // 对于长难句这种没有设置开始页的,读取最后一次
|
|
|
userReport = userReportService.getLastByPaper(userId, paper.getId());
|
|
|
}
|
|
|
if (userReport == null){
|
|
|
- userReport = userReportService.addByPaper(paper, setting, initReportCallback.get(PaperModule.ValueOf(paper.getPaperModule())));
|
|
|
+ userReport = userReportService.newByPaper(paper, setting);
|
|
|
+ InitReport callback = initReportCallback.get(PaperModule.ValueOf(paper.getPaperModule()));
|
|
|
+ callback.callback(userReport, paper);
|
|
|
+ userReportService.add(userReport);
|
|
|
}
|
|
|
|
|
|
return relationReport(userReport);
|
|
@@ -502,7 +463,11 @@ public class QuestionFlowService {
|
|
|
if (!userReport.getUserId().equals(userId)){
|
|
|
throw new ParameterException("试卷不存在");
|
|
|
}
|
|
|
- userQuestion = userQuestionService.addByReport(userReport, userQuestion, nextCallback.get(PaperModule.ValueOf(userReport.getPaperModule())));
|
|
|
+ UserQuestion lastQuestion = userQuestion;
|
|
|
+ userQuestion = userQuestionService.newByReport(userReport, lastQuestion);
|
|
|
+ InitQuestion callback = nextCallback.get(PaperModule.ValueOf(userReport.getPaperModule()));
|
|
|
+ callback.callback(userQuestion, userReport, lastQuestion);
|
|
|
+ userQuestion = userQuestionService.add(userQuestion);
|
|
|
}
|
|
|
|
|
|
return userQuestion;
|
|
@@ -568,27 +533,47 @@ public class QuestionFlowService {
|
|
|
if (origin != PaperOrigin.EXAMINATION){
|
|
|
throw new ParameterException("不是模考试卷");
|
|
|
}
|
|
|
- JSONObject setting = userReport.getSetting();
|
|
|
|
|
|
+ ExaminationPaper paper = examinationPaperService.get(userReport.getOriginId());
|
|
|
+
|
|
|
+ JSONObject setting = userReport.getSetting();
|
|
|
// 当前stage,补全所有时间,切换成下一个stage
|
|
|
- String stage = setting.getString("stage");
|
|
|
JSONArray order = setting.getJSONArray("order");
|
|
|
+ String stage = setting.getString("stage");
|
|
|
JSONObject time = setting.getJSONObject("time");
|
|
|
JSONObject number = setting.getJSONObject("number");
|
|
|
Integer useTime = time.getInteger(stage);
|
|
|
Integer totalTime = toolsService.examinationSubjectTime(stage);
|
|
|
time.put(stage, totalTime);
|
|
|
- setting.put("stage", order.getString(order.indexOf(stage) + 1));
|
|
|
- // 更新setting
|
|
|
- userReportService.edit(UserReport.builder().id(userReportId).setting(setting).build());
|
|
|
|
|
|
+ // 自动提交所有该stage的题目
|
|
|
+ Integer totalNumber = toolsService.examinationSubjectNumber(stage);
|
|
|
// 自动提交最后一题
|
|
|
- UserQuestion userQuestion = userQuestionService.getLastByReport(userId, userReportId);
|
|
|
- if(userQuestion != null && userQuestion.getUserTime() == 0){
|
|
|
- userQuestion.setUserTime(totalTime - useTime);
|
|
|
- userQuestion.setSetting(new JSONObject());
|
|
|
- userQuestion.setUserAnswer(new JSONObject());
|
|
|
- this.submit(userId, userQuestion);
|
|
|
+ UserQuestion lastQuestion = userQuestionService.getLastByReport(userId, userReportId);
|
|
|
+ UserQuestion question;
|
|
|
+ if(lastQuestion != null && lastQuestion.getUserTime() == 0){
|
|
|
+ lastQuestion.setUserTime(totalTime - useTime);
|
|
|
+ this.submit(userId, lastQuestion);
|
|
|
+ }
|
|
|
+ // 判断未完成题目数,自动生成
|
|
|
+ question = userQuestionService.newByReport(userReport, lastQuestion);
|
|
|
+ while(number.getIntValue(stage) < totalNumber){
|
|
|
+ examinationCompute(paper, userReport, lastQuestion, question);
|
|
|
+ question = userQuestionService.add(question);
|
|
|
+ lastQuestion = question;
|
|
|
+ question = userQuestionService.newByReport(userReport, lastQuestion);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新setting
|
|
|
+ userReportService.edit(UserReport.builder()
|
|
|
+ .id(userReportId)
|
|
|
+ .setting(setting).build());
|
|
|
+
|
|
|
+ // 如果是最后阶段。直接完成
|
|
|
+ int index = order.indexOf(stage);
|
|
|
+ if (index == order.size() - 1){
|
|
|
+ // 完成所有阶段,结束考试
|
|
|
+ this.finish(userId, userReport.getId());
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
@@ -633,6 +618,68 @@ public class QuestionFlowService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 模考完整出题逻辑
|
|
|
+ * @param paper
|
|
|
+ * @param report
|
|
|
+ * @param lastQuestion
|
|
|
+ * @param question
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean examinationCompute(ExaminationPaper paper, UserReport report, UserQuestion lastQuestion, UserQuestion question){
|
|
|
+ JSONObject setting = report.getSetting();
|
|
|
+ JSONArray order = setting.getJSONArray("order");
|
|
|
+ String stage = setting.getString("stage");
|
|
|
+ JSONObject time = setting.getJSONObject("time");
|
|
|
+ JSONObject number = setting.getJSONObject("number");
|
|
|
+ time.put(stage, time.getIntValue(stage)+ lastQuestion.getUserTime());
|
|
|
+ Integer totalNumber = toolsService.examinationSubjectNumber(stage);
|
|
|
+ // 判断数量是否已经完成
|
|
|
+ if (number.getIntValue(stage) >= totalNumber){
|
|
|
+ // 进入下一阶段
|
|
|
+ int index = order.indexOf(stage);
|
|
|
+ if (index == order.size() - 1){
|
|
|
+ // 完成所有阶段,结束考试
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ stage = order.getString(index + 1);
|
|
|
+ setting.put("stage", stage);
|
|
|
+ }
|
|
|
+ // 获取本阶段完成数,剩余题目数
|
|
|
+ Integer subnumber = number.getIntValue(stage);
|
|
|
+ Integer surplus = totalNumber - subnumber;
|
|
|
+ QuestionSubject subject = QuestionSubject.ValueOf(stage);
|
|
|
+ List<String> questionTypes = QuestionType.FromSubject(subject);
|
|
|
+ List<UserQuestion> userQuestionList = userQuestionService.listByReportAndType(report.getUserId(), report.getId(), questionTypes);
|
|
|
+ Collection ids = Transform.getIds(userQuestionList, UserQuestion.class, "questionNoId");
|
|
|
+ // 根据设置出题
|
|
|
+ Integer questionNoId = 0;
|
|
|
+ if (paper.getIsAdapt() > 0 && QuestionSubject.SupportAdapt(subject)){
|
|
|
+ switch(subject){
|
|
|
+ case VERBAL:
|
|
|
+ questionNoId = verbalCompute(paper, setting, subnumber, ids, userQuestionList);
|
|
|
+ break;
|
|
|
+ case QUANT:
|
|
|
+ questionNoId = quantCompute(paper, setting, subnumber, ids, userQuestionList);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ throw new ParameterException("模考出题流程错误:"+subject.key+"不支持适应性判断");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ questionNoId = randomCompute(subject, paper, questionTypes, setting, subnumber, ids, userQuestionList);
|
|
|
+ }
|
|
|
+ if (questionNoId == 0) {
|
|
|
+ throw new ParameterException("模考出题流程错误:题目生成错误");
|
|
|
+ }
|
|
|
+ QuestionNoRelation relation = questionNoService.getWithRelation(questionNoId);
|
|
|
+ question.setQuestionNoId(relation.getId());
|
|
|
+ question.setQuestionId(relation.getQuestionId());
|
|
|
+ question.setQuestionType(relation.getQuestion().getQuestionType());
|
|
|
+ question.setTime(toolsService.computerTime(relation));
|
|
|
+ // 更新题目数
|
|
|
+ number.put(stage, subnumber + 1);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ /**
|
|
|
* 语文出题计算
|
|
|
* @param setting
|
|
|
* @param subnumber
|
|
@@ -1425,7 +1472,6 @@ public class QuestionFlowService {
|
|
|
|
|
|
// 题型难度分计算
|
|
|
QuestionDifficult questionDifficult = QuestionDifficult.ValueOf(difficultKey);
|
|
|
- Integer difficultScore = QuestionDifficult.GetScore(questionDifficult);
|
|
|
|
|
|
if (userQuestion.getIsCorrect() > 0){
|
|
|
typeInfo.put("diffCorrect", typeInfo.getFloatValue("diffCorrect") + toolsService.diffScore(relation.getTotalNumber(), relation.getTotalCorrect(), questionDifficult));
|
|
@@ -1433,7 +1479,8 @@ public class QuestionFlowService {
|
|
|
typeInfo.put("diffIncorrect", typeInfo.getFloatValue("diffIncorrect") + toolsService.diffScore(relation.getTotalNumber(), relation.getTotalCorrect(), questionDifficult));
|
|
|
}
|
|
|
|
|
|
- subjectInfo.put("difficultScore", subjectInfo.getIntValue("difficultScore")+difficultScore);
|
|
|
+ float difficultScore = relation.getQuestion().getDifficultScore();
|
|
|
+ subjectInfo.put("difficultScore", subjectInfo.getFloatValue("difficultScore")+difficultScore);
|
|
|
}
|
|
|
|
|
|
// 计算难度平均值
|
|
@@ -1447,10 +1494,10 @@ public class QuestionFlowService {
|
|
|
// 学科得分计算
|
|
|
JSONObject quantSubject = subjectMap.getJSONObject(QuestionSubject.QUANT.key);
|
|
|
JSONObject quantInfo = quantSubject.getJSONObject("info");
|
|
|
- Integer quantScore = toolsService.quantScore(quantInfo.getIntValue("number"), quantInfo.getIntValue("userNumber"), quantInfo.getInteger("difficultScore"), quantInfo.getInteger("userCorrect"));
|
|
|
+ Integer quantScore = toolsService.quantScore(quantInfo.getIntValue("number"), quantInfo.getIntValue("userNumber"), quantInfo.getFloatValue("difficultScore"), quantInfo.getInteger("userCorrect"));
|
|
|
JSONObject verbalSubject = subjectMap.getJSONObject(QuestionSubject.VERBAL.key);
|
|
|
JSONObject verbalInfo = verbalSubject.getJSONObject("info");
|
|
|
- Integer verbalScore = toolsService.verbalScore(verbalInfo.getIntValue("number"), verbalInfo.getIntValue("userNumber"), verbalInfo.getInteger("difficultScore"), verbalInfo.getInteger("userCorrect"));
|
|
|
+ Integer verbalScore = toolsService.verbalScore(verbalInfo.getIntValue("number"), verbalInfo.getIntValue("userNumber"), verbalInfo.getFloatValue("difficultScore"), verbalInfo.getInteger("userCorrect"));
|
|
|
JSONObject irSubject = subjectMap.getJSONObject(QuestionSubject.IR.key);
|
|
|
JSONObject irInfo = irSubject.getJSONObject("info");
|
|
|
Integer irScore = toolsService.irScore(irInfo.getIntValue("number"), irInfo.getIntValue("userNumber"), irInfo.getInteger("difficultScore"), irInfo.getInteger("userCorrect"));
|