From ef0953f86752a635e216eeef62ad5f2e80f163e7 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 10 Jul 2019 17:08:43 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E8=AF=84=E9=98=85?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=9A=84=E5=88=86=E6=95=B0=E8=AF=84=E5=88=A4?= =?UTF-8?q?=E6=A0=87=E5=87=86=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 1 + app/helpers/exercises_helper.rb | 28 ++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 9a7838a96..68be45660 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1040,6 +1040,7 @@ class ExercisesController < ApplicationController @exercise_questions = @exercise_questions.order("question_number ASC") end # 判断问题是否已回答还是未回答 + @exercise_questions = @exercise_questions.includes(:exercise_stand_answers,:exercise_answers,:exercise_shixun_answers) if @t_user_exercise_status == 3 get_each_student_exercise(@exercise.id,@exercise_questions,@exercise_current_user_id) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 0b64cb916..25255de85 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -9,11 +9,32 @@ module ExercisesHelper @ex_obj_array = [] exercise_obj_status.each do |q| if q.question_type == 5 - ques_score = q.exercise_shixun_answers.search_shixun_answers("user_id",user_id).pluck(:score).sum + answers_content = q.exercise_shixun_answers.search_shixun_answers("user_id",user_id) else - ques_score = q.exercise_answers.search_answer_users("user_id",user_id).score_reviewed.pluck(:score).sum + answers_content = q.exercise_answers.includes(:exercise_choices).search_answer_users("user_id",user_id) end + if q.question_type <= 2 + if answers_content.present? #学生有回答时 + answer_choice_array = [] + answers_content.each do |a| + answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置 + end + user_answer_content = answer_choice_array.sort + standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个 + if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分 + ques_score = q.question_score + else + ques_score = 0.0 + end + else + ques_score = 0.0 + end + else + ques_score = answers_content.select(:score).pluck(:score).sum + end + + if ques_score >= q.question_score #满分作答为正确 ques_score = q.question_score stand_answer = 1 @@ -370,7 +391,8 @@ module ExercisesHelper standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个 if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分 if standard_answer.count > 0 - q_score_1 = (q.question_score.to_f / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 + q_score_1 = q.question_score + # q_score_1 = (q.question_score.to_f / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 else q_score_1 = 0.0 end From 88a85bff7db9c71a0ace287606a1f9515102e25d Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 10 Jul 2019 17:12:17 +0800 Subject: [PATCH 02/10] fixbug --- app/helpers/exercises_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 25255de85..018bc2c39 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -11,7 +11,7 @@ module ExercisesHelper if q.question_type == 5 answers_content = q.exercise_shixun_answers.search_shixun_answers("user_id",user_id) else - answers_content = q.exercise_answers.includes(:exercise_choices).search_answer_users("user_id",user_id) + answers_content = q.exercise_answers.search_answer_users("user_id",user_id) end if q.question_type <= 2 From e7da0d9be83609256420292bd2822a03e8ad20dd Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 10 Jul 2019 17:39:59 +0800 Subject: [PATCH 03/10] fixbug --- app/controllers/exercises_controller.rb | 2 +- app/helpers/exercises_helper.rb | 30 +++++++++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 4be76fc59..6af48dbd1 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1130,7 +1130,7 @@ class ExercisesController < ApplicationController @is_teacher_or = @user_course_identity < Course::STUDENT ? 1 : 0 @student_status = 2 # @exercise_answerer = User.find_by(id:@exercise_current_user_id) #试卷回答者 - @exercise_questions = @exercise.exercise_questions.order("question_number ASC") + @exercise_questions = @exercise.exercise_questions.includes(:exercise_shixun_challenges,:exercise_standard_answers,:exercise_answers,:exercise_shixun_answers).order("question_number ASC") @question_status = [] get_exercise_status = @exercise.get_exercise_status(current_user) if @ex_user.present? && @is_teacher_or == 0 diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 018bc2c39..314a90403 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -34,7 +34,6 @@ module ExercisesHelper ques_score = answers_content.select(:score).pluck(:score).sum end - if ques_score >= q.question_score #满分作答为正确 ques_score = q.question_score stand_answer = 1 @@ -663,6 +662,7 @@ module ExercisesHelper user_score = nil shixun_type = 0 question_comment = [] + # user_score_pre = nil if ques_type == 5 exercise_answers = q.exercise_shixun_answers.search_shixun_answers("user_id",ex_answerer_id) else @@ -670,10 +670,26 @@ module ExercisesHelper end if student_status == 2 #当前为老师,或为学生且已提交 user_score_pre = exercise_answers.score_reviewed - if ques_type == 4 && user_score_pre.blank? #主观题时,且没有大于0的分数时,为空 - user_score = nil - else + if ques_type == 4 #主观题时,且没有大于0的分数时,为空 + user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : nil + elsif ques_type == 5 || ques_type == 3 user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : 0.0 + else + if exercise_answers.present? #判断题和选择题时, + answer_choice_array = [] + exercise_answers.each do |a| + answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置 + end + user_answer_content = answer_choice_array.sort + standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个 + if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分 + user_score = q.question_score + else + user_score = 0.0 + end + else + user_score = 0.0 + end end end @@ -681,9 +697,9 @@ module ExercisesHelper user_score = q.question_score end if ques_type <= 2 - answered_content = exercise_answers.pluck(:exercise_choice_id) + answered_content = exercise_answers&.pluck(:exercise_choice_id) elsif ques_type == 3 - exercise_answers.each do |a| + exercise_answers&.each do |a| u_answer = { "choice_id":a.exercise_choice_id, "answer_text": a.answer_text @@ -691,7 +707,7 @@ module ExercisesHelper answered_content.push(u_answer) end elsif ques_type == 4 - answered_content = exercise_answers.pluck(:answer_text) + answered_content = exercise_answers&.pluck(:answer_text) end if ques_type == 5 #存在实训题,及已经做了实训题的 if ex_status == 3 || is_teacher_or == 1 #如果试卷已截止,则可以看到分数,否则不能查看分数 From 092ececc96b12f491b1c9f5d1025a7bf2d63e8e5 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 11 Jul 2019 09:26:26 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=AF=95=E8=AE=BE?= =?UTF-8?q?=E9=80=89=E9=A2=98=E6=9D=83=E9=99=90=E4=B8=8D=E5=A4=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/commons_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/commons_controller.rb b/app/controllers/commons_controller.rb index 1f6dce053..fa5e14dc1 100644 --- a/app/controllers/commons_controller.rb +++ b/app/controllers/commons_controller.rb @@ -44,8 +44,8 @@ class CommonsController < ApplicationController def validate_power code = case params[:object_type].strip - when 'message' - if current_user.course_identity(@object.board.course) >= 5 && @object.author != current_user + when 'message', 'journals_for_message' + if current_user.course_identity(@object.board.course) >= Course::STUDENT && @object.author != current_user 403 else 200 From 036037df2246bff68671d2efb6400bdccad6f1d2 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 11 Jul 2019 09:31:49 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=B8=96=E5=AD=90=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/commons_controller.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/commons_controller.rb b/app/controllers/commons_controller.rb index fa5e14dc1..a23d4dba7 100644 --- a/app/controllers/commons_controller.rb +++ b/app/controllers/commons_controller.rb @@ -44,12 +44,18 @@ class CommonsController < ApplicationController def validate_power code = case params[:object_type].strip - when 'message', 'journals_for_message' + when 'message' if current_user.course_identity(@object.board.course) >= Course::STUDENT && @object.author != current_user 403 else 200 end + when 'journals_for_message' + if current_user.course_identity(@object.jour.course) >= Course::STUDENT && @object.user != current_user + 403 + else + 200 + end else current_user.admin? ? 200 : 403 end From 37737fe7866d8aa83624ca058536cbeb274b7370 Mon Sep 17 00:00:00 2001 From: jasder Date: Thu, 11 Jul 2019 09:48:24 +0800 Subject: [PATCH 06/10] =?UTF-8?q?FIX=20=E5=A4=84=E7=90=86=E7=82=B9?= =?UTF-8?q?=E8=B5=9E=E6=95=B0=E5=BC=82=E5=B8=B8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/messages_controller.rb | 5 ++++- app/models/message.rb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index f684b27f3..0c61e2b69 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -87,7 +87,10 @@ class MessagesController < ApplicationController end def show - @message = Message.includes(:attachments, :message_detail, :children, :author => :user_extension, :board => [{course: :board_course_modules}]).find_by_id params[:id] + @message = Message.includes(:attachments, :message_detail, + :children, :author => :user_extension, + :board => [{course: :board_course_modules}]) + .find_by_id params[:id] return normal_status(-2, "ID为#{params[:id]}的帖子不存在") if @message.nil? @attachment_size = @message.attachments.size diff --git a/app/models/message.rb b/app/models/message.rb index 6b41cdd95..7588ddc2a 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -73,7 +73,7 @@ class Message < ApplicationRecord # 包含二级回复的总点赞数 def total_praises_count - descendants.sum(:praises_count) + praises_count + descendants.sum(:praises_count) end # 包含二级回复数的总回复数 From 79d1e96e36e8d25bcf996da5853989614834b479 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 11 Jul 2019 09:57:52 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index b8a5ec53c..56fe8fc35 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -44,7 +44,7 @@ class ShixunsController < ApplicationController ## 搜索关键字 匹配关卡名, 用户名, 实训名 和 空格多搜索 if params[:keyword].present? keyword = params[:keyword].strip - @shixuns = @shixuns.joins(:users, challenges: :challenge_tags). + @shixuns = @shixuns.joins(:user, challenges: :challenge_tags). where("challenge_tags.name like '%#{keyword}%' or challenges.subject like '%#{keyword}%' or concat(lastname, firstname) like '%#{keyword}%' From 3a0e19b48bfdea0deddcdfd46ad85430ab579396 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 11 Jul 2019 10:18:50 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 56fe8fc35..20ff348a6 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -45,10 +45,11 @@ class ShixunsController < ApplicationController if params[:keyword].present? keyword = params[:keyword].strip @shixuns = @shixuns.joins(:user, challenges: :challenge_tags). - where("challenge_tags.name like '%#{keyword}%' - or challenges.subject like '%#{keyword}%' - or concat(lastname, firstname) like '%#{keyword}%' - or shixuns.name like '%#{keyword.split(" ").join("%")}%'").distinct + where("challenge_tags.name like :keyword + or challenges.subject like :keyword + or concat(lastname, firstname) like :keyword + or shixuns.name like :name", + keyword: "%#{keyword}%", name: "%#{keyword.split(" ").join("%")}%").distinct end ## 筛选 状态 @@ -66,17 +67,17 @@ class ShixunsController < ApplicationController bsort = params[:sort] || 'desc' case params[:order_by] || 'publish_time' when 'new' - @shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.created_at #{bsort}") + @shixuns = @shixuns.reorder("shixuns.status = 2 desc, shixuns.created_at #{bsort}") when 'hot' - @shixuns = @shixuns.order("shixuns.status = 2 desc, myshixuns_count #{bsort}") + @shixuns = @shixuns.reorder("shixuns.status = 2 desc, shixuns.myshixuns_count #{bsort}") when 'mine' - @shixuns = @shixuns.order("shixuns.created_at #{bsort}") + @shixuns = @shixuns.reorder("shixuns.created_at #{bsort}") else - @shixuns = @shixuns.order("shixuns.status = 2 desc, publish_time #{bsort}") + @shixuns = @shixuns.reorder("shixuns.status = 2 desc, shixuns.publish_time #{bsort}") end - - @total_count = @shixuns.count + # 用id计数会快10MS左右。 + @total_count = @shixuns.count("shixuns.id") ## 分页参数 page = params[:page] || 1 From aaa0513ad5fa6fa6ee59d458a1087a6aea54ae08 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 11 Jul 2019 10:38:05 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E4=B8=BB=E9=A1=B5=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 20ff348a6..714351561 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -67,16 +67,16 @@ class ShixunsController < ApplicationController bsort = params[:sort] || 'desc' case params[:order_by] || 'publish_time' when 'new' - @shixuns = @shixuns.reorder("shixuns.status = 2 desc, shixuns.created_at #{bsort}") + @shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.created_at #{bsort}") when 'hot' - @shixuns = @shixuns.reorder("shixuns.status = 2 desc, shixuns.myshixuns_count #{bsort}") + @shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.myshixuns_count #{bsort}") when 'mine' - @shixuns = @shixuns.reorder("shixuns.created_at #{bsort}") + @shixuns = @shixuns.order("shixuns.created_at #{bsort}") else - @shixuns = @shixuns.reorder("shixuns.status = 2 desc, shixuns.publish_time #{bsort}") + @shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.publish_time #{bsort}") end - # 用id计数会快10MS左右。 + # 用id计数会快10+MS左右,随着数据的增加,性能会提升一些。 @total_count = @shixuns.count("shixuns.id") ## 分页参数 From c9d4714ef8fb0e42ff6fd41d17e1cadc96dd1cad Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 11 Jul 2019 10:45:30 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E6=88=91=E7=9A=84=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- app/models/shixun.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 714351561..c237da5e2 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -76,7 +76,7 @@ class ShixunsController < ApplicationController @shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.publish_time #{bsort}") end - # 用id计数会快10+MS左右,随着数据的增加,性能会提升一些。 + # 用id计数会快10+MS左右,对于搜索的内容随着数据的增加,性能会提升一些。 @total_count = @shixuns.count("shixuns.id") ## 分页参数 diff --git a/app/models/shixun.rb b/app/models/shixun.rb index cb305efaf..afad10397 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -52,7 +52,7 @@ class Shixun < ApplicationRecord end } - scope :visible, -> { where("status != -1") } + scope :visible, -> { where.not(status: -1) } scope :published, lambda{ where(status: 2) } scope :unhidden, lambda{ where(hidden: 0, status: 2) } scope :field_for_recommend, lambda{ select([:id, :name, :identifier, :myshixuns_count]) }