From ddc67bc14f08e21e53ac51310cb7cbcb0662179c Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 9 Jul 2019 14:03:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E4=BD=9C=E5=93=81=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E7=9A=84=E5=B7=B2=E8=AF=84=E6=95=B0=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/course.rb | 2 +- app/models/graduation_task.rb | 12 ++++++------ app/models/homework_common.rb | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/models/course.rb b/app/models/course.rb index d36d5d2c5..06090f236 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -258,7 +258,7 @@ class Course < ApplicationRecord # 是否具有分班权限,返回分班的id def group_course_power(user_id) - teacher_course_groups.where(user_id: user_id).pluck(:id) + teacher_course_groups.where(user_id: user_id).pluck(:course_group_id) end #课程动态公共表记录 diff --git a/app/models/graduation_task.rb b/app/models/graduation_task.rb index 030978817..e247f2b6e 100644 --- a/app/models/graduation_task.rb +++ b/app/models/graduation_task.rb @@ -100,15 +100,15 @@ class GraduationTask < ApplicationRecord SELECT count(distinct graduation_work_id) cnt FROM graduation_work_scores WHERE reviewer_role IN(1,2) AND graduation_work_id IN(SELECT id FROM graduation_works WHERE graduation_task_id = #{self.id} AND user_id IN(SELECT user_id FROM course_members WHERE role = 4 AND course_group_id - IN(SELECT course_group_id FROM teacher_course_groups WHERE id IN(#{course_group_ids.join(",")})) + IN(#{course_group_ids.join(",")}) ) ) } else %Q{ SELECT COUNT(distinct graduation_work_id) cnt FROM graduation_works gw - JOIN graduation_work_scores gwc ON gw.graduation_task_id = gwc.graduation_task_id - WHERE reviewer_role IN(1,2) AND gwc.graduation_task_id = #{self.id} + JOIN graduation_work_scores gwc ON gw.id = gwc.graduation_work_id + WHERE reviewer_role IN(1,2) AND gw.graduation_task_id = #{self.id} } end GraduationWorkScore.find_by_sql(sql).first.try(:cnt).to_i @@ -127,7 +127,7 @@ class GraduationTask < ApplicationRecord sql = %Q{ SELECT count(*) cnt FROM graduation_works gw WHERE work_status = 0 AND gw.graduation_task_id = #{self.id} AND gw.user_id IN( SELECT user_id FROM course_members WHERE role = 4 AND course_group_id - IN( SELECT course_group_id FROM teacher_course_groups WHERE id not IN(#{course_group_ids.join(",")}) ) + IN(#{course_group_ids.join(",")}) ) } GraduationWork.find_by_sql(sql).first.try(:cnt) @@ -144,7 +144,7 @@ class GraduationTask < ApplicationRecord sql = %Q{ SELECT count(*) cnt FROM graduation_works gw WHERE work_status = 1 AND gw.graduation_task_id = #{self.id} AND gw.user_id IN( SELECT user_id FROM course_members WHERE role = 4 AND course_group_id - IN( SELECT course_group_id FROM teacher_course_groups WHERE id IN(#{course_group_ids.join(",")}) ) + IN(#{course_group_ids.join(",")}) ) } GraduationWork.find_by_sql(sql).first.try(:cnt) @@ -160,7 +160,7 @@ class GraduationTask < ApplicationRecord sql = %Q{ SELECT count(*) cnt FROM graduation_works gw WHERE work_status = 2 AND gw.graduation_task_id = #{self.id} AND gw.user_id IN( SELECT user_id FROM course_members WHERE role = 4 AND course_group_id - IN( SELECT course_group_id FROM teacher_course_groups WHERE id IN(#{course_group_ids.join(",")}) ) + IN(#{course_group_ids.join(",")}) ) } GraduationWork.find_by_sql(sql).first.try(:cnt) diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 80b92d175..335b898fb 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -197,7 +197,7 @@ class HomeworkCommon < ApplicationRecord JOIN student_works_scores sws on sws.student_work_id = sw.id WHERE reviewer_role IN(1,2) AND sw.id IN (SELECT id FROM student_works WHERE homework_common_id = #{self.id} AND user_id IN (SELECT user_id FROM course_members WHERE role = 4 AND course_group_id - IN (SELECT course_group_id FROM teacher_course_groups WHERE id IN(#{course_group_ids.join(",")})) + IN (#{course_group_ids.join(",")}) ) ) }