From c5c2dfb372789f0870629a79f8f3cce9cb653e9c Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 31 Aug 2019 17:04:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=8D=E5=88=B6=E5=AE=9E=E8=AE=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/javascripts/initialization_data.js | 2 + .../stylesheets/initialization_data.scss | 3 + .../initialization_data_controller.rb | 114 ++++++++++++++++++ app/helpers/initialization_data_helper.rb | 2 + .../initialization_data_controller_spec.rb | 5 + .../initialization_data_helper_spec.rb | 15 +++ 6 files changed, 141 insertions(+) create mode 100644 app/assets/javascripts/initialization_data.js create mode 100644 app/assets/stylesheets/initialization_data.scss create mode 100644 app/controllers/initialization_data_controller.rb create mode 100644 app/helpers/initialization_data_helper.rb create mode 100644 spec/controllers/initialization_data_controller_spec.rb create mode 100644 spec/helpers/initialization_data_helper_spec.rb diff --git a/app/assets/javascripts/initialization_data.js b/app/assets/javascripts/initialization_data.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/initialization_data.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/initialization_data.scss b/app/assets/stylesheets/initialization_data.scss new file mode 100644 index 000000000..e2fa6abac --- /dev/null +++ b/app/assets/stylesheets/initialization_data.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the initialization_data controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/initialization_data_controller.rb b/app/controllers/initialization_data_controller.rb new file mode 100644 index 000000000..ac0601752 --- /dev/null +++ b/app/controllers/initialization_data_controller.rb @@ -0,0 +1,114 @@ +class InitializationDataController < ApplicationController + + def init_subjects + raise("实践课程id不能为空") if params[:paths].blank? + paths = params[:paths].split(",") + origin_database = EduSetting.where(name: origin_database)&.value + database = EduSetting.where(name: database)&.value + # 获取原始数据库导入数据 + get_origin_data origin_database, paths + # 创建初始数据 + create_init_data database + + + + end + + + + private + def get_origin_data origin_database, paths + connect_to_origin_date(origin_database) + @subjects = get_subject_data(paths) + @stages = get_stages_data(@subjects) + @stage_shixuns = get_stage_shixuns_data(@stages) + @shixuns = get_shixun_data(@stage_shixuns) + @shixun_mirror_repositories = get_shixun_mirror_repositories_data(@shixuns) + @shixun_tag_repertoires = get_shixun_tag_repertoires_data(@shixuns) + @shixun_service_configs = get_shixun_service_configs_data(@shixuns) + @challenges = get_challenges_data(@shixuns) + @challenge_tags = get_challenge_tags_data(@challenges) + @test_sets = get_test_sets_data(@challenges) + @challenge_chooses = get_challenge_chooses_data(@challenges) + @challenge_questions = get_challenge_questions_data(@challenge_chooses) + end + + def create_init_data database + connect_to_origin_date database + #copy_shixuns + + end + + # 链接库 + def connect_to_origin_date database + ActiveRecord::Base.establish_connection( + adapter: "mysql2", + host: "localhost", + username: "root", + password: "123456", + database: "#{database}" + ) + end + + # 查询需要的路径 + def get_subject_data paths + Subject.where(id: paths) + end + + # 获取实践课程的章节 + def get_stages_data subjects + Stage.where(subject_id: subjects) + end + + # 获取时间课程的关联实训表 + def get_stage_shixuns_data stages + StageShixun.where(stage_id: stages) + end + + # 获取实训数据 + def get_shixun_data stage_shixuns + Shixun.where(id: stage_shixuns.map(&:shixun_id)) + end + + # 获取关卡数据 + def get_challenges_data shixuns + Challenge.where(shixun_id: shixuns) + end + + # 获取关卡标签数据 + def get_challenge_tags_data challenges + ChallengeTag.where(challenge_id: challenges) + end + + # 获取实训技能标签数据 + def get_shixun_mirror_repositories_data shixuns + ShixunMirrorRepository.where(shixun_id: shixuns) + end + + # 获取实训标签 + def get_shixun_tag_repertoires_data shixuns + ShixunTagRepertoire.where(shixun_id: shixuns) + end + + # 获取实训镜像配置 + def get_shixun_service_configs_data shixuns + ShixunServiceConfig.where(shixun_id: shixuns) + end + + # 获取测试集数据 + def get_test_sets_data challenges + TestSet.where(challenge_id: challenges) + end + + # 获取选择题题目 + def get_challenge_chooses_data challenges + ChallengeChoose.where(challenge_id: challenges) + end + + # 复制选择题选项 + def get_challenge_questions_data challenge_chooses + ChallengeQuestion.where(challenge_choose_id: challenge_chooses) + end + + +end diff --git a/app/helpers/initialization_data_helper.rb b/app/helpers/initialization_data_helper.rb new file mode 100644 index 000000000..c1c4a1d6e --- /dev/null +++ b/app/helpers/initialization_data_helper.rb @@ -0,0 +1,2 @@ +module InitializationDataHelper +end diff --git a/spec/controllers/initialization_data_controller_spec.rb b/spec/controllers/initialization_data_controller_spec.rb new file mode 100644 index 000000000..b51d45c9b --- /dev/null +++ b/spec/controllers/initialization_data_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe InitializationDataController, type: :controller do + +end diff --git a/spec/helpers/initialization_data_helper_spec.rb b/spec/helpers/initialization_data_helper_spec.rb new file mode 100644 index 000000000..1e3151d56 --- /dev/null +++ b/spec/helpers/initialization_data_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the InitializationDataHelper. For example: +# +# describe InitializationDataHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe InitializationDataHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end