From 6e18d221112013a4d783dea3828ce224d3be623d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 09:42:59 +0800 Subject: [PATCH 01/19] =?UTF-8?q?=E6=89=93=E5=BC=80=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index d9588cb5b..290b4387d 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -518,7 +518,7 @@ class ShixunsController < ApplicationController ActiveRecord::Base.transaction do begin - #cloud_bridge = edu_setting('cloud_bridge') + cloud_bridge = edu_setting('cloud_bridge') myshixun_identifier = generate_identifier Myshixun, 10 myshixun = @shixun.myshixuns.create!(user_id: current_user.id, identifier: myshixun_identifier, modify_time: @shixun.modify_time, reset_time: @shixun.reset_time, From 11c7e95a4606c25f27f6a1ba081534a5cdeff73b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 09:44:00 +0800 Subject: [PATCH 02/19] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AF=95=E5=8D=B7?= =?UTF-8?q?=E7=9A=84=E5=88=A0=E9=99=A4=E6=85=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/exercise_question.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/exercise_question.rb b/app/models/exercise_question.rb index 5f456e21f..607ad1a29 100644 --- a/app/models/exercise_question.rb +++ b/app/models/exercise_question.rb @@ -5,11 +5,11 @@ class ExerciseQuestion < ApplicationRecord belongs_to :shixun, optional: true has_many :exercise_choices, :dependent => :destroy - has_many :exercise_answers, :dependent => :destroy + has_many :exercise_answers has_many :exercise_shixun_challenges,:dependent => :destroy - has_many :exercise_shixun_answers, :dependent => :destroy - has_many :exercise_answer_comments, :dependent => :destroy - has_many :exercise_standard_answers, :dependent => :destroy + has_many :exercise_shixun_answers + has_many :exercise_answer_comments + has_many :exercise_standard_answers scope :insert_question_ex, lambda {|k| where("question_number > ?",k)} scope :find_by_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 From fc2685a9d8433f36a1f2775ba5c4ed8acd607053 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 10:07:55 +0800 Subject: [PATCH 03/19] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=88=E4=BD=9C?= =?UTF-8?q?=E8=80=85=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 290b4387d..743594749 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -624,8 +624,11 @@ class ShixunsController < ApplicationController def add_collaborators raise("搜索内容不能为空") unless params[:search] member_ids = "(" + @shixun.shixun_members.map(&:user_id).join(',') + ")" - condition = "%#{params[:search].strip}%".gsub(" ","") - @users = User.where("id not in #{member_ids} and status = 1 and LOWER(concat(lastname, firstname, login, mail, nickname)) LIKE '#{condition}'") + user_name = "%#{params[:user_name].strip}%" + school_name = "%#{params[:school_name].strip}%" + @users = User.joins(user_extension: :school).where("users.id not in #{member_ids} AND users.status = 1 AND + LOWER(users.lastname) LIKE '#{user_name}' AND LOWER(schools.name) LIKE + '#{school_name}' ") end def shixun_members_added From e1c40cd30d9288e6a0b3e5cb03f44c5c8f0f9d3d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 10:11:27 +0800 Subject: [PATCH 04/19] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=88=E4=BD=9C?= =?UTF-8?q?=E8=80=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 743594749..ecbcbf872 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -626,9 +626,13 @@ class ShixunsController < ApplicationController member_ids = "(" + @shixun.shixun_members.map(&:user_id).join(',') + ")" user_name = "%#{params[:user_name].strip}%" school_name = "%#{params[:school_name].strip}%" - @users = User.joins(user_extension: :school).where("users.id not in #{member_ids} AND users.status = 1 AND + if user_name.present? || school_name.present? + @users = User.joins(user_extension: :school).where("users.id not in #{member_ids} AND users.status = 1 AND LOWER(users.lastname) LIKE '#{user_name}' AND LOWER(schools.name) LIKE - '#{school_name}' ") + '#{school_name}'") + else + @users = User.none + end end def shixun_members_added From 72c304faa5707b76035221cf2812e21fd88664ec Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 10:22:03 +0800 Subject: [PATCH 05/19] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E9=80=89?= =?UTF-8?q?=E9=A1=B9=E9=9A=8F=E6=9C=BA=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exercise_questions/_exercise_questions.json.jbuilder | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/exercise_questions/_exercise_questions.json.jbuilder b/app/views/exercise_questions/_exercise_questions.json.jbuilder index 7a05c2e11..9445862ba 100644 --- a/app/views/exercise_questions/_exercise_questions.json.jbuilder +++ b/app/views/exercise_questions/_exercise_questions.json.jbuilder @@ -6,10 +6,11 @@ json.question_type question.question_type json.question_score question.question_score.round(1).to_s if question.question_type <= 2 #当为选择题或判断题时,只显示选项的位置 standard_answers_array = question.get_standard_answer_ids - exercise_choices = choices.order("choice_position ASC") ex_choice_random_boolean = (exercise_type.present? && exercise_type == 3 && (question.exercise.choice_random)) ? true : false #问题的选项随机打乱 if ex_choice_random_boolean - exercise_choices = exercise_choices.order("RAND()") + exercise_choices = choices.order("RAND()") + else + exercise_choices = choices.order("choice_position ASC") end json.question_choices do json.array! exercise_choices.each_with_index.to_a do |a,index| From 21c0d774e4d9e717b747dceb2de164bd6aa37210 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 10:26:11 +0800 Subject: [PATCH 06/19] =?UTF-8?q?=E5=8F=91=E9=80=81=E8=87=B3=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E8=AF=BE=E7=A8=8B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index ecbcbf872..f8c2fce68 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -674,14 +674,14 @@ class ShixunsController < ApplicationController limit = params[:limit] || 20 if params[:search] search = "%#{params[:search].to_s.strip.downcase}%" - course_ids = Course.find_by_sql("SELECT c.id FROM courses c, members m, member_roles mr - WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9) + course_ids = Course.find_by_sql("SELECT c.id FROM courses c, course_members m + WHERE m.course_id = c.id AND m.role in (1,2,3) AND m.user_id=#{current_user.id} AND c.is_delete = 0 AND c.is_end = 0 AND c.name like '#{search}' ").map(&:id) else - course_ids = Course.find_by_sql("SELECT c.id, c.name FROM courses c, members m, member_roles mr - WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9) + course_ids = Course.find_by_sql("SELECT c.id, c.name FROM courses c, course_members m + WHERE m.course_id = c.id AND m.role in (1,2,3) AND m.user_id=#{current_user.id} AND c.is_delete = 0 AND c.is_end = 0").map(&:id) end From fa9448967bc96d6b679ae28c5a6718dd2fc789b2 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 10:32:56 +0800 Subject: [PATCH 07/19] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E5=8F=91=E9=80=81?= =?UTF-8?q?=E8=87=B3=E8=AF=BE=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index f8c2fce68..e3a658d7c 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -693,7 +693,7 @@ class ShixunsController < ApplicationController # 将实训发送到课程 def send_to_course @course = Course.find(params[:course_id]) - homework = HomeworksService.new.create_homework shixun, @course, nil, current_user + homework = HomeworksService.new.create_homework @shixun, @course, nil, current_user end # 二维码扫描下载 From d4bdc7e8e2145f730875937b70917d89082c9d25 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 10:34:50 +0800 Subject: [PATCH 08/19] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=8F=91=E9=80=81?= =?UTF-8?q?=E8=87=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/shixuns/send_to_course.json.jbuilder | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/views/shixuns/send_to_course.json.jbuilder b/app/views/shixuns/send_to_course.json.jbuilder index dd087d3e2..b2e30f985 100644 --- a/app/views/shixuns/send_to_course.json.jbuilder +++ b/app/views/shixuns/send_to_course.json.jbuilder @@ -1,4 +1,3 @@ json.status 1 json.message "发送成功" -json.url course_homework_commons_path(@course.id, type: 4) -# json.url "#{Rails::configuration.educoder['old_edu_host']}/homework_common?course=#{@course.id}&homework_type=4" \ No newline at end of file +json.course_id @course.id \ No newline at end of file From 863dad51b1ab2d80da23070c020c20da2df13d53 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 10:37:41 +0800 Subject: [PATCH 09/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=95=E5=8D=B7?= =?UTF-8?q?=E7=AD=94=E9=A2=98=E5=88=97=E8=A1=A8=E7=9A=84=E5=AD=A6=E7=94=9F?= =?UTF-8?q?=E5=92=8C=E8=80=81=E5=B8=88=E8=A7=86=E8=A7=92=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 | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 7e7e1070d..fd2877cc8 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -508,15 +508,14 @@ module ExercisesHelper current_user_group_name = course_group.first.name if course_group.present? end teacher_review = ex_user.subjective_score < 0.0 ? false : true - if ex_user_exercise_status != 3 || commit_status != 1 #试卷未截止或用户未提交 - # if (user_status != 0 && ex_user_exercise_status != 3)|| commit_status == 0 #不为教师,且试卷未截止;当前用户未提交 不显示分数 - ex_object_score = nil - ex_subject_score = nil - score = nil - else + if (user_status == 0 && commit_status == 1) || (user_status == 1 && ex_user_exercise_status == 3 && commit_status == 1) #老师都可以看,学生,需在试卷已提交,且已截止的情况下看 ex_object_score = ex_user.objective_score < 0.0 ? 0.0 : ex_user.objective_score.round(1).to_s ex_subject_score = ex_user.subjective_score < 0.0 ? nil : ex_user.subjective_score.round(1).to_s score = ex_user.score.present? ? ex_user.score.round(1).to_s : 0.0.to_s + else + ex_object_score = nil + ex_subject_score = nil + score = nil end { From 4122ccf438accbacf156baf67012c98f2041e37a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 10:48:23 +0800 Subject: [PATCH 10/19] fix bug --- app/helpers/exercises_helper.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index fd2877cc8..8db7e8bfa 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -638,6 +638,9 @@ module ExercisesHelper if student_status == 2 #当前为老师,或为学生且已提交 user_score = exercise_answers.score_reviewed.pluck(:score).sum end + if user_score > q.question_score + user_score = q.question_score + end if ques_type <= 2 answered_content = exercise_answers.pluck(:exercise_choice_id) elsif ques_type == 3 From 76028ceca5e290dd7a620176189d6c673bd1a7cb Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 10:59:31 +0800 Subject: [PATCH 11/19] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E5=8F=91=E9=80=81=E8=87=B3=E5=8A=9F=E8=83=BD=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/subjects_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 4b954584b..c73fec500 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -164,8 +164,8 @@ class SubjectsController < ApplicationController end def choose_course - course_ids = Course.find_by_sql("SELECT c.id FROM courses c, members m, member_roles mr - WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9) + course_ids = Course.find_by_sql("SELECT c.id FROM courses c, course_members m + WHERE m.course_id = c.id AND m.role in (1,2,3) AND m.user_id=#{current_user.id} AND c.is_delete = 0 AND c.is_end = 0").map(&:id) @courses = Course.where(id: course_ids) @none_shixun_ids = ShixunSchool.where("school_id != #{current_user.user_extension.try(:school_id)}").pluck(:shixun_id) From 6f900946d79d9cf912431b02fcc66d4eeaf89680 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 11:08:15 +0800 Subject: [PATCH 12/19] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index e3a658d7c..5f7c13964 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -622,7 +622,6 @@ class ShixunsController < ApplicationController end def add_collaborators - raise("搜索内容不能为空") unless params[:search] member_ids = "(" + @shixun.shixun_members.map(&:user_id).join(',') + ")" user_name = "%#{params[:user_name].strip}%" school_name = "%#{params[:school_name].strip}%" From 2a010194578c773162e856a6812ea74adb83b667 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 12:23:10 +0800 Subject: [PATCH 13/19] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E7=9A=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/exercise.rb | 13 ++++++++++--- app/models/exercise_answer.rb | 8 +++++++- app/models/exercise_choice.rb | 11 +++++++++-- app/models/exercise_question.rb | 10 ++++++++-- app/models/exercise_shixun_answer.rb | 7 ++++++- 5 files changed, 40 insertions(+), 9 deletions(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 0c8b97ca7..af84a5c49 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -3,9 +3,9 @@ class Exercise < ApplicationRecord belongs_to :exercise_bank, optional: true belongs_to :user - has_many :exercise_users,:dependent => :destroy - has_many :exercise_questions,:dependent => :destroy - has_many :exercise_group_settings,:dependent => :destroy + has_many :exercise_users + has_many :exercise_questions + has_many :exercise_group_settings has_many :tidings, as: :container has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :destroy @@ -19,6 +19,13 @@ class Exercise < ApplicationRecord validates :exercise_name, length: { maximum: 60, too_long: "60 characters is the maximum allowed" } after_create :create_exercise_list + after_destroy :destroy_other_relations + + def destroy_other_relations + exercise_users.destroy_all + exercise_questions.destroy_all + exercise_group_settings.destroy_all + end def create_exercise_list str = "" diff --git a/app/models/exercise_answer.rb b/app/models/exercise_answer.rb index 465fa036b..96fbe17bb 100644 --- a/app/models/exercise_answer.rb +++ b/app/models/exercise_answer.rb @@ -3,7 +3,7 @@ class ExerciseAnswer < ApplicationRecord belongs_to :user belongs_to :exercise_question belongs_to :exercise_choice, optional: true - has_many :exercise_answer_comments, :dependent => :destroy + has_many :exercise_answer_comments scope :search_exercise_answer, lambda { |name,key| where("#{name} = ?",key)} scope :search_answer_users, lambda {|name,ids| where("#{name}":ids)} @@ -11,4 +11,10 @@ class ExerciseAnswer < ApplicationRecord scope :exercise_answer_is_right, -> {where("score > ?",0.0)} #判断答案是否正确,根据分数总和大于0 scope :score_reviewed, lambda {where("score >= ?",0.0)} #是否评分,用于判断主观题的 + after_destroy :destroy_answers_relations + + def destroy_answers_relations + exercise_answer_comments.destroy_all + end + end \ No newline at end of file diff --git a/app/models/exercise_choice.rb b/app/models/exercise_choice.rb index 525251ce6..f4f5c5a16 100644 --- a/app/models/exercise_choice.rb +++ b/app/models/exercise_choice.rb @@ -1,9 +1,16 @@ class ExerciseChoice < ApplicationRecord belongs_to :exercise_question - has_many :exercise_answers, :dependent => :destroy - has_many :exercise_standard_answers, :dependent => :destroy + has_many :exercise_answers + has_many :exercise_standard_answers scope :find_choice_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 scope :left_choice_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 + + after_destroy :destroy_choices_relations + + def destroy_choices_relations + exercise_answers.destroy_all + exercise_standard_answers.destroy_all + end end \ No newline at end of file diff --git a/app/models/exercise_question.rb b/app/models/exercise_question.rb index 607ad1a29..c236b657c 100644 --- a/app/models/exercise_question.rb +++ b/app/models/exercise_question.rb @@ -4,9 +4,9 @@ class ExerciseQuestion < ApplicationRecord belongs_to :exercise belongs_to :shixun, optional: true - has_many :exercise_choices, :dependent => :destroy + has_many :exercise_choices has_many :exercise_answers - has_many :exercise_shixun_challenges,:dependent => :destroy + has_many :exercise_shixun_challenges has_many :exercise_shixun_answers has_many :exercise_answer_comments has_many :exercise_standard_answers @@ -17,6 +17,12 @@ class ExerciseQuestion < ApplicationRecord scope :find_objective_questions, -> {where("question_type != ?",4)} #查找全部客观题 # scope :next_exercise, lambda {|k| where("question_number > ?",k).first} # scope :last_exercise, lambda {|k| where("question_number < ?",k).last} + after_destroy :destroy_questions_relations + + def destroy_questions_relations + exercise_choices.destroy_all + exercise_shixun_challenges.destroy_all + end def question_type_name case self.question_type diff --git a/app/models/exercise_shixun_answer.rb b/app/models/exercise_shixun_answer.rb index 8548e497d..72a6999d6 100644 --- a/app/models/exercise_shixun_answer.rb +++ b/app/models/exercise_shixun_answer.rb @@ -2,7 +2,7 @@ class ExerciseShixunAnswer < ApplicationRecord belongs_to :exercise_question belongs_to :user belongs_to :exercise_shixun_challenge - has_many :exercise_answer_comments, :dependent => :destroy + has_many :exercise_answer_comments # status 0: 未通过, 1:通过 # attr_accessible :answer_text, :score, :status scope :search_shixun_answers, lambda {|name,ids| where("#{name}":ids)} @@ -10,4 +10,9 @@ class ExerciseShixunAnswer < ApplicationRecord scope :shixun_no_full_scores, lambda { |score| where("score > 0.0 AND score < ?",score)} scope :score_reviewed, lambda {where("score is not NULL AND score >= ?",0.0)} #是否评分 + after_destroy :destroy_shixun_relations + + def destroy_shixun_relations + exercise_answer_comments.destroy_all + end end From 7a007dbd44315ea14fe384b50dedb1f6212f6404 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 12:38:32 +0800 Subject: [PATCH 14/19] fix bug --- app/models/exercise.rb | 15 ++++----------- app/models/exercise_answer.rb | 8 +------- app/models/exercise_choice.rb | 10 ++-------- app/models/exercise_question.rb | 11 ++--------- app/models/exercise_shixun_answer.rb | 7 +------ 5 files changed, 10 insertions(+), 41 deletions(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index af84a5c49..60409e51d 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -3,11 +3,11 @@ class Exercise < ApplicationRecord belongs_to :exercise_bank, optional: true belongs_to :user - has_many :exercise_users - has_many :exercise_questions - has_many :exercise_group_settings + has_many :exercise_users, :dependent => :delete_all + has_many :exercise_questions, :dependent => :delete_all + has_many :exercise_group_settings, :dependent => :delete_all has_many :tidings, as: :container - has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :destroy + has_many :course_acts, class_name: 'CourseActivity', as: :course_act, :dependent => :delete_all scope :is_exercise_published, -> { where("exercise_status > ? ",1)} scope :unified_setting, -> { where("unified_setting = ?",true) } @@ -19,13 +19,6 @@ class Exercise < ApplicationRecord validates :exercise_name, length: { maximum: 60, too_long: "60 characters is the maximum allowed" } after_create :create_exercise_list - after_destroy :destroy_other_relations - - def destroy_other_relations - exercise_users.destroy_all - exercise_questions.destroy_all - exercise_group_settings.destroy_all - end def create_exercise_list str = "" diff --git a/app/models/exercise_answer.rb b/app/models/exercise_answer.rb index 96fbe17bb..11558f937 100644 --- a/app/models/exercise_answer.rb +++ b/app/models/exercise_answer.rb @@ -3,7 +3,7 @@ class ExerciseAnswer < ApplicationRecord belongs_to :user belongs_to :exercise_question belongs_to :exercise_choice, optional: true - has_many :exercise_answer_comments + has_many :exercise_answer_comments, :dependent => :delete_all scope :search_exercise_answer, lambda { |name,key| where("#{name} = ?",key)} scope :search_answer_users, lambda {|name,ids| where("#{name}":ids)} @@ -11,10 +11,4 @@ class ExerciseAnswer < ApplicationRecord scope :exercise_answer_is_right, -> {where("score > ?",0.0)} #判断答案是否正确,根据分数总和大于0 scope :score_reviewed, lambda {where("score >= ?",0.0)} #是否评分,用于判断主观题的 - after_destroy :destroy_answers_relations - - def destroy_answers_relations - exercise_answer_comments.destroy_all - end - end \ No newline at end of file diff --git a/app/models/exercise_choice.rb b/app/models/exercise_choice.rb index f4f5c5a16..72dc30c9d 100644 --- a/app/models/exercise_choice.rb +++ b/app/models/exercise_choice.rb @@ -1,16 +1,10 @@ class ExerciseChoice < ApplicationRecord belongs_to :exercise_question - has_many :exercise_answers - has_many :exercise_standard_answers + has_many :exercise_answers, :dependent => :delete_all + has_many :exercise_standard_answers, :dependent => :delete_all scope :find_choice_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 scope :left_choice_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 - after_destroy :destroy_choices_relations - - def destroy_choices_relations - exercise_answers.destroy_all - exercise_standard_answers.destroy_all - end end \ No newline at end of file diff --git a/app/models/exercise_question.rb b/app/models/exercise_question.rb index c236b657c..2c9b281c3 100644 --- a/app/models/exercise_question.rb +++ b/app/models/exercise_question.rb @@ -4,9 +4,9 @@ class ExerciseQuestion < ApplicationRecord belongs_to :exercise belongs_to :shixun, optional: true - has_many :exercise_choices + has_many :exercise_choices, :dependent => :delete_all has_many :exercise_answers - has_many :exercise_shixun_challenges + has_many :exercise_shixun_challenges, :dependent => :delete_all has_many :exercise_shixun_answers has_many :exercise_answer_comments has_many :exercise_standard_answers @@ -15,14 +15,7 @@ class ExerciseQuestion < ApplicationRecord scope :find_by_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 scope :left_question_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 scope :find_objective_questions, -> {where("question_type != ?",4)} #查找全部客观题 - # scope :next_exercise, lambda {|k| where("question_number > ?",k).first} - # scope :last_exercise, lambda {|k| where("question_number < ?",k).last} - after_destroy :destroy_questions_relations - def destroy_questions_relations - exercise_choices.destroy_all - exercise_shixun_challenges.destroy_all - end def question_type_name case self.question_type diff --git a/app/models/exercise_shixun_answer.rb b/app/models/exercise_shixun_answer.rb index 72a6999d6..a9550c024 100644 --- a/app/models/exercise_shixun_answer.rb +++ b/app/models/exercise_shixun_answer.rb @@ -2,7 +2,7 @@ class ExerciseShixunAnswer < ApplicationRecord belongs_to :exercise_question belongs_to :user belongs_to :exercise_shixun_challenge - has_many :exercise_answer_comments + has_many :exercise_answer_comments, :dependent => :delete_all # status 0: 未通过, 1:通过 # attr_accessible :answer_text, :score, :status scope :search_shixun_answers, lambda {|name,ids| where("#{name}":ids)} @@ -10,9 +10,4 @@ class ExerciseShixunAnswer < ApplicationRecord scope :shixun_no_full_scores, lambda { |score| where("score > 0.0 AND score < ?",score)} scope :score_reviewed, lambda {where("score is not NULL AND score >= ?",0.0)} #是否评分 - after_destroy :destroy_shixun_relations - - def destroy_shixun_relations - exercise_answer_comments.destroy_all - end end From e233d90197bc70ef7775c364f3bdb13e2c6673a1 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 12:48:41 +0800 Subject: [PATCH 15/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=95=E5=8D=B7?= =?UTF-8?q?=E5=92=8C=E9=97=AE=E5=8D=B7=E5=88=A0=E9=99=A4=E5=85=B3=E8=81=94?= =?UTF-8?q?=E4=B8=BAdelete=5Fall?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/poll.rb | 10 +++++----- app/models/poll_answer.rb | 2 +- app/models/poll_question.rb | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/models/poll.rb b/app/models/poll.rb index 1cead3291..f72239ba7 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -4,13 +4,13 @@ class Poll < ApplicationRecord belongs_to :exercise_bank, optional: true # belongs_to :exercise_bank - has_many :poll_questions,dependent: :destroy - has_many :poll_users, :dependent => :destroy + has_many :poll_questions,dependent: :delete_all + has_many :poll_users, :dependent => :delete_all has_many :users, :through => :poll_users #该文件被哪些用户提交答案过 - has_many :poll_group_settings, :dependent => :destroy - has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :destroy + has_many :poll_group_settings, :dependent => :delete_all + has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :delete_all - has_many :tidings, as: :container, dependent: :destroy + has_many :tidings, as: :container, dependent: :delete_all scope :publish_or_not, -> { where("polls_status > ? ",1)} scope :only_public, -> {where("is_public = ?",true)} diff --git a/app/models/poll_answer.rb b/app/models/poll_answer.rb index 423198bbf..8e2421328 100644 --- a/app/models/poll_answer.rb +++ b/app/models/poll_answer.rb @@ -3,7 +3,7 @@ class PollAnswer < ApplicationRecord # include Redmine::SafeAttributes belongs_to :poll_question - has_many :poll_votes, :dependent => :destroy + has_many :poll_votes, :dependent => :delete_all scope :find_answer_by_custom, lambda {|k,v| where("#{k}":v)} #根据传入的参数查找问题 scope :left_answer_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 diff --git a/app/models/poll_question.rb b/app/models/poll_question.rb index 1fc8e0c16..a0854aa48 100644 --- a/app/models/poll_question.rb +++ b/app/models/poll_question.rb @@ -1,9 +1,9 @@ class PollQuestion < ApplicationRecord belongs_to :poll - has_many :poll_answers, :dependent => :destroy + has_many :poll_answers, :dependent => :delete_all attr_accessor :question_answers, :question_other_anser - has_many :poll_votes, :dependent => :destroy + has_many :poll_votes scope :ques_count, lambda {|k| where("question_type = ?",k)} scope :ques_necessary, -> {where("is_necessary = ?",1)} From d183334d919a1b5e6188041d7271c59b240e7e47 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 28 Jun 2019 13:57:09 +0800 Subject: [PATCH 16/19] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 7 +++-- app/models/challenge.rb | 40 +++++++++++++++--------- app/views/challenges/index.json.jbuilder | 2 +- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index f2a964c8d..bce0ae3c2 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -149,7 +149,11 @@ class ChallengesController < ApplicationController def index uid_logger("identifier: #{params}") # 通过调试发现 这里includes(:games)性能会慢10倍 - @challenges = @shixun.challenges.fields_for_list + # @challenges = @shixun.challenges.fields_for_list + @challenges = Challenge.fields_for_list.includes(:games).where("challenges.shixun_id" => @shixun.id) + + # @challenges = Challenge.includes(:games).where("games.user_id" => 12).where(shixun_id: @shixun.id) + @editable = current_user.manager_of_shixun?(@shixun) && @shixun.status == 0 @user = current_user end @@ -247,7 +251,6 @@ class ChallengesController < ApplicationController # 关卡位置被修改,需要修改脚本 script = modify_shixun_script @shixun, @shixun.evaluate_script @shixun.update_column(:evaluate_script, script) - end def index_up diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 5495dd7a3..f25ce330a 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -51,9 +51,8 @@ class Challenge < ApplicationRecord end # 开启挑战 - def open_game(user_id) - game = self.games.select([:status, :identifier]).where(user_id: user_id).first - shixun = self.shixun + def open_game user_id, challenge_id, shixun + game = games.select{|game| game.challenge_id = challenge_id && game.user_id == user_id}.first if game.present? shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : "" else @@ -61,18 +60,31 @@ class Challenge < ApplicationRecord end end + # # 开启挑战 + # def open_game(user_id, shixun) + # + # + # game = self.games.select([:status, :identifier]).where(user_id: user_id).first + # game = self.games.select{|game| game.user_id == user_id} + # if game.present? + # shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : "" + # else + # "/api/shixuns/#{shixun.identifier}/shixun_exec" + # end + # end + ## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成 def user_tpi_status user_id # todo: 以前没加索引导致相同关卡,同一用户有多个games - game = self.games.where(user_id: user_id).last - status = - if game.blank? - self.position == 1 ? 1 : 0 - elsif game.status == 2 - 2 - else - 1 - end + game = games.select{|game| game.user_id == user_id }.last + + if game.blank? + self.position == 1 ? 1 : 0 + elsif game.status == 2 + 2 + else + 1 + end end ## 选择题答案 @@ -85,12 +97,12 @@ class Challenge < ApplicationRecord # 关卡用户通关数 def user_passed_count - games.where(status: 2).count + games.select{|game| game.status == 2}.size end # 关卡用户正在挑战的人数 def playing_count - games.where(status: [0, 1]).count + games.select{|game| game.status == 0 || game.status == 1}.size end def last_challenge diff --git a/app/views/challenges/index.json.jbuilder b/app/views/challenges/index.json.jbuilder index 0b90b5ca5..dc122b8c4 100644 --- a/app/views/challenges/index.json.jbuilder +++ b/app/views/challenges/index.json.jbuilder @@ -17,7 +17,7 @@ if @challenges.present? json.passed_count challenge.user_passed_count json.playing_count challenge.playing_count json.name_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) - json.open_game challenge.open_game(@user.id) + json.open_game challenge.open_game(@user.id, challenge.id, @shixun) if @editable json.edit_url edit_shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) json.delete_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) From aa4dfd6190599fdfdbd21d50b37e1e3a6839eb97 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 14:10:09 +0800 Subject: [PATCH 17/19] fix bug --- app/helpers/exercises_helper.rb | 10 +++++----- app/views/exercises/start_answer.json.jbuilder | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 8db7e8bfa..cec6dd0ff 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -46,7 +46,7 @@ module ExercisesHelper sub_answer_score = sub_answer.first.score else stand_status = 0 - sub_answer_score = 0.0 + sub_answer_score = nil end sub_score = { @@ -54,7 +54,7 @@ module ExercisesHelper "q_type":s.question_type, "q_position":s.question_number, "stand_status":stand_status, - "user_score":sub_answer_score.round(1).to_s + "user_score":sub_answer_score.present? ? sub_answer_score.round(1).to_s : nil } @ex_sub_array.push(sub_score) end @@ -627,7 +627,7 @@ module ExercisesHelper #学生的分数状态及回答的内容 def user_question_answers(q,ex_answerer_id,student_status,is_teacher_or,ex_status,ques_type,ex_type) answered_content = [] - user_score = 0.0 + user_score = nil shixun_type = 0 question_comment = [] if q.question_type == 5 @@ -638,7 +638,7 @@ module ExercisesHelper if student_status == 2 #当前为老师,或为学生且已提交 user_score = exercise_answers.score_reviewed.pluck(:score).sum end - if user_score > q.question_score + if user_score.present? && (user_score > q.question_score) user_score = q.question_score end if ques_type <= 2 @@ -667,7 +667,7 @@ module ExercisesHelper question_comment = q.exercise_answer_comments.search_answer_comments("exercise_answer_id",q_answer_id) end { - "user_score": user_score.round(1), + "user_score": user_score.present? ? user_score.round(1) : nil, "answered_content":answered_content, "shixun_type":shixun_type, "question_comment":question_comment diff --git a/app/views/exercises/start_answer.json.jbuilder b/app/views/exercises/start_answer.json.jbuilder index 4cc461d56..42d611712 100644 --- a/app/views/exercises/start_answer.json.jbuilder +++ b/app/views/exercises/start_answer.json.jbuilder @@ -40,8 +40,8 @@ json.exercise_questions do question_info = get_exercise_question_info(question,@exercise,@exercise_user_current,@ex_answerer.id) # json.q_position q[:ques_number] #问题的序号,当问题为随机时,重新更新后的问题序号 if @t_user_exercise_status == 3 - this_answer_status = "0.0" - user_score = "0.0" + this_answer_status = 0 + user_score = nil if all_question_status.size > 0 this_ques_status = all_question_status.detect {|f| f[:q_id] == question.id} this_answer_status = this_ques_status[:stand_status] From d1f721b249d86400226c2f91a89390407e01cc62 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 28 Jun 2019 14:12:04 +0800 Subject: [PATCH 18/19] left out join --- app/controllers/challenges_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 3782468d4..5503dfe63 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -150,7 +150,7 @@ class ChallengesController < ApplicationController uid_logger("identifier: #{params}") # 通过调试发现 这里includes(:games)性能会慢10倍 # @challenges = @shixun.challenges.fields_for_list - @challenges = Challenge.fields_for_list.includes(:games).where("challenges.shixun_id" => @shixun.id) + @challenges = Challenge.fields_for_list.left_outer_joins(:games).where("challenges.shixun_id" => @shixun.id) # @challenges = Challenge.includes(:games).where("games.user_id" => 12).where(shixun_id: @shixun.id) From c8bfb0b4c1a92f572b601eb68ee2c10001a954e8 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 28 Jun 2019 14:14:23 +0800 Subject: [PATCH 19/19] .. --- app/controllers/challenges_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 5503dfe63..b821929d6 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -150,7 +150,7 @@ class ChallengesController < ApplicationController uid_logger("identifier: #{params}") # 通过调试发现 这里includes(:games)性能会慢10倍 # @challenges = @shixun.challenges.fields_for_list - @challenges = Challenge.fields_for_list.left_outer_joins(:games).where("challenges.shixun_id" => @shixun.id) + @challenges = Challenge.fields_for_list.where(shixun_id: @shixun.id) # @challenges = Challenge.includes(:games).where("games.user_id" => 12).where(shixun_id: @shixun.id)