From 29b486c112bea8a579c2874a8e0b6513ebeb5773 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 2 Sep 2019 11:34:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=8D=E5=88=B6=E5=8E=9F=E5=A7=8B=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../initialization_data_controller.rb | 187 +++++++++++++++++- config/routes.rb | 1 + 2 files changed, 180 insertions(+), 8 deletions(-) diff --git a/app/controllers/initialization_data_controller.rb b/app/controllers/initialization_data_controller.rb index ac0601752..0921fee25 100644 --- a/app/controllers/initialization_data_controller.rb +++ b/app/controllers/initialization_data_controller.rb @@ -1,6 +1,6 @@ class InitializationDataController < ApplicationController - def init_subjects + def index raise("实践课程id不能为空") if params[:paths].blank? paths = params[:paths].split(",") origin_database = EduSetting.where(name: origin_database)&.value @@ -10,12 +10,9 @@ class InitializationDataController < ApplicationController # 创建初始数据 create_init_data database - - end - private def get_origin_data origin_database, paths connect_to_origin_date(origin_database) @@ -27,6 +24,7 @@ class InitializationDataController < ApplicationController @shixun_tag_repertoires = get_shixun_tag_repertoires_data(@shixuns) @shixun_service_configs = get_shixun_service_configs_data(@shixuns) @challenges = get_challenges_data(@shixuns) + @challenge_answers = get_challenge_answers_data(@challenges) @challenge_tags = get_challenge_tags_data(@challenges) @test_sets = get_test_sets_data(@challenges) @challenge_chooses = get_challenge_chooses_data(@challenges) @@ -35,7 +33,19 @@ class InitializationDataController < ApplicationController def create_init_data database connect_to_origin_date database - #copy_shixuns + copy_subject_data + copy_stages_data + copy_stage_shixuns_data + copy_shixun_data + copy_shixun_mirror_repositories_data + copy_shixun_tag_repertoires_data + copy_shixun_service_configs_data + copy_challenges_data + copy_challenge_answers_data + copy_challenge_tags_data + copy_test_sets_data + copy_challenge_chooses_data + copy_challenge_questions_data end @@ -50,65 +60,226 @@ class InitializationDataController < ApplicationController ) end - # 查询需要的路径 + # 获取需要的路径 def get_subject_data paths Subject.where(id: paths) end + # 创建需要的路径 + def copy_subject_data + subject_attrs = %i[id name description status major_id learning_notes introduction homepage_show user_id + repertoire_id score_count publish_time subject_level_system_id excellent] + Subject.bulk_insert(*subject_attrs) do |worker| + @subjects.each do |subject| + base_attr = subject.attributes.dup.except("user_id", "stages_count", "stage_shixuns_count", "shixuns_count") + worker.add(base_attr.merge(user_id: 1)) + # 复制成员 + SubjectMember.create(subject_id: subject.id, user_id: 1, role: 1) + end + end + end + # 获取实践课程的章节 def get_stages_data subjects Stage.where(subject_id: subjects) end - # 获取时间课程的关联实训表 + # 创建需要的章节 + def copy_stages_data + stage_attrs = %i[id subject_id name description user_id position ] + Stage.bulk_insert(*stage_attrs) do |worker| + @stages.each do |stage| + base_attr = stage.attributes.dup.except("user_id", "shixuns_count") + worker.add(base_attr.merge(user_id: 1)) + end + end + end + + # 获取实践课程的关联实训表 def get_stage_shixuns_data stages StageShixun.where(stage_id: stages) end + # 创建实践课程关联实训表 + def copy_stage_shixuns_data + stage_shixun_attrs = %i[id subject_id stage_id shixun_id position] + StageShixun.bulk_insert(*stage_shixun_attrs) do |worker| + @stage_shixuns.each do |stage_shixun| + base_attr = stage_shixun.attributes.dup + worker.add(base_attr) + end + end + end + # 获取实训数据 def get_shixun_data stage_shixuns Shixun.where(id: stage_shixuns.map(&:shixun_id)) end + # 创建实训数据 + def copy_shixun_data + shixun_attrs = %i[id name user_id gpid status authentication identifier trainee major_id webssh homepage_show hidden + fork_from can_copy modify_time reset_time publish_time closer_id end_time git_url vnc + mirror_script_id image_text code_hidden task_pass exec_time test_set_permission sigle_training hide_code + multi_webssh excute_time repo_name averge_star opening_time forbid_copy pod_life local_status evaluate_script + description propaedeutics] + + Shixun.bulk_insert(*shixun_attrs) do |worker| + @shixuns.each do |shixun| + base_attr = shixun.attributes.dup.except("user_id", "challenges_count", "myshixuns_count", "use_scope") + worker.add(base_attr.merge(user_id: 1)) + # 创建实训成员 + ShixunMember.create(user_id: 1, shixun_id: shixun.id, role: 1) + end + end + end + # 获取关卡数据 def get_challenges_data shixuns Challenge.where(shixun_id: shixuns) end + # 创建关卡数据 + def copy_challenges_data + challenge_attrs = %i[id shixun_id subject user_id status position task_pass score path evaluation_way difficulty + exec_path code_line st web_route picture_path expect_picture_path modify_time challenge_tags_count original_picture_path + show_type test_set_score test_set_average exec_time] + Challenge.bulk_insert(*challenge_attrs) do |worker| + @challenges.each do |challenge| + base_attr = challenge.attributes.dup.except("user_id", "praises_count", "memory_limit", "request_limit", "time_limit", + "lower_cpu_limit", "cpu_limit", "visits") + worker.add(base_attr.merge(user_id: 1)) + end + end + end + + # 获取参考答案 + def get_challenge_answers_data challenges + ChallengeAnswer.where(challenge_id: challenges) + end + + # 复制参考答案 + def copy_challenge_answers_data + answer_attrs = %i[id name contents score level challenge_id] + ChallengeAnswer.bulk_insert(*answer_attrs) do |worker| + @challenge_answers.each do |answer| + base_attr = answer.attributes.dup + worker.add(base_attr) + end + end + end + # 获取关卡标签数据 def get_challenge_tags_data challenges ChallengeTag.where(challenge_id: challenges) end - # 获取实训技能标签数据 + # 创建关卡标签数据 + def copy_challenge_tags_data + tag_attrs = %i[id name challenge_id challenge_choose_id] + ChallengeTag.bulk_insert(*tag_attrs) do |worker| + @challenge_tags.each do |tag| + base_attr = tag.attributes.dup + worker.add(base_attr) + end + end + end + + # 获取实训镜像标签数据 def get_shixun_mirror_repositories_data shixuns ShixunMirrorRepository.where(shixun_id: shixuns) end + # 创建实训镜像标签 + def copy_shixun_mirror_repositories_data + repository_attrs = %i[id shixun_id mirror_repository_id] + ShixunMirrorRepository.bulk_insert(*repository_attrs) do |worker| + @shixun_mirror_repositories.each do |repository| + base_attr = repository.attributes.dup + worker.add(base_attr) + end + end + end + # 获取实训标签 def get_shixun_tag_repertoires_data shixuns ShixunTagRepertoire.where(shixun_id: shixuns) end + # 创建实训标签 + def copy_shixun_tag_repertoires_data + repository_attrs = %i[id shixun_id tag_repertoire_id] + ShixunTagRepertoire.bulk_insert(*repository_attrs) do |worker| + @shixun_tag_repertoires.each do |repository| + base_attr = repository.attributes.dup + worker.add(base_attr) + end + end + end + # 获取实训镜像配置 def get_shixun_service_configs_data shixuns ShixunServiceConfig.where(shixun_id: shixuns) end + # 创建镜像配置 + def copy_shixun_service_configs_data + config_attrs = %i[id shixun_id cpu_limit memory_limit request_limit lower_cpu_limit resource_limit mirror_repository_id] + ShixunServiceConfig.bulk_insert(*config_attrs) do |worker| + @shixun_service_configs.each do |config| + base_attr = config.attributes.dup + worker.add(base_attr) + end + end + end + # 获取测试集数据 def get_test_sets_data challenges TestSet.where(challenge_id: challenges) end + # 创建测试集数据 + def copy_test_sets_data + set_attrs = %i[id input output challenge_id is_public result position score] + TestSet.bulk_insert(*set_attrs) do |worker| + @test_sets.each do |set| + base_attr = set.attributes.dup + worker.add(base_attr) + end + end + end + # 获取选择题题目 def get_challenge_chooses_data challenges ChallengeChoose.where(challenge_id: challenges) end + # 创建选择题题目数据 + def copy_challenge_chooses_data + choose_attrs = %i[id subject challenge_id standard_answer answer score difficult category position] + ChallengeChoose.bulk_insert(*choose_attrs) do |worker| + @challenge_chooses.each do |choose| + base_attr = choose.attributes.dup + worker.add(base_attr) + end + end + end + # 复制选择题选项 def get_challenge_questions_data challenge_chooses ChallengeQuestion.where(challenge_choose_id: challenge_chooses) end + # 创建选择题选项数据 + def copy_challenge_questions_data + question_attrs = %i[id option_name challenge_choose_id right_key position] + ChallengeQuestion.bulk_insert(*question_attrs) do |worker| + @challenge_questions.each do |question| + base_attr = question.attributes.dup + worker.add(base_attr) + end + end + end + end diff --git a/config/routes.rb b/config/routes.rb index 7e2cf72f3..a8d0de44c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -33,6 +33,7 @@ Rails.application.routes.draw do end end + resources :initialization_data resources :tem_tests # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html #