From dbd1fa02bbb57919e04307dc95ea95240e2f96d9 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 18 Dec 2019 17:19:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=A6=E6=A0=A1=E7=BB=9F=E8=AE=A1=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E7=9A=84=E6=8E=A5=E5=8F=A3=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/colleges_controller.rb | 8 ++++-- .../colleges/course_statistics.json.jbuilder | 11 ++++++++ .../colleges/student_shixun.json.jbuilder | 10 +++++++ app/views/colleges/teachers.json.jbuilder | 11 ++++++++ config/routes.rb | 26 +++++++++---------- 5 files changed, 51 insertions(+), 15 deletions(-) create mode 100644 app/views/colleges/course_statistics.json.jbuilder create mode 100644 app/views/colleges/student_shixun.json.jbuilder create mode 100644 app/views/colleges/teachers.json.jbuilder diff --git a/app/controllers/colleges_controller.rb b/app/controllers/colleges_controller.rb index 4c33ad5e5..71009d2dd 100644 --- a/app/controllers/colleges_controller.rb +++ b/app/controllers/colleges_controller.rb @@ -1,7 +1,7 @@ class CollegesController < ApplicationController include PaginateHelper - layout 'college' + # layout 'college' before_action :require_login before_action :check_college_present! @@ -21,6 +21,7 @@ class CollegesController < ApplicationController # 实训总数 @shixuns_count = Shixun.visible.joins('left join user_extensions on user_extensions.user_id = shixuns.user_id') .where(user_extensions: { school_id: current_school.id }).count + render json: { teachers_count: @teachers_count, students_count: @students_count, courses_count: @courses_count, shixuns_count: @shixuns_count } end def shixun_time @@ -43,6 +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 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) + @teacher_count = UserExtension.where(school_id: current_school.id) + .select('SUM(IF(identity=0, 1, 0)) AS teachers_count').first.teachers_count @teachers = @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}") @@ -94,11 +97,11 @@ class CollegesController < ApplicationController def course_statistics courses = Course.where(school_id: current_school.id, is_delete: 0).where.not(id: 1309) + @course_count = courses.size courses = courses.left_joins(practice_homeworks: { student_works: { myshixun: :games } }) .select('courses.id, courses.name, courses.is_end, sum(games.evaluate_count) evaluating_count') .group('courses.id').order('is_end asc, evaluating_count desc') - params[:per_page] = 8 @courses = paginate courses course_ids = @courses.map(&:id) @@ -114,6 +117,7 @@ class CollegesController < ApplicationController # 学生实训 def student_shixun + @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) student_ids = @students.map(&:id) diff --git a/app/views/colleges/course_statistics.json.jbuilder b/app/views/colleges/course_statistics.json.jbuilder new file mode 100644 index 000000000..fcc83177a --- /dev/null +++ b/app/views/colleges/course_statistics.json.jbuilder @@ -0,0 +1,11 @@ +json.courses @courses do |course| + json.(course, :id, :name, :is_end, :evaluating_count) + json.teachers course.teacher_users.map(&:real_name).join('、') + json.student_count @student_count.fetch(course.id, 0) + json.shixun_work_count @shixun_work_count.fetch(course.id, 0) + json.attachment_count @attachment_count.fetch(course.id, 0) + json.message_count @message_count.fetch(course.id, 0) + json.other_work_count @exercise_count.fetch(course.id, 0) + @poll_count.fetch(course.id, 0) + @other_work_count.fetch(course.id, 0) + json.activity_time @active_time[course.id]&.strftime('%Y-%m-%d %H:%M') +end +json.course_count @course_count \ No newline at end of file diff --git a/app/views/colleges/student_shixun.json.jbuilder b/app/views/colleges/student_shixun.json.jbuilder new file mode 100644 index 000000000..431603afa --- /dev/null +++ b/app/views/colleges/student_shixun.json.jbuilder @@ -0,0 +1,10 @@ +json.teachers @students do |student| + json.login student.login + json.name student.real_name + json.student_id student.student_id + json.shixun_count @shixun_count.fetch(student.id, 0) + json.study_shixun_count @study_shixun_count.fetch(student.id, 0) + json.grade student.grade + json.experience student.experience +end +json.student_count @student_count \ No newline at end of file diff --git a/app/views/colleges/teachers.json.jbuilder b/app/views/colleges/teachers.json.jbuilder new file mode 100644 index 000000000..29b383fa4 --- /dev/null +++ b/app/views/colleges/teachers.json.jbuilder @@ -0,0 +1,11 @@ +json.teachers @teachers do |teacher| + json.login teacher['login'] + json.name teacher['real_name'] + json.course_count teacher['course_count'] + json.shixun_work_count teacher['shixun_work_count'] + json.un_shixun_work_count teacher['un_shixun_work_count'] + json.student_count teacher['student_count'] + json.complete_rate teacher['complete_rate'] + json.publish_shixun_count teacher['publish_shixun_count'] +end +json.teacher_count @teacher_count \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 2ef60b45f..e15b216ce 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -977,6 +977,19 @@ Rails.application.routes.draw do post :entry end end + + resources :colleges, only: [] do + member do + get :statistics + get :course_statistics + get :student_shixun + get :shixun_time + get :shixun_report_count + get :teachers + get :shixun_chart_data + get :student_hot_evaluations + end + end end namespace :admins do @@ -1287,19 +1300,6 @@ Rails.application.routes.draw do end end - resources :colleges, only: [] do - member do - get :statistics - get :course_statistics - get :student_shixun - get :shixun_time - get :shixun_report_count - get :teachers - get :shixun_chart_data - get :student_hot_evaluations - end - end - resources :partners, only: [] do member do get :customers