use of com.cas.sim.tis.entity.LibraryAnswer in project TeachingInSimulation by ScOrPiOzzy.
the class StudentQuestionPaper method loadQuestions.
private void loadQuestions() {
this.paper.getChildren().clear();
boolean onlyWrong = filter.getSelectedToggle() != null;
List<LibraryAnswer> answers = SpringUtil.getBean(LibraryAnswerAction.class).findAnswersByPublish(pid, onlyWrong);
for (int i = 0; i < answers.size(); i++) {
int index = i + 1;
LibraryAnswer answer = answers.get(i);
Question question = answer.getQuestion();
RecordQuestionItem item = new RecordQuestionItem(index, answer);
item.setOnMouseClicked(e -> {
selectQuestion(question, item);
});
paper.getChildren().add(item);
if (i == 0) {
selectQuestion(question, item);
}
}
}
use of com.cas.sim.tis.entity.LibraryAnswer in project TeachingInSimulation by ScOrPiOzzy.
the class ExamController method initialize.
public void initialize(LibraryPublish publish) {
clear();
this.publish = publish;
this.library = publish.getLibrary();
this.libraryName.setTitle(library.getName());
// 创建答题卡项
List<Question> questions = this.library.getQuestions();
// // XXX 暂时不做:顺序打乱
// Collections.shuffle(questions);
float total = 0f;
for (int i = 0; i < questions.size(); i++) {
ToggleButton toggle = new ToggleButton(String.valueOf(i + 1));
toggle.getStyleClass().add("undo");
toggle.setUserData(i);
toggle.setWrapText(false);
flow.getChildren().add(toggle);
group.getToggles().add(toggle);
Question question = questions.get(i);
LibraryAnswer libraryAnswer = new LibraryAnswer();
libraryAnswer.setIndex(i);
libraryAnswer.setQuestion(question);
libraryAnswer.setQuestionId(question.getId());
this.answers.put(i, libraryAnswer);
total += question.getPoint();
}
this.total.setText(String.valueOf(total));
groupListener = (b, o, n) -> {
if (o == null) {
return;
} else if (n == null) {
this.group.selectToggle(o);
return;
}
if (!submited) {
// 验证上一个试题是否作答完成
checkAnswer((ToggleButton) o);
}
// 加载下一个试题
currIndex = (int) n.getUserData();
prev.setDisable(false);
next.setDisable(false);
if (currIndex <= 0) {
prev.setDisable(true);
}
if (currIndex >= questions.size() - 1) {
next.setDisable(true);
}
loadQuestion();
};
group.selectedToggleProperty().addListener(groupListener);
group.selectToggle(group.getToggles().get(0));
loadQuestion();
// 启动计时器
timeline = new Timeline();
timeline.setCycleCount(Timeline.INDEFINITE);
timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(1), (ActionEvent event1) -> {
cost++;
this.minute.setText(String.valueOf(cost / 60));
this.second.setText(String.valueOf(cost % 60));
}));
timeline.play();
}
use of com.cas.sim.tis.entity.LibraryAnswer in project TeachingInSimulation by ScOrPiOzzy.
the class ExamController method finish.
public void finish() {
// 提交前更新一下当前显示试题的答案
checkAnswer((ToggleButton) group.getSelectedToggle());
// 计时暂停
timeline.stop();
// 计算得分
float score = 0;
for (int i = 0; i < answers.size(); i++) {
LibraryAnswer libraryAnswer = answers.get(i);
Question question = libraryAnswer.getQuestion();
int type = question.getType();
if (QuestionType.SUBJECTIVE.getType() == type) {
continue;
}
ToggleButton button = (ToggleButton) group.getToggles().get(i);
button.getStyleClass().remove("undo");
button.getStyleClass().remove("done");
score += libraryAnswer.getScore();
if (AnswerState.ANSWER_STATE_RIGHT.getType() == libraryAnswer.getCorrected()) {
button.getStyleClass().add("right");
} else {
button.getStyleClass().add("wrong");
}
}
this.score.setText(String.valueOf(score));
int pid = publish.getId();
LibraryRecord record = new LibraryRecord();
record.setCost(cost);
record.setScore(score);
record.setPublishId(pid);
record.setCreator(Session.get(Session.KEY_LOGIN_ID));
List<LibraryAnswer> libraryAnswers = new ArrayList<>(this.answers.values());
SpringUtil.getBean(LibraryRecordAction.class).addRecord(record, libraryAnswers);
back.setVisible(true);
submited = true;
group.selectToggle(group.getToggles().get(0));
}
use of com.cas.sim.tis.entity.LibraryAnswer in project TeachingInSimulation by ScOrPiOzzy.
the class LibraryRecordServiceImpl method addRecord.
@Override
public void addRecord(LibraryRecord record, List<LibraryAnswer> answers) {
// 1.获取事务控制管理器
DataSourceTransactionManager transactionManager = SpringUtil.getBean(DataSourceTransactionManager.class);
// 2.获取事务定义
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
// 3.设置事务隔离级别,开启新事务
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
// 4.获得事务状态
TransactionStatus status = transactionManager.getTransaction(def);
try {
saveUseGeneratedKeys(record);
int recordId = record.getId();
for (LibraryAnswer answer : answers) {
answer.setRecordId(recordId);
}
answerService.save(answers);
LibraryPublish publish = publishService.findById(record.getPublishId());
// 获得班级总人数
if (publish.getClassId() == null) {
publish.setAverage(MathUtil.round(2, record.getScore()));
} else {
Condition userCon = new Condition(User.class);
Criteria criteria = userCon.createCriteria();
criteria.andEqualTo("classId", publish.getClassId());
criteria.andEqualTo("del", 0);
int total = userService.getTotalBy(userCon);
// 获得已交卷成绩总和
LibraryRecordMapper recordMapper = (LibraryRecordMapper) mapper;
float sum = recordMapper.getRecordScoresSumByPublishId(publish.getId());
publish.setAverage(MathUtil.round(2, sum / total));
}
// 更新平均成绩
publishService.update(publish);
transactionManager.commit(status);
} catch (Exception e) {
e.printStackTrace();
transactionManager.rollback(status);
}
}
use of com.cas.sim.tis.entity.LibraryAnswer in project TeachingInSimulation by ScOrPiOzzy.
the class ExamController method loadQuestion.
/**
* 加载题目
* @param index 打乱以后的序号
* @param question
*/
private void loadQuestion() {
// 获得答题结果对象
LibraryAnswer libraryAnswer = answers.get(currIndex);
// // 加载题目
// this.question.setText(question.getTitle());
// 根据题目类型处理
int type = libraryAnswer.getQuestion().getType();
switch(QuestionType.getQuestionType(type)) {
case CHOICE:
ChoiceOption choice = new ChoiceOption(currIndex + 1, libraryAnswer, submited);
this.options.setContent(choice);
this.current = choice;
break;
case JUDGMENT:
JudgmentOption judgment = new JudgmentOption(currIndex + 1, libraryAnswer, submited);
this.options.setContent(judgment);
this.current = judgment;
break;
case BLANK:
BlankOption blank = new BlankOption(currIndex + 1, libraryAnswer, submited);
this.options.setContent(blank);
this.current = blank;
break;
case SUBJECTIVE:
SubjectiveOption subjective = new SubjectiveOption(currIndex + 1, libraryAnswer, submited);
this.options.setContent(subjective);
this.current = subjective;
break;
default:
break;
}
}
Aggregations