From 77cee20dc65f1ec54e14a23d43efd7fd026feab5 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 28 Jun 2019 11:27:54 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 24 ++++++++++++------------ app/models/exercise.rb | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 10332752..2175aa3e 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -2437,8 +2437,8 @@ class CoursesController < ApplicationController sheet1[count_row,column+=1] = member.course_group_id == 0 ? "暂无" : member.course_group.name # current_col = 5 shixun_score = 0 - homeworks.where(:homework_type => 4).includes(:student_works).each do |homework| - student_works = homework.student_works.where("user_id = #{member.user.id}") + homeworks.where(:homework_type => 4).includes(:score_student_works).each do |homework| + student_works = homework.score_student_works.select{|work| work.user_id == member.user.id} if student_works.empty? sheet1[count_row,column+=1] = 0 else @@ -2449,8 +2449,8 @@ class CoursesController < ApplicationController # current_col += 1 end common_score = 0 - homeworks.where(:homework_type => 1).includes(:student_works).each do |homework| - student_works = homework.student_works.where("user_id = #{member.user.id}") + homeworks.where(:homework_type => 1).includes(:score_student_works).each do |homework| + student_works = homework.score_student_works.select{|work| work.user_id == member.user.id} if student_works.empty? sheet1[count_row,column+=1] = 0 else @@ -2461,8 +2461,8 @@ class CoursesController < ApplicationController # current_col += 1 end group_score = 0 - homeworks.where(:homework_type => 3).includes(:student_works).each do |homework| - student_works = homework.student_works.where("user_id = #{member.user.id}") + homeworks.where(:homework_type => 3).includes(:score_student_works).each do |homework| + student_works = homework.score_student_works.select{|work| work.user_id == member.user.id} if student_works.empty? sheet1[count_row,column+=1] = 0 else @@ -2473,8 +2473,8 @@ class CoursesController < ApplicationController # current_col += 1 end exercise_score = 0 - exercises.includes(:exercise_users).each do |exercise| - exercise_user = exercise.exercise_users.where("user_id = #{member.user.id}") + exercises.includes(:score_exercise_users).each do |exercise| + exercise_user = exercise.score_exercise_users.select{|work| work.user_id == member.user.id} if exercise_user.empty? sheet1[count_row,column+=1] = 0 else @@ -2562,7 +2562,7 @@ class CoursesController < ApplicationController count_row += 1 end - homeworks.where(:homework_type => 4).includes(:score_student_works).each_with_index do |home, i| + homeworks.where(:homework_type => 4).each_with_index do |home, i| sheet = book.create_worksheet :name => "#{home.name}" sheet[0,0] = "课程编号" sheet[0,1] = course.id @@ -2596,7 +2596,7 @@ class CoursesController < ApplicationController end end - homeworks.where(:homework_type => 1).includes(:score_student_works).each_with_index do |home, i| + homeworks.where(:homework_type => 1).each_with_index do |home, i| sheet = book.create_worksheet :name => "普通作业第#{i+1}次" sheet[0,0] = "课程编号" sheet[0,1] = course.id @@ -2643,7 +2643,7 @@ class CoursesController < ApplicationController end - homeworks.where(:homework_type => 3).includes(:score_student_works).each_with_index do |home, i| + homeworks.where(:homework_type => 3).each_with_index do |home, i| sheet = book.create_worksheet :name => "分组作业第#{i+1}次" sheet[0,0] = "课程编号" sheet[0,1] = course.id @@ -2691,7 +2691,7 @@ class CoursesController < ApplicationController end end - exercises.includes(:score_exercise_users).each_with_index do |exercise, i| + exercises.each_with_index do |exercise, i| sheet = book.create_worksheet :name => "试卷第#{i+1}次" sheet[0,0] = "课程编号" sheet[0,1] = course.id diff --git a/app/models/exercise.rb b/app/models/exercise.rb index f82b6047..cb65c5ce 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -7,7 +7,7 @@ class Exercise < ActiveRecord::Base has_many :exercise_group_settings, :dependent => :destroy has_many :exercise_questions, :dependent => :destroy,:order => "#{ExerciseQuestion.table_name}.question_number" has_many :exercise_users, :dependent => :destroy, :conditions => "exercise_users.is_delete = 0" - has_many :score_exercise_users, :conditions => "exercise_users.is_delete = 0 and commit_status != 0", :order => "exercise_users.score desc" + has_many :score_exercise_users, :class_name => "ExerciseUser", :conditions => "exercise_users.is_delete = 0 and commit_status != 0", :order => "exercise_users.score desc" has_many :users, :through => :exercise_users #该测试被哪些用户提交答案过 has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy # 课程消息