From e269f32591c3b3907b20751b68c39d5d027247d6 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 21 Jun 2019 17:33:04 +0800 Subject: [PATCH 01/12] fix --- app/controllers/messages_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 5569ec165..3dac97899 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -22,13 +22,13 @@ class MessagesController < ApplicationController messages = @board.messages.root_nodes.by_keywords(params[:search]) - messages = messages.order('(sticky = 1) DESC') # 置顶 + messages = messages.reorder('(sticky = 1) DESC') # 置顶 messages = case sort_type - when 'time' then messages.reorder("created_on #{sort}") - when 'hot' then messages.reorder("descendants_count #{sort}") - else messages.reorder("created_on #{sort}") + when 'time' then messages.order("created_on #{sort}") + when 'hot' then messages.order("descendants_count #{sort}") + else messages.order("created_on #{sort}") end messages = messages.includes(:author) From 471edd3607fff9aab1176a21b501f46a39741038 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 21 Jun 2019 19:17:58 +0800 Subject: [PATCH 02/12] fix bug --- app/helpers/application_helper.rb | 2 +- app/helpers/exercises_helper.rb | 1 - app/tasks/exercise_publish_task.rb | 32 +++++++++++------------------- lib/tasks/poll_publish.rake | 7 ++++--- 4 files changed, 17 insertions(+), 25 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ac50e78d3..42bc16343 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -109,7 +109,7 @@ module ApplicationHelper # 计算到结束还有多长时间 **天**小时**分 def how_much_time(time) - if time.nil? + if time.nil? || time < Time.now #6.21 -hs 增加小于time.now '' else result = ((time - Time.now.to_i).to_i / (24*60*60)).to_s + " 天 " diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 53b2fa4c1..95ec0ac24 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -323,7 +323,6 @@ module ExercisesHelper else show_unreview_count = nil end - logger.info("##########__________exercise_end_time__________###############{exercise_end_time}") if exercise_status == 2 && exercise_end_time.present? ex_left_time = how_much_time(exercise_end_time) diff --git a/app/tasks/exercise_publish_task.rb b/app/tasks/exercise_publish_task.rb index 7f3ee63ee..9d62e4d2e 100644 --- a/app/tasks/exercise_publish_task.rb +++ b/app/tasks/exercise_publish_task.rb @@ -5,7 +5,7 @@ class ExercisePublishTask def publish Rails.logger.info("log--------------------------------exercise_publish start") puts "--------------------------------exercise_publish start" - exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now) + exercises = Exercise.includes(:exercise_users).where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now) exercises.each do |exercise| exercise.update_column('exercise_status', 2) course = exercise.course @@ -67,21 +67,21 @@ class ExercisePublishTask end def end - exercises = Exercise.where("end_time <= ? and exercise_status = ?",Time.now,2) + Rails.logger.info("log--------------------------------exercise_end start") + puts "--------------------------------exercise_end start" + # 1。统一设置的试卷 + exercises = Exercise.includes(:exercise_users,:exercise_questions).where("exercise_status = 2 AND unified_setting = true AND end_time <= ?",Time.now) exercises.each do |exercise| - course = exercise.course ex_type = exercise.exercise_questions.pluck(:question_type).uniq - exercise.update_attribute('exercise_status', 3) + exercise.update_column('exercise_status', 3) exercise.exercise_users.each do |exercise_user| if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? - # exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true) s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] if ex_type.include?(4) #是否包含主观题 subjective_score = exercise_user.subjective_score else subjective_score = -1.0 end - # subjective_score = exercise_user.subjective_score total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score total_score = s_score + total_score_subjective_score commit_option = { @@ -93,21 +93,20 @@ class ExercisePublishTask :subjective_score => subjective_score } exercise_user.update_attributes(commit_option) - # if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? - # exercise_user.update_attributes(:subjective_score => 0) - # end end end end - all_exercises = Exercise.where("end_time > ? and exercise_status = ?",Time.now,2) + # 2.非统一的试卷 + all_exercises = Exercise.includes(:exercise_group_settings,:exercise_users,:exercise_questions).where("unified_setting = false AND exercise_status = 2 AND end_time > ?",Time.now) exercise_ids = all_exercises.blank? ? "(-1)" : "(" + all_exercises.map(&:id).join(",") + ")" ex_group_settings = ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}") ex_group_settings.each do |exercise_setting| exercise = exercise_setting.exercise + exercise.update_column('exercise_status', 3) ex_types = exercise.exercise_questions.pluck(:question_type).uniq users = exercise.course.students.where(:course_group_id => exercise_setting.course_group_id) - exercise_users = exercise.exercise_users.where(:user_id => users.map(&:user_id)) + exercise_users = exercise.exercise_users.where(:user_id => users.pluck(:user_id)) exercise_users.each do |exercise_user| if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? @@ -117,7 +116,6 @@ class ExercisePublishTask subjective_score = -1.0 end s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] - # subjective_score = exercise_user.subjective_score total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score total_score = s_score + total_score_subjective_score commit_option = { @@ -129,17 +127,11 @@ class ExercisePublishTask :subjective_score => subjective_score } exercise_user.update_attributes(commit_option) - # exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true) - - # s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] - # exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0))) - # if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? - # exercise_user.update_attributes(:subjective_score => 0.0) - # end end end end - Rails.logger.info("log--------------------------------exercise_end completed") + Rails.logger.info("log--------------------------------exercise_end end") + puts "--------------------------------exercise_end end" end end \ No newline at end of file diff --git a/lib/tasks/poll_publish.rake b/lib/tasks/poll_publish.rake index c33ad3afb..d10db7a5d 100644 --- a/lib/tasks/poll_publish.rake +++ b/lib/tasks/poll_publish.rake @@ -6,7 +6,7 @@ namespace :poll_publish do task :publish => :environment do puts "--------------------------------poll_publish start" # 统一设置发布时间的问卷 - polls = Poll.where("publish_time is not null and polls_status = 1 and publish_time <=?",Time.now) + polls = Poll.includes(:poll_users).where("publish_time is not null and polls_status = 1 and publish_time <=?",Time.now) polls.each do |poll| poll.update_attributes(:polls_status => 2) course = poll.course @@ -71,7 +71,7 @@ namespace :poll_publish do task :nearly_end => :environment do puts "--------------------------------poll_nearly_end start" # 统一设置发布时间的问卷 - polls = Poll.where("polls_status = 2 and unified_setting = 1 and end_time <=? and end_time > ?", Time.now + 86400, Time.now + 84600) + polls = Poll.includes(:poll_users).where("polls_status = 2 and unified_setting = 1 and end_time <=? and end_time > ?", Time.now + 86400, Time.now + 84600) polls.each do |poll| if poll.tidings.where(:parent_container_type => "NearlyEnd").count == 0 course = poll.course @@ -111,7 +111,7 @@ namespace :poll_publish do end task :end => :environment do - polls = Poll.where("polls_status = 2 and unified_setting = 1 and end_time <=?",Time.now) + polls = Poll.includes(:poll_users).where("polls_status = 2 and unified_setting = 1 and end_time <=?",Time.now) polls.each do |poll| poll.update_attributes(:polls_status => 3) poll.poll_users.each do |poll_user| @@ -123,6 +123,7 @@ namespace :poll_publish do PollGroupSetting.where("end_time < ? and end_time > ?", Time.now + 1800, Time.now - 1800).each do |poll_setting| poll = poll_setting.poll + poll.update_column('polls_status',3) users = poll.course.course_members.where(:course_group_id => poll_setting.course_group_id) poll_users = poll.poll_users.where(:user_id => users.map(&:user_id)) From 0babcc3195e67dab8516fb3c846252289d7097fe Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 21 Jun 2019 19:57:50 +0800 Subject: [PATCH 03/12] =?UTF-8?q?exercise=E5=AE=9A=E6=97=B6=E6=88=AA?= =?UTF-8?q?=E6=AD=A2=E7=9A=84=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 2 +- app/tasks/exercise_publish_task.rb | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 95ec0ac24..1b201d875 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -352,7 +352,7 @@ module ExercisesHelper score2 = 0.0 #填空题 score5 = 0.0 #实训题 ques_stand = [] #问题是否正确 - exercise_questions = exercise.exercise_questions + exercise_questions = exercise.exercise_questions.includes(:exercise_answers,:exercise_shixun_answers,:exercise_standard_answers) exercise_questions.each do |q| if q.question_type != 5 answers_content = q.exercise_answers.search_answer_users("user_id",user.id) #学生的答案 diff --git a/app/tasks/exercise_publish_task.rb b/app/tasks/exercise_publish_task.rb index 9d62e4d2e..6f18dc403 100644 --- a/app/tasks/exercise_publish_task.rb +++ b/app/tasks/exercise_publish_task.rb @@ -70,12 +70,12 @@ class ExercisePublishTask Rails.logger.info("log--------------------------------exercise_end start") puts "--------------------------------exercise_end start" # 1。统一设置的试卷 - exercises = Exercise.includes(:exercise_users,:exercise_questions).where("exercise_status = 2 AND unified_setting = true AND end_time <= ?",Time.now) + exercises = Exercise.includes(:exercise_users,:exercise_questions).where("exercise_status = 2 AND unified_setting = true AND end_time <= ?",Time.now + 900) exercises.each do |exercise| ex_type = exercise.exercise_questions.pluck(:question_type).uniq exercise.update_column('exercise_status', 3) exercise.exercise_users.each do |exercise_user| - if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? + if exercise_user.commit_status == 0 && exercise_user.start_at.present? s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] if ex_type.include?(4) #是否包含主观题 subjective_score = exercise_user.subjective_score @@ -84,6 +84,8 @@ class ExercisePublishTask end total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score total_score = s_score + total_score_subjective_score + Rails.logger.info("log-------------total_score-------------------total_scoretotal_scoretotal_scoretotal_score#{total_score}") + commit_option = { :status => 1, :commit_status => 1, @@ -98,12 +100,15 @@ class ExercisePublishTask end # 2.非统一的试卷 - all_exercises = Exercise.includes(:exercise_group_settings,:exercise_users,:exercise_questions).where("unified_setting = false AND exercise_status = 2 AND end_time > ?",Time.now) + all_exercises = Exercise.includes(:exercise_group_settings,:exercise_users,:exercise_questions).where("unified_setting = false AND exercise_status = 2 AND end_time > ?",Time.now + 900) exercise_ids = all_exercises.blank? ? "(-1)" : "(" + all_exercises.map(&:id).join(",") + ")" ex_group_settings = ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}") ex_group_settings.each do |exercise_setting| exercise = exercise_setting.exercise - exercise.update_column('exercise_status', 3) + if exercise&.end_time <= Time.now + exercise.update_column('exercise_status', 3) + end + ex_types = exercise.exercise_questions.pluck(:question_type).uniq users = exercise.course.students.where(:course_group_id => exercise_setting.course_group_id) exercise_users = exercise.exercise_users.where(:user_id => users.pluck(:user_id)) From d0942590513334483e89139c51333c6496afe0bd Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 21 Jun 2019 20:51:37 +0800 Subject: [PATCH 04/12] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=95=E5=8D=B7?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E5=88=86=E6=95=B0=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 6 - app/controllers/concerns/git_helper.rb | 6 + app/helpers/exercises_helper.rb | 145 ++++++++++++---------- 3 files changed, 86 insertions(+), 71 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 98dd577a1..d1aac6f3a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -349,12 +349,6 @@ class ApplicationController < ActionController::Base end end - #实训题的关卡url初始化 - def challenge_path(path) - cha_path = path.present? ? path.split(";") : [] - cha_path.reject(&:blank?)[0].try(:strip) - end - # 适用与已经用url_safe编码后,回调字符串形式 def tran_base64_decode64(str) s_size = str.size % 4 diff --git a/app/controllers/concerns/git_helper.rb b/app/controllers/concerns/git_helper.rb index 0d8c91a55..f6724a654 100644 --- a/app/controllers/concerns/git_helper.rb +++ b/app/controllers/concerns/git_helper.rb @@ -49,4 +49,10 @@ module GitHelper GitService.fork_repository(repo_path: original_rep_path, fork_repository_path: (new_repo_name + ".git")) container.update_attributes!(:repo_name => new_repo_name) end + + #实训题的关卡url初始化 + def challenge_path(path) + cha_path = path.present? ? path.split(";") : [] + cha_path.reject(&:blank?)[0].try(:strip) + end end \ No newline at end of file diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 1b201d875..67eb373ef 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -352,7 +352,7 @@ module ExercisesHelper score2 = 0.0 #填空题 score5 = 0.0 #实训题 ques_stand = [] #问题是否正确 - exercise_questions = exercise.exercise_questions.includes(:exercise_answers,:exercise_shixun_answers,:exercise_standard_answers) + exercise_questions = exercise.exercise_questions.includes(:exercise_answers,:exercise_shixun_answers,:exercise_standard_answers,:exercise_shixun_challenges) exercise_questions.each do |q| if q.question_type != 5 answers_content = q.exercise_answers.search_answer_users("user_id",user.id) #学生的答案 @@ -360,84 +360,99 @@ module ExercisesHelper answers_content = q.exercise_shixun_answers.search_shixun_answers("user_id",user.id) #学生的答案 end if q.question_type <= 2 #为选择题或判断题时 - 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 #答案一致,多选或单选才给分,答案不对不给分 - if standard_answer.count > 0 - multi_each_score = (q.question_score / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 - else - multi_each_score = 0.0 + if answers_content.present? #学生有回答时 + answer_choice_array = [] + answers_content.each do |a| + answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置 end - answers_content.update_all(:score => multi_each_score) - score1 = score1 + q.question_score - end - elsif q.question_type == 3 #填空题 - null_standard_answer = q.exercise_standard_answers - standard_answer_array = null_standard_answer.select(:exercise_choice_id,:answer_text) - standard_answer_ids = standard_answer_array.pluck(:exercise_choice_id).reject(&:blank?).uniq #标准答案的exercise_choice_id数组 - standard_answer_count = standard_answer_ids.count - if standard_answer_count > 0 #存在标准答案时才有分数 - each_standard_score = (q.question_score.to_f / standard_answer_count).round(1) #每一空的得分 - else - each_standard_score = 0.0 - end - if q.is_ordered - answers_content.each do |u| - i_standard_answer = standard_answer_array.where(exercise_choice_id:u.exercise_choice_id).pluck(:answer_text).reject(&:blank?).map!(&:downcase) #该选项的全部标准答案 - if i_standard_answer.include?(u.answer_text.downcase) #该空的标准答案包含用户的答案才有分数 - u.update_attribute("score",each_standard_score) - score2 = score2 + each_standard_score + user_answer_content = answer_choice_array.sort + 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 / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 + else + q_score_1 = 0.0 end + answers_content.update_all(:score => q_score_1) + score1 = score1 + q.question_score end else - st_answer_text = standard_answer_array.pluck(:answer_text).reject(&:blank?).map!(&:downcase) - answers_content.each do |u| - u_answer_text = u.answer_text.downcase - if st_answer_text.include?(u_answer_text) #只要标准答案包含用户的答案,就有分数。同时,下一次循环时,就会删除该标准答案。防止用户的相同答案获分 - u.update_attribute("score",each_standard_score) - score2 = score2 + each_standard_score - st_answer_text.delete(u_answer_text) + score1 += 0.0 + end + elsif q.question_type == 3 #填空题 + if answers_content.present? + null_standard_answer = q.exercise_standard_answers + standard_answer_array = null_standard_answer.select(:exercise_choice_id,:answer_text) + standard_answer_ids = standard_answer_array.pluck(:exercise_choice_id).reject(&:blank?).uniq #标准答案的exercise_choice_id数组 + standard_answer_count = standard_answer_ids.count + if standard_answer_count > 0 #存在标准答案时才有分数 + q_score_2 = (q.question_score.to_f / standard_answer_count) #每一空的得分 + else + q_score_2 = 0.0 + end + if q.is_ordered + answers_content.each do |u| + i_standard_answer = standard_answer_array.where(exercise_choice_id:u.exercise_choice_id).pluck(:answer_text).reject(&:blank?).map!(&:downcase) #该选项的全部标准答案 + if i_standard_answer.include?(u.answer_text.downcase) #该空的标准答案包含用户的答案才有分数 + u.update_column('score',q_score_2) + score2 = score2 + q_score_2 + end + end + else + st_answer_text = standard_answer_array.pluck(:answer_text).reject(&:blank?).map!(&:downcase) + answers_content.each do |u| + u_answer_text = u.answer_text.downcase + if st_answer_text.include?(u_answer_text) #只要标准答案包含用户的答案,就有分数。同时,下一次循环时,就会删除该标准答案。防止用户的相同答案获分 + u.update_column("score",q_score_2) + score2 = score2 + q_score_2 + st_answer_text.delete(u_answer_text) + end end end + else + score2 += 0.0 end elsif q.question_type == 5 #实训题时,主观题这里不评分 - q.exercise_shixun_challenges.each do |exercise_cha| - game = Game.user_games(user.id,exercise_cha.challenge_id).first #当前用户的关卡 - if game.present? - exercise_cha_score = 0 - answer_status = 0 - cha_path = challenge_path exercise_cha.challenge.path - if game.status == 2 && game.final_score >= 0 - exercise_cha_score = game.real_score exercise_cha.question_score #每一关卡的得分 - answer_status = 1 - end - if exercise_cha.exercise_shixun_answers.search_shixun_answers("user_id",user.id).blank? #把关卡的答案存入试卷的实训里 - game_challenge = game.game_codes.search_challenge_path(cha_path).first - if game_challenge.present? - game_code = game_challenge - code = game_code.try(:new_code) + if answers_content.present? + q.exercise_shixun_challenges.each do |exercise_cha| + game = Game.user_games(user.id,exercise_cha.challenge_id).first #当前用户的关卡 + if game.present? + exercise_cha_score = 0.0 + answer_status = 0 + cha_path = challenge_path exercise_cha.challenge.path + if game.status == 2 && game.final_score >= 0 + exercise_cha_score = exercise_cha.question_score #每一关卡的得分 + answer_status = 1 + end + ex_shixun_answer_content = answers_content.where(exercise_shixun_challenge_id: exercise_cha.id) + if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里 + game_challenge = game.game_codes.search_challenge_path(cha_path).first + if game_challenge.present? + game_code = game_challenge + code = game_code.try(:new_code) + else + code = git_fle_content(exercise_cha.shixun.repo_path,cha_path) + end + sx_option = { + :exercise_question_id => q.id, + :exercise_shixun_challenge_id => exercise_cha.id, + :user_id => user.id, + :score => exercise_cha_score, + :answer_text => code, + :status => answer_status + } + ExerciseShixunAnswer.create(sx_option) else - code = git_fle_content(exercise_cha.shixun.repo_path,cha_path) + ex_shixun_answer_content.first.update_column('score',exercise_cha_score) end - sx_option = { - :exercise_question_id => q.id, - :exercise_shixun_challenge_id => exercise_cha.id, - :user_id => user.id, - :score => exercise_cha_score, - :answer_text => code, - :status => answer_status - } - ExerciseShixunAnswer.create(sx_option) + score5 += exercise_cha_score end - score5 += exercise_cha_score end + else + score5 += 0.0 end end - user_scores = answers_content.score_reviewed.pluck(:score).sum + user_scores = answers_content.present? ? answers_content.score_reviewed.pluck(:score).sum : 0.0 if user_scores > 0 stand_answer = 1 else From 7135094316a7113c1d5f6dd79e1e6028fbdaff85 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 22 Jun 2019 09:12:23 +0800 Subject: [PATCH 05/12] fix reply message api --- app/controllers/messages_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 3dac97899..60a1c171c 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -51,7 +51,8 @@ class MessagesController < ApplicationController def reply return normal_status(2, "回复内容不能为空") if params[:content].blank? - @reply = Message.create!(board: @message.board, root: @message.root, author: current_user, parent: @message, + @reply = Message.create!(board: @message.board, root_id: @message.root_id || @message.id, + author: current_user, parent: @message, message_detail_attributes: { content: params[:content] }) From 2420ce6a1ba0491b23a25a8e9fd9efe95e8ae52b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 09:29:57 +0800 Subject: [PATCH 06/12] fix bug --- app/tasks/exercise_publish_task.rb | 2 -- app/views/exercise_questions/_exercise_questions.json.jbuilder | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/tasks/exercise_publish_task.rb b/app/tasks/exercise_publish_task.rb index 6f18dc403..282968755 100644 --- a/app/tasks/exercise_publish_task.rb +++ b/app/tasks/exercise_publish_task.rb @@ -84,8 +84,6 @@ class ExercisePublishTask end total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score total_score = s_score + total_score_subjective_score - Rails.logger.info("log-------------total_score-------------------total_scoretotal_scoretotal_scoretotal_score#{total_score}") - commit_option = { :status => 1, :commit_status => 1, diff --git a/app/views/exercise_questions/_exercise_questions.json.jbuilder b/app/views/exercise_questions/_exercise_questions.json.jbuilder index 10dc46abf..b5a01ed06 100644 --- a/app/views/exercise_questions/_exercise_questions.json.jbuilder +++ b/app/views/exercise_questions/_exercise_questions.json.jbuilder @@ -1,5 +1,6 @@ json.question_id question.id -json.question_number question.question_number +# json.question_number question.question_number +json.q_position question.question_number json.question_title question.question_title json.question_type question.question_type json.question_score question.question_score.round(1).to_s From 7ddd0c4f5d45bf07be04a03e306b12033a88b2c3 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 22 Jun 2019 09:42:39 +0800 Subject: [PATCH 07/12] fix user shixuns list filter bug and n+1 bug --- app/controllers/users/shixuns_controller.rb | 4 ++++ app/decorators/shixun_decorator.rb | 4 ---- app/models/shixun.rb | 4 ++++ app/services/users/shixun_service.rb | 2 +- app/views/users/shixuns/shared/_shixun.json.jbuilder | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/controllers/users/shixuns_controller.rb b/app/controllers/users/shixuns_controller.rb index c4c0d4c07..7b840a0a1 100644 --- a/app/controllers/users/shixuns_controller.rb +++ b/app/controllers/users/shixuns_controller.rb @@ -4,6 +4,10 @@ class Users::ShixunsController < Users::BaseController @count = shixuns.count @shixuns = paginate(shixuns.includes(:first_tag_repertoire), special: true) + + ids = @shixuns.map(&:id) + @finished_challenges_count_map = Game.joins(:myshixun).where(user_id: observed_user.id, status: 2) + .where(myshixuns: { shixun_id: ids }).group('myshixuns.shixun_id').count end private diff --git a/app/decorators/shixun_decorator.rb b/app/decorators/shixun_decorator.rb index 50e2e27eb..4b7a0714a 100644 --- a/app/decorators/shixun_decorator.rb +++ b/app/decorators/shixun_decorator.rb @@ -1,8 +1,4 @@ module ShixunDecorator - def finished_challenges_count(user) - Game.joins(:myshixun).where(user_id: user.id, status: 2, myshixuns: { shixun_id: id }).count - end - def human_status I18n.t("shixun.status.#{status}") end diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 9ccefca92..556a4400f 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -233,4 +233,8 @@ class Shixun < ApplicationRecord shixun_members.where(role: [1, 2]).exists?(user_id: user.id) end + + def finished_challenges_count(user) + Game.joins(:myshixun).where(user_id: user.id, status: 2, myshixuns: { shixun_id: id }).count + end end diff --git a/app/services/users/shixun_service.rb b/app/services/users/shixun_service.rb index b5e5586f1..4730a5777 100644 --- a/app/services/users/shixun_service.rb +++ b/app/services/users/shixun_service.rb @@ -58,7 +58,7 @@ class Users::ShixunService when 'passed' then 1 when 'processing' then 0 end - relations.where(myshixuns: { status: status }) if status + relations = relations.where(myshixuns: { status: status }) if status relations end diff --git a/app/views/users/shixuns/shared/_shixun.json.jbuilder b/app/views/users/shixuns/shared/_shixun.json.jbuilder index 13cc3a9ee..8427ead58 100644 --- a/app/views/users/shixuns/shared/_shixun.json.jbuilder +++ b/app/views/users/shixuns/shared/_shixun.json.jbuilder @@ -6,4 +6,4 @@ json.name shixun.name json.status shixun.status json.human_status shixun.human_status json.challenges_count shixun.challenges_count -json.finished_challenges_count shixun.finished_challenges_count(user) \ No newline at end of file +json.finished_challenges_count @finished_challenges_count_map&.fetch(shixun.id, 0) || shixun.finished_challenges_count(user) \ No newline at end of file From ab6c1bd682d153ff779b2a1fff97e38176d1c24f Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 22 Jun 2019 09:45:42 +0800 Subject: [PATCH 08/12] fix user projects filter bug --- app/services/users/subject_service.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/users/subject_service.rb b/app/services/users/subject_service.rb index e0d8377c2..7e3eaaa81 100644 --- a/app/services/users/subject_service.rb +++ b/app/services/users/subject_service.rb @@ -65,7 +65,7 @@ class Users::SubjectService when 'finished' then subjects.having('finished = 1').map(&:id) end - relations.where(id: subject_ids) if subject_ids.present? + relations = relations.where(id: subject_ids) if subject_ids.present? relations end @@ -75,7 +75,7 @@ class Users::SubjectService when 'applying' then 1 when 'published' then 2 end - relations.where(status: status) if status + relations = relations.where(status: status) if status relations end From 130a39ed5b2eac847ed6116ca8e49932d3ac4f5f Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 09:46:14 +0800 Subject: [PATCH 09/12] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/course.rb | 7 ++++--- app/models/homework_common.rb | 11 ++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/models/course.rb b/app/models/course.rb index e4ade6e9f..a2f5add51 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -165,7 +165,7 @@ class Course < ApplicationRecord all_course_module_types.each do |type| hidden_value = course_module_types.include?(type) ? 0 : 1 - course_module = get_course_module_by_type(type, self.id) + course_module = course_modules.where(module_type: type).first course_module.update_attribute(:hidden, hidden_value) if course_module.present? end end @@ -174,8 +174,9 @@ class Course < ApplicationRecord %w[activity shixun_homework common_homework group_homework graduation exercise poll attachment board course_group] end - def get_course_module_by_type(type, course_id) - CourseModule.where(course_id: course_id, module_type: type).first + def get_course_module_by_type(type) + #CourseModule.where(course_id: course_id, module_type: type).first + self.course_modules.where(module_type: type).first end # 创建课程讨论区 diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index d67b6e0fd..c3bfd2dd9 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -170,7 +170,7 @@ class HomeworkCommon < ApplicationRecord #删除时更新题库中的引用数 def update_homework_bank_quotes - old_banks = HomeworkBank.where(homework_common_id: self.id) + old_banks = self.homework_bank unless old_banks.blank? old_banks.each do |bank| bank.update_attributes(quotes: (bank.quotes - 1) > 0 ? (bank.quotes - 1) : 0, homework_common_id: nil) @@ -243,10 +243,15 @@ class HomeworkCommon < ApplicationRecord end def min_group_publish_time - HomeworkGroupSetting.where("homework_common_id = #{self.id} and publish_time is not null").pluck(:publish_time).min + #HomeworkGroupSetting.where("homework_common_id = #{self.id} and publish_time is not null").pluck(:publish_time).min + # 可以使用includes + self.homework_group_settings.where("publish_time is not null").pluck(:publish_time).min end def max_group_end_time - HomeworkGroupSetting.where("homework_common_id = #{self.id} and end_time is not null").pluck(:end_time).max + #HomeworkGroupSetting.where("homework_common_id = #{self.id} and end_time is not null").pluck(:end_time).max + # 可以使用includes + self.homework_group_settings.where("end_time is not null").pluck(:end_time).max + end end From e318ee25b5707c9c66f57aa9242b115bbd0a56c6 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 09:53:35 +0800 Subject: [PATCH 10/12] fix bug --- .../exercise_questions/_exercise_questions.json.jbuilder | 2 +- app/views/exercises/start_answer.json.jbuilder | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/views/exercise_questions/_exercise_questions.json.jbuilder b/app/views/exercise_questions/_exercise_questions.json.jbuilder index b5a01ed06..7a05c2e11 100644 --- a/app/views/exercise_questions/_exercise_questions.json.jbuilder +++ b/app/views/exercise_questions/_exercise_questions.json.jbuilder @@ -1,6 +1,6 @@ json.question_id question.id # json.question_number question.question_number -json.q_position question.question_number +json.q_position ques_position.present? ? ques_position : question.question_number json.question_title question.question_title json.question_type question.question_type json.question_score question.question_score.round(1).to_s diff --git a/app/views/exercises/start_answer.json.jbuilder b/app/views/exercises/start_answer.json.jbuilder index fb9916696..4cc461d56 100644 --- a/app/views/exercises/start_answer.json.jbuilder +++ b/app/views/exercises/start_answer.json.jbuilder @@ -36,9 +36,9 @@ json.partial! "exercises/exercise_scores" json.exercise_questions do json.array! @exercise_all_questions do |q| question = q[:question] - ques_position = q[:ques_number] #问题的序号,当问题为随机时,重新更新后的问题序号 + # ques_position = q[:ques_number] #问题的序号,当问题为随机时,重新更新后的问题序号 question_info = get_exercise_question_info(question,@exercise,@exercise_user_current,@ex_answerer.id) - json.q_position ques_position + # json.q_position q[:ques_number] #问题的序号,当问题为随机时,重新更新后的问题序号 if @t_user_exercise_status == 3 this_answer_status = "0.0" user_score = "0.0" @@ -58,6 +58,7 @@ json.exercise_questions do user_answer: question_info[:answered_content], choices:question.exercise_choices, exercise_type:3, - shixun_type:question_info[:shixun_type] + shixun_type:question_info[:shixun_type], + ques_position: q[:ques_number] end end \ No newline at end of file From 2ec730e4fd1772250b1ea8f06b9cbc39b10b6e32 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 10:01:13 +0800 Subject: [PATCH 11/12] fix bug --- app/views/exercise_questions/edit.json.jbuilder | 3 ++- app/views/exercise_questions/show.json.jbuilder | 3 ++- app/views/exercises/_user_exercise_info.json.jbuilder | 3 ++- app/views/exercises/blank_exercise.json.jbuilder | 3 ++- app/views/exercises/edit.json.jbuilder | 3 ++- app/views/exercises/show.json.jbuilder | 3 ++- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/views/exercise_questions/edit.json.jbuilder b/app/views/exercise_questions/edit.json.jbuilder index 32567d813..35db720c7 100644 --- a/app/views/exercise_questions/edit.json.jbuilder +++ b/app/views/exercise_questions/edit.json.jbuilder @@ -5,4 +5,5 @@ json.partial! "exercise_questions/exercise_questions", choices:@exercise_choices, shixun_challenges: @exercise_question_shixun, exercise_type:1, - user_answer:[] \ No newline at end of file + user_answer:[], + ques_position:nil \ No newline at end of file diff --git a/app/views/exercise_questions/show.json.jbuilder b/app/views/exercise_questions/show.json.jbuilder index e8662a611..c27fe21a5 100644 --- a/app/views/exercise_questions/show.json.jbuilder +++ b/app/views/exercise_questions/show.json.jbuilder @@ -5,4 +5,5 @@ json.partial! "exercise_questions/exercise_questions", choices:@exercise_choices, shixun_challenges: @exercise_question_shixun, exercise_type:1, - user_answer:[] + user_answer:[], + ques_position:nil diff --git a/app/views/exercises/_user_exercise_info.json.jbuilder b/app/views/exercises/_user_exercise_info.json.jbuilder index a3b7b208c..5b5d0c725 100644 --- a/app/views/exercises/_user_exercise_info.json.jbuilder +++ b/app/views/exercises/_user_exercise_info.json.jbuilder @@ -62,7 +62,8 @@ json.exercise_questions do shixun_challenges: q.exercise_shixun_challenges, exercise_type: ex_type, user_answer: user_ques_answers[:answered_content], - shixun_type: user_ques_answers[:shixun_type] + shixun_type: user_ques_answers[:shixun_type], + ques_position:nil if user_ques_comments.count > 0 json.question_comments do json.partial! "exercises/exercise_comments", question_comment:user_ques_answers[:question_comment].first diff --git a/app/views/exercises/blank_exercise.json.jbuilder b/app/views/exercises/blank_exercise.json.jbuilder index 631f0dcb3..16b5449fb 100644 --- a/app/views/exercises/blank_exercise.json.jbuilder +++ b/app/views/exercises/blank_exercise.json.jbuilder @@ -11,7 +11,8 @@ json.exercise_questions do choices:q.exercise_choices, shixun_challenges: q.exercise_shixun_challenges, exercise_type:2, - user_answer:[] + user_answer:[], + ques_position:nil end end diff --git a/app/views/exercises/edit.json.jbuilder b/app/views/exercises/edit.json.jbuilder index 61ec71db5..71a6fcf07 100644 --- a/app/views/exercises/edit.json.jbuilder +++ b/app/views/exercises/edit.json.jbuilder @@ -15,7 +15,8 @@ json.exercise_questions do shixun_challenges: q.exercise_shixun_challenges, exercise_type:1, user_answer:[], - shixun_type:0 + shixun_type:0, + ques_position:nil end end diff --git a/app/views/exercises/show.json.jbuilder b/app/views/exercises/show.json.jbuilder index 8f6517c2c..d92eebeab 100644 --- a/app/views/exercises/show.json.jbuilder +++ b/app/views/exercises/show.json.jbuilder @@ -18,7 +18,8 @@ json.exercise_questions do shixun_challenges: q.exercise_shixun_challenges, exercise_type:1, user_answer:[], - shixun_type:0 + shixun_type:0, + ques_position:nil end end From 5d3c49f1972f643f3fa106395fbe221a32e9c7d9 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 22 Jun 2019 10:19:56 +0800 Subject: [PATCH 12/12] fix user homepage info api --- app/decorators/user_decorator.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/decorators/user_decorator.rb b/app/decorators/user_decorator.rb index 0ee9a4b43..a0f9f7fdd 100644 --- a/app/decorators/user_decorator.rb +++ b/app/decorators/user_decorator.rb @@ -39,19 +39,19 @@ module UserDecorator apply = ApplyAction.order(created_at: :desc).find_by(user_id: id, container_type: 'TrialAuthorization') - apply && !apply.status.zero? + apply.present? && !apply.status.zero? end # 是否已经签到 def attendance_signed? attendance = Attendance.find_by(user_id: id) - attendance && Util.days_between(Time.zone.now, attendance.created_at).zero? + attendance.present? && Util.days_between(Time.zone.now, attendance.created_at).zero? end # 明日签到金币 def tomorrow_attendance_gold - Attendance.find_by(user_id: id)&.next_gold + Attendance.find_by(user_id: id)&.next_gold || 50 end # ----------- 账号管理 -------------