dev_new_shixunsrepository
cxt 5 years ago
parent 6e94c6436c
commit d12c747edc

@ -21,7 +21,7 @@ class CourseSecondCategoriesController < ApplicationController
else
@course_module.course_second_categories.where("position > #{@category.position} and position <= ?", params[:position]).update_all("position = position - 1")
end
@category.update_attributes(position: params[:position])
@category.update!(position: params[:position])
normal_status(0, "移动成功")
else
normal_status(-1, "位置没有变化")

@ -182,7 +182,7 @@ class CoursesController < ApplicationController
CreateSubjectCourseStudentJob.perform_later(@course.id) if @course.subject && @course.subject.subject_appointments.count > 0
rescue => e
uid_logger_error(e.message)
tip_exception(e.message)
tip_exception("调用失败")
raise ActiveRecord::Rollback
end
end
@ -292,8 +292,8 @@ class CoursesController < ApplicationController
if next_inform.blank?
render_error('已经到达最顶部')
else
inform.update_attribute(:position, (inform.position + 1))
next_inform.update_attribute(:position, inform.position - 1)
inform.update!(position: (inform.position + 1))
next_inform.update!(position: inform.position - 1)
render_ok
end
end
@ -306,8 +306,8 @@ class CoursesController < ApplicationController
if last_inform.blank?
render_error('已经到达最底部')
else
inform.update_attribute(:position, (inform.position - 1))
last_inform.update_attribute(:position, inform.position + 1)
inform.update!(position: (inform.position - 1))
last_inform.update!(position: inform.position + 1)
render_ok
end
end
@ -353,7 +353,7 @@ class CoursesController < ApplicationController
# 邀请码停用/启用
def set_invite_code_halt
begin
@course.update_attribute('invite_code_halt', @course.invite_code_halt == 0 ? 1 : 0)
@course.update!(invite_code_halt: @course.invite_code_halt == 0 ? 1 : 0)
normal_status(0, "成功")
rescue => e
uid_logger_error(e.message)
@ -364,7 +364,7 @@ class CoursesController < ApplicationController
# 设置课堂私有/公有
def set_public_or_private
begin
@course.update_attribute('is_public', @course.is_public == 1 ? 0 : 1)
@course.update!(is_public: @course.is_public == 1 ? 0 : 1)
normal_status(0, "成功")
rescue => e
uid_logger_error(e.message)
@ -551,7 +551,7 @@ class CoursesController < ApplicationController
graduation_group_id = GraduationGroup.find(params[:graduation_group_id].to_i).id
@course_member_list.each do |course_member|
course_member = CourseMember.find(course_member[:course_member_id].to_i)
course_member.update_attributes(graduation_group_id: graduation_group_id)
course_member.update!(graduation_group_id: graduation_group_id)
end
normal_status(0, "成功")
rescue => e
@ -711,7 +711,7 @@ class CoursesController < ApplicationController
CourseDeleteStudentNotifyJob.perform_later(@course.id, [course_member.user_id], current_user.id)
course_member.destroy!
course_student.update_attributes(is_active: 1) if course_student.present? && !course_student.is_active
course_student.update!(is_active: 1) if course_student.present? && !course_student.is_active
normal_status(0, "删除成功")
rescue => e
uid_logger_error(e.message)
@ -726,8 +726,8 @@ class CoursesController < ApplicationController
tip_exception("切换失败") unless course_member.STUDENT?
course_teacher = CourseMember.find_by!(user_id: current_user.id, role: %i[CREATOR PROFESSOR], course_id: @course.id)
course_member.update_attributes(is_active: 0)
course_teacher.update_attributes(is_active: 1)
course_member.update!(is_active: 0)
course_teacher.update!(is_active: 1)
normal_status(0, "切换成功")
rescue => e
uid_logger_error(e.message)
@ -742,8 +742,8 @@ class CoursesController < ApplicationController
tip_exception("切换失败") unless course_member.STUDENT?
course_teacher = CourseMember.find_by!(user_id: current_user.id, role: %i[ASSISTANT_PROFESSOR], course_id: @course.id)
course_member.update_attributes(is_active: 0)
course_teacher.update_attributes(is_active: 1)
course_member.update!(is_active: 0)
course_teacher.update!(is_active: 1)
normal_status(0, "切换成功")
rescue => e
uid_logger_error(e.message)
@ -782,7 +782,7 @@ class CoursesController < ApplicationController
# 课堂如果还有其他身份的用户则更新is_active
course_teacher = CourseMember.find_by(user_id: current_user.id, role: %i[CREATOR PROFESSOR ASSISTANT_PROFESSOR], course_id: @course.id)
course_student.destroy!
course_teacher.update_attributes(is_active: 1) if course_teacher.present? && !course_teacher.is_active
course_teacher.update!(is_active: 1) if course_teacher.present? && !course_teacher.is_active
CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, [current_user.id])
normal_status(0, "退出成功")
end
@ -959,7 +959,7 @@ class CoursesController < ApplicationController
member_teacher = CourseMember.find_by(user_id: course_member.user_id, course_id: @course.id, role: %i[CREATOR PROFESSOR ASSISTANT_PROFESSOR])
student_ids << course_member.user_id
course_member.destroy!
member_teacher.update_attributes(is_active: 1) if member_teacher.present?
member_teacher.update!(is_active: 1) if member_teacher.present?
end
end
CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, student_ids) if student_ids.present?
@ -990,7 +990,7 @@ class CoursesController < ApplicationController
if existing_course_member.present?
if existing_course_member.STUDENT?
existing_course_member.update_attributes(course_group_id: course_group_id)
existing_course_member.update!(course_group_id: course_group_id)
else
new_student.is_active = 0 if existing_course_member.is_active
new_student.save!
@ -1142,7 +1142,7 @@ class CoursesController < ApplicationController
existing_student = CourseMember.find_by(course_id: course.id, role: %i[STUDENT], user_id: current_user.id)
if existing_student.present?
# 如果在该课堂已经存在学生身份,且邀请码为分班邀请码,则将其直接加入分班
existing_student.update_attributes(course_group_id: course_group.id) if course_group.present?
existing_student.update!(course_group_id: course_group.id) if course_group.present?
else
correspond_teacher_exist = current_user.none_admin_teacher_of_course? course
new_student = CourseMember.new(user_id: current_user.id, course_id: course.id, role: 4)

@ -14,7 +14,7 @@ class ExerciseAnswersController < ApplicationController
ea = @exercise_question.exercise_answers.search_answer_users("user_id",current_user.id) #试卷的当前用户的答案
if q_type == Exercise::SINGLE || q_type == Exercise::JUDGMENT #选择题(单选)/判断题
if ea.exists?
ea.first.update_attribute(:exercise_choice_id,choice_id )
ea.first.update!(exercise_choice_id: choice_id )
else
answer_option = {
:user_id => current_user.id,
@ -68,7 +68,7 @@ class ExerciseAnswersController < ApplicationController
:exercise_question_id => @exercise_question.id
}
if ea.present? #已经回答了的,
ea.first.update_attribute("answer_text",answer_text)
ea.first.update!(answer_text: answer_text)
else
answer_option.merge!(answer_text:answer_text)
ex_a = ExerciseAnswer.new(answer_option)
@ -116,7 +116,7 @@ class ExerciseAnswersController < ApplicationController
:score => total_score,
:subjective_score => subjective_score
}
@exercise_user.update_attributes(commit_option)
@exercise_user.update!(commit_option)
normal_status(-1,"试卷提交时间已截止!")
end
end

@ -44,7 +44,7 @@ class ExerciseQuestionsController < ApplicationController
end
end
if @exercise_question.save
if @exercise_question.save!
#为选择题(包括单选和多选)的时候,创建问题选项
ques_type = @exercise_question.question_type
if ques_type <= Exercise::MULTIPLE
@ -59,7 +59,7 @@ class ExerciseQuestionsController < ApplicationController
:choice_text => choice.strip
}
question_choices = @exercise_question.exercise_choices.new(choice_option)
question_choices.save
question_choices.save!
end
#标准答案的存储,如:["1","2","3"..]等1对应A2对应B3对应C。。。
standard_answer.each do |a|
@ -69,7 +69,7 @@ class ExerciseQuestionsController < ApplicationController
:exercise_choice_id => choice_id #即为选择的位置参数
}
question_standard_answer = ExerciseStandardAnswer.new(standard_option)
question_standard_answer.save
question_standard_answer.save!
if standard_answer.count > 1 && ques_type == Exercise::SINGLE #当标准答案数大于1且不为多选时修改为多选
@exercise_question.update_attribute("question_type",Exercise::MULTIPLE)
elsif standard_answer.count == 1 && ques_type == Exercise::MULTIPLE
@ -85,8 +85,8 @@ class ExerciseQuestionsController < ApplicationController
:choice_position => c,
:choice_text => choice.strip
}
question_choices = @exercise_question.exercise_choices.create(choice_option)
question_choices.save
question_choices = @exercise_question.exercise_choices.create!(choice_option)
question_choices.save!
end
standard_answer = params[:standard_answers] #对应选项的id
standard_option = {
@ -94,7 +94,7 @@ class ExerciseQuestionsController < ApplicationController
:exercise_choice_id => standard_answer.first.to_i
}
question_standard_answer = ExerciseStandardAnswer.new(standard_option)
question_standard_answer.save
question_standard_answer.save!
elsif ques_type == Exercise::COMPLETION #填空题,每空的参考答案有多个,那么以位置对应
standard_answer = params[:standard_answers]
standard_answer.each do |a|
@ -107,7 +107,7 @@ class ExerciseQuestionsController < ApplicationController
:answer_text => n
}
question_standard_answer = ExerciseStandardAnswer.new(standard_option)
question_standard_answer.save
question_standard_answer.save!
end
end
elsif ques_type == Exercise::SUBJECTIVE #简答题
@ -119,7 +119,7 @@ class ExerciseQuestionsController < ApplicationController
:answer_text => a,
}
question_standard_answer = ExerciseStandardAnswer.new(standard_option)
question_standard_answer.save
question_standard_answer.save!
end
end
elsif ques_type == Exercise::PRACTICAL #实训题
@ -135,10 +135,10 @@ class ExerciseQuestionsController < ApplicationController
:position => (index + 1),
:question_score => shixun_scores[index].present? ? shixun_scores[index].to_f.round(1) : 5
}
ex_shixun_challenge = ExerciseShixunChallenge.create(shixun_option)
ex_shixun_challenge = ExerciseShixunChallenge.create!(shixun_option)
question_score += ex_shixun_challenge.question_score # 问题的分数,为各个关卡分数的总和
end
@exercise_question.update_attributes(:question_score => question_score,:shixun_name=> shixun_name)
@exercise_question.update!(:question_score => question_score,:shixun_name=> shixun_name)
end
end
rescue Exception => e
@ -188,7 +188,7 @@ class ExerciseQuestionsController < ApplicationController
choices_array = params[:question_choices]
stan_answer_params = params[:standard_answers]
standard_answer = stan_answer_params.present? ? stan_answer_params.uniq.reject(&:blank?) : []
@exercise_question.update_attributes(question_options)
@exercise_question.update!(question_options)
#当选项存在时,可修改选项内容,但是不能更改选项的位置(即不能增删选项)
if choices_array.present?
ex_choices = @exercise_question.exercise_choices
@ -218,7 +218,7 @@ class ExerciseQuestionsController < ApplicationController
:choice_text => choices_array[i-1].strip
}
question_choices = @exercise_question.exercise_choices.new(choice_option)
question_choices.save
question_choices.save!
end
end
end
@ -243,7 +243,7 @@ class ExerciseQuestionsController < ApplicationController
:exercise_choice_id => s.to_i #即为选择的位置参数
}
question_standard_answer = ExerciseStandardAnswer.new(standard_option)
question_standard_answer.save
question_standard_answer.save!
end
end
@ -296,7 +296,7 @@ class ExerciseQuestionsController < ApplicationController
:answer_text => null_choice_text[i-1]
}
question_standard_answer = ExerciseStandardAnswer.new(standard_option)
question_standard_answer.save
question_standard_answer.save!
end
end
else
@ -323,7 +323,7 @@ class ExerciseQuestionsController < ApplicationController
:answer_text => n
}
question_standard_answer = ExerciseStandardAnswer.new(standard_option)
question_standard_answer.save
question_standard_answer.save!
end
end
end
@ -340,19 +340,19 @@ class ExerciseQuestionsController < ApplicationController
:answer_text => main_standard_answer,
}
question_standard_answer = ExerciseStandardAnswer.new(standard_option)
question_standard_answer.save
question_standard_answer.save!
end
elsif @exercise_question.question_type == Exercise::PRACTICAL
question_score = 0
shixun_name = params[:shixun_name] || @exercise_question.shixun_name
@exercise_question.exercise_shixun_challenges.each_with_index do |challenge, index|
challenge.question_score = params[:question_scores][index].to_f.round(1)
challenge.save
challenge.save!
question_score += params[:question_scores][index].to_f.round(1)
end
@exercise_question.question_score = question_score
@exercise_question.shixun_name = shixun_name
@exercise_question.save
@exercise_question.save!
end
#当试卷已发布时(试卷的总状态),当标准答案修改时,如有已提交的学生,需重新计算分数.
@ -397,7 +397,7 @@ class ExerciseQuestionsController < ApplicationController
new_objective_score = objective_score + update_objective_score
total_score = ex_user.score + update_objective_score
total_score = total_score < 0.0 ? 0.0 : total_score
ex_user.update_attributes(objective_score:new_objective_score,score:total_score)
ex_user.update!(objective_score:new_objective_score,score:total_score)
end
end
end
@ -526,7 +526,7 @@ class ExerciseQuestionsController < ApplicationController
:score => @c_score,
:answer_text => ""
}
ExerciseAnswer.create(answer_option)
ExerciseAnswer.create!(answer_option)
ex_answer_old = 0
end
if ex_obj_score <= 0.0
@ -545,7 +545,7 @@ class ExerciseQuestionsController < ApplicationController
:objective_score => new_obj_score,
:score => total_scores
}
@exercise_current_user.update_attributes(ex_scores)
@exercise_current_user.update!(ex_scores)
elsif @exercise_question.question_type == Exercise::COMPLETION #当为填空题,更新问题的总分,
@ -561,7 +561,7 @@ class ExerciseQuestionsController < ApplicationController
:score => @c_score,
:answer_text => ""
}
ExerciseAnswer.create(answer_option)
ExerciseAnswer.create!(answer_option)
new_obj_score = ex_obj_score + @c_score
end
@ -575,7 +575,7 @@ class ExerciseQuestionsController < ApplicationController
:objective_score => new_obj_score,
:score => total_scores
}
@exercise_current_user.update_attributes(ex_scores)
@exercise_current_user.update!(ex_scores)
elsif @exercise_question.question_type == Exercise::SUBJECTIVE #当为主观题时
if ex_answers.exists?
ex_answers_old_score = ex_answers.first.score > 0.0 ? ex_answers.first.score : 0.0 #原分数小于0取0
@ -588,7 +588,7 @@ class ExerciseQuestionsController < ApplicationController
:score => @c_score,
:answer_text => ""
}
ExerciseAnswer.create(answer_option)
ExerciseAnswer.create!(answer_option)
new_sub_score = ex_subj_score + @c_score
end
total_scores = ex_obj_score + new_sub_score
@ -601,7 +601,7 @@ class ExerciseQuestionsController < ApplicationController
:subjective_score => new_sub_score,
:score => total_scores
}
@exercise_current_user.update_attributes(ex_scores)
@exercise_current_user.update!(ex_scores)
elsif @exercise_question.question_type == Exercise::PRACTICAL
ex_answers = @exercise_question.exercise_shixun_answers.where(user_id:@user_id,exercise_shixun_challenge_id:@shixun_a_id)
@ -618,7 +618,7 @@ class ExerciseQuestionsController < ApplicationController
:score => @c_score,
:status => 0
}
ExerciseShixunAnswer.create(ex_shixun_option)
ExerciseShixunAnswer.create!(ex_shixun_option)
new_obj_score = ex_obj_score + @c_score
end
total_scores = new_obj_score + ex_subj_score
@ -631,7 +631,7 @@ class ExerciseQuestionsController < ApplicationController
:objective_score => new_obj_score,
:score => total_scores
}
@exercise_current_user.update_attributes(ex_scores)
@exercise_current_user.update!(ex_scores)
end
comments = params[:comment]
question_comment = @exercise_question.exercise_answer_comments&.first
@ -643,7 +643,7 @@ class ExerciseQuestionsController < ApplicationController
:exercise_answer_id => ex_answers.present? ? ex_answers.first.id : nil,
:user_id => current_user.id
}
question_comment.update_attributes(comment_option)
question_comment.update!(comment_option)
@exercise_comments = question_comment
else
ex_answer_comment_id = @exercise_question.exercise_answers.find_by(user_id: @user_id).try(:id)

@ -130,7 +130,7 @@ class ExercisesController < ApplicationController
:time => -1,
:exercise_status => 1
}
@exercise = Exercise.create(exercise_options)
@exercise = Exercise.create!(exercise_options)
rescue Exception => e
uid_logger_error(e.message)
tip_exception("试卷创建失败!")
@ -161,7 +161,7 @@ class ExercisesController < ApplicationController
:exercise_name => ex_name,
:exercise_description => ex_desc,
}
@exercise.update_attributes(exercise_options)
@exercise.update!(exercise_options)
normal_status(0,"试卷更新成功!")
rescue Exception => e
uid_logger_error(e.message)
@ -294,7 +294,7 @@ class ExercisesController < ApplicationController
begin
check_ids = Exercise.where(id: params[:check_ids])
check_ids.each do |exercise|
exercise.update_attribute('is_public', true)
exercise.update!(is_public: true)
end
normal_status(0, "试卷已设为公开!")
rescue Exception => e
@ -318,7 +318,7 @@ class ExercisesController < ApplicationController
:description => exercise.exercise_description,
:course_list_id => exercise.course.try(:course_list_id)
}
current_ex_bank.update_attributes(ex_params)
current_ex_bank.update!(ex_params)
# question_bank = QuestionBank.ques_by_container(current_ex_bank.id,current_ex_bank.container_type).first #该习题库是否存在于问题库里
# ques_params = {
# :name => current_ex_bank.name,
@ -352,7 +352,7 @@ class ExercisesController < ApplicationController
# question_bank = QuestionBank.new ques_params
# question_bank.save
# end
exercise.update_attributes!(exercise_bank_id: current_ex_bank.id)
exercise.update!(exercise_bank_id: current_ex_bank.id)
end
# 试卷的问题的输入
exercise.exercise_questions.each do |q|
@ -365,7 +365,7 @@ class ExercisesController < ApplicationController
:shixun_name => q.shixun_name
}
exercise_bank_question = current_ex_bank.exercise_bank_questions.new option
exercise_bank_question.save
exercise_bank_question.save!
## 试卷选项的输入
if q.question_type != Exercise::PRACTICAL #不为实训题时,试卷选项加入试题答案库
ex_choices = q.exercise_choices
@ -376,7 +376,7 @@ class ExercisesController < ApplicationController
:choice_text =>c.choice_text
}
ex_bank_choice = exercise_bank_question.exercise_bank_choices.new choice_option
ex_bank_choice.save
ex_bank_choice.save!
end
ex_standard.each do |s|
ex_stand = {
@ -384,7 +384,7 @@ class ExercisesController < ApplicationController
:answer_text => s.answer_text
}
ex_stand_bank = exercise_bank_question.exercise_bank_standard_answers.new ex_stand
ex_stand_bank.save
ex_stand_bank.save!
end
else #当为实训题时
shixun_challenges = q.exercise_shixun_challenges
@ -396,11 +396,11 @@ class ExercisesController < ApplicationController
:question_score => c.question_score
}
shixun_challenge_bank = exercise_bank_question.exercise_bank_shixun_challenges.new challenge_option
shixun_challenge_bank.save
shixun_challenge_bank.save!
end
end
end
current_ex_bank.save
current_ex_bank.save!
end
normal_status(0, "题库更新成功!")
rescue Exception => e
@ -486,7 +486,7 @@ class ExercisesController < ApplicationController
:publish_time => params_publish_time,
:end_time => params_end_time
}
@exercise.update_attributes(exercise_params)
@exercise.update!(exercise_params)
@exercise.exercise_group_settings.destroy_all
normal_status(0, "试卷设置成功!")
end
@ -539,7 +539,7 @@ class ExercisesController < ApplicationController
:end_time => exercise_end_time
}
end
the_group_setting.update_attributes!(ex_group_params)
the_group_setting.update!(ex_group_params)
end
end
if new_group_ids.size > 0
@ -590,7 +590,7 @@ class ExercisesController < ApplicationController
:publish_time => p_time,
:end_time => e_time
}
@exercise.update_attributes(exercise_params)
@exercise.update!(exercise_params)
if @exercise.exercise_status == Exercise::PUBLISHED
if @exercise.course_acts.size == 0
@exercise.course_acts << CourseActivity.new(:user_id => @exercise.user_id,:course_id => @exercise.course_id)
@ -629,9 +629,9 @@ class ExercisesController < ApplicationController
objective_score = @exercise.objective_score > 0 ? params[:objective_score].to_f.round(2) : 0
score = subjective_score + objective_score
if exercise_user.commit_status == 1
exercise_user.update_attributes!(score: score, subjective_score: subjective_score, objective_score: objective_score)
exercise_user.update!(score: score, subjective_score: subjective_score, objective_score: objective_score)
else
exercise_user.update_attributes!(start_at: start_at_time, end_at: Time.now, status: 1, commit_status: 1, score: score,
exercise_user.update!(start_at: start_at_time, end_at: Time.now, status: 1, commit_status: 1, score: score,
subjective_score: subjective_score, objective_score: objective_score, commit_method: 5)
end
@ -777,7 +777,7 @@ class ExercisesController < ApplicationController
exercise_group_setting = exercise.exercise_group_settings.find_in_exercise_group("course_group_id",i).first #根据课堂分班的id寻找试卷所在的班级
group_end_time = params[:detail] ? group_end_times[index] : ex_end_time
if exercise_group_setting.present? #如果该试卷分组存在,则更新,否则新建
exercise_group_setting.update_attributes!(publish_time: Time.now, end_time: group_end_time)
exercise_group_setting.update!(publish_time: Time.now, end_time: group_end_time)
else
p_course_group = {
:exercise_id => exercise.id,
@ -787,7 +787,7 @@ class ExercisesController < ApplicationController
:end_time => group_end_time,
}
new_exercise_group = exercise.exercise_group_settings.new p_course_group
new_exercise_group.save
new_exercise_group.save!
end
end
# group_ids = params[:group_ids]
@ -806,7 +806,7 @@ class ExercisesController < ApplicationController
:exercise_status => ex_status,
:unified_setting => ex_unified
}
exercise.update_attributes(exercise_params)
exercise.update!(exercise_params)
if exercise.course_acts.size == 0
exercise.course_acts << CourseActivity.new(:user_id => exercise.user_id,:course_id => exercise.course_id)
@ -859,7 +859,7 @@ class ExercisesController < ApplicationController
if exercise.unified_setting && g_course.map(&:to_i).sort == all_course_group_ids.sort #开始为统一设置
exercise.exercise_group_settings.destroy_all
new_ex_status = set_exercise_status(exercise.publish_time,Time.now)
exercise.update_attributes(:end_time => Time.now,:exercise_status => new_ex_status)
exercise.update!(:end_time => Time.now,:exercise_status => new_ex_status)
exercise_users = exercise.exercise_users
else
course_members_ids = course_students.course_find_by_ids("course_group_id",g_course).pluck(:user_id).uniq #该班级的全部学生
@ -878,7 +878,7 @@ class ExercisesController < ApplicationController
:publish_time => exercise.publish_time,
:end_time => exercise.end_time
}
ExerciseGroupSetting.create(ex_group_options)
ExerciseGroupSetting.create!(ex_group_options)
end
end
end
@ -893,17 +893,17 @@ class ExercisesController < ApplicationController
:publish_time => exercise.publish_time,
:end_time => Time.now
}
ExerciseGroupSetting.create(ex_group_options)
ExerciseGroupSetting.create!(ex_group_options)
end
end
new_end_time = exercise.exercise_group_settings.end_time_no_null.map(&:end_time) # 试卷结束时间不为空的
new_end_time_s = new_end_time.count > 0 ? new_end_time.max : Time.now
new_ex_status = set_exercise_status(exercise.publish_time,new_end_time_s)
exercise.update_attributes(:end_time => new_end_time_s,:exercise_status => new_ex_status,:unified_setting => false)
exercise.update!(:end_time => new_end_time_s,:exercise_status => new_ex_status,:unified_setting => false)
end
else
exercise_users = exercise.exercise_users
exercise.update_attributes(:exercise_status => 3, :end_time => Time.now,:unified_setting => true)
exercise.update!(:exercise_status => 3, :end_time => Time.now,:unified_setting => true)
end
ex_user_ids = exercise_users.pluck(:id)
@ -946,7 +946,7 @@ class ExercisesController < ApplicationController
if exercise_user.present?
if exercise_user.commit_status == 1 && @exercise.get_exercise_status(current_user) == Exercise::PUBLISHED #用户已提交且试卷提交中
if @exercise.time == -1 || ((Time.now.to_i - exercise_user.start_at.to_i) < @exercise.time.to_i * 60)
exercise_user.update_attributes(:score => nil, :end_at => nil, :status => nil, :commit_status => 0,
exercise_user.update!(:score => nil, :end_at => nil, :status => nil, :commit_status => 0,
:objective_score => 0.0, :subjective_score => -1.0)
exercise_user.user.exercise_shixun_answers.search_shixun_answers("exercise_question_id",ex_question_ids).destroy_all
exercise_answers = exercise_user.user.exercise_answers.search_answer_users("exercise_question_id",ex_question_ids)
@ -1046,7 +1046,7 @@ class ExercisesController < ApplicationController
@exercise_user_current = ex_users_current&.first
if ex_users_current.exists?
if @exercise_user_current.start_at.blank?
@exercise_user_current.update_attribute("start_at",Time.now)
@exercise_user_current.update!(start_at: Time.now)
end
else
if @user_course_identity > Course::ASSISTANT_PROFESSOR #当为老师的时候不创建exercise_user表理论上老师是不能进入答题的
@ -1056,7 +1056,7 @@ class ExercisesController < ApplicationController
:start_at => Time.now
}
exercise_user_current = ExerciseUser.new(exercise_user_params)
exercise_user_current.save
exercise_user_current.save!
end
end
@t_user_exercise_status = @exercise.get_exercise_status(current_user)
@ -1174,7 +1174,7 @@ class ExercisesController < ApplicationController
:subjective_score => subjective_score,
:commit_method => @answer_committed_user&.commit_method.to_i > 0 ? @answer_committed_user&.commit_method.to_i : params[:commit_method].to_i
}
@answer_committed_user.update_attributes!(commit_option)
@answer_committed_user.update!(commit_option)
CommitExercsieNotifyJobJob.perform_later(@exercise.id, current_user.id)
normal_status(0,"试卷提交成功!")
else

@ -52,7 +52,7 @@ class GraduationWorksController < ApplicationController
begin
work = @task.graduation_works.find_by!(user_id: params[:user_id])
tip_exception("只有组长才能删除组员") if work.commit_user_id != current_user.id
work.update_attributes(description: nil, project_id: 0, late_penalty: 0, work_status: 0, commit_time: nil,
work.update!(description: nil, project_id: 0, late_penalty: 0, work_status: 0, commit_time: nil,
update_time: nil, group_id: 0, commit_user_id: nil, final_score: nil, work_score: nil,
teacher_score: nil, teaching_asistant_score: nil, update_user_id: nil)
work.attachments.destroy_all
@ -89,12 +89,12 @@ class GraduationWorksController < ApplicationController
GraduationWork.create(user_id: current_user.id, graduation_task_id: @task.id, course_id: @task.course_id)
if work.work_status == 0 && work.project_id == 0
work.update_attributes(project_id: project.id, update_time: Time.now)
work.update!(project_id: project.id, update_time: Time.now)
# 将老师加入项目
project_member = project.members.where(user_id: @task.user_id).first
if project_member.present?
project_member.member_roles.first.update_attributes(role_id: 3) if project_member.member_roles.first.present?
project_member.member_roles.first.update!(role_id: 3) if project_member.member_roles.first.present?
else
member = Member.create(user_id: @task.user_id, project_id: project.id)
member.member_roles << MemberRole.new(role_id: 3)
@ -127,7 +127,7 @@ class GraduationWorksController < ApplicationController
Tiding.where(user_id: @task.user_id, trigger_user_id: current_user.id, container_id: work.project.id,
container_type: 'ManagerJoinProject').destroy_all
work.update_attributes(project_id: 0)
work.update!(project_id: 0)
normal_status("取消关联成功")
rescue Exception => e
@ -177,7 +177,7 @@ class GraduationWorksController < ApplicationController
student_ids += members
for i in 0 .. members.count-1
stu_work = @task.graduation_works.where(user_id: members[i].to_i).first || GraduationWork.new
stu_work.update_attributes(user_id: members[i].to_i, description: graduation_work.description,
stu_work.update!(user_id: members[i].to_i, description: graduation_work.description,
graduation_task_id: @task.id, project_id: graduation_work.project_id,
late_penalty: graduation_work.late_penalty, work_status: graduation_work.work_status,
commit_time: Time.now, update_time: Time.now, group_id: graduation_work.group_id,
@ -238,7 +238,7 @@ class GraduationWorksController < ApplicationController
# 原成员更新描述、更新时间以及附件
@task.graduation_works.where(group_id: @work.group_id, user_id: (work_user_ids & params_user_ids)).each do |work|
work.update_attributes(update_time: Time.now, description: @work.description, update_user_id: current_user.id)
work.update!(update_time: Time.now, description: @work.description, update_user_id: current_user.id)
work.attachments.destroy_all
@work.attachments.each do |attachment|
att = attachment.copy
@ -264,7 +264,7 @@ class GraduationWorksController < ApplicationController
(params_user_ids - work_user_ids).each do |user_id|
stu_work = @task.graduation_works.where(user_id: user_id).empty? ? GraduationWork.new :
@task.graduation_works.where(user_id: user_id).first
stu_work.update_attributes(user_id: user_id, description: @work.description, graduation_task_id: @task.id,
stu_work.update!(user_id: user_id, description: @work.description, graduation_task_id: @task.id,
project_id: @work.project_id, late_penalty: @work.late_penalty,
work_status: @work.work_status, commit_time: Time.now, update_time: Time.now,
group_id: @work.group_id, commit_user_id: @work.commit_user_id, update_user_id: current_user.id)
@ -323,9 +323,9 @@ class GraduationWorksController < ApplicationController
# 如果作品是未提交的状态则更新为已提交
if !new_score.score.nil? && @work.work_status == 0
@work.update_attributes(work_status: 1, commit_time: Time.now)
@work.update!(work_status: 1, commit_time: Time.now)
if @task.task_type == 2
@work.update_attributes(group_id: @task.graduation_works.where("work_status != 0").select("distinct group_id").count + 1)
@work.update!(group_id: @task.graduation_works.where("work_status != 0").select("distinct group_id").count + 1)
end
end
@ -392,7 +392,7 @@ class GraduationWorksController < ApplicationController
graduation_task_id: @task.id, comment: "使用调分功能调整了作业最终成绩:#{params[:comment]}",
user_id: User.current.id, reviewer_role: 1, is_ultimate: 1)
new_score.save!
@work.update_attributes(ultimate_score: 1, work_score: params[:score].to_f)
@work.update!(ultimate_score: 1, work_score: params[:score].to_f)
Tiding.create!(user_id: @work.user_id, trigger_user_id: current_user.id, container_id: new_score.id,
container_type: "AdjustScore", parent_container_id: @task.id,
@ -445,9 +445,9 @@ class GraduationWorksController < ApplicationController
end
Attachment.associate_container(params[:attachment_ids], @work.id, @work.class, 7)
revise_attachment = Attachment.where(attachtype: 7, container_id: @work.id, container_type: "GraduationWork").last
revise_attachment.update_attributes(description: params[:description]) if revise_attachment.present?
revise_attachment.update!(description: params[:description]) if revise_attachment.present?
@work.update_attributes(update_time: Time.now)
@work.update!(update_time: Time.now)
normal_status("提交成功")
rescue Exception => e
@ -465,7 +465,7 @@ class GraduationWorksController < ApplicationController
if @work_assign_teacher.present?
# graduation_group_id: 已经是答辩组的需要 将答辩组清空
@work_assign_teacher.update_attributes(graduation_group_id: 0)
@work_assign_teacher.update!(graduation_group_id: 0)
else
@work.graduation_work_comment_assignations << GraduationWorkCommentAssignation.new(graduation_task_id: @task.id,
user_id: params[:user_id],

@ -1451,7 +1451,7 @@ class HomeworkCommonsController < ApplicationController
if user_review.present?
user_review.update_attributes!(:code_rate => user_rate)
else
homework.homework_review_results.create(:user_id => user, :code_rate => user_rate)
homework.homework_review_results.create!(:user_id => user, :code_rate => user_rate)
end
end
nuser_ids = results.user_lists.map(&:user_id).uniq

@ -44,7 +44,7 @@ class PollQuestionsController < ApplicationController
@poll.poll_questions.insert_question(ques_num).update_all("question_number = question_number + 1")
end
end
if @poll_question.save
if @poll_question.save!
if params[:question_type] != 3
p_answer = params[:question_answers]
p_other_answer = params[:question_other_answer]
@ -56,7 +56,7 @@ class PollQuestionsController < ApplicationController
:answer_text => answer
}
poll_answers = @poll_question.poll_answers.new question_option
poll_answers.save
poll_answers.save!
end
# 新增答案的其他选项
if p_other_answer
@ -65,7 +65,7 @@ class PollQuestionsController < ApplicationController
:answer_text => ''
}
poll_answers = @poll_question.poll_answers.new question_option
poll_answers.save
poll_answers.save!
end
end
end
@ -118,7 +118,7 @@ class PollQuestionsController < ApplicationController
if answer # 判断该位置的answer是否存在存在则更新.不存在则跳到下一步
answer.answer_text = p_answer[i-1]
answer.answer_position = i
answer.save
answer.save!
else
answer_options = {
:answer_position => i,
@ -137,12 +137,12 @@ class PollQuestionsController < ApplicationController
@poll_question.poll_answers.new question_option
else
other_answer.answer_position = p_answer_count + 1
other_answer.save
other_answer.save!
end
end
end
@poll_question.update_attributes(poll_questions_params)
@poll_question.update!(poll_questions_params)
rescue Exception => e
uid_logger_error(e.message)
tip_exception("更新失败")
@ -198,8 +198,8 @@ class PollQuestionsController < ApplicationController
if opr.to_s == "up"
last_q_p = @poll.poll_questions.find_by(question_number: (current_q_p-1)) #当前问题的前一个问题
if last_q_p.present?
@poll_question.update_attribute("question_number", (current_q_p - 1))
last_q_p.update_attribute("question_number", current_q_p) # 重新获取当前问题的位置
@poll_question.update!(question_number: (current_q_p - 1))
last_q_p.update!(question_number: current_q_p) # 重新获取当前问题的位置
normal_status(0, "问题上移成功!")
else
normal_status(-1, "移动失败,已经是第一个问题了!")
@ -207,8 +207,8 @@ class PollQuestionsController < ApplicationController
elsif opr.to_s == "down"
next_q_p = @poll.poll_questions.find_by(question_number: (current_q_p+1)) #当前问题的后一个问题
if next_q_p.present?
@poll_question.update_attribute("question_number", (current_q_p + 1))
next_q_p.update_attribute("question_number", current_q_p)
@poll_question.update!(question_number: (current_q_p + 1))
next_q_p.update!(question_number: current_q_p)
normal_status(0, "问题下移成功!")
else

@ -31,15 +31,15 @@ class PollVotesController < ApplicationController
current_user_answer = user_votes.first
if current_user_answer&.poll_answer_id != question_answer_id #如果说更换了答案,则以前的答案删除,并新建记录
current_user_answer.destroy
PollVote.create(vote_answer_params)
PollVote.create!(vote_answer_params)
else
if question_answer_text.present?
current_user_answer.update_attribute("vote_text", question_answer_text)
current_user_answer.update!(vote_text: question_answer_text)
end
end
else
PollVote.create(vote_answer_params)
PollVote.create!(vote_answer_params)
end
elsif question_type == 2 #多选题的话答案应该是1个以上
question_answer_ids = params[:poll_answer_id] ? params[:poll_answer_id] : [] #该答案的id
@ -48,7 +48,7 @@ class PollVotesController < ApplicationController
ques_vote_id = question_answer_ids.map(&:to_i).max
ques_vote = user_votes.find_by(poll_answer_id: ques_vote_id)
if ques_vote.present?
ques_vote.update_attributes!(vote_text: question_answer_text)
ques_vote.update!(vote_text: question_answer_text)
else
answer_option = {
:user_id => current_user.id,
@ -93,14 +93,14 @@ class PollVotesController < ApplicationController
else #主观题的输入
# current_vote_text = user_votes.find_vote_text
if user_votes.present?
user_votes.first.update_attribute("vote_text", question_answer_text)
user_votes.first.update!(vote_text: question_answer_text)
# if question_answer_text.present?
# user_votes.first.update_attribute("vote_text", question_answer_text)
# else
# user_votes.destroy_all
# end
else
PollVote.create(vote_answer_params)
PollVote.create!(vote_answer_params)
end
end
@current_question_number = @poll_question.question_number

@ -137,7 +137,7 @@ class PollsController < ApplicationController
:polls_status => 1,
:polls_type => "Course",
}
@poll = Poll.create(poll_options)
@poll = Poll.create!(poll_options)
rescue Exception => e
uid_logger_error(e.message)
tip_exception("问卷创建失败!")
@ -167,7 +167,7 @@ class PollsController < ApplicationController
:polls_name => poll_name,
:polls_description => poll_des
}
@poll.update_attributes(poll_params)
@poll.update!(poll_params)
normal_status(0,"问卷更新成功!")
rescue Exception => e
uid_logger_error(e.message)
@ -297,7 +297,7 @@ class PollsController < ApplicationController
poll_group_setting = poll.poll_group_settings.find_in_poll_group("course_group_id",i).first #根据课堂分班的id寻找问卷所在的班级
group_end_time = params[:detail] ? group_end_times[index] : ex_end_time
if poll_group_setting.present? #如果该问卷分组存在,则更新,否则新建
poll_group_setting.update_attributes!(publish_time: Time.now, end_time: group_end_time)
poll_group_setting.update!(publish_time: Time.now, end_time: group_end_time)
else
p_course_group = {
:poll_id => poll.id,
@ -326,7 +326,7 @@ class PollsController < ApplicationController
:polls_status => poll_status,
:unified_setting => poll_unified
}
poll.update_attributes(poll_params)
poll.update!(poll_params)
if poll.course_acts.size == 0
poll.course_acts << CourseActivity.new(:user_id => poll.user_id,:course_id => poll.course_id)
end
@ -390,10 +390,10 @@ class PollsController < ApplicationController
new_end_time = poll_group_setting.end_time_present.map(&:end_time) # 问卷结束时间不为空的
new_end_time_s = new_end_time.size > 0 ? new_end_time.max : Time.now
new_poll_status = set_poll_status(poll.publish_time,new_end_time_s)
poll.update_attributes(:end_time => new_end_time_s,:polls_status => new_poll_status,:unified_setting => poll_unified)
poll.update!(:end_time => new_end_time_s,:polls_status => new_poll_status,:unified_setting => poll_unified)
elsif poll.unified_setting
poll_users = poll.poll_users
poll.update_attributes(:polls_status => 3, :end_time => Time.now)
poll.update!(:polls_status => 3, :end_time => Time.now)
end
poll_users = poll_users.where("commit_status = 0 and start_at is not null")
poll_users.update_all(:commit_status => 1, :end_at => Time.now)
@ -470,7 +470,7 @@ class PollsController < ApplicationController
:publish_time => p_time,
:end_time => e_time
}
@poll.update_attributes(poll_options)
@poll.update!(poll_options)
normal_status(0,"分班问卷撤销发布成功!")
else
normal_status(-1,"请选择撤销发布班级!")
@ -490,7 +490,7 @@ class PollsController < ApplicationController
:end_time => nil,
:unified_setting => true
}
@poll.update_attributes(poll_new_params)
@poll.update!(poll_new_params)
@poll.poll_group_settings.destroy_all
normal_status(0,"问卷撤销发布成功!")
@ -531,7 +531,7 @@ class PollsController < ApplicationController
begin
check_ids = Poll.where(id:params[:check_ids])
check_ids.each do |poll|
poll.update_attribute('is_public', true)
poll.update!(is_public: true)
end
normal_status(0, "问卷已设为公开!")
rescue Exception => e
@ -555,13 +555,13 @@ class PollsController < ApplicationController
:description => poll.polls_description,
:course_list_id => poll.course.try(:course_list_id)
}
current_ex_bank.update_attributes(ex_params)
current_ex_bank.update!(ex_params)
question_bank = QuestionBank.ques_by_container(current_ex_bank.id,current_ex_bank.container_type) #该习题库是否存在于问题库里
ques_params = {
:name => current_ex_bank.name,
:course_list_id => current_ex_bank.course_list_id
}
question_bank.first.update_attributes(ques_params) if question_bank.present?
question_bank.first.update!(ques_params) if question_bank.present?
current_ex_bank.exercise_bank_questions.destroy_all # 更新后,习题库的问题全部删除,后续重新再建
else
ex_params = {
@ -575,7 +575,7 @@ class PollsController < ApplicationController
:quotes => 1
}
current_ex_bank= ExerciseBank.new ex_params
if current_ex_bank.save #如果习题库保存成功则会创建问题库question_bank
if current_ex_bank.save! #如果习题库保存成功则会创建问题库question_bank
ques_params = {
:name => current_ex_bank.name,
:container_id => current_ex_bank.id,
@ -586,9 +586,9 @@ class PollsController < ApplicationController
:course_list_id => current_ex_bank.course_list_id
}
question_bank = QuestionBank.new ques_params
question_bank.save
question_bank.save!
end
poll.update_attributes!(exercise_bank_id: current_ex_bank.id)
poll.update!(exercise_bank_id: current_ex_bank.id)
end
# 问卷的问题的输入
poll.poll_questions.each do |f|
@ -601,7 +601,7 @@ class PollsController < ApplicationController
:min_choices => f.min_choices
}
exercise_bank_question = current_ex_bank.exercise_bank_questions.new option
exercise_bank_question.save
exercise_bank_question.save!
## 问卷答案的输入
f.poll_answers.each do |a|
choice_option = {
@ -609,7 +609,7 @@ class PollsController < ApplicationController
:choice_text => a.answer_text
}
exercise_bank_c = exercise_bank_question.exercise_bank_choices.new choice_option
exercise_bank_c.save
exercise_bank_c.save!
end
end
end
@ -746,7 +746,7 @@ class PollsController < ApplicationController
:publish_time => params_publish_time,
:end_time => params_end_time
}
@poll.update_attributes(poll_params)
@poll.update!(poll_params)
@poll.poll_group_settings.destroy_all
normal_status(0, "问卷设置成功!")
end
@ -800,7 +800,7 @@ class PollsController < ApplicationController
:end_time => poll_end_time
}
end
the_group_setting.update_attributes(poll_group_params)
the_group_setting.update!(poll_group_params)
end
end
if new_group_ids.size > 0
@ -813,7 +813,7 @@ class PollsController < ApplicationController
:end_time => poll_end_time
}
new_poll_group = PollGroupSetting.new(poll_group_params)
new_poll_group.save
new_poll_group.save!
end
end
end
@ -848,7 +848,7 @@ class PollsController < ApplicationController
:publish_time => p_time,
:end_time => e_time
}
@poll.update_attributes(poll_params)
@poll.update!(poll_params)
if @poll.polls_status == 2
if @poll.course_acts.size == 0
@poll.course_acts << CourseActivity.new(:user_id => @poll.user_id,:course_id => @poll.course_id)
@ -880,10 +880,10 @@ class PollsController < ApplicationController
:start_at => Time.now,
:commit_status => 0
}
PollUser.create(poll_user_params)
PollUser.create!(poll_user_params)
end
elsif poll_user_current.start_at.nil?
poll_user_current.update_attributes(:start_at => Time.now)
poll_user_current.update!(:start_at => Time.now)
end
if @user_course_identity < Course::STUDENT || (@poll_status == 3) || (poll_user_current.present? && poll_user_current.commit_status == 1)
@ -963,7 +963,7 @@ class PollsController < ApplicationController
:commit_status => 1,
:end_at => Time.now
}
poll_user_current.update_attributes(poll_user_params)
poll_user_current.update!(poll_user_params)
CommitPollNotifyJobJob.perform_later(@poll.id, current_user.id)
normal_status(0, "问卷提交成功!")
end

@ -264,7 +264,7 @@ class StudentWorksController < ApplicationController
if project_member.present?
project_member.member_roles.take.update_attributes!(role_id: 3) if project_member.member_roles.take.present?
else
member = Member.create(user_id: @homework.user_id, project_id: project.id)
member = Member.create!(user_id: @homework.user_id, project_id: project.id)
member.member_roles << MemberRole.new(role_id: 3)
Tiding.create(user_id: @homework.user_id, trigger_user_id: current_user.id, container_id: project.id,
container_type: 'ManagerJoinProject', belong_container_id: project.id,
@ -737,7 +737,7 @@ class StudentWorksController < ApplicationController
else
comment = "根据实训报告中最终提交的代码调整第#{challenge.position}关分数"
end
challenge_score = @work.challenge_work_scores.create(challenge_id: params[:challenge_id], user_id: current_user.id, score: params[:score],
challenge_score = @work.challenge_work_scores.create!(challenge_id: params[:challenge_id], user_id: current_user.id, score: params[:score],
comment: comment)
challenge_score.create_tiding current_user.id
if @work.work_status != 0 && @work.myshixun

Loading…
Cancel
Save