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] }) 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/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 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 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