|
|
@ -43,8 +43,94 @@ class WelcomeController < ApplicationController
|
|
|
|
render :json => {status: 0, message: "success"}
|
|
|
|
render :json => {status: 0, message: "success"}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def subject_to_local
|
|
|
|
|
|
|
|
subject_ids = params[:subject_ids].split(",")
|
|
|
|
|
|
|
|
subjects = Subject.where(id: subject_ids)
|
|
|
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
|
|
|
subjects.each do |subject|
|
|
|
|
|
|
|
|
if LocalSubject.where(subject_id: subject.id).blank?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local_subject = LocalSubject.create!(name: subject.name, description: subject.description, status: 0,
|
|
|
|
|
|
|
|
learning_notes: subject.learning_notes, introduction: subject.introduction,
|
|
|
|
|
|
|
|
stages_count: subject.stages_count, stage_shixuns_count: subject.stage_shixuns_count,
|
|
|
|
|
|
|
|
subject_id: subject.id, shixuns_count: subject.shixuns_count)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 同步复制章节
|
|
|
|
|
|
|
|
if subject.stages.present?
|
|
|
|
|
|
|
|
subject.stages.each do |stage|
|
|
|
|
|
|
|
|
new_stage = LocalStage.new
|
|
|
|
|
|
|
|
new_stage.attributes = stage.attributes.dup.except("id","user_id")
|
|
|
|
|
|
|
|
new_stage.local_subject_id = local_subject.id
|
|
|
|
|
|
|
|
new_stage.save!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if stage.stage_shixuns.present?
|
|
|
|
|
|
|
|
stage.stage_shixuns.each do |stage_shixun|
|
|
|
|
|
|
|
|
new_stage_shixun = LocalStageShixun.new
|
|
|
|
|
|
|
|
new_stage_shixun.attributes = stage_shixun.attributes.dup.except("id")
|
|
|
|
|
|
|
|
new_stage_shixun.local_subject_id = local_subject.id
|
|
|
|
|
|
|
|
new_stage_shixun.local_subject_id = new_stage.id
|
|
|
|
|
|
|
|
new_stage_shixun.save!
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 复制实训
|
|
|
|
|
|
|
|
_shixun_to_local(stage.shixuns)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
render :json => {status: 0, message: "success"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
|
|
|
logger.error("shixun_local_in ##{e.message}")
|
|
|
|
|
|
|
|
render :json => {status: -1, message: "error,#{e.message}"}
|
|
|
|
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def local_to_subject
|
|
|
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
|
|
|
subject_list = []
|
|
|
|
|
|
|
|
LocalSubject.find_each do |local_subject|
|
|
|
|
|
|
|
|
subject = Subject.create!(name: local_subject.name, description: local_subject.description, user_id: User.current.id,
|
|
|
|
|
|
|
|
status: 0, learning_notes: local_subject.learning_notes, introduction: local_subject.introduction,
|
|
|
|
|
|
|
|
stages_count: local_subject.stages_count, stage_shixuns_count: local_subject.stage_shixuns_count,
|
|
|
|
|
|
|
|
shixuns_count: local_subject.shixuns_count, visits: 1)
|
|
|
|
|
|
|
|
m = SubjectMember.new(:user_id => User.current.id, :role => 1)
|
|
|
|
|
|
|
|
subject.subject_members << m
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 同步章节信息
|
|
|
|
|
|
|
|
local_stages = LocalStage.where(local_subject_id: local_subject.id)
|
|
|
|
|
|
|
|
if local_stages.present?
|
|
|
|
|
|
|
|
local_stages.each do |local_stage|
|
|
|
|
|
|
|
|
new_stage = Stage.new
|
|
|
|
|
|
|
|
new_stage.attributes = local_stage.attributes.dup.except("id","local_subject_id","subject_id")
|
|
|
|
|
|
|
|
new_stage.subject_id = subject.id
|
|
|
|
|
|
|
|
new_stage.save!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 同步章节实训关联表
|
|
|
|
|
|
|
|
local_stage_shixuns = LocalStageShixun.where(local_stage_id: local_stage.id)
|
|
|
|
|
|
|
|
local_stage_shixuns.each do |local_stage_shixun|
|
|
|
|
|
|
|
|
# 先同步实训
|
|
|
|
|
|
|
|
local_shixun = LocalShixun.where(id: local_stage_shixun.local_shixun_id).first
|
|
|
|
|
|
|
|
shixun = _local_to_shixun local_shixun if local_shixun.present?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
new_stage_shixun = StageShixun.new
|
|
|
|
|
|
|
|
new_stage_shixun.position = local_stage_shixun.position
|
|
|
|
|
|
|
|
new_stage_shixun.stage_id = new_stage.id
|
|
|
|
|
|
|
|
new_stage_shixun.subject_id = subject.id
|
|
|
|
|
|
|
|
new_stage_shixun.shixun_id = shixun.try(:id)
|
|
|
|
|
|
|
|
new_stage_shixun.save!
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
subject_list << subject.id
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
render :json => {status: 0, message: "success", identifier: subject_list}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def shixun_to_local
|
|
|
|
def shixun_to_local
|
|
|
|
identifiers = params[:identifiers].split(",")
|
|
|
|
identifiers = params[:identifiers].split(",")
|
|
|
|