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(",")}) ) ) }