From 870952ecda289510032e0b837f79d53b1edea760 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 26 Jun 2019 11:20:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E5=93=81=E5=88=97=E8=A1=A8=E7=9A=84?= =?UTF-8?q?=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homework_commons_controller.rb | 4 ++-- app/helpers/homework_commons_helper.rb | 12 +++++----- app/models/homework_common.rb | 24 +++++++++---------- .../homework_commons/index.json.jbuilder | 4 ++-- .../homework_commons/works_list.json.jbuilder | 6 ++--- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 58e68dfce..e58484941 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -89,7 +89,7 @@ class HomeworkCommonsController < ApplicationController @homework_commons = @homework_commons.page(page).per(15) if @homework_type == 4 - @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :shixuns) + @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :shixuns, :student_works) elsif @homework_type == 3 @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :homework_detail_group) else @@ -134,7 +134,7 @@ class HomeworkCommonsController < ApplicationController @student_works = [] end elsif @user_course_identity < Course::STUDENT - @student_works = @homework.teacher_works(@current_user.id) + @student_works = @homework.teacher_works(@member) @all_member_count = @student_works.count elsif @user_course_identity > Course::STUDENT && @homework.work_public @student_works = student_works diff --git a/app/helpers/homework_commons_helper.rb b/app/helpers/homework_commons_helper.rb index 0d166729c..2d3827fac 100644 --- a/app/helpers/homework_commons_helper.rb +++ b/app/helpers/homework_commons_helper.rb @@ -174,8 +174,8 @@ module HomeworkCommonsHelper end # 作品数统计:type: 1 已提交 0 未提交 - def studentwork_count homework_common, type, user_id - student_works = homework_common.teacher_works(user_id) + def studentwork_count homework_common, type, member + student_works = homework_common.teacher_works(member) type == 1 ? student_works.select{|work| work.work_status != 0}.size : student_works.select{|work| work.work_status = 0}.size end @@ -223,10 +223,10 @@ module HomeworkCommonsHelper end # 作品状态 - def homework_status homework, user_id - [{id: 0, name: "未提交", count: homework.unfinished_count(user_id)}, - {id: 1, name: "按时提交", count: homework.finished_count(user_id)}, - {id: 2, name: "延时提交", count: homework.delay_finished_count(user_id)}] + def homework_status homework, member + [{id: 0, name: "未提交", count: homework.unfinished_count(member)}, + {id: 1, name: "按时提交", count: homework.finished_count(member)}, + {id: 2, name: "延时提交", count: homework.delay_finished_count(member)}] end # 作品分数的显示 diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index c3bfd2dd9..6a117eff1 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -78,20 +78,20 @@ class HomeworkCommon < ApplicationRecord # 根据是否统一发布获取作业的作品列表 def all_works student_works = self.unified_setting ? self.student_works : - self.student_works.where(user_id: self.course.students.where( - course_group_id: self.published_settings.pluck(:course_group_id)). - pluck(:user_id)) + self.student_works.joins("join course_members cm on student_works.user_id=cm.user_id"). + where(course_members: {course_group_id: self.published_settings.pluck(:course_group_id)}) end # 分班权限的老师可见的作品列表 - def teacher_works user_id - member = course.course_member(user_id) + def teacher_works member + # member = course.course_member(user_id) teacher_course_groups = member.try(:teacher_course_groups) all_student_works = self.all_works # 有分班权限的统计管理的分班且已发布的学生情况 if member.present? && teacher_course_groups.size > 0 group_ids = teacher_course_groups.pluck(:course_group_id) - all_student_works = all_student_works.where(user_id: course.students.where(course_group_id: group_ids).pluck(:user_id)) + all_student_works = all_student_works.joins("join course_members cm on student_works.user_id=cm.user_id"). + where(course_members: {course_group_id: group_ids}) end all_student_works end @@ -216,17 +216,17 @@ class HomeworkCommon < ApplicationRecord end # 作品未提交数 - def unfinished_count user_id - self.teacher_works(user_id).unfinished.count + def unfinished_count member + self.teacher_works(member).unfinished.count end # 任务按时提交数 - def finished_count user_id - self.teacher_works(user_id).finished.count + def finished_count member + self.teacher_works(member).finished.count end - def delay_finished_count user_id - self.teacher_works(user_id).delay_finished.count + def delay_finished_count member + self.teacher_works(member).delay_finished.count end # 分组作业的最大分组id diff --git a/app/views/homework_commons/index.json.jbuilder b/app/views/homework_commons/index.json.jbuilder index 262d4d92d..d718550c1 100644 --- a/app/views/homework_commons/index.json.jbuilder +++ b/app/views/homework_commons/index.json.jbuilder @@ -23,8 +23,8 @@ json.homeworks @homework_commons.each do |homework| json.allow_late homework.allow_late unless curr_status[:status].include?("未发布") - json.commit_count studentwork_count homework, 1, @user.id - json.uncommit_count studentwork_count homework, 0, @user.id + json.commit_count studentwork_count homework, 1, @member + json.uncommit_count studentwork_count homework, 0, @member end if @user_course_identity < Course::STUDENT diff --git a/app/views/homework_commons/works_list.json.jbuilder b/app/views/homework_commons/works_list.json.jbuilder index a1618d8ff..0c1ed0c5b 100644 --- a/app/views/homework_commons/works_list.json.jbuilder +++ b/app/views/homework_commons/works_list.json.jbuilder @@ -20,12 +20,12 @@ if @user_course_identity < Course::STUDENT if @homework.homework_type != "practice" json.teacher_comment teacher_comment @homework, @current_user.id end - json.task_status homework_status @homework, @current_user.id + json.task_status homework_status @homework, @member json.course_group_info course_group_info @course, @current_user.id elsif @user_course_identity == Course::STUDENT - json.commit_count studentwork_count @homework, 1, @current_user.id - json.uncommit_count studentwork_count @homework, 0, @current_user.id + json.commit_count studentwork_count @homework, 1, @member + json.uncommit_count studentwork_count @homework, 0, @member json.left_time left_time @homework, @current_user.id if @homework.homework_type == "practice"