You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
3.0 KiB
115 lines
3.0 KiB
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
|