From d5ba511313fddcdfbc92837d83dc9b3cadb3cd6f Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 6 Nov 2019 10:52:24 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E5=A4=8D?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/duplicate_course_service.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/services/duplicate_course_service.rb b/app/services/duplicate_course_service.rb index acff0a726..21ed0e109 100644 --- a/app/services/duplicate_course_service.rb +++ b/app/services/duplicate_course_service.rb @@ -94,8 +94,8 @@ class DuplicateCourseService < ApplicationService exercise = course.exercises.create!(attrs.merge(user_id: user.id)) origin_exercise.exercise_questions.find_each do |origin_question| - question_attrs = origin_question.as_json(only: %i[question_title question_type question_number question_score]) - question_attrs[:question_type] ||= 1 + question_attrs = origin_question.as_json(only: %i[question_title question_type question_number question_score shixun_name shixun_id]) + # question_attrs[:question_type] ||= 1 question = exercise.exercise_questions.create!(question_attrs) exercise_choice_map = {} @@ -103,15 +103,20 @@ class DuplicateCourseService < ApplicationService choice_attrs = { choice_position: index + 1, choice_text: origin_choice.choice_text } choice = question.exercise_choices.create!(choice_attrs) - exercise_choice_map[origin_choice.id] = choice.id + # exercise_choice_map[origin_choice.id] = choice.id 标准答案中存的是choice_position, 直接取原题的exercise_choice_id就行 end origin_question.exercise_standard_answers.find_each do |origin_answer| question.exercise_standard_answers.create!( - exercise_choice_id: exercise_choice_map[origin_answer.exercise_choice_id], + exercise_choice_id: origin_answer.exercise_choice_id, answer_text: origin_answer.answer_text ) end + + origin_question.exercise_shixun_challenges.find_each do |sc, index| + question.exercise_shixun_challenges.create!({position: index+1, challenge_id: sc.challenge_id, + shixun_id: sc.shixun_id, question_score: sc.question_score}) + end end origin_exercise.exercise_bank.increment!(:quotes) if exercise.exercise_bank From 91ee4daab9c35e467ba73f0fa007a1a6c48f258b Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 6 Nov 2019 11:00:26 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/duplicate_course_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/duplicate_course_service.rb b/app/services/duplicate_course_service.rb index 21ed0e109..299f9a45a 100644 --- a/app/services/duplicate_course_service.rb +++ b/app/services/duplicate_course_service.rb @@ -113,7 +113,7 @@ class DuplicateCourseService < ApplicationService ) end - origin_question.exercise_shixun_challenges.find_each do |sc, index| + origin_question.exercise_shixun_challenges.each_with_index do |sc, index| question.exercise_shixun_challenges.create!({position: index+1, challenge_id: sc.challenge_id, shixun_id: sc.shixun_id, question_score: sc.question_score}) end From a87160a6342dd0cd34417a2a026c0ae3f5f9b863 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 6 Nov 2019 11:03:56 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E5=A4=8D?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/duplicate_course_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/duplicate_course_service.rb b/app/services/duplicate_course_service.rb index 299f9a45a..fa57a8901 100644 --- a/app/services/duplicate_course_service.rb +++ b/app/services/duplicate_course_service.rb @@ -94,7 +94,7 @@ class DuplicateCourseService < ApplicationService exercise = course.exercises.create!(attrs.merge(user_id: user.id)) origin_exercise.exercise_questions.find_each do |origin_question| - question_attrs = origin_question.as_json(only: %i[question_title question_type question_number question_score shixun_name shixun_id]) + question_attrs = origin_question.as_json(only: %i[question_title question_type question_number question_score shixun_name shixun_id is_ordered level]) # question_attrs[:question_type] ||= 1 question = exercise.exercise_questions.create!(question_attrs) From ef1273a8071d278d837b649c4f8de989b3092a83 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 6 Nov 2019 11:42:54 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E9=82=AE=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/messages_controller.rb | 2 +- app/mailers/user_mailer.rb | 2 +- .../user_mailer/course_message_email.html.erb | 15 ++++----------- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index c1e08d440..66c294c06 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -207,7 +207,7 @@ class MessagesController < ApplicationController def notify_course_students message, course course.students.includes(:user).each do |student| - UserMailer.course_message_email(student&.user&.mail, message.id).deliver_now if student&.user&.mail + UserMailer.course_message_email(student&.user&.mail, message.id).deliver_later if student&.user&.mail end end end diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 5cd9d787c..6e957b4df 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -12,6 +12,6 @@ class UserMailer < ApplicationMailer def course_message_email(mail, message_id) @message = Message.find_by(id: message_id) @course = @message&.board&.course - mail(to: mail, subject: '课堂通知') if @message.present? && @course.present? + mail(to: mail, subject: '课堂发布了新的帖子') if @message.present? && @course.present? end end diff --git a/app/views/user_mailer/course_message_email.html.erb b/app/views/user_mailer/course_message_email.html.erb index 66c75414b..4b09f180c 100644 --- a/app/views/user_mailer/course_message_email.html.erb +++ b/app/views/user_mailer/course_message_email.html.erb @@ -1,7 +1,7 @@ - <%= @course.name %>通知 + <%= @course.name %> 发布了新的帖子