From 2f67425e2a4675c2bd5a1e47f42b388bc64d9f93 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 20 Aug 2019 18:59:39 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E9=97=AE=E9=A2=98=E5=92=8C=E6=A0=87=E5=87=86=E7=AD=94?= =?UTF-8?q?=E6=A1=88=E7=9A=84=E7=AE=97=E5=88=86=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 6 ++++++ ...190820102040_change_exercise_1930_position.rb | 16 ++++++++++++++++ lib/tasks/excellent_course_exercise.rake | 7 +++++++ 3 files changed, 29 insertions(+) create mode 100644 db/migrate/20190820102040_change_exercise_1930_position.rb diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index ace9e062e..baf594a42 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -403,6 +403,12 @@ module ExercisesHelper end user_answer_content = answer_choice_array.sort standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个 + + #TODO: 旧版多选题的标准答案是放在一个里面的,新版又做成了一个题有多个标准答案(exercise_choice_id存放的是标准答案的位置..) + if q.question_type == 1 && standard_answer.size == 1 + standard_answer = standard_answer.first.to_s.split("").map(&:to_i) + end + if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分 if standard_answer.size > 0 q_score_1 = q.question_score diff --git a/db/migrate/20190820102040_change_exercise_1930_position.rb b/db/migrate/20190820102040_change_exercise_1930_position.rb new file mode 100644 index 000000000..601fb4eed --- /dev/null +++ b/db/migrate/20190820102040_change_exercise_1930_position.rb @@ -0,0 +1,16 @@ +class ChangeExercise1930Position < ActiveRecord::Migration[5.2] + def change + + #正式版的1930试卷的位置出现问题 + # + ex = Exercise.find_by(id:1930) + ex.exercise_questions.each_with_index do |q,index| + q.update_attributes(question_number:index+1) + end + + ex_q_bank = ex.exercise_bank.exercise_bank_questions + ex_q_bank.each_with_index do |q,index| + q.update_attributes(question_number:index+1) + end + end +end diff --git a/lib/tasks/excellent_course_exercise.rake b/lib/tasks/excellent_course_exercise.rake index d337fbd73..0d8875806 100644 --- a/lib/tasks/excellent_course_exercise.rake +++ b/lib/tasks/excellent_course_exercise.rake @@ -103,6 +103,13 @@ namespace :excellent_course_exercise do end user_answer_content = answer_choice_array.sort standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个 + + #TODO: 旧版多选题的标准答案是放在一个里面的,新版又做成了一个题有多个标准答案(exercise_choice_id存放的是标准答案的位置..) + + if q.question_type == 1 && standard_answer.size == 1 + standard_answer = standard_answer.first.to_s.split("").map(&:to_i) + end + if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分 if standard_answer.size > 0 q_score_1 = q.question_score From 046a4916c2ebe16efdf3fd8c48d0b7d4fd86476f Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 21 Aug 2019 14:51:20 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E6=B3=A8=E5=86=8C=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 2 +- app/controllers/application_controller.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 2524c53d8..e62dcf6ed 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -38,7 +38,7 @@ class AccountsController < ApplicationController return normal_status(-2, "验证码已失效") if !verifi_code&.effective? end - code = generate_identifier User, 8 + code = generate_identifier User, 8, pre login = pre + code @user = User.new(admin: false, login: login, mail: email, phone: phone, type: "User") @user.password = params[:password] diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e7b4bdac6..54c07d1c1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -396,10 +396,10 @@ class ApplicationController < ActionController::Base end # 随机生成字符 - def generate_identifier(container, num) + def generate_identifier(container, num, pre='') code = DCODES.sample(num).join if container == User - while container.exists?(login: code) do + while container.exists?(login: pre+code) do code = DCODES.sample(num).join end else From b039fd5839c56bf3b43ab2d2f368796fb19b2bbb Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 21 Aug 2019 14:56:47 +0800 Subject: [PATCH 3/6] =?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/models/subject.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/subject.rb b/app/models/subject.rb index 5116cce75..b8d6eef8b 100644 --- a/app/models/subject.rb +++ b/app/models/subject.rb @@ -19,7 +19,7 @@ class Subject < ApplicationRecord has_many :stages, -> { order("stages.position ASC") }, dependent: :destroy # 开放课堂 - has_many :courses, -> { order("courses.id ASC") } + has_many :courses, -> { where("is_delete = 0").order("courses.id ASC") } validates :name, length: { maximum: 60 } validates :description, length: { maximum: 5000 } From bd7cb436711e207f1a9040d6a088bbb67b969209 Mon Sep 17 00:00:00 2001 From: caishi <1149225589@qq.com> Date: Wed, 21 Aug 2019 14:57:31 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=AD=94=E9=A2=98-?= =?UTF-8?q?=E8=AF=84=E9=98=85=E9=A1=B5=E9=9D=A2=EF=BC=8C=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E9=A2=98=E4=BC=9A=E6=96=B0=E5=BC=80=E7=A9=BA?= =?UTF-8?q?=E7=99=BD=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../react/src/modules/courses/exercise/question/shixunAnswer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/react/src/modules/courses/exercise/question/shixunAnswer.js b/public/react/src/modules/courses/exercise/question/shixunAnswer.js index f1fb09227..d8644f8c4 100644 --- a/public/react/src/modules/courses/exercise/question/shixunAnswer.js +++ b/public/react/src/modules/courses/exercise/question/shixunAnswer.js @@ -276,7 +276,7 @@ class shixunAnswer extends Component{ } { item.operation ? - this.scrollToAnchor(`${questionType.question_id}${index+1}`)}>查看 + this.scrollToAnchor(`${questionType.question_id}${index+1}`)}>查看 : -- } From fd3dfaaa594baf249da297ff5e200ea0a4a00b0a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 21 Aug 2019 15:10:44 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E9=97=AE=E9=A2=98=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exercise_questions_controller.rb | 2 +- ...820102040_change_exercise_1930_position.rb | 29 +++++++++++++------ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index 52915a8ba..75ada699d 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -348,7 +348,7 @@ class ExerciseQuestionsController < ApplicationController #当试卷已发布时(试卷的总状态),当标准答案修改时,如有已提交的学生,需重新计算分数. - if @exercise.exercise_status == Exercise::PUBLISHED + if @exercise.exercise_status >= Exercise::PUBLISHED ex_users_committed = @exercise.exercise_users.exercise_user_committed if ex_users_committed.size > 0 ex_users_committed.each do |ex_user| diff --git a/db/migrate/20190820102040_change_exercise_1930_position.rb b/db/migrate/20190820102040_change_exercise_1930_position.rb index 601fb4eed..bbd73c033 100644 --- a/db/migrate/20190820102040_change_exercise_1930_position.rb +++ b/db/migrate/20190820102040_change_exercise_1930_position.rb @@ -1,16 +1,27 @@ class ChangeExercise1930Position < ActiveRecord::Migration[5.2] def change + exs = Exercise.all.includes(:exercise_questions) + exs.each do |ex| + ex_questions = ex&.exercise_questions&.select(:id,:question_number,:exercise_id)&.order("question_number ASC") + if ex_questions.exists? + ex_questions.each_with_index do |q,index| + q_num = index + 1 + if q.question_number.to_i != q_num + q.update_attributes(question_number: q_num) + end + end + end - #正式版的1930试卷的位置出现问题 - # - ex = Exercise.find_by(id:1930) - ex.exercise_questions.each_with_index do |q,index| - q.update_attributes(question_number:index+1) + ex_q_bank = ex&.exercise_bank&.exercise_bank_questions&.select(:id,:question_number,:exercise_bank_id,:shixun_id)&.order("question_number ASC") + if ex_q_bank.exists? + ex_q_bank.each_with_index do |q,index| + q_num_1 = index + 1 + if q.question_number.to_i != q_num_1 + q.update_attributes(question_number: q_num_1) + end + end + end end - ex_q_bank = ex.exercise_bank.exercise_bank_questions - ex_q_bank.each_with_index do |q,index| - q.update_attributes(question_number:index+1) - end end end From 46e12baea9899cc2d42fccd8c24d516360486491 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 21 Aug 2019 15:21:30 +0800 Subject: [PATCH 6/6] add puts when migrate --- db/migrate/20190820102040_change_exercise_1930_position.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/db/migrate/20190820102040_change_exercise_1930_position.rb b/db/migrate/20190820102040_change_exercise_1930_position.rb index bbd73c033..c46616e28 100644 --- a/db/migrate/20190820102040_change_exercise_1930_position.rb +++ b/db/migrate/20190820102040_change_exercise_1930_position.rb @@ -2,9 +2,10 @@ class ChangeExercise1930Position < ActiveRecord::Migration[5.2] def change exs = Exercise.all.includes(:exercise_questions) exs.each do |ex| - ex_questions = ex&.exercise_questions&.select(:id,:question_number,:exercise_id)&.order("question_number ASC") + ex_questions = ex&.exercise_questions&.select(:id,:question_number,:exercise_id)&.order("question_number ASC") #试卷的位置迁移 if ex_questions.exists? ex_questions.each_with_index do |q,index| + puts index q_num = index + 1 if q.question_number.to_i != q_num q.update_attributes(question_number: q_num) @@ -12,9 +13,10 @@ class ChangeExercise1930Position < ActiveRecord::Migration[5.2] end end - ex_q_bank = ex&.exercise_bank&.exercise_bank_questions&.select(:id,:question_number,:exercise_bank_id,:shixun_id)&.order("question_number ASC") + ex_q_bank = ex&.exercise_bank&.exercise_bank_questions&.select(:id,:question_number,:exercise_bank_id,:shixun_id)&.order("question_number ASC") #试卷的习题库位置迁移 if ex_q_bank.exists? ex_q_bank.each_with_index do |q,index| + puts index q_num_1 = index + 1 if q.question_number.to_i != q_num_1 q.update_attributes(question_number: q_num_1)