diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 875050642..6a7599f28 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -184,14 +184,13 @@ class ApplicationController < ActionController::Base
end
# 系统全局认证
- #
def check_auth
- if !current_user.profile_completed?
- info_url = '/account/profile'
- tip_exception(402, info_url)
- elsif current_user.certification != 1
+ if current_user.certification != 1
day_cer = UserDayCertification.find_by(user_id: current_user.id)
tip_exception(407, "系统未授权") unless (Time.now.to_i - day_cer.try(:created_at).to_i) < 86400
+ elsif !current_user.profile_completed?
+ info_url = '/account/profile'
+ tip_exception(402, info_url)
end
end
diff --git a/app/controllers/competitions/competition_modules_controller.rb b/app/controllers/competitions/competition_modules_controller.rb
index da9873c43..c4692af70 100644
--- a/app/controllers/competitions/competition_modules_controller.rb
+++ b/app/controllers/competitions/competition_modules_controller.rb
@@ -15,7 +15,17 @@ class Competitions::CompetitionModulesController < Competitions::BaseController
md = current_module.competition_module_md_content || current_module.build_competition_module_md_content
md.name = params[:md_name]
md.content = params[:md_content]
- md.save!
+
+ ActiveRecord::Base.transaction do
+ md.save!
+
+ attachment_ids = Array.wrap(params[:attachment_ids]).map(&:to_i)
+ old_attachment_ids = md.attachments.pluck(:id)
+
+ destroy_ids = old_attachment_ids - attachment_ids
+ md.attachments.where(id: destroy_ids).delete_all
+ Attachment.where(id: attachment_ids - old_attachment_ids).update_all(container: md)
+ end
render_ok
end
diff --git a/app/controllers/competitions/competition_teams_controller.rb b/app/controllers/competitions/competition_teams_controller.rb
index 34c80d24c..e03810b61 100644
--- a/app/controllers/competitions/competition_teams_controller.rb
+++ b/app/controllers/competitions/competition_teams_controller.rb
@@ -4,9 +4,16 @@ class Competitions::CompetitionTeamsController < Competitions::BaseController
end
def create
- team = current_competition.competition_teams.new(user: current_user)
- Competitions::SaveTeamService.call(team, save_params)
+ if current_competition.personal? # 个人赛报名
+ Competitions::CreatePersonalTeamService.call(current_competition, current_user)
+ else
+ team = current_competition.competition_teams.new(user: current_user)
+ Competitions::SaveTeamService.call(team, save_params)
+ end
render_ok
+
+ rescue Competitions::CreatePersonalTeamService::Error => ex
+ render_error(ex.message)
end
def update
@@ -22,6 +29,20 @@ class Competitions::CompetitionTeamsController < Competitions::BaseController
render_error(ex.message)
end
+ def leave
+ team = current_competition.competition_teams.find(params[:id])
+ member = team.team_members.find_by(user_id: current_user.id)
+ return render_error('您不是该战队的成员') if member.blank?
+
+ if member.user_id == team.user_id
+ team.destroy! # 队长退出,战队解散
+ else
+ member.destroy!
+ end
+
+ render_ok
+ end
+
private
def all_competition_teams
@@ -33,13 +54,13 @@ class Competitions::CompetitionTeamsController < Competitions::BaseController
end
@count = teams.count
- @teams = paginate(teams.includes(:user, users: :user_extension))
+ @teams = paginate(teams.includes(:user, users: { user_extension: :school }))
end
def user_competition_teams
teams = current_competition.competition_teams
teams = teams.joins(:team_members).where(team_members: { user_id: current_user.id })
- @teams = teams.includes(:user, users: :user_extension).to_a
+ @teams = teams.includes(:user, users: { user_extension: :school }).to_a
@count = @teams.size
end
diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb
index f26e97849..03c943f8d 100644
--- a/app/controllers/exercises_controller.rb
+++ b/app/controllers/exercises_controller.rb
@@ -667,6 +667,7 @@ class ExercisesController < ApplicationController
#立即发布的弹窗内容
def publish_modal
+
ActiveRecord::Base.transaction do
begin
exercise_ids = params[:check_ids]
@@ -685,6 +686,9 @@ class ExercisesController < ApplicationController
#首页批量或单独 立即发布,应是跳出弹窗,设置开始时间和截止时间。
def publish
+ tip_exception("缺少截止时间参数") if params[:end_time].blank?
+ tip_exception("截止时间不能早于当前时间") if params[:end_time] <= strf_time(Time.now)
+ tip_exception("截止时间不能晚于课堂结束时间") if @course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day)
ActiveRecord::Base.transaction do
begin
check_ids = Exercise.where(id: params[:check_ids])
diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb
index 4996a11ca..3a49f4d80 100644
--- a/app/controllers/games_controller.rb
+++ b/app/controllers/games_controller.rb
@@ -47,7 +47,7 @@ class GamesController < ApplicationController
max_query_index = @game.query_index.to_i
# 统计评测时间
- record_onsume_time = EvaluateRecord.where(game_id: @game.id).first.try(:consume_time)
+ record_onsume_time = EvaluateRecord.where(game_id: @game.id).first.try(:pod_execute)
# myshixun_manager判断用户是否有权限查看隐藏测试集(TPM管理员;平台认证的老师;花费金币查看者)
myshixun_manager = @identity < User::EDU_GAME_MANAGER
@@ -712,6 +712,7 @@ class GamesController < ApplicationController
uid_logger("################params[:resubmit]: #{params[:resubmit]}")
uid_logger("################resubmit_identifier: #{resubmit_identifier}")
uid_logger("################time_out: #{params[:time_out]}")
+ sec_key = params[:sec_key]
if (params[:time_out] == "false") && ((params[:resubmit].blank? && @game.status == 1) || (params[:resubmit].present? &&
(params[:resubmit] != resubmit_identifier)))
# 代码评测的信息
@@ -740,14 +741,14 @@ class GamesController < ApplicationController
end
else # 重新评测
# 如果满足前面的条件,进入此处只可能是结果已返回并存入了数据库
- if params[:resubmit] == resubmit_identifier # 本次重新评测结果已经返回并存入数据库
+ if params[:resubmit] == resubmit_identifier # 本次重新评测结果已经返回并存入数据库
game_status = (@game.retry_status == 2 ? 2 : 0) # retry_status是判断重新评测的通关情况。2表示通关
end
end
# 实训的最大评测次数,这个值是为了优化查询,每次只取最新的最新一次评测的结果集
max_query_index = @game.query_index
- #max_query_index = @game.outputs.first.try(:query_index)
+ # max_query_index = @game.outputs.first.try(:query_index)
# 区分评测过未评测过,未评测过按需求取数据
testset_detail max_query_index.to_i, game_challenge
@@ -757,9 +758,10 @@ class GamesController < ApplicationController
web_route = game_challenge.try(:web_route)
mirror_name = @shixun.mirror_name
+ e_record = EvaluateRecord.where(:identifier => sec_key).first
# 轮询结束,更新评测统计耗时
if game_status == 0 || game_status == 2
- e_record = EvaluateRecord.where(:game_id => @game.id).first
+
if e_record
front_js = format("%.3f", (Time.now.to_f - e_record.try(:updated_at).to_f)).to_f
consume_time = format("%.3f", (Time.now - e_record.created_at)).to_f
@@ -767,9 +769,10 @@ class GamesController < ApplicationController
end
end
- uid_logger("game is is #{@game.id}, record id is #{e_record.try(:id)}, time is**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}")
+ uid_logger("game is #{@game.id}, record id is #{e_record.try(:id)}, time is**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}")
# 记录前端总耗时
- record_consume_time = EvaluateRecord.where(:game_id => @game.id).first.try(:consume_time)
+ record_consume_time = e_record.try(:pod_execute)
+ max_mem = e_record.try(:max_mem)
# 实训制作者当前拥有的金币
grade = User.where(:id => @game.user_id).pluck(:grade).first
@@ -780,7 +783,7 @@ class GamesController < ApplicationController
@base_date = {grade: grade, gold: score, experience: experience, status: game_status, had_done: had_done,
position: game_challenge.position, port: port, record_consume_time: record_consume_time,
mirror_name: mirror_name, picture: picture, web_route: web_route, star: @game.star,
- next_game: next_game, prev_game: prev_game}
+ next_game: next_game, prev_game: prev_game, max_mem: max_mem}
end
# 记录实训花费的时间
@@ -852,7 +855,7 @@ class GamesController < ApplicationController
if max_query_index > 0
uid_logger("max_query_index is #{max_query_index} game id is #{@game.id}, challenge_id is #{challenge.id}")
- @qurey_test_sets = TestSet.find_by_sql("SELECT o.code, o.actual_output, o.out_put, o.result, o.test_set_position,
+ @qurey_test_sets = TestSet.find_by_sql("SELECT o.code, o.actual_output, o.out_put, o.result, o.test_set_position, o.ts_time,
o.query_index, t.is_public, t.input, t.output, o.compile_success FROM outputs o, games g, challenges c,
test_sets t where g.id=#{@game.id} and c.id=#{challenge.id} and o.query_index=#{max_query_index}
and g.id = o.game_id and c.id= g.challenge_id and t.challenge_id = c.id and
@@ -866,8 +869,9 @@ class GamesController < ApplicationController
end
@last_compile_output = @qurey_test_sets.first['out_put'].gsub(/\n/, '
').gsub(/\t/, " \; \; \; \; \; \; \; \;") if @qurey_test_sets.first['out_put'].present?
else
+ # 没有评测过,第一次进来后的呈现方式
@qurey_test_sets = TestSet.find_by_sql("SELECT t.is_public, t.input, t.output, t.position
- FROM test_sets t where t.challenge_id = #{challenge.id}")
+ FROM test_sets t where t.challenge_id = #{challenge.id}")
end
end
diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb
index c6fca1c99..cb31f2464 100644
--- a/app/controllers/myshixuns_controller.rb
+++ b/app/controllers/myshixuns_controller.rb
@@ -46,6 +46,7 @@ class MyshixunsController < ApplicationController
end
# 代码运行中的信息接口
+ # 这个方法是中间层主动调用的,点击评测后,中间层会发送参数过来,告诉目前Pod的启动情况,一次评测会调用两次请求
def code_runinng_message
begin
jsonTestDetails = JSON.parse(params[:jsonTestDetails])
@@ -100,12 +101,13 @@ class MyshixunsController < ApplicationController
game_id = jsonTestDetails['buildID']
sec_key = jsonTestDetails['sec_key']
- # 资源消耗
- res_usage = jsonTestDetails['resUsage']
-
logger.info("training_task_status start#1**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}")
resubmit = jsonTestDetails['resubmit']
outPut = tran_base64_decode64(jsonTestDetails['outPut'])
+ # 资源消耗
+ uid_logger("##########!!!!!!#{jsonTestDetails['resUsage']}")
+ max_mem = tran_base64_decode64(jsonTestDetails['resUsage']) if jsonTestDetails['resUsage'].present?
+ uid_logger("##########!!!!!!#{max_mem}")
jenkins_testsets = jsonTestDetails['msg']
compile_success = jsonTestDetails['compileSuccess']
# message = Base64.decode64(params[:msg]) unless params[:msg].blank?
@@ -130,6 +132,7 @@ class MyshixunsController < ApplicationController
# is_public = test_sets.where(:position => j_test_set['caseId']).first.try(:is_public)
logger.info "actual_output:################################################# #{actual_output}"
+ ts_time = format("%.3f", j_test_set['testSetTime'].to_i).to_f
Output.create!(:code => status, :game_id => game_id, :out_put => outPut, :test_set_position => j_test_set['caseId'],
:actual_output => actual_output, :result => j_test_set['passed'].to_i, :query_index => max_query_index,
:compile_success => compile_success.to_i, :sec_key => sec_key, :ts_time => j_test_set['testSetTime'])
@@ -140,7 +143,7 @@ class MyshixunsController < ApplicationController
end
end
uid_logger("#############status: #{status}")
- record = EvaluateRecord.where(:game_id => game_id).first
+ record = EvaluateRecord.where(:identifier => sec_key).first
logger.info("training_task_status start#3**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}")
answer_deduction_percentage = (100 - game.answer_deduction) / 100.to_f # 查看答案后剩余分数的百分比.
# answer_deduction是查看答案的扣分比例
@@ -200,8 +203,9 @@ class MyshixunsController < ApplicationController
test_cases_time = format("%.3f", (Time.now.to_f - t1.to_f)).to_f
if record.present?
consume_time = format("%.3f", (Time.now - record.created_at)).to_f
+ uid_logger("11122233334444#{max_mem}, #{sec_key}")
record.update_attributes!(:consume_time => consume_time, :git_pull => timeCost['pull'] , :create_pod => timeCost['createPod'],
- :pod_execute => timeCost['execute'], :test_cases => test_cases_time,
+ :pod_execute => timeCost['execute'], :test_cases => test_cases_time, :max_mem => max_mem,
:brige => timeCost['evaluateAllTime'], :return_back => return_back_time)
end
uid_logger("training_task_status start#4**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}")
diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb
index 3fc17c661..f5003a0c7 100644
--- a/app/controllers/polls_controller.rb
+++ b/app/controllers/polls_controller.rb
@@ -205,15 +205,15 @@ class PollsController < ApplicationController
@is_teacher_or = 1
@user_poll_answer = 3 #教师页面
end
- poll_status = @poll.get_poll_status(current_user)
+ @poll_status = @poll.get_poll_status(current_user)
poll_id_array = [@poll.id]
@poll_publish_count = get_user_permission_course(poll_id_array,2).count #是否存在已发布的
@poll_unpublish_count = get_user_permission_course(poll_id_array,1).count #是否存在未发布的
if (@poll_publish_count == 0) && (@poll_unpublish_count == 0) #即表示没有分班
- if poll_status == 1
+ if @poll_status == 1
@poll_unpublish_count = 1 #试卷未发布,且课堂没有分班的时候
- elsif poll_status == 2
+ elsif @poll_status == 2
@poll_publish_count = 1 #试卷未发布,且课堂没有分班的时候
end
end
@@ -244,6 +244,9 @@ class PollsController < ApplicationController
end
#首页批量或单独 立即发布,应是跳出弹窗,设置开始时间和截止时间。
def publish
+ tip_exception("缺少截止时间参数") if params[:end_time].blank?
+ tip_exception("截止时间不能早于当前时间") if params[:end_time] <= strf_time(Time.now)
+ tip_exception("截止时间不能晚于课堂结束时间") if @course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day)
ActiveRecord::Base.transaction do
begin
check_ids = Poll.where(id: params[:check_ids])
diff --git a/app/models/competition.rb b/app/models/competition.rb
index f5d146ab4..024478ad6 100644
--- a/app/models/competition.rb
+++ b/app/models/competition.rb
@@ -23,6 +23,11 @@ class Competition < ApplicationRecord
status?
end
+ # 是否为个人赛
+ def personal?
+ competition_staffs.maximum(:maximum) == 1
+ end
+
# 报名是否结束
def enroll_ended?
enroll_end_time.blank? || enroll_end_time < Time.now
diff --git a/app/models/discuss.rb b/app/models/discuss.rb
index 00e3209c0..2d9c00110 100644
--- a/app/models/discuss.rb
+++ b/app/models/discuss.rb
@@ -41,9 +41,7 @@ class Discuss < ApplicationRecord
# end
def child_discuss(user)
- user.admin? ?
- Discuss.where(parent_id: self.id).includes(:user).reorder(created_at: :asc) :
- Discuss.where(parent_id: self.id, :hidden => false).includes(:user).reorder(created_at: :asc)
+ Discuss.where(parent_id: self.id).includes(:user).reorder(created_at: :asc)
end
private
diff --git a/app/models/exercise.rb b/app/models/exercise.rb
index aba0a00bc..825f7cd9f 100644
--- a/app/models/exercise.rb
+++ b/app/models/exercise.rb
@@ -127,8 +127,10 @@ class Exercise < ApplicationRecord
#判断是否为分班,如果分班,试卷的截止时间为当前分班时间,否则为试卷的截止时间
def get_exercise_status(user)
- return Exercise::UNPUBLISHED if user.nil?
- if user.student_of_course?(course) #当为学生的时候,需根据分班来判断试卷状态
+ if course.is_end
+ status = 4
+ else
+ if user.present? && user.student_of_course?(course) #当为学生的时候,需根据分班来判断试卷状态
ex_time = get_exercise_times(user_id,false)
pb_time = ex_time[:publish_time]
ed_time = ex_time[:end_time]
@@ -139,8 +141,9 @@ class Exercise < ApplicationRecord
else
status = Exercise::UNPUBLISHED
end
- else
- status = exercise_status #当为老师的时候,则为试卷的总状态
+ else
+ status = exercise_status #当为老师的时候,则为试卷的总状态
+ end
end
status
end
diff --git a/app/models/game.rb b/app/models/game.rb
index 88d636998..ae056a702 100644
--- a/app/models/game.rb
+++ b/app/models/game.rb
@@ -61,7 +61,7 @@ class Game < ApplicationRecord
if self.status == 2 # 通关了则取实际得分,没通关则取总分
gold = (shixun_status <= 1) ? 0 : self.final_score.to_i
# 只要过关了,查看了答案经验值就是0;通关前查看了答案金final_score为负数
- experience = (shixun_status <= 1 || self.final_score.to_i < 0) ? 0 : challenge.score.to_i
+ experience = (shixun_status <= 1 || self.final_score.to_i < 0) ? 0 : self.final_score.to_i
else
gold = challenge.score.to_i
experience = gold
diff --git a/app/models/poll.rb b/app/models/poll.rb
index e6a363f1d..7f0d2fd94 100644
--- a/app/models/poll.rb
+++ b/app/models/poll.rb
@@ -100,19 +100,23 @@ class Poll < ApplicationRecord
end
def get_poll_status(user)
- if user.student_of_course?(course)
- ex_time = get_poll_times(user_id,false)
- pb_time = ex_time[:publish_time]
- ed_time = ex_time[:end_time]
- if pb_time.present? && ed_time.present? && pb_time <= Time.now && ed_time > Time.now
- status = 2
- elsif ed_time.present? && ed_time <= Time.now
- status = 3
+ if course.is_end
+ status = 4
+ else
+ if user.present? && user.student_of_course?(course)
+ ex_time = get_poll_times(user_id,false)
+ pb_time = ex_time[:publish_time]
+ ed_time = ex_time[:end_time]
+ if pb_time.present? && ed_time.present? && pb_time <= Time.now && ed_time > Time.now
+ status = 2
+ elsif ed_time.present? && ed_time <= Time.now
+ status = 3
+ else
+ status = 1
+ end
else
- status = 1
+ status = polls_status
end
- else
- status = polls_status
end
status
end
diff --git a/app/models/searchable/dependents/challenge_tag.rb b/app/models/searchable/dependents/challenge_tag.rb
index fdec79d1b..51ef804dd 100644
--- a/app/models/searchable/dependents/challenge_tag.rb
+++ b/app/models/searchable/dependents/challenge_tag.rb
@@ -10,7 +10,7 @@ module Searchable::Dependents::ChallengeTag
def check_searchable_dependents
if new_record? || name_previously_changed?
- challenge.shixun.reindex(:searchable_challenge_data)
+ challenge.shixun.reindex
end
end
end
\ No newline at end of file
diff --git a/app/models/searchable/dependents/stage.rb b/app/models/searchable/dependents/stage.rb
index 262ddd36f..d4207fec8 100644
--- a/app/models/searchable/dependents/stage.rb
+++ b/app/models/searchable/dependents/stage.rb
@@ -9,7 +9,7 @@ module Searchable::Dependents::Stage
def check_searchable_dependents
if name_previously_changed? || description_previously_changed?
- subject.reindex(:searchable_stages_data)
+ subject.reindex
end
end
end
\ No newline at end of file
diff --git a/app/models/searchable/dependents/user.rb b/app/models/searchable/dependents/user.rb
index 761704d06..f6dcaa430 100644
--- a/app/models/searchable/dependents/user.rb
+++ b/app/models/searchable/dependents/user.rb
@@ -10,13 +10,13 @@ module Searchable::Dependents::User
def check_searchable_dependents
if firstname_previously_changed? || lastname_previously_changed? || user_extension.school_id_previously_changed?
# reindex shixun
- created_shixuns.each{ |shixun| shixun.reindex(:searchable_user_data) }
+ created_shixuns.each(&:reindex)
# reindex course
manage_courses.each(&:reindex)
# reindex subject
- created_subjects.each { |subject| subject.reindex(:searchable_user_data) }
+ created_subjects.each(&:reindex)
end
end
end
\ No newline at end of file
diff --git a/app/services/competitions/create_personal_team_service.rb b/app/services/competitions/create_personal_team_service.rb
new file mode 100644
index 000000000..12b595cae
--- /dev/null
+++ b/app/services/competitions/create_personal_team_service.rb
@@ -0,0 +1,27 @@
+class Competitions::CreatePersonalTeamService < ApplicationService
+ Error = Class.new(StandardError)
+
+ attr_reader :competition, :user
+
+ def initialize(competition, user)
+ @competition = competition
+ @user = user
+ end
+
+ def call
+ raise Error, '个人赛才能报名' unless competition.personal?
+
+ is_teacher = user.is_teacher?
+ raise Error, '本竞赛的参赛者限定为:学生' if is_teacher && competition.teacher_enroll_forbidden?
+ raise Error, '本竞赛的参赛者限定为:教师' if !is_teacher && competition.member_enroll_forbidden?
+
+ enrolled = competition.competition_teams.exists?(user_id: user.id)
+ multiple_limited = (is_teacher && competition.teacher_multiple_limited?) || (!is_teacher && competition.member_multiple_limited?)
+ raise Error, '您已报名该竞赛' if enrolled && multiple_limited
+
+ ActiveRecord::Base.transaction do
+ team = competition.competition_teams.create!(name: user.show_name, user_id: user.id)
+ team.team_members.create!(competition_id: competition, user_id: user.id, role: 1, is_teacher: is_teacher)
+ end
+ end
+end
\ No newline at end of file
diff --git a/app/services/competitions/save_team_service.rb b/app/services/competitions/save_team_service.rb
index c134e70d7..1021e6e6d 100644
--- a/app/services/competitions/save_team_service.rb
+++ b/app/services/competitions/save_team_service.rb
@@ -17,6 +17,7 @@ class Competitions::SaveTeamService < ApplicationService
is_teacher = team.user.is_teacher?
ActiveRecord::Base.transaction do
team.generate_invite_code if new_record
+ team.team_type = 1 # 组队竞赛
team.name = params[:name].to_s.strip
team.save!
diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb
index 5e763d1cc..4a2373f3f 100644
--- a/app/templates/exercise_export/blank_exercise.html.erb
+++ b/app/templates/exercise_export/blank_exercise.html.erb
@@ -81,25 +81,25 @@