|
|
|
@ -30,6 +30,17 @@ class WelcomeController < ApplicationController
|
|
|
|
|
require 'simple_xlsx_reader'
|
|
|
|
|
|
|
|
|
|
DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z)
|
|
|
|
|
def local_init
|
|
|
|
|
LocalShixun.delete_all
|
|
|
|
|
LocalMirrorRepository.delete_all
|
|
|
|
|
LocalShixunTagRepertoire.delete_all
|
|
|
|
|
LocalChallenge.delete_all
|
|
|
|
|
LocalTestSet.delete_all
|
|
|
|
|
LocalChallengeTag.delete_all
|
|
|
|
|
render :json => {status: 0, message: "success"}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def shixun_to_local
|
|
|
|
|
identifiers = params[:identifiers].split(",")
|
|
|
|
|
shixuns = Shixun.where(identifier: identifiers)
|
|
|
|
@ -62,7 +73,7 @@ class WelcomeController < ApplicationController
|
|
|
|
|
if shixun.challenges.present?
|
|
|
|
|
shixun.challenges.each do |challenge|
|
|
|
|
|
new_challenge = LocalChallenge.new
|
|
|
|
|
new_challenge.attributes = challenge.attributes.dup.except("id","shixun_id","user_id")
|
|
|
|
|
new_challenge.attributes = challenge.attributes.dup.except("id","shixun_id","user_id", "test_set_score")
|
|
|
|
|
new_challenge.local_shixun_id = local_shixun.id
|
|
|
|
|
new_challenge.save!
|
|
|
|
|
# 评测题,选择题暂时不考虑
|
|
|
|
@ -98,6 +109,7 @@ class WelcomeController < ApplicationController
|
|
|
|
|
|
|
|
|
|
def local_to_shixun
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
shixun_list = []
|
|
|
|
|
LocalShixun.find_each do |local_shixun|
|
|
|
|
|
identifier = generate_identifier
|
|
|
|
|
shixun = Shixun.create!(name: local_shixun.name, description: local_shixun.description, user_id: User.current.id,
|
|
|
|
@ -141,7 +153,7 @@ class WelcomeController < ApplicationController
|
|
|
|
|
if local_challenges.present?
|
|
|
|
|
local_challenges.each do |local_challenge|
|
|
|
|
|
new_challenge = Challenge.new
|
|
|
|
|
new_challenge.attributes = local_challenge.attributes.dup.except("id","local_shixun_id","user_id")
|
|
|
|
|
new_challenge.attributes = local_challenge.attributes.dup.except("id","local_shixun_id","user_id", "test_set_score")
|
|
|
|
|
new_challenge.user_id = User.current.id
|
|
|
|
|
new_challenge.shixun_id = shixun.id
|
|
|
|
|
new_challenge.save!
|
|
|
|
@ -166,8 +178,9 @@ class WelcomeController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
render :json => {status: 0, message: "success", identifier: shixun.identifier}
|
|
|
|
|
shixun_list << shixun.identifier
|
|
|
|
|
end
|
|
|
|
|
render :json => {status: 0, message: "success", identifier: shixun_list}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|