From 17527970fc1f1fb37fe0672fb343f9ff03f322fc Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 27 Jun 2019 09:16:22 +0800 Subject: [PATCH] =?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/homework_common.rb | 5 ++--- app/models/student_work.rb | 16 ++++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 9ed80e746..d55973ed8 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -78,8 +78,7 @@ class HomeworkCommon < ApplicationRecord # 根据是否统一发布获取作业的作品列表 def all_works student_works = self.unified_setting ? self.student_works : - self.student_works.joins("join course_members on student_works.user_id=course_members.user_id"). - where(course_members: {course_group_id: self.published_settings.pluck(:course_group_id)}) + self.student_works.joins("join course_members on student_works.user_id=course_members.user_id").where(course_members: {course_group_id: self.published_settings.pluck(:course_group_id)}) end # 分班权限的老师可见的作品列表 @@ -90,7 +89,7 @@ class HomeworkCommon < ApplicationRecord # 有分班权限的统计管理的分班且已发布的学生情况 if member.present? && teacher_course_groups.size > 0 group_ids = teacher_course_groups.pluck(:course_group_id) - all_student_works = all_student_works.joins("join course_members course_members on student_works.user_id=course_members.user_id"). + all_student_works = all_student_works.joins("join course_members on student_works.user_id=course_members.user_id"). where(course_members: {course_group_id: group_ids}) end all_student_works diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 8acc2e098..a2379f1a8 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -39,34 +39,34 @@ class StudentWork < ApplicationRecord # 助教评分次数 def ta_comment_count - self.student_works_scores.where(reviewer_role: 2).group_by(&:user_id).count + self.student_works_scores.select{|score| score.reviewer_role == 2}.group_by(&:user_id).count end # 匿评次数 def student_comment_num - homework_common.homework_detail_manual.comment_status > 2 ? self.student_works_scores.where(reviewer_role: 3).group_by(&:user_id).count : 0 + homework_common.homework_detail_manual.comment_status > 2 ? self.student_works_scores.select{|score| score.reviewer_role == 3}.group_by(&:user_id).count : 0 end # 匿评申诉总条数 def appeal_all_count - homework_common.homework_detail_manual.comment_status >= 3 ? self.student_works_scores.where("reviewer_role = 3 and appeal_status != 0"). - group_by(&:user_id).count : 0 + homework_common.homework_detail_manual.comment_status >= 3 ? self.student_works_scores. + select{|score| score.reviewer_role == 3 && score.appeal_status != 0}.group_by(&:user_id).count : 0 end # 匿评申诉待处理条数 def appeal_deal_count - homework_common.homework_detail_manual.comment_status >= 3 ? self.student_works_scores.where("reviewer_role = 3 and appeal_status = 1"). - group_by(&:user_id).count : 0 + homework_common.homework_detail_manual.comment_status >= 3 ? self.student_works_scores. + select{|score| score.reviewer_role == 3 && score.appeal_status == 1}.group_by(&:user_id).count : 0 end # 当前用户该作品的匿评申诉总条数 def my_appeal_all_count user_id - student_works_scores.where("reviewer_role = 3 and appeal_status != 0 and user_id = #{user_id}").size + student_works_scores.select{|score| score.reviewer_role == 3 && score.appeal_status != 0 && score.user_id = user_id}.size end # 当前用户该作品的匿评申诉总条数 def my_appeal_deal_count user_id - student_works_scores.where("reviewer_role = 3 and appeal_status = 1 and user_id = #{user_id}").size + student_works_scores.select{|score| score.reviewer_role == 3 && score.appeal_status == 1 && score.user_id = user_id}.size end # 分组名