From 7498740e87527587e5d752760fb784afb526f566 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 16 Oct 2019 18:35:01 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E7=AB=9E=E8=B5=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../competitions/competitions_controller.rb | 14 ++++--- .../competitions/common_header.json.jbuilder | 12 ++++++ .../competitions/index.json.jbuilder | 26 ++++++------- .../competitions/show.json.jbuilder | 38 +------------------ config/routes.rb | 2 +- 5 files changed, 37 insertions(+), 55 deletions(-) create mode 100644 app/views/competitions/competitions/common_header.json.jbuilder diff --git a/app/controllers/competitions/competitions_controller.rb b/app/controllers/competitions/competitions_controller.rb index 77159fdaf..30df949f6 100644 --- a/app/controllers/competitions/competitions_controller.rb +++ b/app/controllers/competitions/competitions_controller.rb @@ -1,6 +1,7 @@ class Competitions::CompetitionsController < Competitions::BaseController skip_before_action :require_login before_action :allow_visit, except: [:index] + before_action :require_admin, only: [:update] def index # 已上架 或者 即将上架 @@ -25,10 +26,16 @@ class Competitions::CompetitionsController < Competitions::BaseController end def show + @competition = current_competition end - def common_header + def update + @competition.update_attributes!(introduction: params[:introduction]) + normal_status("更新成功") + end + def common_header + @competition = current_competition end private @@ -38,9 +45,6 @@ class Competitions::CompetitionsController < Competitions::BaseController end def allow_visit - unless current_competition.published? || admin_or_business? - render_forbidden - return - end + render_forbidden unless current_competition.published? || admin_or_business? end end \ No newline at end of file diff --git a/app/views/competitions/competitions/common_header.json.jbuilder b/app/views/competitions/competitions/common_header.json.jbuilder new file mode 100644 index 000000000..f172dae86 --- /dev/null +++ b/app/views/competitions/competitions/common_header.json.jbuilder @@ -0,0 +1,12 @@ +json.extract! @competition, :id, :name, :sub_title, :identifier, :bonus, :mode +json.visits_count @competition.visits +member_count = @competition.team_members.count +json.member_count member_count.zero? ? 268 : member_count + +json.start_time @competition.start_time&.strftime("%Y-%m-%d") +json.end_time @competition.end_time&.strftime("%Y-%m-%d") +json.enroll_end_time @competition.enroll_end_time&.strftime("%Y-%m-%d %H:%M:%S") + +json.published @competition.published? +json.nearly_published @competition.published_at.present? + diff --git a/app/views/competitions/competitions/index.json.jbuilder b/app/views/competitions/competitions/index.json.jbuilder index 4b8390a7d..8e99d754d 100644 --- a/app/views/competitions/competitions/index.json.jbuilder +++ b/app/views/competitions/competitions/index.json.jbuilder @@ -1,7 +1,7 @@ json.count @count json.competitions do json.array! @competitions.each do |competition| - json.extract! competition, :id, :identifier, :name, :sub_title, :bonus, :description + json.extract! competition, :id, :identifier, :name, :sub_title, :bonus, :description, :mode json.visits_count competition.visits member_count = @member_count_map&.fetch(competition.id, 0) || competition.team_members.count @@ -12,18 +12,18 @@ json.competitions do json.nearly_published competition.published_at.present? json.single_stage (@stage_count_map&.fetch(competition.id, 0) || competition.competition_stages.count) == 1 - json.start_time competition.display_start_time - json.end_time competition.display_end_time - json.enroll_end_time competition.display_enroll_end_time + json.start_time competition.start_time&.strftime("%Y-%m-%d") + json.end_time competition.end_time&.strftime("%Y-%m-%d") + json.enroll_end_time competition.enroll_end_time&.strftime("%Y-%m-%d %H:%M:%S") - section = competition.current_stage_section - if section - json.current_stage do - - json.name section.competition_stage.name - json.start_time section.display_start_time - json.end_time section.display_end_time - end - end + # section = competition.current_stage_section + # if section + # json.current_stage do + # + # json.name section.competition_stage.name + # json.start_time section.display_start_time + # json.end_time section.display_end_time + # end + # end end end \ No newline at end of file diff --git a/app/views/competitions/competitions/show.json.jbuilder b/app/views/competitions/competitions/show.json.jbuilder index 18216ee92..f96949398 100644 --- a/app/views/competitions/competitions/show.json.jbuilder +++ b/app/views/competitions/competitions/show.json.jbuilder @@ -1,36 +1,2 @@ -competition = current_competition -json.extract! competition, :id, :name, :sub_title, :identifier - -json.start_time competition.display_start_time -json.end_time competition.display_end_time -json.enroll_end_time competition.display_enroll_end_time - -json.images do - json.array! competition.attachments, partial: 'attachments/attachment_simple', as: :attachment -end - -json.competition_stages do - stages = competition.competition_stages.includes(competition_stage_sections: :competition_entries) - json.array! stages.each do |stage| - json.extract! stage, :id, :name - - json.sections do - json.array! stage.competition_stage_sections.each do |section| - json.extract! section, :id, :name - - decorator_section = ActiveDecorator::Decorator.instance.decorate(section) - json.start_time decorator_section.display_start_time - json.end_time decorator_section.display_end_time - - is_start = section.start_time > Time.now - json.entries do - json.array! section.competition_entries.each do |entry| - json.extract! entry, :id, :name - - json.url is_start ? entry.url : '' - end - end - end - end - end -end \ No newline at end of file +json.extract! @competition, :id, :introduction +json.image_url url_to_avatar(@competition) \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index a2e7337b1..f9efaf794 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -781,7 +781,7 @@ Rails.application.routes.draw do resources :repertoires, only: [:index] scope module: :competitions do - resources :competitions, only: [:index, :show] do + resources :competitions, only: [:index, :show, :update] do resources :competition_modules, only: [:index, :show, :update] resource :competition_staff resources :competition_teams, only: [:index, :show] do From a1796ee2c4010f8ef025ba337f6bbf07ea3c6e32 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 19 Oct 2019 10:45:55 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E7=AB=9E=E8=B5=9BAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../competition_teams_controller.rb | 92 +++++++++++ .../competitions/competitions_controller.rb | 151 +++++++++++++++++- app/helpers/competitions_helper.rb | 54 +++++++ app/models/chart_rule.rb | 6 + app/models/competition.rb | 19 ++- app/models/competition_award.rb | 3 + app/models/competition_mode_setting.rb | 3 +- app/models/competition_module.rb | 17 ++ app/models/competition_score.rb | 6 + app/models/competition_stage.rb | 10 ++ app/models/competition_team.rb | 9 ++ app/models/inform.rb | 2 + app/models/shixun.rb | 1 + .../course_detail.json.jbuilder | 28 ++++ .../shixun_detail.json.jbuilder | 41 +++++ .../competitions/chart_list.xlsx.axlsx | 18 +++ .../competitions/chart_rules.json.jbuilder | 5 + .../competitions/charts.json.jbuilder | 21 +++ .../competitions/common_header.json.jbuilder | 12 ++ .../competitions/enroll.json.jbuilder | 0 .../competitions/informs.json.jbuilder | 6 + .../competitions/md_content.json.jbuilder | 4 + config/routes.rb | 9 ++ ...3840_add_competition_id_to_mode_setting.rb | 7 + ...0191017092449_migrate_competition_score.rb | 29 ++++ ...0191018022821_create_competition_awards.rb | 12 ++ ...018030029_add_rate_to_competition_stage.rb | 5 + spec/models/chart_rule_spec.rb | 5 + spec/models/competition_award_spec.rb | 5 + spec/models/competition_score_spec.rb | 5 + 30 files changed, 582 insertions(+), 3 deletions(-) create mode 100644 app/helpers/competitions_helper.rb create mode 100644 app/models/chart_rule.rb create mode 100644 app/models/competition_award.rb create mode 100644 app/models/competition_score.rb create mode 100644 app/views/competitions/competition_teams/course_detail.json.jbuilder create mode 100644 app/views/competitions/competition_teams/shixun_detail.json.jbuilder create mode 100644 app/views/competitions/competitions/chart_list.xlsx.axlsx create mode 100644 app/views/competitions/competitions/chart_rules.json.jbuilder create mode 100644 app/views/competitions/competitions/charts.json.jbuilder create mode 100644 app/views/competitions/competitions/enroll.json.jbuilder create mode 100644 app/views/competitions/competitions/informs.json.jbuilder create mode 100644 app/views/competitions/competitions/md_content.json.jbuilder create mode 100644 db/migrate/20191017063840_add_competition_id_to_mode_setting.rb create mode 100644 db/migrate/20191017092449_migrate_competition_score.rb create mode 100644 db/migrate/20191018022821_create_competition_awards.rb create mode 100644 db/migrate/20191018030029_add_rate_to_competition_stage.rb create mode 100644 spec/models/chart_rule_spec.rb create mode 100644 spec/models/competition_award_spec.rb create mode 100644 spec/models/competition_score_spec.rb diff --git a/app/controllers/competitions/competition_teams_controller.rb b/app/controllers/competitions/competition_teams_controller.rb index e03810b61..f504b226e 100644 --- a/app/controllers/competitions/competition_teams_controller.rb +++ b/app/controllers/competitions/competition_teams_controller.rb @@ -1,4 +1,63 @@ class Competitions::CompetitionTeamsController < Competitions::BaseController + before_action :tech_mode, only: [:shixun_detail, :course_detail] + + def shixun_detail + start_time = current_competition.competition_mode_setting&.start_time || current_competition.start_time + end_time = current_competition.competition_mode_setting&.end_time || current_competition.end_time + + team_user_ids = @team.team_members.pluck(:user_id) + shixuns = Shixun.where(user_id: team_user_ids, status: 2) + .where('shixuns.created_at > ? && shixuns.created_at <= ?', start_time, end_time) + shixuns = shixuns.joins('left join shixuns forked_shixuns on forked_shixuns.fork_from = shixuns.id and forked_shixuns.status = 2') + shixuns = shixuns.select('shixuns.id, shixuns.identifier, shixuns.user_id, shixuns.myshixuns_count, shixuns.name, shixuns.fork_from, sum(forked_shixuns.myshixuns_count) forked_myshixun_count') + @shixuns = shixuns.group('shixuns.id').order('shixuns.myshixuns_count desc').includes(:user) + + shixun_ids = @shixuns.map(&:id) + @myshixun_count_map = get_valid_myshixun_count(shixun_ids) + @original_myshixun_count_map = @myshixun_count_map.clone + # forked shixun valid myshixun count + forked_shixun_map = Shixun.where(status: 2, fork_from: shixun_ids).select('id, fork_from') + forked_shixun_map = forked_shixun_map.each_with_object({}) { |sx, obj| obj[sx.id] = sx.fork_from } + @forked_myshixun_count_map = get_valid_myshixun_count(forked_shixun_map.keys) + @forked_myshixun_count_map.each { |k, v| @myshixun_count_map[forked_shixun_map[k]] += v } + + @course_count_map = get_valid_course_count(shixun_ids) + @forked_map = get_valid_course_count(forked_shixun_map.keys) + @forked_course_count_map = {} + @forked_map.each do |forked_id, course_count| + @forked_course_count_map[forked_shixun_map[forked_id]] ||= 0 + @forked_course_count_map[forked_shixun_map[forked_id]] += course_count + end + @forked_shixun_map = forked_shixun_map + end + + def course_detail + start_time = current_competition.competition_mode_setting&.start_time || current_competition.start_time + end_time = current_competition.competition_mode_setting&.end_time || current_competition.end_time + @team_user_ids = @team.team_members.pluck(:user_id) + + student_count_subquery = CourseMember.where('course_id = courses.id AND role = 4').select('count(*)').to_sql + subquery = StudentWork.where('homework_common_id = hcs.id') + .select('sum(compelete_status !=0 ) as finish, count(*) as total') + .having('total != 0 and finish >= (total / 2)').to_sql + course_ids = Course.where('courses.created_at > ?', start_time) + .where('courses.created_at <= ?', end_time) + .where("(#{student_count_subquery}) >= 3") + .where("exists(select 1 from homework_commons hcs where hcs.course_id = courses.id and hcs.publish_time is not null and hcs.publish_time < NOW() and hcs.homework_type = 4 and exists(#{subquery}))") + .joins('join course_members on course_members.course_id = courses.id and course_members.role in (1,2,3)') + .where(course_members: { user_id: @team_user_ids }).pluck(:id) + courses = Course.where(id: course_ids).joins(:practice_homeworks).where('homework_commons.publish_time < now()') + @courses = courses.select('courses.id, courses.name, courses.members_count, count(*) shixun_homework_count') + .group('courses.id').order('shixun_homework_count desc').having('shixun_homework_count > 0') + + course_ids = @courses.map(&:id) + @course_myshixun_map = Myshixun.joins(student_works: :homework_common) + .where(homework_commons: { course_id: course_ids }) + .where('exists(select 1 from games where games.myshixun_id = myshixuns.id and games.status = 2)') + .group('homework_commons.course_id').count + @course_shixun_count_map = get_valid_shixun_count(course_ids) + end + def index admin_or_business? ? all_competition_teams : user_competition_teams end @@ -67,4 +126,37 @@ class Competitions::CompetitionTeamsController < Competitions::BaseController def save_params params.permit(:name, teacher_ids: [], member_ids: []) end + + def tech_mode + # render_not_found if current_competition.mode != 3 + @team = current_competition.competition_teams.find_by(id: params[:id]) + end + + def get_valid_myshixun_count(ids) + Myshixun.where(shixun_id: ids) + .where('exists(select 1 from games where games.myshixun_id = myshixuns.id and games.status = 2)') + .group('shixun_id').count + end + + def get_valid_course_count(ids) + percentage_sql = StudentWork.where('homework_common_id = homework_commons.id and homework_commons.publish_time is not null and homework_commons.publish_time < NOW()') + .select('sum(compelete_status !=0 ) as finish, count(*) as total') + .having('total != 0 and finish >= (total / 2)').to_sql + + Course.joins(practice_homeworks: :homework_commons_shixun) + .where('shixun_id in (?)', ids) + .where("exists (#{percentage_sql})") + .group('shixun_id').count + end + + def get_valid_shixun_count(ids) + percentage_sql = StudentWork.where('homework_common_id = homework_commons.id and homework_commons.publish_time is not null and homework_commons.publish_time < NOW()') + .select('sum(compelete_status !=0 ) as finish, count(*) as total') + .having('total != 0 and finish >= (total / 2)').to_sql + Shixun.joins(homework_commons_shixuns: :homework_common) + .where(homework_commons: { homework_type: 4 }) + .where('course_id in (?)', ids) + .where("exists (#{percentage_sql})") + .group('course_id').count + end end diff --git a/app/controllers/competitions/competitions_controller.rb b/app/controllers/competitions/competitions_controller.rb index 30df949f6..03a276952 100644 --- a/app/controllers/competitions/competitions_controller.rb +++ b/app/controllers/competitions/competitions_controller.rb @@ -1,7 +1,10 @@ class Competitions::CompetitionsController < Competitions::BaseController + include CompetitionsHelper + skip_before_action :require_login before_action :allow_visit, except: [:index] - before_action :require_admin, only: [:update] + before_action :require_admin, only: [:update, :update_inform] + before_action :chart_visible, only: [:charts, :chart_rules] def index # 已上架 或者 即将上架 @@ -36,6 +39,98 @@ class Competitions::CompetitionsController < Competitions::BaseController def common_header @competition = current_competition + @competition_modules = @competition.unhidden_competition_modules + @user = current_user + end + + def informs + status = params[:status] || 1 + @informs = current_competition.informs.where(status: status) + end + + def update_inform + tip_exception("标题和内容不能为空") if params[:name].blank? || params[:description].blank? + tip_exception("status参数有误") if params[:status].blank? || ![1, 2].include?(params[:status].to_i) + ActiveRecord::Base.transaction do + if params[:inform_id] + inform = current_competition.informs.find_by!(id: params[:inform_id]) + inform.update_attributes!(name: params[:name], description: params[:description]) + else + inform = current_competition.informs.create!(name: params[:name], description: params[:description], status: params[:status]) + end + Attachment.associate_container(params[:attachment_ids], inform.id, inform.class) if params[:attachment_ids] + normal_status("更新成功") + end + end + + def md_content + @md_content = CompetitionModuleMdContent.find_by!(id: params[:md_content_id]) + end + + def update_md_content + tip_exception("标题和内容不能为空") if params[:name].blank? || params[:content].blank? + ActiveRecord::Base.transaction do + if params[:md_content_id] + md_content = CompetitionModuleMdContent.find_by!(id: params[:md_content_id]) + md_content.update_attributes!(name: params[:name], content: params[:content]) + else + md_content = CompetitionModuleMdContent.create!(name: params[:name], content: params[:content]) + end + Attachment.associate_container(params[:attachment_ids], md_content.id, md_content.class) if params[:attachment_ids] + normal_status("更新成功") + end + end + + def chart_rules + @competition = current_competition + @stages = @competition.competition_stages + @rule_contents = @competition.chart_rules + end + + def update_chart_rules + tip_exception("内容不能为空") if params[:content].blank? + @competition = current_competition + @stage = @competition.competition_stages.find_by!(id: params[:stage_id]) if params[:stage_id] + chart_rule = @competition.chart_rules.where(competition_stage_id: @stage&.id).first + if chart_rule + chart_rule.update_attributes!(content: params[:content]) + else + @competition.chart_rules.create!(competition_stage_id: @stage&.id, content: params[:content]) + end + normal_status("更新成功") + end + + def charts + @competition = current_competition + if params[:stage_id] + @stage = @competition.competition_stages.find_by(id: params[:stage_id]) + end + + if @competition.identifier == "gcc-annotation-2018" + @records = @competition.competition_teams.joins(:competition_scores) + .select("competition_teams.*, score, cost_time").order("score desc, cost_time desc") + else + @records = @competition.competition_teams.joins(:competition_scores).where(competition_scores: {competition_stage_id: @stage&.id.to_i}) + .select("competition_teams.*, score, cost_time").order("score desc, cost_time desc") + end + + current_team_ids = @competition.team_members.where(user_id: current_user.id).pluck(:competition_team_id).uniq + @user_ranks = @records.select{|com_team| current_team_ids.include?(com_team.id)} + @records = @records.where("score > 0") + if params[:format] == "xlsx" + @records = @records.includes(user: [user_extension: :school], team_members: :user) + respond_to do |format| + format.xlsx{ + set_export_cookies + chart_to_xlsx(@records, @competition) + exercise_export_name = "#{@competition.name}比赛成绩" + render xlsx: "#{exercise_export_name.strip}",template: "competitions/competitions/chart_list.xlsx.axlsx",locals: + {table_columns: @competition_head_cells, chart_lists: @competition_cells_column} + } + end + else + @records = @records.includes(:user, :team_members).limit(@competition.awards_count) + end end private @@ -47,4 +142,58 @@ class Competitions::CompetitionsController < Competitions::BaseController def allow_visit render_forbidden unless current_competition.published? || admin_or_business? end + + def chart_visible + chart_module = current_competition.competition_modules.find_by(name: "排行榜") + render_forbidden unless (chart_module.present? && !chart_module.hidden) || admin_or_business? + end + + # 竞赛成绩导出 + def chart_to_xlsx records, competition + @competition_head_cells = [] + @competition_cells_column = [] + + max_staff = competition.competition_staffs.sum(:maximum) + if max_staff < 2 # 个人赛 + @competition_head_cells = %w(序号 姓名 学校 学号) + else # 战队赛 + @competition_head_cells = %w(序号 战队名 指导老师 队员 学校) + end + + statistic_stages = competition.competition_stages.where("rate > 0") + statistic_stages.each do |stage| + @competition_head_cells += ["#{stage.name}得分", "#{stage.name}用时"] + end + @competition_head_cells += ["总得分", "总用时"] if statistic_stages.size > 1 + competition_scores = competition.competition_scores + + records.each_with_index do |record, index| + row_cells_column = [] + row_cells_column << index + 1 + record_user = record.user + if max_staff < 2 + row_cells_column << record_user.real_name + row_cells_column << record_user.school_name + row_cells_column << record_user.student_id + else + row_cells_column << record.name + row_cells_column << record.teachers_name + row_cells_column << record.members_name + row_cells_column << chart_school_str(record.team_members.select{|member| !member.is_teacher}.pluck(:user_id)) + end + + statistic_stages.each do |stage| + stage_score = competition_scores.select{|score| score.competition_stage_id == stage.id && score.competition_team_id == record.id}.first + row_cells_column << stage_score&.score.to_f.round(2) + row_cells_column << com_spend_time(stage_score&.cost_time.to_i) + end + + if statistic_stages.size > 1 + row_cells_column << record&.score.to_f.round(2) + row_cells_column << com_spend_time(record&.cost_time.to_i) + end + + @competition_cells_column.push(row_cells_column) + end + end end \ No newline at end of file diff --git a/app/helpers/competitions_helper.rb b/app/helpers/competitions_helper.rb new file mode 100644 index 000000000..66c7eec41 --- /dev/null +++ b/app/helpers/competitions_helper.rb @@ -0,0 +1,54 @@ +module CompetitionsHelper + def chart_school_str user_ids + chart_school_name = "" + chart_school_name = School.where(id: UserExtension.where(user_id: user_ids).pluck(:school_id).uniq).pluck(:name).join("、") + end + + # 耗时:小时、分、秒 00:00:00 + # 小于1秒钟则不显示 + def com_spend_time time + hour = time / (60*60) + min = time % (60*60) / 60 + sec = time % (60*60) % 60 + hour_str = "00" + min_str = "00" + sec_str = "00" + if hour >= 1 && hour < 10 + hour_str = "0#{hour}" + elsif hour >= 10 + hour_str = "#{hour}" + end + + if min >= 1 && min < 10 + min_str = "0#{min}" + elsif min >= 10 + min_str = "#{min}" + end + + if sec >= 1 && sec < 10 + sec_str = "0#{sec}" + elsif sec >= 10 + sec_str = "#{sec}" + end + + time = "#{hour_str} : #{min_str} : #{sec_str}" + return time + end + + def chart_stages competition + stages = [] + statistic_stages = competition.competition_stages.where("rate > 0") + if competition.end_time && competition.end_time < Time.now && statistic_stages.size > 1 + stages << {id: nil, name: "总排行榜", rate: 1.0, start_time: competition.start_time, end_time: competition.end_time} + end + + statistic_stages.each do |stage| + if stage.max_end_time && stage.max_end_time < Time.now + stages << {id: stage.id, name: "#{stage.name}排行榜", rate: stage.rate, start_time: stage.min_start_time, end_time: stage.max_end_time} + end + end + + stages = stages.sort { |a, b| b[:end_time] <=> a[:end_time] } if stages.size > 0 + return stages + end +end \ No newline at end of file diff --git a/app/models/chart_rule.rb b/app/models/chart_rule.rb new file mode 100644 index 000000000..de8fceaf1 --- /dev/null +++ b/app/models/chart_rule.rb @@ -0,0 +1,6 @@ +class ChartRule < ApplicationRecord + belongs_to :competition + belongs_to :competition_stage, optional: true + + validates :content, length: { maximum: 1000 } +end diff --git a/app/models/competition.rb b/app/models/competition.rb index 9055adefc..23b1e3c81 100644 --- a/app/models/competition.rb +++ b/app/models/competition.rb @@ -9,12 +9,19 @@ class Competition < ApplicationRecord has_many :competition_teams, dependent: :destroy has_many :team_members, dependent: :destroy + has_many :chart_rules, dependent: :destroy + + has_many :competition_scores, dependent: :destroy has_many :competition_staffs, dependent: :destroy has_one :teacher_staff, -> { where(category: :teacher) }, class_name: 'CompetitionStaff' has_one :member_staff, -> { where.not(category: :teacher) }, class_name: 'CompetitionStaff' + has_one :competition_mode_setting, dependent: :destroy + + has_many :informs, as: :container, dependent: :destroy + has_many :attachments, as: :container, dependent: :destroy - has_many :attachments, as: :container + has_many :competition_awards, dependent: :destroy after_create :create_competition_modules @@ -81,6 +88,16 @@ class Competition < ApplicationRecord member_staff.mutiple_limited? end + def max_min_stage_time + CompetitionStageSection.find_by_sql("SELECT MAX(end_time) as max_end_time, MIN(start_time) as min_start_time, + competition_stage_id FROM competition_stage_sections WHERE competition_id = #{id} + GROUP BY competition_stage_id order by competition_stage_id") + end + + def awards_count + competition_awards.pluck(:num)&.sum > 0 ? competition_awards.pluck(:num)&.sum : 20 + end + private def create_competition_modules diff --git a/app/models/competition_award.rb b/app/models/competition_award.rb new file mode 100644 index 000000000..715d82ee2 --- /dev/null +++ b/app/models/competition_award.rb @@ -0,0 +1,3 @@ +class CompetitionAward < ApplicationRecord + belongs_to :competition +end diff --git a/app/models/competition_mode_setting.rb b/app/models/competition_mode_setting.rb index b6bafa7c3..e8d6c17d7 100644 --- a/app/models/competition_mode_setting.rb +++ b/app/models/competition_mode_setting.rb @@ -1,3 +1,4 @@ class CompetitionModeSetting < ApplicationRecord - belongs_to :course + belongs_to :course, optional: true + belongs_to :competition end diff --git a/app/models/competition_module.rb b/app/models/competition_module.rb index be73bf3c1..9579533da 100644 --- a/app/models/competition_module.rb +++ b/app/models/competition_module.rb @@ -4,4 +4,21 @@ class CompetitionModule < ApplicationRecord belongs_to :competition has_one :competition_module_md_content, dependent: :destroy + + def module_url + case name + when "首页", "赛制介绍" + "/competitions/#{competition.identifier}" + when "通知公告" + "/competitions/#{competition.identifier}/informs?status=1" + when "参赛手册" + "/competitions/#{competition.identifier}/informs?status=2" + when "排行榜" + "/competitions/#{competition.identifier}/charts" + when "报名" + "/competitions/#{competition.identifier}/competition_teams" + else + url || "/competitions/#{competition.identifier}/md_content?md_content_id=#{competition_module_md_content&.id}" + end + end end diff --git a/app/models/competition_score.rb b/app/models/competition_score.rb new file mode 100644 index 000000000..ce7bad427 --- /dev/null +++ b/app/models/competition_score.rb @@ -0,0 +1,6 @@ +class CompetitionScore < ApplicationRecord + belongs_to :user + belongs_to :competition + belongs_to :competition_stage, optional: true + belongs_to :competition_team, optional: true +end diff --git a/app/models/competition_stage.rb b/app/models/competition_stage.rb index 60d4b1644..dec777b39 100644 --- a/app/models/competition_stage.rb +++ b/app/models/competition_stage.rb @@ -3,5 +3,15 @@ class CompetitionStage < ApplicationRecord has_many :competition_stage_sections, dependent: :destroy has_many :competition_entries, dependent: :destroy + has_many :competition_scores, dependent: :destroy + has_one :chart_rule, dependent: :destroy + + def min_start_time + competition_stage_sections.where("start_time is not null").pluck(:start_time).min + end + + def max_end_time + competition_stage_sections.where("end_time is not null").pluck(:end_time).max + end end \ No newline at end of file diff --git a/app/models/competition_team.rb b/app/models/competition_team.rb index 625b29421..878f58882 100644 --- a/app/models/competition_team.rb +++ b/app/models/competition_team.rb @@ -7,6 +7,7 @@ class CompetitionTeam < ApplicationRecord has_many :team_members, dependent: :destroy has_many :users, through: :team_members, source: :user + has_many :competition_scores, dependent: :destroy has_many :members, -> { without_teachers }, class_name: 'TeamMember' has_many :teachers, -> { only_teachers }, class_name: 'TeamMember' @@ -30,4 +31,12 @@ class CompetitionTeam < ApplicationRecord self.code = code code end + + def teachers_name + teachers.map{|teacher| teacher.user.real_name}.join(",") + end + + def members_name + members.map{|member| member.user.real_name}.join(",") + end end \ No newline at end of file diff --git a/app/models/inform.rb b/app/models/inform.rb index 5caf80c5f..d486b6f11 100644 --- a/app/models/inform.rb +++ b/app/models/inform.rb @@ -3,4 +3,6 @@ class Inform < ApplicationRecord validates :name, length: { maximum: 60 } validates :description, length: { maximum: 5000 } + + has_many :attachments, as: :container, dependent: :destroy end diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 0cdb2e82b..efa3098fc 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -27,6 +27,7 @@ class Shixun < ApplicationRecord has_one :first_shixun_tag_repertoire, class_name: 'ShixunTagRepertoire' has_one :first_tag_repertoire, through: :first_shixun_tag_repertoire, source: :tag_repertoire + has_many :homework_commons_shixuns, class_name: 'HomeworkCommonsShixun' #实训的关卡 has_many :exercise_shixun_challenges, :dependent => :destroy diff --git a/app/views/competitions/competition_teams/course_detail.json.jbuilder b/app/views/competitions/competition_teams/course_detail.json.jbuilder new file mode 100644 index 000000000..ce37d9568 --- /dev/null +++ b/app/views/competitions/competition_teams/course_detail.json.jbuilder @@ -0,0 +1,28 @@ +total_students_count = 0 +total_shixun_homework_count = 0 +total_course_score = 0 + +json.courses @courses.each do |course| + students_count = course.students.count + total_students_count += students_count + total_shixun_homework_count += course['shixun_homework_count'].to_i + + score = 500 + 5 * @course_shixun_count_map.fetch(course.id, 0) * @course_myshixun_map.fetch(course.id, 0) + total_course_score += score + + teacher = course.teachers.where(user_id: @team_user_ids).first.user + json.creator teacher&.real_name + json.creator_login teacher&.login + json.course_name course.name + json.course_id course.id + json.students_count students_count + json.shixun_homework_count course['shixun_homework_count'] + json.valid_count @course_myshixun_map.fetch(course.id, 0) + json.score score +end + +json.total_course_count @courses.size +json.total_students_count total_students_count +json.total_shixun_homework_count total_shixun_homework_count +json.total_valid_count @course_myshixun_map.values.reduce(:+) +json.total_course_score total_course_score \ No newline at end of file diff --git a/app/views/competitions/competition_teams/shixun_detail.json.jbuilder b/app/views/competitions/competition_teams/shixun_detail.json.jbuilder new file mode 100644 index 000000000..abeb8c85c --- /dev/null +++ b/app/views/competitions/competition_teams/shixun_detail.json.jbuilder @@ -0,0 +1,41 @@ +total_myshixun_count = 0 +total_forked_myshixun_count = 0 +total_shixun_score = 0 + +json.shixuns @shixuns.each do |shixun| + total_myshixun_count += shixun.myshixuns_count + total_forked_myshixun_count += shixun['forked_myshixun_count'].to_i + + valid_course_count = @course_count_map.fetch(shixun.id, 0) + valid_student_count = @original_myshixun_count_map.fetch(shixun.id, 0) + score = + if shixun.fork_from.blank? + 500 + 50 * valid_course_count + 10 * valid_student_count + else + 100 + 10 * valid_course_count + 5 * valid_student_count + end + + @forked_shixun_map.each do |shixun_id, fork_from_id| + next if fork_from_id != shixun.id + + score += 100 + 10 * @forked_map.fetch(shixun_id, 0) + 5 * @forked_myshixun_count_map.fetch(shixun_id, 0) + end + + total_shixun_score += score + + json.creator shixun.user.real_name + json.creator_login shixun.user.login + json.shixun_name shixun.name + json.shixun_identifier shixun.identifier + json.forked shixun.fork_from.present? + json.myshixuns_count shixun.myshixuns_count + json.forked_myshixun_count shixun['forked_myshixun_count'].to_i + json.valid_count @myshixun_count_map.fetch(shixun.id, 0) + json.score score +end + +json.shixun_count @shixuns.size +json.total_myshixun_count total_myshixun_count +json.total_forked_myshixun_count total_forked_myshixun_count +json.total_valid_count @myshixun_count_map.values.reduce(:+) +json.total_shixun_score total_shixun_score \ No newline at end of file diff --git a/app/views/competitions/competitions/chart_list.xlsx.axlsx b/app/views/competitions/competitions/chart_list.xlsx.axlsx new file mode 100644 index 000000000..2186b6ffd --- /dev/null +++ b/app/views/competitions/competitions/chart_list.xlsx.axlsx @@ -0,0 +1,18 @@ + +wb = xlsx_package.workbook +# wb.use_autowidth = false +wb.styles do |s| + sz_all = s.add_style :border => { :style => :thin, :color =>"000000" },:alignment => {:horizontal => :center} + blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 20,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {:horizontal => :center} + wb.add_worksheet(:name => "比赛成绩") do |sheet| + sheet.sheet_view.show_grid_lines = false + sheet.add_row table_columns, :style => blue_cell + if chart_lists.count > 0 + chart_lists.each do |user| + sheet.add_row user, :height => 20,:style => sz_all + end #each_widh_index + end + sheet.column_widths *([20]*sheet.column_info.count) + sheet.column_info.first.width = 12 + end #add_worksheet +end \ No newline at end of file diff --git a/app/views/competitions/competitions/chart_rules.json.jbuilder b/app/views/competitions/competitions/chart_rules.json.jbuilder new file mode 100644 index 000000000..bf1d04689 --- /dev/null +++ b/app/views/competitions/competitions/chart_rules.json.jbuilder @@ -0,0 +1,5 @@ +json.rule_contents @rule_contents.each do |rule| + json.(rule, :id, :content, :competition_stage_id) +end + +json.stages chart_stages @competition \ No newline at end of file diff --git a/app/views/competitions/competitions/charts.json.jbuilder b/app/views/competitions/competitions/charts.json.jbuilder new file mode 100644 index 000000000..f59f377f7 --- /dev/null +++ b/app/views/competitions/competitions/charts.json.jbuilder @@ -0,0 +1,21 @@ +json.user_ranks @user_ranks.each do |user_rank| + rank = @records.map(&:id).index(user_rank.id) + rank = rank.present? ? (rank+1) : 0 + json.rank rank == 0 ? "--" : user_rank.rank + json.team_name user_rank.name + json.user_name user_rank.user.real_name + json.cost_time rank == 0 && user_rank.cost_time ? "--" : com_spend_time(user_rank.cost_time) + json.score rank == 0 ? "--" : user_rank.score.round(2) +end + +json.teams @records.each do |record| + record_user = record.user + json.team_name record.name + json.record_user_name record_user.real_name + json.user_image url_to_avatar(record_user) + json.user_login record_user.login + school_name = chart_school_str record.team_members.select{|member| !member.is_teacher}.pluck(:user_id) + json.school_name school_name + json.score record&.score&.round(2) + json.spend_time record.cost_time ? com_spend_time(record.cost_time) : "--" +end \ No newline at end of file diff --git a/app/views/competitions/competitions/common_header.json.jbuilder b/app/views/competitions/competitions/common_header.json.jbuilder index f172dae86..882d1d1c0 100644 --- a/app/views/competitions/competitions/common_header.json.jbuilder +++ b/app/views/competitions/competitions/common_header.json.jbuilder @@ -10,3 +10,15 @@ json.enroll_end_time @competition.enroll_end_time&.strftime("%Y-%m-%d %H:%M:%S") json.published @competition.published? json.nearly_published @competition.published_at.present? +json.competition_modules @competition_modules do |com_module| + json.(com_module, :name, :position) + json.module_url com_module.module_url +end + +json.stages + +if @competition.mode == 1 + json.course_id @competition.competition_mode_setting&.course_id + json.member_of_course @user.member_of_course?(@competition.competition_mode_setting&.course) +end + diff --git a/app/views/competitions/competitions/enroll.json.jbuilder b/app/views/competitions/competitions/enroll.json.jbuilder new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/competitions/competitions/informs.json.jbuilder b/app/views/competitions/competitions/informs.json.jbuilder new file mode 100644 index 000000000..1b40c93e7 --- /dev/null +++ b/app/views/competitions/competitions/informs.json.jbuilder @@ -0,0 +1,6 @@ +json.informs @informs.each do |inform| + json.(inform, :id, :name, :description) + json.attachments inform.attachments do |atta| + json.partial! "attachments/attachment_simple", locals: {attachment: atta} + end +end \ No newline at end of file diff --git a/app/views/competitions/competitions/md_content.json.jbuilder b/app/views/competitions/competitions/md_content.json.jbuilder new file mode 100644 index 000000000..45325cecb --- /dev/null +++ b/app/views/competitions/competitions/md_content.json.jbuilder @@ -0,0 +1,4 @@ +json.(@md_content, :id, :name, :content) +json.attachments @md_content.attachments do |atta| + json.partial! "attachments/attachment_simple", locals: {attachment: atta} +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index f9efaf794..75fcf9a04 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -787,12 +787,21 @@ Rails.application.routes.draw do resources :competition_teams, only: [:index, :show] do post :join, on: :collection post :leave, on: :member + get :course_detail, on: :member + get :shixun_detail, on: :member end resources :teachers, only: [:index] resources :students, only: [:index] member do get :common_header + get :informs + post :update_inform + get :md_content + post :update_md_content + get :charts + get :chart_rules + post :update_chart_rules end end end diff --git a/db/migrate/20191017063840_add_competition_id_to_mode_setting.rb b/db/migrate/20191017063840_add_competition_id_to_mode_setting.rb new file mode 100644 index 000000000..ef68d395b --- /dev/null +++ b/db/migrate/20191017063840_add_competition_id_to_mode_setting.rb @@ -0,0 +1,7 @@ +class AddCompetitionIdToModeSetting < ActiveRecord::Migration[5.2] + def change + add_column :competition_mode_settings, :competition_id, :integer + + add_index :competition_mode_settings, :competition_id + end +end diff --git a/db/migrate/20191017092449_migrate_competition_score.rb b/db/migrate/20191017092449_migrate_competition_score.rb new file mode 100644 index 000000000..095f403c5 --- /dev/null +++ b/db/migrate/20191017092449_migrate_competition_score.rb @@ -0,0 +1,29 @@ +class MigrateCompetitionScore < ActiveRecord::Migration[5.2] + def change + CompetitionModule.where(name: "排行榜", hidden: 0).each do |com_module| + competition = com_module.competition + if competition.present? + puts competition.id + if competition.identifier == 'hn' || competition.identifier == 'gcc-task-2019' + p_rate = 0.2 + f_rate = 0.8 + else + p_rate = 0.15 + f_rate = 0.85 + end + pre_stage = competition.competition_stages.where(:name => "预赛").first + final_stage = competition.competition_stages.where(:name => "决赛").first + + competition.competition_teams.each do |team| + f_score = team.competition_scores.where(:competition_stage_id => final_stage.try(:id)).first + # 预赛记录 + p_score = team.competition_scores.where(:competition_stage_id => pre_stage.try(:id)).first + s_score = (f_score.try(:score).to_f * f_rate + p_score.try(:score).to_f * p_rate).try(:round, 2) + s_spend_time = f_score.try(:cost_time).to_i + p_score.try(:cost_time).to_i + CompetitionScore.create(:user_id => team.user_id, :competition_team_id => team.id, :competition_id => competition.id, + :competition_stage_id => 0, :score => s_score, :cost_time => s_spend_time) + end + end + end + end +end diff --git a/db/migrate/20191018022821_create_competition_awards.rb b/db/migrate/20191018022821_create_competition_awards.rb new file mode 100644 index 000000000..9da6068ce --- /dev/null +++ b/db/migrate/20191018022821_create_competition_awards.rb @@ -0,0 +1,12 @@ +class CreateCompetitionAwards < ActiveRecord::Migration[5.2] + def change + create_table :competition_awards do |t| + t.references :competition, index: true + t.string :name + t.integer :num, default: 0 + t.integer :award_type, default: 0 + + t.timestamps + end + end +end diff --git a/db/migrate/20191018030029_add_rate_to_competition_stage.rb b/db/migrate/20191018030029_add_rate_to_competition_stage.rb new file mode 100644 index 000000000..6e819cc17 --- /dev/null +++ b/db/migrate/20191018030029_add_rate_to_competition_stage.rb @@ -0,0 +1,5 @@ +class AddRateToCompetitionStage < ActiveRecord::Migration[5.2] + def change + add_column :competition_stages, :rate, :float, default: 1.0 + end +end diff --git a/spec/models/chart_rule_spec.rb b/spec/models/chart_rule_spec.rb new file mode 100644 index 000000000..b3059c94d --- /dev/null +++ b/spec/models/chart_rule_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ChartRule, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/competition_award_spec.rb b/spec/models/competition_award_spec.rb new file mode 100644 index 000000000..dac3bddcf --- /dev/null +++ b/spec/models/competition_award_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe CompetitionAward, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/competition_score_spec.rb b/spec/models/competition_score_spec.rb new file mode 100644 index 000000000..d0f1372b1 --- /dev/null +++ b/spec/models/competition_score_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe CompetitionScore, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From c337d36794aacf075a31d4e58164b39841a7a376 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 19 Oct 2019 14:11:13 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/javascripts/admins/competitions/index.js | 11 +++++++++++ app/controllers/homework_commons_controller.rb | 2 +- app/views/admins/competition_settings/show.html.erb | 9 +++++++++ config/admins/sidebar.yml | 3 ++- 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 app/assets/javascripts/admins/competitions/index.js diff --git a/app/assets/javascripts/admins/competitions/index.js b/app/assets/javascripts/admins/competitions/index.js new file mode 100644 index 000000000..ae4593d33 --- /dev/null +++ b/app/assets/javascripts/admins/competitions/index.js @@ -0,0 +1,11 @@ +$(document).on('turbolinks:load', function() { + if ($('body.admins-competitions-index-page').length > 0) { + $('.modal.admin-upload-file-modal').on('upload:success', function(e, data){ + var $imageElement = $('.competition-image-' + data.source_id); + $imageElement.attr('src', data.url); + $imageElement.show(); + $imageElement.next().html('重新上传'); + }) + } +}); + diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 60cf2d6c5..168d05299 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -1058,8 +1058,8 @@ class HomeworkCommonsController < ApplicationController tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if @course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day) else + tip_exception("缺少分班截止时间参数") if params[:group_end_times].blank? group_end_times = params[:group_end_times].reject(&:blank?).map{|time| time.to_time} - tip_exception("缺少截止时间参数") if group_end_times.blank? tip_exception("截止时间和分班参数的个数不一致") if group_end_times.length != group_ids.length group_end_times.each do |time| tip_exception("分班截止时间不能早于当前时间") if time <= Time.now diff --git a/app/views/admins/competition_settings/show.html.erb b/app/views/admins/competition_settings/show.html.erb index e69de29bb..8249f2737 100644 --- a/app/views/admins/competition_settings/show.html.erb +++ b/app/views/admins/competition_settings/show.html.erb @@ -0,0 +1,9 @@ +<% + define_admin_breadcrumbs do + add_admin_breadcrumb('竞赛列表', admins_competitions_path) + add_admin_breadcrumb(@competition.name) + end +%> + + + diff --git a/config/admins/sidebar.yml b/config/admins/sidebar.yml index 71e77e218..b722f2505 100644 --- a/config/admins/sidebar.yml +++ b/config/admins/sidebar.yml @@ -1,3 +1,4 @@ admins-mirror_scripts: 'admins-mirror_repositories' admins-laboratory_settings: 'admins-laboratories' -admins-carousels: 'admins-laboratories' \ No newline at end of file +admins-carousels: 'admins-laboratories' +admins-competition_settings: 'admins-competitions' \ No newline at end of file From b53c3137d133052c7ce71b1cd41f7ec44633f6b7 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 19 Oct 2019 15:17:22 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BA=91=E5=AE=9E=E9=AA=8C=E5=AE=9A?= =?UTF-8?q?=E5=88=B6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/laboratory_setting.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/laboratory_setting.rb b/app/models/laboratory_setting.rb index 32848dca2..ca62f5c91 100644 --- a/app/models/laboratory_setting.rb +++ b/app/models/laboratory_setting.rb @@ -43,7 +43,7 @@ class LaboratorySetting < ApplicationRecord navbar: [ { 'name' => '实践课程', 'link' => '/paths', 'hidden' => false }, { 'name' => '翻转课堂', 'link' => '/courses', 'hidden' => false }, - { 'name' => '实现项目', 'link' => '/shixuns', 'hidden' => false }, + { 'name' => '实训项目', 'link' => '/shixuns', 'hidden' => false }, { 'name' => '在线竞赛', 'link' => '/competitions', 'hidden' => false }, { 'name' => '教学案例', 'link' => '/moop_cases', 'hidden' => false }, { 'name' => '交流问答', 'link' => '/forums', 'hidden' => false }, From acd5c28bb136eef547cef472b7c08ae6bfada3c5 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 19 Oct 2019 16:28:17 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admins/competitions_controller.rb | 1 + app/helpers/application_helper.rb | 8 ++++++++ app/models/module_setting.rb | 2 ++ .../admins/competition_settings/show.html.erb | 7 +++++++ app/views/admins/competitions/index.html.erb | 19 +++++++++++++++++++ .../admins/competitions/shared/_td.html.erb | 2 +- .../20191019075105_create_module_settings.rb | 12 ++++++++++++ spec/models/module_setting_spec.rb | 5 +++++ 8 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 app/models/module_setting.rb create mode 100644 db/migrate/20191019075105_create_module_settings.rb create mode 100644 spec/models/module_setting_spec.rb diff --git a/app/controllers/admins/competitions_controller.rb b/app/controllers/admins/competitions_controller.rb index 3b9b63243..f501564ab 100644 --- a/app/controllers/admins/competitions_controller.rb +++ b/app/controllers/admins/competitions_controller.rb @@ -11,6 +11,7 @@ class Admins::CompetitionsController < Admins::BaseController ids = @competitions.map(&:id) @member_count_map = TeamMember.where(competition_id: ids).group(:competition_id).count + @competition_hot = ModuleSetting.exists?(module_type: "Competition", property: "hot") respond_to do |format| format.js format.html diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index dbdcaea40..1d684350c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -142,6 +142,14 @@ module ApplicationHelper end end + # 主页banner图 + def banner_img(source_type) + if File.exist?(disk_filename(source_type, "banner")) + ctime = File.ctime(disk_filename(source_type, "banner")).to_i + File.join("images/avatars", ["#{source_type}", "banner"]) + "?t=#{ctime}" + end + end + def disk_filename(source_type,source_id,image_file=nil) File.join(storage_path, "#{source_type}", "#{source_id}") end diff --git a/app/models/module_setting.rb b/app/models/module_setting.rb new file mode 100644 index 000000000..36fc45e6f --- /dev/null +++ b/app/models/module_setting.rb @@ -0,0 +1,2 @@ +class ModuleSetting < ApplicationRecord +end diff --git a/app/views/admins/competition_settings/show.html.erb b/app/views/admins/competition_settings/show.html.erb index 8249f2737..6272687e4 100644 --- a/app/views/admins/competition_settings/show.html.erb +++ b/app/views/admins/competition_settings/show.html.erb @@ -5,5 +5,12 @@ end %> +