|
|
|
@ -11,7 +11,7 @@ class DuplicateCourseService < ApplicationService
|
|
|
|
|
@course = copy_course!
|
|
|
|
|
|
|
|
|
|
copy_course_modules!
|
|
|
|
|
|
|
|
|
|
Rails.logger.info("###########second_category_list#{@second_category_list}")
|
|
|
|
|
join_course!
|
|
|
|
|
|
|
|
|
|
copy_homework_commons!
|
|
|
|
@ -36,9 +36,17 @@ class DuplicateCourseService < ApplicationService
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def copy_course_modules!
|
|
|
|
|
@second_category_list = {}
|
|
|
|
|
origin_course.course_modules.each do |course_module|
|
|
|
|
|
attrs = course_module.as_json(only: %i[module_type position hidden module_name])
|
|
|
|
|
CourseModule.create!(attrs.merge(course_id: course.id))
|
|
|
|
|
new_course_module = CourseModule.create!(attrs.merge(course_id: course.id))
|
|
|
|
|
# 复制子目录
|
|
|
|
|
course_module.course_second_categories.each do |second_category|
|
|
|
|
|
category_attr = second_category.as_json(only: %i[category_type name position])
|
|
|
|
|
new_second_category =
|
|
|
|
|
CourseSecondCategory.create!(category_attr.merge(course_id: course.id, course_module_id: new_course_module.id))
|
|
|
|
|
@second_category_list[second_category.id] = new_second_category.id
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
@ -50,7 +58,10 @@ class DuplicateCourseService < ApplicationService
|
|
|
|
|
origin_course.homework_commons.where(homework_type: %i[normal group practice]).find_each do |origin_homework|
|
|
|
|
|
homework_attrs = origin_homework.as_json(only: %i[name description homework_type homework_bank_id reference_answer])
|
|
|
|
|
|
|
|
|
|
homework = HomeworkCommon.create!(homework_attrs.merge(user_id: user.id, course_id: course.id))
|
|
|
|
|
course_second_category_id = @second_category_list[origin_homework.course_second_category_id]
|
|
|
|
|
|
|
|
|
|
homework = HomeworkCommon.create!(homework_attrs.merge(user_id: user.id, course_id: course.id,
|
|
|
|
|
course_second_category_id:course_second_category_id))
|
|
|
|
|
|
|
|
|
|
origin_homework.attachments.find_each do |origin_attachment|
|
|
|
|
|
attachment = origin_attachment.copy
|
|
|
|
@ -71,6 +82,7 @@ class DuplicateCourseService < ApplicationService
|
|
|
|
|
HomeworksService.new.create_shixun_homework_cha_setting(homework, origin_homework.shixuns.first)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
origin_homework.increment!(:quotes)
|
|
|
|
|
origin_homework.homework_bank.increment!(:quotes) if origin_homework.homework_bank
|
|
|
|
|
end
|
|
|
|
@ -138,9 +150,9 @@ class DuplicateCourseService < ApplicationService
|
|
|
|
|
attachment.copy_from = origin_attachment.copy_from || origin_attachment.id
|
|
|
|
|
attachment.is_publish = 0
|
|
|
|
|
attachment.attachtype ||= 4
|
|
|
|
|
attachment.course_second_category_id = @second_category_list[origin_attachment.course_second_category_id]
|
|
|
|
|
|
|
|
|
|
attachment.save!
|
|
|
|
|
|
|
|
|
|
origin_course.update_quotes(attachment)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|