diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 88ed373d9..1039a648a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -27,6 +27,12 @@ module ApplicationHelper sanitize content, tags: tags, attributes: attributes end + # MD5加密 + def base64_encode(content) + return nil if content.blank? + Base64.encode64(content) + end + def graduation_navigation graduation graduation.class.to_s == "GraduationTopic" ? "毕设选题" : "毕设任务" end diff --git a/app/jobs/statistic_studentwork_job.rb b/app/jobs/statistic_studentwork_job.rb new file mode 100644 index 000000000..039ba7810 --- /dev/null +++ b/app/jobs/statistic_studentwork_job.rb @@ -0,0 +1,18 @@ +class StatisticStudentworkJob < ApplicationJob + queue_as :default + + def perform(*args) + School.find_in_batches(batch_size: 50) do |school| + Parallel.each_with_index(school, in_processes: 5) do |s| + student_work = StudentWork.find_by_sql("SELECT count(*) AS count + FROM student_works + JOIN user_extensions AS u ON u.user_id = student_works.user_id AND u.school_id = #{s.id}") + + report = SchoolReport.find_or_initialize_by(school_id: s.id) + report.school_name = s.name + report.student_work_count = student_work.first['count'] + report.save + end + end + end +end diff --git a/app/services/admins/school_base_statistic_service.rb b/app/services/admins/school_base_statistic_service.rb index cbad5d45a..24bf1380f 100644 --- a/app/services/admins/school_base_statistic_service.rb +++ b/app/services/admins/school_base_statistic_service.rb @@ -4,8 +4,8 @@ class Admins::SchoolBaseStatisticService < ApplicationService attr_reader :params sort_columns :student_count, :teacher_count, :course_count, :course_group_count, - :attachment_count, :video_count, :normal_work_count, :shixun_work_count, :evaluate_count, - :student_work_count, :exercise_count, default_direction: :desc + :attachment_count, :video_count, :normal_work_count, :shixun_work_count, :shixun_evaluate_count, + :student_works_num, :exercise_count, default_direction: :desc def initialize(params) @params = params @@ -22,7 +22,6 @@ class Admins::SchoolBaseStatisticService < ApplicationService count = schools.count.count # 根据排序字段进行查询 schools = query_by_sort_column(schools, params[:sort_by]) - schools.reorder("#{ params[:sort_by] != 0} desc") schools = custom_sort(schools, params[:sort_by], params[:sort_direction]) schools = schools.limit(page_size).offset(offset) @@ -33,25 +32,23 @@ class Admins::SchoolBaseStatisticService < ApplicationService def package_other_data(schools) ids = schools.map(&:id) - student_count = CourseMember.course_students.joins(course: :school).group(:school_id).where("role= 'STUDENT' AND courses.is_delete = false AND schools.id in (?)", ids).count("distinct user_id") + student_count = UserExtension.where(school_id: ids, identity: :student).group(:school_id).count teachers = UserExtension.where(school_id: ids, identity: :teacher).group(:school_id) teacher_count = teachers.count courses = Course.where(is_delete: 0, school_id: ids).group(:school_id) course_count= courses.count course_group_count = courses.joins(:course_groups).count attachment_count = courses.joins(:attachments).count - video_count = teachers.joins(user: :videos).where("videos.delete_state IS NOT NULL").count + video_count = teachers.joins(user: :videos).where("videos.delete_state IS NULL").count - homeworks = HomeworkCommon.joins(:course).where(courses: { school_id: ids }).where("courses.is_delete = false") + homeworks = HomeworkCommon.joins("JOIN user_extensions ON homework_commons.user_id = user_extensions.user_id").where(user_extensions: {school_id: ids}) shixun_work_count = homeworks.where(homework_type: 4).group(:school_id).count normal_work_count = homeworks.where(homework_type: 1).group(:school_id).count - student_work_count = homeworks.joins(:student_works).group(:school_id).count - evaluate_count = EvaluateRecord.unscoped.joins('JOIN homework_commons_shixuns hcs ON hcs.shixun_id = evaluate_records.shixun_id - JOIN homework_commons hc ON hcs.homework_common_id = hc.id AND hc.homework_type = 4 - JOIN course_members ON course_members.user_id = evaluate_records.user_id - JOIN courses ON course_members.course_id = courses.id AND hc.course_id = courses.id') - .where(courses: { school_id: ids }) - .group(:school_id).count + + reports = SchoolReport.where(school_id: ids) + evaluate_count = reports.each_with_object({}) { |report, obj| obj[report.school_id] = report.shixun_evaluate_count } + student_work_count = reports.each_with_object({}) { |report, obj| obj[report.school_id] = report.student_work_count } + exercise_count = Exercise.joins(:course).where(courses: { school_id: ids }).group(:school_id).count schools.map do |school| @@ -67,7 +64,7 @@ class Admins::SchoolBaseStatisticService < ApplicationService normal_work_count: normal_work_count[school.id], shixun_work_count: shixun_work_count[school.id], student_work_count: student_work_count[school.id], - evaluate_count: evaluate_count[school.id], + shixun_evaluate_count: evaluate_count[school.id], exercise_count: exercise_count[school.id] } end @@ -82,9 +79,8 @@ class Admins::SchoolBaseStatisticService < ApplicationService schools.joins('LEFT JOIN user_extensions ue ON ue.school_id = schools.id AND ue.identity = 0') .select("#{base_query_column}, COUNT(*) teacher_count") when 'student_count' then - schools.joins("LEFT JOIN courses ue ON ue.school_id = schools.id AND ue.is_delete = FALSE - LEFT JOIN course_members ON course_members.course_id = ue.id AND course_members.role = 'STUDENT'") - .select("#{base_query_column}, COUNT(distinct user_id) student_count") + schools.joins('LEFT JOIN user_extensions ue ON ue.school_id = schools.id AND ue.identity = 1') + .select("#{base_query_column}, COUNT(*) student_count") when 'course_count' then schools.joins('LEFT JOIN courses ON courses.school_id = schools.id AND courses.is_delete = false') .select("#{base_query_column}, COUNT(*) course_count") @@ -101,26 +97,19 @@ class Admins::SchoolBaseStatisticService < ApplicationService LEFT JOIN videos ON videos.user_id = ue.user_id AND videos.delete_state IS NOT NULL") .select("#{base_query_column}, COUNT(*) video_count") when 'normal_work_count' then - schools.joins("LEFT JOIN courses ON courses.school_id = schools.id - LEFT JOIN homework_commons ON homework_commons.course_id = courses.id AND homework_commons.homework_type = 0") + schools.joins("LEFT JOIN user_extensions ON user_extensions.school_id = schools.id + LEFT JOIN homework_commons ON homework_commons.user_id = user_extensions.user_id AND homework_commons.homework_type = 0") .select("#{base_query_column}, COUNT(*) normal_work_count") when 'shixun_work_count' then - schools.joins("LEFT JOIN courses ON courses.school_id = schools.id - LEFT JOIN homework_commons ON homework_commons.course_id = courses.id AND homework_commons.homework_type = 4") + schools.joins("LEFT JOIN user_extensions ON user_extensions.school_id = schools.id + LEFT JOIN homework_commons ON homework_commons.user_id = user_extensions.user_id AND homework_commons.homework_type = 4") .select("#{base_query_column}, COUNT(*) shixun_work_count") when 'student_work_count' then - schools.joins("LEFT JOIN courses ON courses.school_id = schools.id - LEFT JOIN homework_commons ON homework_commons.course_id = courses.id - LEFT JOIN student_works ON student_works.homework_common_id = homework_commons.id") + schools.joins("LEFT JOIN school_reports ON school_reports.school_id = schools.id") .select("#{base_query_column}, COUNT(*) student_work_count") - when 'evaluate_count' then - schools.joins(' - LEFT JOIN courses ON courses.school_id = schools.id AND courses.is_delete = false - LEFT JOIN course_members ON course_members.course_id = courses.id - LEFT JOIN evaluate_records ON course_members.user_id = evaluate_records.user_id - LEFT JOIN homework_commons_shixuns hcs ON hcs.shixun_id = evaluate_records.shixun_id - LEFT JOIN homework_commons hc ON hcs.homework_common_id = hc.id AND hc.homework_type = 4') - .select("#{base_query_column}, COUNT(*) evaluate_count") + when 'shixun_evaluate_count' then + schools.joins('LEFT JOIN school_reports ON school_reports.school_id = schools.id') + .select("#{base_query_column}, COUNT(*) shixun_evaluate_count") when 'exercise_count' then schools.joins('LEFT JOIN courses cs ON cs.school_id = schools.id AND cs.is_delete = 0 LEFT JOIN exercises ON exercises.course_id = cs.id') diff --git a/app/views/admins/school_base_statistics/_list.html.erb b/app/views/admins/school_base_statistics/_list.html.erb index aab91f5c7..c1d8fbee0 100644 --- a/app/views/admins/school_base_statistics/_list.html.erb +++ b/app/views/admins/school_base_statistics/_list.html.erb @@ -12,7 +12,7 @@ <%= sort_tag('普通作业', name: 'normal_work_count', path: admins_school_base_statistics_path) %> <%= sort_tag('实训作业', name: 'shixun_work_count', path: admins_school_base_statistics_path) %> <%= sort_tag('作业文件', name: 'student_work_count', path: admins_school_base_statistics_path) %> - <%= sort_tag('评测次数', name: 'evaluate_count', path: admins_school_base_statistics_path) %> + <%= sort_tag('评测次数', name: 'shixun_evaluate_count', path: admins_school_base_statistics_path) %> <%= sort_tag('在线试卷', name: 'exercise_count', path: admins_school_base_statistics_path) %> @@ -34,7 +34,7 @@ <%= statistic[:normal_work_count].to_i %> <%= statistic[:shixun_work_count].to_i %> <%= statistic[:student_work_count].to_i %> - <%= statistic[:evaluate_count].to_i %> + <%= statistic[:shixun_evaluate_count].to_i %> <%= statistic[:exercise_count].to_i %> diff --git a/app/views/homework_commons/publish_groups.json.jbuilder b/app/views/homework_commons/publish_groups.json.jbuilder index b77d14fe7..b0ba5b2d3 100644 --- a/app/views/homework_commons/publish_groups.json.jbuilder +++ b/app/views/homework_commons/publish_groups.json.jbuilder @@ -1,7 +1,7 @@ json.course_groups @course_groups do |group| json.id group.id json.name group.name - json.end_time @group_settings.select{|group_setting| group_setting.course_group_id == group.id}.first&.end_time + json.end_time @homework.unified_setting ? @homework.end_time : @group_settings.select{|group_setting| group_setting.course_group_id == group.id}.first&.end_time end json.end_time @homework.end_time json.late_time @homework.late_time \ No newline at end of file diff --git a/app/views/users/videos/_video.json.jbuilder b/app/views/users/videos/_video.json.jbuilder index 5b0bc7a6e..ac030ce12 100644 --- a/app/views/users/videos/_video.json.jbuilder +++ b/app/views/users/videos/_video.json.jbuilder @@ -1,4 +1,6 @@ json.extract! video, :id, :title, :cover_url, :file_url, :play_url, :vv, :user_id, :transcoded +json.play_url base64_encode(video.play_url) +json.file_url base64_encode(video.file_url) json.play_duration video.video_play_duration json.published_at video.display_published_at json.created_at video.display_created_at diff --git a/db/migrate/20200325091127_add_statistic_to_school_report.rb b/db/migrate/20200325091127_add_statistic_to_school_report.rb new file mode 100644 index 000000000..e2b7a9311 --- /dev/null +++ b/db/migrate/20200325091127_add_statistic_to_school_report.rb @@ -0,0 +1,5 @@ +class AddStatisticToSchoolReport < ActiveRecord::Migration[5.2] + def change + add_column :school_reports, :student_work_count, :integer, default: 0 + end +end diff --git a/lib/tasks/sync_student_work.rake b/lib/tasks/sync_student_work.rake new file mode 100644 index 000000000..f38fa1beb --- /dev/null +++ b/lib/tasks/sync_student_work.rake @@ -0,0 +1,7 @@ +desc "同步学院或者单位学生作业数" + +namespace :sync_student_work do + task outpus_count: :environment do + StatisticStudentworkJob.perform_later + end +end \ No newline at end of file diff --git a/public/react/src/modules/courses/Resource/index.js b/public/react/src/modules/courses/Resource/index.js index 4f12bce66..c96ba7abd 100644 --- a/public/react/src/modules/courses/Resource/index.js +++ b/public/react/src/modules/courses/Resource/index.js @@ -1011,7 +1011,7 @@ class Fileslists extends Component{ :"":""} {this.props.isAdmin()?
  • - 移动到... + 移动到目录