学校统计页面接口调整

chromesetting
cxt 5 years ago
parent 6eb5e56382
commit 9c3bff5e9f

@ -44,8 +44,8 @@ class CollegesController < ApplicationController
(SELECT count(c.id) FROM courses c, course_members m WHERE c.id != 1309 and m.course_id = c.id AND m.user_id=users.id AND m.role in (1,2,3) and c.school_id = #{current_school.id} AND c.is_delete = 0) as course_count (SELECT count(c.id) FROM courses c, course_members m WHERE c.id != 1309 and m.course_id = c.id AND m.user_id=users.id AND m.role in (1,2,3) and c.school_id = #{current_school.id} AND c.is_delete = 0) as course_count
FROM `users`, user_extensions ue where ue.school_id=#{current_school.id} and users.id=ue.user_id and ue.identity=0 ORDER BY publish_shixun_count desc, course_count desc, id desc LIMIT 10") FROM `users`, user_extensions ue where ue.school_id=#{current_school.id} and users.id=ue.user_id and ue.identity=0 ORDER BY publish_shixun_count desc, course_count desc, id desc LIMIT 10")
# ).order("publish_shixun_count desc, experience desc").limit(10) # ).order("publish_shixun_count desc, experience desc").limit(10)
@teacher_count = UserExtension.where(school_id: current_school.id) # @teacher_count = UserExtension.where(school_id: current_school.id)
.select('SUM(IF(identity=0, 1, 0)) AS teachers_count').first.teachers_count # .select('SUM(IF(identity=0, 1, 0)) AS teachers_count').first.teachers_count
@teachers = @teachers =
@teachers.map do |teacher| @teachers.map do |teacher|
course_ids = Course.find_by_sql("SELECT c.id FROM courses c, course_members m WHERE c.id != 1309 and m.course_id = c.id AND m.role in (1,2,3) AND m.user_id=#{teacher.id} AND c.is_delete = 0 and c.school_id = #{current_school.id}") course_ids = Course.find_by_sql("SELECT c.id FROM courses c, course_members m WHERE c.id != 1309 and m.course_id = c.id AND m.role in (1,2,3) AND m.user_id=#{teacher.id} AND c.is_delete = 0 and c.school_id = #{current_school.id}")
@ -99,7 +99,7 @@ class CollegesController < ApplicationController
@course_count = courses.size @course_count = courses.size
courses = courses.left_joins(practice_homeworks: { student_works: { myshixun: :games } }) courses = courses.left_joins(practice_homeworks: { student_works: { myshixun: :games } })
.select('courses.id, courses.name, courses.is_end, sum(games.evaluate_count) evaluating_count') .select('courses.id, courses.name, courses.is_end, IFNULL(sum(games.evaluate_count), 0) evaluating_count')
.group('courses.id').order('is_end asc, evaluating_count desc') .group('courses.id').order('is_end asc, evaluating_count desc')
@courses = paginate courses @courses = paginate courses
@ -117,7 +117,7 @@ class CollegesController < ApplicationController
# 学生实训 # 学生实训
def student_shixun def student_shixun
@student_count = User.joins(:user_extension).where(user_extensions: { school_id: current_school.id, identity: 1 }).count # @student_count = User.joins(:user_extension).where(user_extensions: { school_id: current_school.id, identity: 1 }).count
@students = User.joins(:user_extension).where(user_extensions: { school_id: current_school.id, identity: 1 }).includes(:user_extension).order('experience desc').limit(10) @students = User.joins(:user_extension).where(user_extensions: { school_id: current_school.id, identity: 1 }).includes(:user_extension).order('experience desc').limit(10)
student_ids = @students.map(&:id) student_ids = @students.map(&:id)

@ -7,4 +7,4 @@ json.teachers @students do |student|
json.grade student.grade json.grade student.grade
json.experience student.experience json.experience student.experience
end end
json.student_count @student_count # json.student_count @student_count

@ -8,4 +8,4 @@ json.teachers @teachers do |teacher|
json.complete_rate teacher['complete_rate'] json.complete_rate teacher['complete_rate']
json.publish_shixun_count teacher['publish_shixun_count'] json.publish_shixun_count teacher['publish_shixun_count']
end end
json.teacher_count @teacher_count # json.teacher_count @teacher_count
Loading…
Cancel
Save