|
|
|
@ -178,6 +178,7 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
def update
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
begin
|
|
|
|
|
standard_answer_change = false
|
|
|
|
|
# 更新试卷题目的内容
|
|
|
|
|
question_options = {
|
|
|
|
|
:question_title => params[:question_title],
|
|
|
|
@ -227,6 +228,8 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
if standard_answer.present?
|
|
|
|
|
if @exercise_question.question_type <= Exercise::JUDGMENT #选择题/判断题,标准答案为一个或多个
|
|
|
|
|
exercise_standard_choices = @exercise_answers_array.pluck(:exercise_choice_id) #问题以前的全部标准答案选项位置
|
|
|
|
|
if exercise_standard_choices.sort != standard_answer.sort #表示答案有更改的
|
|
|
|
|
standard_answer_change = true
|
|
|
|
|
common_standard_choices = standard_answer & exercise_standard_choices # 传入的标准答案的选项位置和以前的并集,即表示不用做更改的
|
|
|
|
|
old_left_standard_choices = exercise_standard_choices - common_standard_choices # 以前的差集共同的,剩余的表示需要删掉
|
|
|
|
|
new_left_standard_choices = standard_answer - common_standard_choices # 传入的标准答案差集共同的,剩余的表示需要新建
|
|
|
|
@ -249,11 +252,15 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
elsif standard_answer.count == 1 && @exercise_question.question_type == Exercise::MULTIPLE
|
|
|
|
|
@exercise_question.update_attribute("question_type",Exercise::SINGLE)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
elsif @exercise_question.question_type == Exercise::COMPLETION #填空题
|
|
|
|
|
old_ex_answer = @exercise_question.exercise_standard_answers #当前问题的全部标准答案
|
|
|
|
|
old_ex_answer_choice_ids = old_ex_answer.pluck(:exercise_choice_id).uniq #全部的答案数组序号
|
|
|
|
|
old_ex_answer_choice_texts = old_ex_answer.pluck(:answer_text).uniq.sort
|
|
|
|
|
new_ex_answer_choice_texts = standard_answer.pluck(:answer_text).sum.uniq.sort
|
|
|
|
|
if old_ex_answer_choice_texts != new_ex_answer_choice_texts #填空题标准答案有更改时,才会更新标准答案
|
|
|
|
|
new_ex_answer_choice_ids = standard_answer.map {|a| a[:choice_id]}.uniq #新传入的答案数组序号
|
|
|
|
|
|
|
|
|
|
old_ex_answer_choice_ids = old_ex_answer.pluck(:exercise_choice_id).uniq #全部的答案数组序号
|
|
|
|
|
standard_answer_change = true
|
|
|
|
|
#删除多余的选项
|
|
|
|
|
if old_ex_answer_choice_ids.count > new_ex_answer_choice_ids.count #有减少的填空
|
|
|
|
|
delete_ex_answer_choice_ids = old_ex_answer_choice_ids - new_ex_answer_choice_ids
|
|
|
|
@ -321,6 +328,7 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if @exercise_question.question_type == Exercise::SUBJECTIVE #主观题
|
|
|
|
|
main_standard_answer = standard_answer.present? ? standard_answer.first : nil
|
|
|
|
|
if @exercise_answers_array.present?
|
|
|
|
@ -348,20 +356,27 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
#当试卷已发布时(试卷的总状态),当标准答案修改时,如有已提交的学生,需重新计算分数.
|
|
|
|
|
|
|
|
|
|
if @exercise.exercise_status >= Exercise::PUBLISHED
|
|
|
|
|
if standard_answer_change && @exercise.exercise_status >= Exercise::PUBLISHED
|
|
|
|
|
ex_users_committed = @exercise.exercise_users.exercise_user_committed
|
|
|
|
|
if ex_users_committed.size > 0
|
|
|
|
|
ex_users_committed.each do |ex_user|
|
|
|
|
|
user = ex_user.user
|
|
|
|
|
objective_score = calculate_student_score(@exercise,user)[:total_score]
|
|
|
|
|
update_objective_score = update_single_score(@exercise_question,ex_user.user_id,standard_answer)
|
|
|
|
|
if update_objective_score != 0
|
|
|
|
|
objective_score = ex_user.objective_score
|
|
|
|
|
subjective_score = ex_user.subjective_score
|
|
|
|
|
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
|
|
|
|
|
total_score = objective_score + total_score_subjective_score
|
|
|
|
|
total_score = objective_score + update_objective_score + total_score_subjective_score
|
|
|
|
|
ex_user.update_attributes(objective_score:objective_score,score:total_score)
|
|
|
|
|
end
|
|
|
|
|
# user = ex_user.user
|
|
|
|
|
# objective_score = calculate_student_score(@exercise,user)[:total_score]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
normal_status(0,"试卷更新成功,因标准答案修改,需重新计算学生成绩!")
|
|
|
|
|
else
|
|
|
|
|
normal_status(0,"试卷更新成功!")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
uid_logger_error(e.message)
|
|
|
|
|
tip_exception("页面调用失败!")
|
|
|
|
|