diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index 8cefa5071..bb28fff54 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -494,6 +494,7 @@ class ExerciseQuestionsController < ApplicationController def adjust_score ActiveRecord::Base.transaction do begin + ex_all_scores = @exercise.exercise_questions.pluck(:question_score).sum ex_obj_score = @exercise_current_user.objective_score #全部客观题得分 ex_subj_score = @exercise_current_user.subjective_score < 0.0 ? 0.0 : @exercise_current_user.subjective_score #全部主观题得分 ex_answers = @exercise_question.exercise_answers.search_answer_users("user_id",@user_id) #当前用户答案的得分 @@ -501,9 +502,11 @@ class ExerciseQuestionsController < ApplicationController if ex_answers.present? #学生有回答时 取学生的答题得分,否则0分 answer_choice_array = [] ex_answers.each do |a| - answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置 + if a.try(:exercise_choice).try(:choice_position).present? + answer_choice_array.push(a&.exercise_choice&.choice_position) #学生答案的位置 + end end - user_answer_content = answer_choice_array.sort + user_answer_content = answer_choice_array.reject(&:blank?).sort standard_answer = @exercise_question.exercise_standard_answers.pluck(:exercise_choice_id).sort if standard_answer.size == 1 # 老数据需要判断学生答题是否正确, 正确取原题得分,否则是0分 standard_answer = standard_answer.first.to_s.split("").map(&:to_i).sort @@ -535,6 +538,8 @@ class ExerciseQuestionsController < ApplicationController total_scores = new_obj_score + ex_subj_score if total_scores < 0.0 total_scores = 0.0 + elsif total_scores > ex_all_scores + total_scores = ex_all_scores end ex_scores = { :objective_score => new_obj_score, @@ -563,6 +568,8 @@ class ExerciseQuestionsController < ApplicationController total_scores = new_obj_score + ex_subj_score if total_scores < 0.0 total_scores = 0.0 + elsif total_scores > ex_all_scores + total_scores = ex_all_scores end ex_scores = { :objective_score => new_obj_score, @@ -587,6 +594,8 @@ class ExerciseQuestionsController < ApplicationController total_scores = ex_obj_score + new_sub_score if total_scores < 0.0 total_scores = 0.0 + elsif total_scores > ex_all_scores + total_scores = ex_all_scores end ex_scores = { :subjective_score => new_sub_score, @@ -615,6 +624,8 @@ class ExerciseQuestionsController < ApplicationController total_scores = new_obj_score + ex_subj_score if total_scores < 0.0 total_scores = 0.0 + elsif total_scores > ex_all_scores + total_scores = ex_all_scores end ex_scores = { :objective_score => new_obj_score, @@ -623,23 +634,26 @@ class ExerciseQuestionsController < ApplicationController @exercise_current_user.update_attributes(ex_scores) end comments = params[:comment] - question_comment = @exercise_question.exercise_answer_comments.first + question_comment = @exercise_question.exercise_answer_comments&.first + if question_comment.present? comment_option = { - :comment => comments.present? ? comments : question_comment.comment, + :comment => comments, :score => @c_score, - :exercise_answer_id => ex_answers.present? ? ex_answers.first.id : nil + :exercise_answer_id => ex_answers.present? ? ex_answers.first.id : nil, + :user_id => current_user.id } question_comment.update_attributes(comment_option) @exercise_comments = question_comment else + ex_answer_comment_id = @exercise_question.exercise_answers.find_by(user_id: @user_id).try(:id) comment_option = { :user_id => current_user.id, :comment => comments, :score => @c_score, :exercise_question_id => @exercise_question.id, :exercise_shixun_answer_id => @shixun_a_id.present? ? @shixun_a_id : nil, - :exercise_answer_id => ex_answers.present? ? ex_answers.first.id : nil + :exercise_answer_id => ex_answer_comment_id } @exercise_comments = ExerciseAnswerComment.new(comment_option) @exercise_comments.save diff --git a/app/models/exercise_answer_comment.rb b/app/models/exercise_answer_comment.rb index 7da0ec4c7..4279ba445 100644 --- a/app/models/exercise_answer_comment.rb +++ b/app/models/exercise_answer_comment.rb @@ -3,7 +3,7 @@ class ExerciseAnswerComment < ApplicationRecord belongs_to :user belongs_to :exercise_question belongs_to :exercise_shixun_answer, optional: true - belongs_to :exercise_answer,optional: true + belongs_to :exercise_answer, optional: true scope :search_answer_comments, lambda {|name,ids| where("#{name}":ids)} end diff --git a/public/react/src/modules/courses/coursesPublic/NewShixunModel.js b/public/react/src/modules/courses/coursesPublic/NewShixunModel.js index 395e4096d..fbb97cbb5 100644 --- a/public/react/src/modules/courses/coursesPublic/NewShixunModel.js +++ b/public/react/src/modules/courses/coursesPublic/NewShixunModel.js @@ -22,18 +22,15 @@ class NewShixunModel extends Component{ } } componentDidMount() { - let{page,type,keyword,order,diff,limit}=this.state; - let status=this.props.statustype===undefined?'all':'published'; - this.setState({ - status:status - }) + let{page,type,keyword,order,diff,limit,status}=this.state; this.getdatalist(page,type,status,keyword,order,diff,limit) } - getdatalist=(page,type,status,keyword,order,diff,limit,pagetype)=>{ + getdatalist=(page,type,newstatus,keyword,order,diff,limit,pagetype)=>{ this.setState({ isspinning:true }) + let status=this.props.statustype===undefined?newstatus:'published'; let url="/shixun_lists.json" axios.get(url,{params:{ page, @@ -142,10 +139,11 @@ class NewShixunModel extends Component{ belongto=(value)=>{ this.setState({ type:value, - keyword:undefined + keyword:undefined, + page:1 }) - let{page,status,keyword,order,diff,limit}=this.state; - this.getdatalist(page,value,status,keyword,order,diff,limit) + let{status,order,diff,limit}=this.state; + this.getdatalist(1,value,status,undefined,order,diff,limit) } updatedlist=(order)=>{ @@ -441,7 +439,7 @@ class NewShixunModel extends Component{ ` } - {JSON.stringify(item.description) == "{}"?"":
{ list[0].setTip }
:""