|
|
@ -13,7 +13,7 @@ class Subjects::CourseUsedInfoService < ApplicationService
|
|
|
|
.where(homework_commons_shixuns: {shixun_id: @shixun_ids})
|
|
|
|
.where(homework_commons_shixuns: {shixun_id: @shixun_ids})
|
|
|
|
course_ids = homework_commons.pluck(:course_id)
|
|
|
|
course_ids = homework_commons.pluck(:course_id)
|
|
|
|
homework_common_ids = homework_commons.pluck("homework_commons.id")
|
|
|
|
homework_common_ids = homework_commons.pluck("homework_commons.id")
|
|
|
|
schools = School.joins(courses: [:course_members, :homework_commons])
|
|
|
|
schools = School.joins(:courses).where(courses: {id: course_ids}).select("schools.*, count(courses.id) course_count")
|
|
|
|
|
|
|
|
|
|
|
|
# name:将该课程使用到课堂的单位
|
|
|
|
# name:将该课程使用到课堂的单位
|
|
|
|
# course_count: 将该课程使用到课堂的数量
|
|
|
|
# course_count: 将该课程使用到课堂的数量
|
|
|
@ -23,11 +23,11 @@ class Subjects::CourseUsedInfoService < ApplicationService
|
|
|
|
course_info =
|
|
|
|
course_info =
|
|
|
|
schools.map do |school|
|
|
|
|
schools.map do |school|
|
|
|
|
name = school.name
|
|
|
|
name = school.name
|
|
|
|
course_count = school.where(courses: {id: course_ids}).count
|
|
|
|
course_count = school.course_count
|
|
|
|
student_count = school.where(course_members: {role: 4}).select("course_members.user_id").distinct.size
|
|
|
|
student_count = school.courses.joins(:course_members).where(course_members: {role: 4, course_id: course_ids})
|
|
|
|
homework_commons = school.where(homework_commons: {id: homework_common_ids})
|
|
|
|
homework_commons = school.courses.joins(:homework_commons).where(homework_commons: {id: homework_common_ids})
|
|
|
|
.select("homework_commons.id")
|
|
|
|
.pluck("homework_commons.id")
|
|
|
|
choice_shixun_num = homework_commons.distinct.size
|
|
|
|
choice_shixun_num = homework_commons.uniq.size
|
|
|
|
choice_shixun_frequency = homework_commons.size
|
|
|
|
choice_shixun_frequency = homework_commons.size
|
|
|
|
{name: name, course_count: course_count, student_count: student_count, choice_shixun_num: choice_shixun_num,
|
|
|
|
{name: name, course_count: course_count, student_count: student_count, choice_shixun_num: choice_shixun_num,
|
|
|
|
choice_shixun_frequency: choice_shixun_frequency}
|
|
|
|
choice_shixun_frequency: choice_shixun_frequency}
|
|
|
|