parent
86493d00dc
commit
c5c2dfb372
@ -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.
|
@ -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/
|
@ -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
|
@ -0,0 +1,2 @@
|
|||||||
|
module InitializationDataHelper
|
||||||
|
end
|
@ -0,0 +1,5 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe InitializationDataController, type: :controller do
|
||||||
|
|
||||||
|
end
|
@ -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
|
Loading…
Reference in new issue