diff --git a/app/controllers/competitions/competitions_controller.rb b/app/controllers/competitions/competitions_controller.rb index 1a80dc7e6..31ed4367d 100644 --- a/app/controllers/competitions/competitions_controller.rb +++ b/app/controllers/competitions/competitions_controller.rb @@ -22,7 +22,7 @@ class Competitions::CompetitionsController < Competitions::BaseController @count = competitions.count competitions = competitions.order(published_at: :desc, online_time: :desc) - @competitions = paginate(competitions.includes(sponsor_schools: :school, current_stage_section: :competition_stage)) + @competitions = paginate(competitions.includes(:competition_mode_setting, sponsor_schools: :school, current_stage_section: :competition_stage)) ids = @competitions.map(&:id) @member_count_map = TeamMember.where(competition_id: ids).group(:competition_id).count diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 3b6273465..9df7a0d6c 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -257,8 +257,8 @@ class CoursesController < ApplicationController user_ids = all_members.map(&:user_id) rank = user_ids.index(current_user.id).to_i + 1 if rank > 10 - current_member = all_members.select{|member| member.user_id == current_user.id} - @course_members << current_member + current_member = all_members.select{|member| member.user_id == current_user.id}.first + @course_members << current_member if current_member.present? end end end diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 5d27de7b8..2bb8ec6cf 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -125,7 +125,7 @@ class HomeworkCommonsController < ApplicationController # 学生已提交作品且补交(提交)已截止、作品公开、非匿评阶段 if @work&.work_status.to_i > 0 && (@homework.work_public || @homework.score_open) && ((!@homework.anonymous_comment && @homework.end_or_late) || (@homework_detail_manual.comment_status > 4 && @homework.end_or_late)) - @student_works = student_works.where("user_id != #{@work.user_id}") + @student_works = student_works.where("student_works.user_id != #{@work.user_id}") # 匿评、申诉阶段只能看到分配给自己的匿评作品 elsif @work&.work_status.to_i > 0 && @homework.anonymous_comment && @homework_detail_manual.comment_status > 2 && @homework_detail_manual.comment_status <= 4 diff --git a/app/models/competition.rb b/app/models/competition.rb index 8613e974a..fa1267025 100644 --- a/app/models/competition.rb +++ b/app/models/competition.rb @@ -49,6 +49,12 @@ class Competition < ApplicationRecord end end + # 报名数 + def team_member_count + course = competition_mode_setting&.course if mode == 2 + course ? course.students.count : team_members.count + end + def sponsor_schools_name sponsor_schools.map{|sponsor| sponsor.school.name} end diff --git a/app/views/competitions/competitions/common_header.json.jbuilder b/app/views/competitions/competitions/common_header.json.jbuilder index a869d920b..0d0f3f4ca 100644 --- a/app/views/competitions/competitions/common_header.json.jbuilder +++ b/app/views/competitions/competitions/common_header.json.jbuilder @@ -1,6 +1,6 @@ json.extract! @competition, :id, :name, :sub_title, :identifier, :bonus, :mode json.visits_count @competition.visits -member_count = @competition.team_members.count +member_count = @competition.team_member_count json.member_count member_count.zero? ? 268 : member_count json.start_time @competition.start_time&.strftime("%Y-%m-%d") diff --git a/app/views/competitions/competitions/index.json.jbuilder b/app/views/competitions/competitions/index.json.jbuilder index c01f0aa59..b7a3f20e0 100644 --- a/app/views/competitions/competitions/index.json.jbuilder +++ b/app/views/competitions/competitions/index.json.jbuilder @@ -5,7 +5,8 @@ json.competitions do json.competition_status competition.competition_status json.visits_count competition.visits - member_count = @member_count_map&.fetch(competition.id, 0) || competition.team_members.count + course = competition.competition_mode_setting&.course if competition.mode == 2 + member_count = course ? course.students.count : (@member_count_map&.fetch(competition.id, 0) || competition.team_members.count) json.member_count member_count.zero? ? 268 : member_count json.image url_to_avatar(competition) diff --git a/app/views/courses/act_score.json.jbuilder b/app/views/courses/act_score.json.jbuilder index 394497635..ed6929b13 100644 --- a/app/views/courses/act_score.json.jbuilder +++ b/app/views/courses/act_score.json.jbuilder @@ -1,7 +1,7 @@ json.course_members @course_members.each do |member| user = member.user - json.user_login user.login - json.user_name user.real_name + json.user_login user&.login + json.user_name user&.real_name # json.course_group member.course_group_name json.total_score member.score end \ No newline at end of file