|
@@ -5,16 +5,12 @@ import com.nuliji.tools.exception.ParameterException;
|
|
|
import com.qxgmat.data.constants.enums.SettingKey;
|
|
|
import com.qxgmat.data.constants.enums.module.PaperModule;
|
|
|
import com.qxgmat.data.constants.enums.module.QuestionModule;
|
|
|
-import com.qxgmat.data.dao.entity.QuestionNo;
|
|
|
-import com.qxgmat.data.dao.entity.UserPaper;
|
|
|
-import com.qxgmat.data.dao.entity.UserQuestion;
|
|
|
-import com.qxgmat.data.dao.entity.UserReport;
|
|
|
+import com.qxgmat.data.dao.entity.*;
|
|
|
import com.qxgmat.data.relation.entity.QuestionNoRelation;
|
|
|
import com.qxgmat.service.*;
|
|
|
-import com.qxgmat.service.annotation.InitPaper;
|
|
|
-import com.qxgmat.service.annotation.InitQuestion;
|
|
|
-import com.qxgmat.service.annotation.InitReport;
|
|
|
+import com.qxgmat.service.annotation.*;
|
|
|
import com.qxgmat.service.inline.QuestionNoService;
|
|
|
+import com.qxgmat.service.inline.QuestionService;
|
|
|
import com.qxgmat.service.inline.SentenceQuestionService;
|
|
|
import com.qxgmat.service.inline.UserReportService;
|
|
|
import com.qxgmat.util.annotation.Callback;
|
|
@@ -41,6 +37,9 @@ public class QuestionFlowService {
|
|
|
private QuestionNoService questionNoService;
|
|
|
|
|
|
@Resource
|
|
|
+ private QuestionService questionService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
private SentenceQuestionService sentenceQuestionService;
|
|
|
|
|
|
@Resource
|
|
@@ -64,14 +63,17 @@ public class QuestionFlowService {
|
|
|
// 初始化报告的callback,根据试卷模块进行后续处理
|
|
|
private Map<PaperModule, InitReport> initReportCallback = new HashMap<>();
|
|
|
|
|
|
- // 根据
|
|
|
+ // 初始化题目,根据试卷模块进行选题处理
|
|
|
private Map<PaperModule, InitQuestion> nextCallback = new HashMap<>();
|
|
|
|
|
|
- // 完成试卷的callback,根据试卷模块进行后续处理
|
|
|
- private Map<PaperModule, Callback> finishCallback = new HashMap<>();
|
|
|
+ // 提交答题的callback,根据试题模块正确判断
|
|
|
+ private Map<QuestionModule, SubmitQuestion> submitCallback = new HashMap<>();
|
|
|
|
|
|
- // 提交答题的callback,根据试题模块进行后续处理
|
|
|
- private Map<QuestionModule, Callback> submitCallback;
|
|
|
+ // 提交答题的callback,根据试题模块后续统计,会过滤满足剔除条件
|
|
|
+ private Map<QuestionModule, SubmitAfterQuestion> submitAfterCallback = new HashMap<>();
|
|
|
+
|
|
|
+ // 完成试卷的callback,根据试卷模块进行后续处理
|
|
|
+ private Map<PaperModule, StatReport> finishCallback = new HashMap<>();
|
|
|
|
|
|
public QuestionFlowService(){
|
|
|
initPaperCallback.put(PaperModule.EXERCISE, (paper, id)->{
|
|
@@ -129,71 +131,75 @@ public class QuestionFlowService {
|
|
|
nextCallback.put(PaperModule.EXERCISE, (question, report, lastQuestion)->{
|
|
|
Integer questionNoId = this.nextId(report.getQuestionNoIds(), lastQuestion!=null ? lastQuestion.getQuestionNoId():null);
|
|
|
if (questionNoId == 0) return false;
|
|
|
- QuestionNoRelation relation = questionNoService.getWithRelation(questionNoId);
|
|
|
- question.setQuestionNoId(relation.getId());
|
|
|
- question.setQuestionId(relation.getQuestionId());
|
|
|
- Integer time = toolsService.computerTime(SettingKey.EXERCISE_TIME, relation);
|
|
|
- question.setTime(time);
|
|
|
+ this.bindQuestionNo(question, questionNoId, SettingKey.EXERCISE_TIME);
|
|
|
return true;
|
|
|
});
|
|
|
nextCallback.put(PaperModule.HOMEWORK_PREVIEW, (question, report, lastQuestion)->{
|
|
|
Integer questionNoId = this.nextId(report.getQuestionNoIds(), lastQuestion!=null ? lastQuestion.getQuestionNoId():null);
|
|
|
if (questionNoId == 0) return false;
|
|
|
- QuestionNoRelation relation = questionNoService.getWithRelation(questionNoId);
|
|
|
- question.setQuestionNoId(relation.getId());
|
|
|
- question.setQuestionId(relation.getQuestionId());
|
|
|
- Integer time = toolsService.computerTime(SettingKey.EXERCISE_TIME, relation);
|
|
|
- question.setTime(time);
|
|
|
+ this.bindQuestionNo(question, questionNoId, SettingKey.EXERCISE_TIME);
|
|
|
return true;
|
|
|
});
|
|
|
nextCallback.put(PaperModule.COLLECT, (question, report, lastQuestion)->{
|
|
|
Integer questionNoId = this.nextId(report.getQuestionNoIds(), lastQuestion!=null ? lastQuestion.getQuestionNoId():null);
|
|
|
if (questionNoId == 0) return false;
|
|
|
- QuestionNoRelation relation = questionNoService.getWithRelation(questionNoId);
|
|
|
- question.setQuestionNoId(relation.getId());
|
|
|
- question.setQuestionId(relation.getQuestionId());
|
|
|
- Integer time = toolsService.computerTime(SettingKey.getTimeByPaperModule(PaperModule.ValueOf(relation.getModule())), relation);
|
|
|
- question.setTime(time);
|
|
|
+ // 根据扩展确定exercise还是examination
|
|
|
+ UserPaper paper = userPaperService.get(report.getPaperId());
|
|
|
+ this.bindQuestionNo(question, questionNoId, SettingKey.getTimeByPaperModule(PaperModule.ValueOf(paper.getModuleExtend())));
|
|
|
return true;
|
|
|
});
|
|
|
nextCallback.put(PaperModule.ERROR, (question, report, lastQuestion)->{
|
|
|
Integer questionNoId = this.nextId(report.getQuestionNoIds(), lastQuestion!=null ? lastQuestion.getQuestionNoId():null);
|
|
|
if (questionNoId == 0) return false;
|
|
|
- QuestionNoRelation relation = questionNoService.getWithRelation(questionNoId);
|
|
|
- question.setQuestionNoId(relation.getId());
|
|
|
- question.setQuestionId(relation.getQuestionId());
|
|
|
- Integer time = toolsService.computerTime(SettingKey.getTimeByPaperModule(PaperModule.ValueOf(relation.getModule())), relation);
|
|
|
- question.setTime(time);
|
|
|
+ // 根据扩展确定exercise还是examination
|
|
|
+ UserPaper paper = userPaperService.get(report.getPaperId());
|
|
|
+ this.bindQuestionNo(question, questionNoId, SettingKey.getTimeByPaperModule(PaperModule.ValueOf(paper.getModuleExtend())));
|
|
|
return true;
|
|
|
});
|
|
|
nextCallback.put(PaperModule.SENTENCE, (question, report, lastQuestion)->{
|
|
|
Integer questionNoId = this.nextId(report.getQuestionNoIds(), lastQuestion!=null ? lastQuestion.getQuestionNoId():null);
|
|
|
if (questionNoId == 0) return false;
|
|
|
- QuestionNoRelation relation = questionNoService.getWithRelation(questionNoId);
|
|
|
+ SentenceQuestion relation = sentenceQuestionService.get(questionNoId);
|
|
|
question.setQuestionNoId(relation.getId());
|
|
|
question.setQuestionId(relation.getQuestionId());
|
|
|
question.setTime(0);
|
|
|
return true;
|
|
|
});
|
|
|
|
|
|
- finishCallback.put(PaperModule.EXERCISE, (obj)->{
|
|
|
- return exercisePaperService.finished((UserPaper) obj);
|
|
|
- });
|
|
|
- finishCallback.put(PaperModule.HOMEWORK_PREVIEW, (obj)->{
|
|
|
- return homeworkPreviewService.finished((UserPaper) obj);
|
|
|
+ submitCallback.put(QuestionModule.BASE, (userQuestion)->{
|
|
|
+ // 判断答题情况
|
|
|
+ JSONObject answer = userQuestion.getUserAnswer();
|
|
|
+ Question question = questionService.get(userQuestion.getQuestionId());
|
|
|
+
|
|
|
+ return true;
|
|
|
});
|
|
|
- finishCallback.put(PaperModule.EXAMINATION, (obj)->{
|
|
|
- return homeworkPreviewService.finished((UserPaper) obj);
|
|
|
+ submitCallback.put(QuestionModule.SENTENCE, (userQuestion)->{
|
|
|
+ // 判断答题情况
|
|
|
+ JSONObject answer = userQuestion.getUserAnswer();
|
|
|
+ Question question = questionService.get(userQuestion.getQuestionId());
|
|
|
+
|
|
|
+ return true;
|
|
|
});
|
|
|
|
|
|
- submitCallback = new HashMap<>();
|
|
|
- submitCallback.put(QuestionModule.BASE, (obj)->{
|
|
|
+ submitAfterCallback.put(QuestionModule.BASE, (userQuestion)->{
|
|
|
// 更新题目及题目编号统计
|
|
|
- return questionNoService.submit((UserQuestion) obj);
|
|
|
+ questionNoService.accumulation(userQuestion);
|
|
|
+ questionService.accumulation(userQuestion);
|
|
|
});
|
|
|
- submitCallback.put(QuestionModule.SENTENCE, (obj)->{
|
|
|
+ submitAfterCallback.put(QuestionModule.SENTENCE, (userQuestion)->{
|
|
|
// 更新题目及题目编号统计
|
|
|
- return sentenceQuestionService.submit((UserQuestion) obj);
|
|
|
+ questionService.accumulation(userQuestion);
|
|
|
+ sentenceQuestionService.accumulation(userQuestion);
|
|
|
+ });
|
|
|
+
|
|
|
+ finishCallback.put(PaperModule.EXERCISE, (report, questionList)->{
|
|
|
+ // report
|
|
|
+ });
|
|
|
+ finishCallback.put(PaperModule.HOMEWORK_PREVIEW, (report, questionList)->{
|
|
|
+
|
|
|
+ });
|
|
|
+ finishCallback.put(PaperModule.EXAMINATION, (report, questionList)->{
|
|
|
+
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -220,6 +226,28 @@ public class QuestionFlowService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 继续做题:判断是否可以继续
|
|
|
+ * @param userId
|
|
|
+ * @param userReportId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public UserReport continueReport(Integer userId, Integer userReportId){
|
|
|
+ UserReport userReport = userReportService.get(userReportId);
|
|
|
+ if (!userReport.getUserId().equals(userId)){
|
|
|
+ throw new ParameterException("试卷不存在");
|
|
|
+ }
|
|
|
+ if (userReport.getDetail() != null && userReport.getFinishTime() != null){
|
|
|
+ throw new ParameterException("做题结束");
|
|
|
+ }
|
|
|
+ if (userReport.getUserNumber()>=userReport.getQuestionNumber()){
|
|
|
+ throw new ParameterException("答题结束,请提交完成");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return userReport;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 获取report的下一道题
|
|
|
* @param userId
|
|
|
* @param userReportId
|
|
@@ -231,6 +259,9 @@ public class QuestionFlowService {
|
|
|
if (userQuestion==null || userQuestion.getUserTime() >0){
|
|
|
// 创建新的question
|
|
|
UserReport report = userReportService.get(userReportId);
|
|
|
+ if (!report.getUserId().equals(userId)){
|
|
|
+ throw new ParameterException("试卷不存在");
|
|
|
+ }
|
|
|
userQuestion = userQuestionService.addByReport(report, userQuestion, nextCallback.get(PaperModule.ValueOf(report.getModule())));
|
|
|
}
|
|
|
|
|
@@ -245,18 +276,31 @@ public class QuestionFlowService {
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional
|
|
|
- public Boolean submit(Integer userId, Integer userQuestionId, JSONObject answer){
|
|
|
+ public Boolean submit(Integer userId, Integer userQuestionId, Integer time, JSONObject answer){
|
|
|
UserQuestion userQuestion = userQuestionService.get(userQuestionId);
|
|
|
if (!userQuestion.getUserId().equals(userId)){
|
|
|
throw new ParameterException("题目不存在");
|
|
|
}
|
|
|
+ userQuestion.setTime(time);
|
|
|
+ userQuestion.setUserAnswer(answer);
|
|
|
+
|
|
|
UserReport userReport = userReportService.get(userQuestion.getReportId());
|
|
|
- // 判断题目是否正确
|
|
|
- // 更新做题记录
|
|
|
|
|
|
+ // 根据report模块获取试题所属模块
|
|
|
QuestionModule module = QuestionModule.WithPaper(PaperModule.ValueOf(userReport.getModule()));
|
|
|
- Callback callback = submitCallback.get(module);
|
|
|
- callback.callback(userQuestion);
|
|
|
+ SubmitQuestion callback = submitCallback.get(module);
|
|
|
+ boolean result = callback.callback(userQuestion);
|
|
|
+ userQuestion.setIsCorrect(result ? 1 : 0);
|
|
|
+ userQuestionService.edit(userQuestion);
|
|
|
+
|
|
|
+ // 根据剔除逻辑判断是否统计
|
|
|
+ if (toolsService.filterTime(userQuestion)){
|
|
|
+ SubmitAfterQuestion afterCallback = submitAfterCallback.get(module);
|
|
|
+ afterCallback.callback(userQuestion);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新对应report记录
|
|
|
+ userReportService.accumulation(userQuestion);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -268,9 +312,24 @@ public class QuestionFlowService {
|
|
|
*/
|
|
|
@Transactional
|
|
|
public Boolean finish(Integer userId, Integer userReportId){
|
|
|
- // 设定paper完成次数加1
|
|
|
-
|
|
|
- // 统计
|
|
|
+ UserReport userReport = userReportService.get(userReportId);
|
|
|
+ if (!userReport.getUserId().equals(userId)){
|
|
|
+ throw new ParameterException("试卷不存在");
|
|
|
+ }
|
|
|
+ if (!userReport.getQuestionNumber().equals(userReport.getUserNumber())){
|
|
|
+ throw new ParameterException("试卷未完成");
|
|
|
+ }
|
|
|
+ if (userReport.getDetail() != null && userReport.getFinishTime() != null){
|
|
|
+ throw new ParameterException("做题结束");
|
|
|
+ }
|
|
|
+ userReport.setFinishTime(new Date());
|
|
|
+ List<UserQuestion> userQuestionList = userQuestionService.listByReport(userId, userReportId);
|
|
|
+ // 分析做题结果
|
|
|
+ StatReport callback = finishCallback.get(PaperModule.ValueOf(userReport.getModule()));
|
|
|
+ callback.callback(userReport, userQuestionList);
|
|
|
+
|
|
|
+ // 统计: 更新对应paper记录
|
|
|
+ userPaperService.accumulation(userReport);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -320,4 +379,23 @@ public class QuestionFlowService {
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 关联绑定questionNo类型试题
|
|
|
+ * @param question
|
|
|
+ * @param questionNoId
|
|
|
+ * @param settingKey
|
|
|
+ */
|
|
|
+ private void bindQuestionNo(UserQuestion question, Integer questionNoId, SettingKey settingKey){
|
|
|
+ QuestionNoRelation relation = questionNoService.getWithRelation(questionNoId);
|
|
|
+ question.setQuestionNoId(relation.getId());
|
|
|
+ question.setQuestionId(relation.getQuestionId());
|
|
|
+ if (settingKey != null) {
|
|
|
+ // 根据试题模块信息,获取对应时间key
|
|
|
+ settingKey = SettingKey.getTimeByPaperModule(PaperModule.ValueOf(relation.getModule()));
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer time = toolsService.computerTime(settingKey, relation);
|
|
|
+ question.setTime(time);
|
|
|
+ }
|
|
|
}
|