Merge branch 'dev_aliyun' of http://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_forum
cxt 6 years ago
commit 23422e5fcf

@ -45,7 +45,13 @@ class CommonsController < ApplicationController
code = code =
case params[:object_type].strip case params[:object_type].strip
when 'message' when 'message'
if current_user.course_identity(@object.board.course) >= 5 && @object.author != current_user 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 403
else else
200 200

@ -1040,6 +1040,7 @@ class ExercisesController < ApplicationController
@exercise_questions = @exercise_questions.order("question_number ASC") @exercise_questions = @exercise_questions.order("question_number ASC")
end end
# 判断问题是否已回答还是未回答 # 判断问题是否已回答还是未回答
@exercise_questions = @exercise_questions.includes(:exercise_stand_answers,:exercise_answers,:exercise_shixun_answers)
if @t_user_exercise_status == 3 if @t_user_exercise_status == 3
get_each_student_exercise(@exercise.id,@exercise_questions,@exercise_current_user_id) get_each_student_exercise(@exercise.id,@exercise_questions,@exercise_current_user_id)
@ -1129,7 +1130,7 @@ class ExercisesController < ApplicationController
@is_teacher_or = @user_course_identity < Course::STUDENT ? 1 : 0 @is_teacher_or = @user_course_identity < Course::STUDENT ? 1 : 0
@student_status = 2 @student_status = 2
# @exercise_answerer = User.find_by(id:@exercise_current_user_id) #试卷回答者 # @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 = [] @question_status = []
get_exercise_status = @exercise.get_exercise_status(current_user) get_exercise_status = @exercise.get_exercise_status(current_user)
if @ex_user.present? && @is_teacher_or == 0 if @ex_user.present? && @is_teacher_or == 0

@ -87,7 +87,10 @@ class MessagesController < ApplicationController
end end
def show 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? return normal_status(-2, "ID为#{params[:id]}的帖子不存在") if @message.nil?
@attachment_size = @message.attachments.size @attachment_size = @message.attachments.size

@ -44,11 +44,12 @@ class ShixunsController < ApplicationController
## 搜索关键字 匹配关卡名, 用户名, 实训名 和 空格多搜索 ## 搜索关键字 匹配关卡名, 用户名, 实训名 和 空格多搜索
if params[:keyword].present? if params[:keyword].present?
keyword = params[:keyword].strip keyword = params[:keyword].strip
@shixuns = @shixuns.joins(:users, challenges: :challenge_tags). @shixuns = @shixuns.joins(:user, challenges: :challenge_tags).
where("challenge_tags.name like '%#{keyword}%' where("challenge_tags.name like :keyword
or challenges.subject like '%#{keyword}%' or challenges.subject like :keyword
or concat(lastname, firstname) like '%#{keyword}%' or concat(lastname, firstname) like :keyword
or shixuns.name like '%#{keyword.split(" ").join("%")}%'").distinct or shixuns.name like :name",
keyword: "%#{keyword}%", name: "%#{keyword.split(" ").join("%")}%").distinct
end end
## 筛选 状态 ## 筛选 状态
@ -68,15 +69,15 @@ class ShixunsController < ApplicationController
when 'new' when 'new'
@shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.created_at #{bsort}") @shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.created_at #{bsort}")
when 'hot' when 'hot'
@shixuns = @shixuns.order("shixuns.status = 2 desc, myshixuns_count #{bsort}") @shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.myshixuns_count #{bsort}")
when 'mine' when 'mine'
@shixuns = @shixuns.order("shixuns.created_at #{bsort}") @shixuns = @shixuns.order("shixuns.created_at #{bsort}")
else else
@shixuns = @shixuns.order("shixuns.status = 2 desc, publish_time #{bsort}") @shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.publish_time #{bsort}")
end end
# 用id计数会快10+MS左右,对于搜索的内容随着数据的增加,性能会提升一些。
@total_count = @shixuns.count @total_count = @shixuns.count("shixuns.id")
## 分页参数 ## 分页参数
page = params[:page] || 1 page = params[:page] || 1

@ -9,9 +9,29 @@ module ExercisesHelper
@ex_obj_array = [] @ex_obj_array = []
exercise_obj_status.each do |q| exercise_obj_status.each do |q|
if q.question_type == 5 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 else
ques_score = q.exercise_answers.search_answer_users("user_id",user_id).score_reviewed.pluck(:score).sum answers_content = q.exercise_answers.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 end
if ques_score >= q.question_score #满分作答为正确 if ques_score >= q.question_score #满分作答为正确
@ -370,7 +390,8 @@ module ExercisesHelper
standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个 standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个
if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分 if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分
if standard_answer.count > 0 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 else
q_score_1 = 0.0 q_score_1 = 0.0
end end
@ -641,6 +662,7 @@ module ExercisesHelper
user_score = nil user_score = nil
shixun_type = 0 shixun_type = 0
question_comment = [] question_comment = []
# user_score_pre = nil
if ques_type == 5 if ques_type == 5
exercise_answers = q.exercise_shixun_answers.search_shixun_answers("user_id",ex_answerer_id) exercise_answers = q.exercise_shixun_answers.search_shixun_answers("user_id",ex_answerer_id)
else else
@ -648,10 +670,26 @@ module ExercisesHelper
end end
if student_status == 2 #当前为老师,或为学生且已提交 if student_status == 2 #当前为老师,或为学生且已提交
user_score_pre = exercise_answers.score_reviewed user_score_pre = exercise_answers.score_reviewed
if ques_type == 4 && user_score_pre.blank? #主观题时且没有大于0的分数时为空 if ques_type == 4 #主观题时且没有大于0的分数时为空
user_score = nil user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : nil
else elsif ques_type == 5 || ques_type == 3
user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : 0.0 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
end end
@ -659,9 +697,9 @@ module ExercisesHelper
user_score = q.question_score user_score = q.question_score
end end
if ques_type <= 2 if ques_type <= 2
answered_content = exercise_answers.pluck(:exercise_choice_id) answered_content = exercise_answers&.pluck(:exercise_choice_id)
elsif ques_type == 3 elsif ques_type == 3
exercise_answers.each do |a| exercise_answers&.each do |a|
u_answer = { u_answer = {
"choice_id":a.exercise_choice_id, "choice_id":a.exercise_choice_id,
"answer_text": a.answer_text "answer_text": a.answer_text
@ -669,7 +707,7 @@ module ExercisesHelper
answered_content.push(u_answer) answered_content.push(u_answer)
end end
elsif ques_type == 4 elsif ques_type == 4
answered_content = exercise_answers.pluck(:answer_text) answered_content = exercise_answers&.pluck(:answer_text)
end end
if ques_type == 5 #存在实训题,及已经做了实训题的 if ques_type == 5 #存在实训题,及已经做了实训题的
if ex_status == 3 || is_teacher_or == 1 #如果试卷已截止,则可以看到分数,否则不能查看分数 if ex_status == 3 || is_teacher_or == 1 #如果试卷已截止,则可以看到分数,否则不能查看分数

@ -73,7 +73,7 @@ class Message < ApplicationRecord
# 包含二级回复的总点赞数 # 包含二级回复的总点赞数
def total_praises_count def total_praises_count
descendants.sum(:praises_count) praises_count + descendants.sum(:praises_count)
end end
# 包含二级回复数的总回复数 # 包含二级回复数的总回复数

@ -52,7 +52,7 @@ class Shixun < ApplicationRecord
end end
} }
scope :visible, -> { where("status != -1") } scope :visible, -> { where.not(status: -1) }
scope :published, lambda{ where(status: 2) } scope :published, lambda{ where(status: 2) }
scope :unhidden, lambda{ where(hidden: 0, status: 2) } scope :unhidden, lambda{ where(hidden: 0, status: 2) }
scope :field_for_recommend, lambda{ select([:id, :name, :identifier, :myshixuns_count]) } scope :field_for_recommend, lambda{ select([:id, :name, :identifier, :myshixuns_count]) }

Loading…
Cancel
Save