|
@@ -5,12 +5,14 @@ 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.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.inline.QuestionNoService;
|
|
|
import com.qxgmat.service.inline.SentenceQuestionService;
|
|
@@ -57,23 +59,25 @@ public class QuestionFlowService {
|
|
|
private ToolsService toolsService;
|
|
|
|
|
|
// 初始化试卷的callback,根据试卷模块进行后续处理
|
|
|
- private Map<PaperModule, InitPaper> initPaperCallback;
|
|
|
+ private Map<PaperModule, InitPaper> initPaperCallback = new HashMap<>();
|
|
|
|
|
|
- // 初始化报告的callback,根据设置进行后续处理
|
|
|
- private Map<PaperModule, InitReport> initReportCallback;
|
|
|
+ // 初始化报告的callback,根据试卷模块进行后续处理
|
|
|
+ private Map<PaperModule, InitReport> initReportCallback = new HashMap<>();
|
|
|
+
|
|
|
+ // 根据
|
|
|
+ private Map<PaperModule, InitQuestion> nextCallback = new HashMap<>();
|
|
|
|
|
|
// 完成试卷的callback,根据试卷模块进行后续处理
|
|
|
- private Map<PaperModule, Callback> finishCallback;
|
|
|
+ private Map<PaperModule, Callback> finishCallback = new HashMap<>();
|
|
|
|
|
|
// 提交答题的callback,根据试题模块进行后续处理
|
|
|
private Map<QuestionModule, Callback> submitCallback;
|
|
|
|
|
|
public QuestionFlowService(){
|
|
|
- initPaperCallback = new HashMap<>();
|
|
|
initPaperCallback.put(PaperModule.EXERCISE, (paper, id)->{
|
|
|
exercisePaperService.initUserPaper(paper, id);
|
|
|
// 获取考题时间
|
|
|
- List<QuestionNoRelation> relationList = questionNoService.listByIds(paper.getQuestionNoIds());
|
|
|
+ List<QuestionNoRelation> relationList = questionNoService.listWithRelationByIds(paper.getQuestionNoIds());
|
|
|
Integer time = toolsService.computerTime(SettingKey.EXERCISE_TIME, relationList);
|
|
|
paper.setTime(time);
|
|
|
});
|
|
@@ -90,40 +94,88 @@ public class QuestionFlowService {
|
|
|
sentencePaperService.initUserPaper(paper, id);
|
|
|
});
|
|
|
|
|
|
- initReportCallback = new HashMap<>();
|
|
|
- initReportCallback.put(PaperModule.EXERCISE, (paper, report)->{
|
|
|
+ initReportCallback.put(PaperModule.EXERCISE, (report, paper)->{
|
|
|
JSONObject setting = report.getSetting();
|
|
|
if (setting.getBoolean("disorder")){
|
|
|
// 随机试题
|
|
|
- report.setQuestionNoIds(this.RandomQuestionNoIds(paper.getQuestionNoIds()));
|
|
|
+ report.setQuestionNoIds(this.randomQuestionNoIds(paper.getQuestionNoIds()));
|
|
|
}
|
|
|
});
|
|
|
- initReportCallback.put(PaperModule.HOMEWORK_PREVIEW, (paper, report)->{
|
|
|
+ initReportCallback.put(PaperModule.HOMEWORK_PREVIEW, (report, paper)->{
|
|
|
JSONObject setting = report.getSetting();
|
|
|
if (setting.getBoolean("disorder")){
|
|
|
// 随机试题
|
|
|
- report.setQuestionNoIds(this.RandomQuestionNoIds(paper.getQuestionNoIds()));
|
|
|
+ report.setQuestionNoIds(this.randomQuestionNoIds(paper.getQuestionNoIds()));
|
|
|
}
|
|
|
});
|
|
|
- initReportCallback.put(PaperModule.COLLECT, (paper, report)->{
|
|
|
+ initReportCallback.put(PaperModule.COLLECT, (report, paper)->{
|
|
|
JSONObject setting = report.getSetting();
|
|
|
if (setting.getBoolean("disorder")){
|
|
|
// 随机试题
|
|
|
- report.setQuestionNoIds(this.RandomQuestionNoIds(paper.getQuestionNoIds()));
|
|
|
+ report.setQuestionNoIds(this.randomQuestionNoIds(paper.getQuestionNoIds()));
|
|
|
}
|
|
|
});
|
|
|
- initReportCallback.put(PaperModule.ERROR, (paper, report)->{
|
|
|
+ initReportCallback.put(PaperModule.ERROR, (report, paper)->{
|
|
|
JSONObject setting = report.getSetting();
|
|
|
if (setting.getBoolean("disorder")){
|
|
|
// 随机试题
|
|
|
- report.setQuestionNoIds(this.RandomQuestionNoIds(paper.getQuestionNoIds()));
|
|
|
+ report.setQuestionNoIds(this.randomQuestionNoIds(paper.getQuestionNoIds()));
|
|
|
}
|
|
|
});
|
|
|
initReportCallback.put(PaperModule.SENTENCE, (paper, report)->{
|
|
|
// 无特殊设置
|
|
|
});
|
|
|
|
|
|
- finishCallback = new HashMap<>();
|
|
|
+ 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);
|
|
|
+ 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);
|
|
|
+ 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);
|
|
|
+ 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);
|
|
|
+ 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);
|
|
|
+ question.setQuestionNoId(relation.getId());
|
|
|
+ question.setQuestionId(relation.getQuestionId());
|
|
|
+ question.setTime(0);
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+
|
|
|
finishCallback.put(PaperModule.EXERCISE, (obj)->{
|
|
|
return exercisePaperService.finished((UserPaper) obj);
|
|
|
});
|
|
@@ -167,13 +219,31 @@ public class QuestionFlowService {
|
|
|
return report;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取report的下一道题
|
|
|
+ * @param userId
|
|
|
+ * @param userReportId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public UserQuestion next(Integer userId, Integer userReportId){
|
|
|
- // 查找未完成的questionid
|
|
|
+ UserQuestion userQuestion = userQuestionService.getLastByReport(userId, userReportId);
|
|
|
+ // 查找未完成的questionId
|
|
|
+ if (userQuestion==null || userQuestion.getUserTime() >0){
|
|
|
+ // 创建新的question
|
|
|
+ UserReport report = userReportService.get(userReportId);
|
|
|
+ userQuestion = userQuestionService.addByReport(report, userQuestion, nextCallback.get(PaperModule.ValueOf(report.getModule())));
|
|
|
+ }
|
|
|
|
|
|
- // 创建新的question
|
|
|
- return null;
|
|
|
+ return userQuestion;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 提交试题
|
|
|
+ * @param userId
|
|
|
+ * @param userQuestionId
|
|
|
+ * @param answer
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Transactional
|
|
|
public Boolean submit(Integer userId, Integer userQuestionId, JSONObject answer){
|
|
|
UserQuestion userQuestion = userQuestionService.get(userQuestionId);
|
|
@@ -190,11 +260,26 @@ public class QuestionFlowService {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 完成试卷,进行试卷分析
|
|
|
+ * @param userId
|
|
|
+ * @param userReportId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Transactional
|
|
|
public Boolean finish(Integer userId, Integer userReportId){
|
|
|
+ // 设定paper完成次数加1
|
|
|
+
|
|
|
+ // 统计
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 重新开始一份试卷:设定试卷reset=1,列表不绑定最后一次考试记录
|
|
|
+ * @param paperId
|
|
|
+ * @param userId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public Boolean restart(Integer paperId, Integer userId){
|
|
|
return userPaperService.reset(paperId, userId);
|
|
|
}
|
|
@@ -204,7 +289,7 @@ public class QuestionFlowService {
|
|
|
* @param questionNoIds
|
|
|
* @return
|
|
|
*/
|
|
|
- private Integer[] RandomQuestionNoIds(Integer[] questionNoIds){
|
|
|
+ private Integer[] randomQuestionNoIds(Integer[] questionNoIds){
|
|
|
Integer[] ran = new Integer[questionNoIds.length];
|
|
|
List<Integer> base = Arrays.stream(questionNoIds).collect(Collectors.toList());
|
|
|
int length = base.size();
|
|
@@ -214,4 +299,25 @@ public class QuestionFlowService {
|
|
|
}
|
|
|
return ran;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 顺序获取下一题
|
|
|
+ * @param ids
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Integer nextId(Integer[] ids, Integer id){
|
|
|
+ if (id == null) return ids[0];
|
|
|
+ boolean flag = false;
|
|
|
+ for(Integer a : ids){
|
|
|
+ if (a.equals(id)){
|
|
|
+ flag = true;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (flag){
|
|
|
+ return a;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
}
|