Search in sources :

Example 1 with LibraryAnswer

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);
        }
    }
}
Also used : LibraryAnswer(com.cas.sim.tis.entity.LibraryAnswer) LibraryAnswerAction(com.cas.sim.tis.action.LibraryAnswerAction) Question(com.cas.sim.tis.entity.Question)

Example 2 with LibraryAnswer

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();
}
Also used : LibraryAnswer(com.cas.sim.tis.entity.LibraryAnswer) ToggleButton(javafx.scene.control.ToggleButton) Timeline(javafx.animation.Timeline) ActionEvent(javafx.event.ActionEvent) KeyFrame(javafx.animation.KeyFrame) Question(com.cas.sim.tis.entity.Question)

Example 3 with LibraryAnswer

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));
}
Also used : LibraryAnswer(com.cas.sim.tis.entity.LibraryAnswer) ToggleButton(javafx.scene.control.ToggleButton) LibraryRecord(com.cas.sim.tis.entity.LibraryRecord) ArrayList(java.util.ArrayList) Question(com.cas.sim.tis.entity.Question) LibraryRecordAction(com.cas.sim.tis.action.LibraryRecordAction)

Example 4 with LibraryAnswer

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);
    }
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) LibraryAnswer(com.cas.sim.tis.entity.LibraryAnswer) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) LibraryRecordMapper(com.cas.sim.tis.mapper.LibraryRecordMapper) TransactionStatus(org.springframework.transaction.TransactionStatus) Criteria(tk.mybatis.mapper.entity.Example.Criteria) DataSourceTransactionManager(org.springframework.jdbc.datasource.DataSourceTransactionManager) LibraryPublish(com.cas.sim.tis.entity.LibraryPublish)

Example 5 with LibraryAnswer

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;
    }
}
Also used : LibraryAnswer(com.cas.sim.tis.entity.LibraryAnswer) BlankOption(com.cas.sim.tis.view.control.imp.exam.BlankOption) SubjectiveOption(com.cas.sim.tis.view.control.imp.exam.SubjectiveOption) JudgmentOption(com.cas.sim.tis.view.control.imp.exam.JudgmentOption) ChoiceOption(com.cas.sim.tis.view.control.imp.exam.ChoiceOption)

Aggregations

LibraryAnswer (com.cas.sim.tis.entity.LibraryAnswer)6 Question (com.cas.sim.tis.entity.Question)3 ToggleButton (javafx.scene.control.ToggleButton)2 LibraryAnswerAction (com.cas.sim.tis.action.LibraryAnswerAction)1 LibraryRecordAction (com.cas.sim.tis.action.LibraryRecordAction)1 LibraryPublish (com.cas.sim.tis.entity.LibraryPublish)1 LibraryRecord (com.cas.sim.tis.entity.LibraryRecord)1 LibraryRecordMapper (com.cas.sim.tis.mapper.LibraryRecordMapper)1 BlankOption (com.cas.sim.tis.view.control.imp.exam.BlankOption)1 ChoiceOption (com.cas.sim.tis.view.control.imp.exam.ChoiceOption)1 JudgmentOption (com.cas.sim.tis.view.control.imp.exam.JudgmentOption)1 SubjectiveOption (com.cas.sim.tis.view.control.imp.exam.SubjectiveOption)1 ArrayList (java.util.ArrayList)1 KeyFrame (javafx.animation.KeyFrame)1 Timeline (javafx.animation.Timeline)1 ActionEvent (javafx.event.ActionEvent)1 DataSourceTransactionManager (org.springframework.jdbc.datasource.DataSourceTransactionManager)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)1 Condition (tk.mybatis.mapper.entity.Condition)1