Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

chromesetting
SylorHuang 5 years ago
commit f6a57b5c92

@ -173,64 +173,70 @@ class ChallengesController < ApplicationController
# tab 0:过关任务的更新; 1:评测设置的更新; 2:表示参考答案的更新; # tab 0:过关任务的更新; 1:评测设置的更新; 2:表示参考答案的更新;
def update def update
ActiveRecord::Base.transaction do begin
tab = params[:tab].to_i ActiveRecord::Base.transaction do
@challenge.update_attributes(challenge_params) tab = params[:tab].to_i
if tab == 0 && @challenge.st == 0 @challenge.update_attributes(challenge_params)
@challenge.challenge_tags.delete_all if tab == 0 && @challenge.st == 0
if params[:challenge_tag].present? @challenge.challenge_tags.delete_all
params[:challenge_tag].each do |input| if params[:challenge_tag].present?
ChallengeTag.create!(:name => input, :challenge_id => @challenge.id) params[:challenge_tag].each do |input|
ChallengeTag.create!(:name => input, :challenge_id => @challenge.id)
end
end end
end elsif tab == 1
elsif tab == 1 path = @challenge.path
path = @challenge.path exec_path = @challenge.exec_path
exec_path = @challenge.exec_path test_set = @challenge.test_sets
test_set = @challenge.test_sets sets_output = test_set.map(&:output)
sets_output = test_set.map(&:output) sets_input = test_set.map(&:input)
sets_input = test_set.map(&:input) sets_open = test_set.map(&:is_public)
sets_open = test_set.map(&:is_public) set_score = test_set.map(&:score)
set_score = test_set.map(&:score) set_match_rule = test_set.map(&:match_rule)
set_match_rule = test_set.map(&:match_rule) params_hidden = params[:test_set].map{|set| set[:hidden].to_i == 0}
params_hidden = params[:test_set].map{|set| set[:hidden].to_i == 0} params_output = params[:test_set].map{|set| set[:output] }
params_output = params[:test_set].map{|set| set[:output] } params_input = params[:test_set].map{|set| set[:input] }
params_input = params[:test_set].map{|set| set[:input] } params_score = params[:test_set].map{|set| set[:score]}
params_score = params[:test_set].map{|set| set[:score]} params_test_set = params[:test_set].map{|set| set[:match_rule]}
params_test_set = params[:test_set].map{|set| set[:match_rule]} # 测试集变化则需要更新(输入、 输出、 是否隐藏)
# 测试集变化则需要更新(输入、 输出、 是否隐藏) if sets_output != params_output || sets_open != params_hidden || sets_input != params_input ||
if sets_output != params_output || sets_open != params_hidden || sets_input != params_input || set_score != params_score || params_test_set != set_match_rule
set_score != params_score || params_test_set != set_match_rule test_set.delete_all unless test_set.blank?
test_set.delete_all unless test_set.blank? params[:test_set].each_with_index do |set, index|
params[:test_set].each_with_index do |set, index| # last 末尾匹配, full: 全完匹配
# last 末尾匹配, full: 全完匹配 logger.info("set: #{set}; match_rule : #{set[:match_rule]}")
logger.info("set: #{set}; match_rule : #{set[:match_rule]}") match_rule = set[:match_rule] == 'last' ? 'last' : 'full'
match_rule = set[:match_rule] == 'last' ? 'last' : 'full' TestSet.create(:challenge_id => @challenge.id,
TestSet.create(:challenge_id => @challenge.id, :input => "#{set[:input]}",
:input => "#{set[:input]}", :output => "#{set[:output]}",
:output => "#{set[:output]}", :is_public => params_hidden[index],
:is_public => params_hidden[index], :score => set[:score],
:score => set[:score], :match_rule => "#{match_rule}",
:match_rule => "#{match_rule}", :position => (index + 1))
:position => (index + 1)) end
@challenge.update_column(:modify_time, Time.now)
# 测试集的
@shixun.myshixuns.update_all(:system_tip => 0)
end end
@challenge.update_column(:modify_time, Time.now) if params[:challenge][:show_type].to_i == -1
# 测试集的 @challenge.update_attributes(picture_path: nil, web_route: nil, expect_picture_path: nil, original_picture_path: nil)
@shixun.myshixuns.update_all(:system_tip => 0) end
end # 关卡评测执行文件如果被修改,需要修改脚本内容
if params[:challenge][:show_type].to_i == -1 script = modify_shixun_script @shixun, @shixun.evaluate_script
@challenge.update_attributes(picture_path: nil, web_route: nil, expect_picture_path: nil, original_picture_path: nil) @shixun.shixun_info.update_column(:evaluate_script, script)
# TODO:
# if path != params[:challenge][:path]
# shixun_modify_status_without_publish(@shixun, 1)
# end
#Attachment.attach_files(@challenge, params[:attachments])
end end
# 关卡评测执行文件如果被修改,需要修改脚本内容
script = modify_shixun_script @shixun, @shixun.evaluate_script
@shixun.shixun_info.update_column(:evaluate_script, script)
# TODO:
# if path != params[:challenge][:path]
# shixun_modify_status_without_publish(@shixun, 1)
# end
#Attachment.attach_files(@challenge, params[:attachments])
end
end
rescue => e
logger_error("##update_challenges: ##{e.message}")
tip_exception("更新失败!")
end end
end end
# 参考答案的'增,删,改' # 参考答案的'增,删,改'

@ -0,0 +1,7 @@
class ModifyTypeForTestSets < ActiveRecord::Migration[5.2]
def change
change_column :test_sets, :input, :longtext
change_column :test_sets, :output, :longtext
end
end
Loading…
Cancel
Save