学生列表导出成绩的优化

dev_forum
cxt 5 years ago
parent b1e13758d3
commit 178a448f54

@ -969,18 +969,13 @@ class CoursesController < ApplicationController
@all_members = @course.students @all_members = @course.students
end end
if name.present? if name.present?
nick_name_search = @all_members.joins(:user).where("nickname like ?","%#{name}%") @all_members = @all_members.joins(user: [:user_extension]).where('concat(users.lastname, users.firstname) like ? or user_extensions.student_id like ?',"%#{name}%","%#{name}%")
if nick_name_search.present?
@all_members = nick_name_search
else
@all_members = @all_members.joins(user: [:user_extension]).where('user_extensions.student_id like ? OR user_extensions.student_realname like ?',"%#{name}%","%#{name}%")
end
end end
@c_homeworks = @course.homework_commons.homework_published.order("publish_time asc, created_at asc") @c_homeworks = @course.homework_commons.homework_published.order("homework_commons.publish_time asc, homework_commons.created_at asc")
@c_exercises = @course.exercises.is_exercise_published.order("publish_time asc, created_at asc") @c_exercises = @course.exercises.is_exercise_published.order("exercises.publish_time asc, exercises.created_at asc")
@c_polls = @course.polls.publish_or_not.order("publish_time asc, created_at asc") @c_polls = @course.polls.publish_or_not.order("polls.publish_time asc, polls.created_at asc")
@c_tasks = @course.graduation_tasks.task_published.order("publish_time asc, created_at asc") @c_tasks = @course.graduation_tasks.task_published.order("graduation_tasks.publish_time asc, graduation_tasks.created_at asc")
if @user_course_identity > Course::ASSISTANT_PROFESSOR if @user_course_identity > Course::ASSISTANT_PROFESSOR
tip_exception(403,"无权限操作") tip_exception(403,"无权限操作")
else else
@ -1058,14 +1053,14 @@ class CoursesController < ApplicationController
def member_to_xlsx(course,all_members,homeworks,exercises,tasks,polls) def member_to_xlsx(course,all_members,homeworks,exercises,tasks,polls)
#课堂的作业信息 #课堂的作业信息
shixun_homeworks = homeworks.search_homework_type(4) #全部实训作业 shixun_homeworks = homeworks.search_homework_type(4).includes(:score_student_works) #全部实训作业
shixun_titles = shixun_homeworks.pluck(:name) + ["总得分"] shixun_titles = shixun_homeworks.pluck(:name) + ["总得分"]
common_homeworks = homeworks.search_homework_type(1) #全部普通作业 common_homeworks = homeworks.search_homework_type(1).includes(:score_student_works) #全部普通作业
common_titles = common_homeworks.pluck(:name)+ ["总得分"] common_titles = common_homeworks.pluck(:name)+ ["总得分"]
group_homeworks = homeworks.search_homework_type(3) #全部分组作业 group_homeworks = homeworks.search_homework_type(3).includes(:score_student_works) #全部分组作业
group_titles = group_homeworks.pluck(:name)+ ["总得分"] group_titles = group_homeworks.pluck(:name)+ ["总得分"]
task_titles = tasks.pluck(:name)+ ["总得分"] task_titles = tasks.includes(:score_graduation_works).pluck(:name) + ["总得分"]
exercise_titles = exercises.pluck(:exercise_name)+ ["总得分"] exercise_titles = exercises.includes(:score_exercise_users).pluck(:exercise_name) + ["总得分"]
total_user_score_array = [] #学生总成绩集合 total_user_score_array = [] #学生总成绩集合
#课堂信息 #课堂信息
@ -1114,7 +1109,7 @@ class CoursesController < ApplicationController
course_user_level = [] course_user_level = []
course_activity_title = "课堂活跃度统计" course_activity_title = "课堂活跃度统计"
user_cell_head = %w(排名 真实姓名 登录名 邮箱 学号 分班 作业完成数(*10) 试卷完成数(*10) 问卷完成数(*7) 资源发布数(*5) 帖子发布数(*2) 帖子回复数(*1) 作业回复数(*1) 活跃度) user_cell_head = %w(排名 真实姓名 登录名 邮箱 学号 分班 作业完成数(*10) 试卷完成数(*10) 问卷完成数(*7) 资源发布数(*5) 帖子发布数(*2) 帖子回复数(*1) 作业回复数(*1) 活跃度)
all_members.each do |u| all_members.includes(user: :user_extension).each do |u|
#用户的基本信息 #用户的基本信息
user = u.user user = u.user
user_login = user.login user_login = user.login
@ -1174,12 +1169,11 @@ class CoursesController < ApplicationController
#实训作业 #实训作业
if shixun_homeworks.count > 0 if shixun_homeworks.count > 0
shixun_homeworks.each do |s| shixun_homeworks.each do |s|
user_student_work = s.student_works.homework_by_user(user.id) #当前用户的对该作业的回答 user_student_work = s.score_student_works.find_by_user_id(user.id) #当前用户的对该作业的回答
if user_student_work.blank? if user_student_work.nil?
h_score = 0.0 #该作业的得分为0 h_score = 0.0 #该作业的得分为0
else else
user_stu_work = user_student_work.first h_score = user_student_work.work_score.nil? ? 0.0 : user_student_work.work_score #用户对该作业的分数
h_score = user_stu_work.work_score.nil? ? 0.0 : user_stu_work.work_score #用户对该作业的分数
end end
shixun_score_array.push(h_score) shixun_score_array.push(h_score)
end end
@ -1191,12 +1185,11 @@ class CoursesController < ApplicationController
#普通作业 #普通作业
if common_homeworks.count > 0 if common_homeworks.count > 0
common_homeworks.each do |c| common_homeworks.each do |c|
user_student_work_1 = c.student_works.homework_by_user(user.id) #当前用户的对该作业的回答 user_student_work_1 = c.score_student_works.find_by_user_id(user.id) #当前用户的对该作业的回答
if user_student_work_1.blank? if user_student_work_1.nil?
h_score_1 = 0.0 #该作业的得分为0 h_score_1 = 0.0 #该作业的得分为0
else else
user_stu_work_1 = user_student_work_1.first h_score_1 = user_student_work_1.work_score.nil? ? 0.0 : user_student_work_1.work_score #用户对该作业的分数
h_score_1 = user_stu_work_1.work_score.nil? ? 0.0 : user_stu_work_1.work_score #用户对该作业的分数
end end
common_score_array.push(h_score_1) common_score_array.push(h_score_1)
end end
@ -1208,12 +1201,11 @@ class CoursesController < ApplicationController
#分组作业 #分组作业
if group_homeworks.count > 0 if group_homeworks.count > 0
group_homeworks.each do |g| group_homeworks.each do |g|
user_student_work_3 = g.student_works.homework_by_user(user.id) #当前用户的对该作业的回答 user_student_work_3 = g.score_student_works.find_by_user_id(user.id) #当前用户的对该作业的回答
if user_student_work_3.blank? if user_student_work_3.nil?
h_score_3 = 0.0 #该作业的得分为0 h_score_3 = 0.0 #该作业的得分为0
else else
user_stu_work_3 = user_student_work_3.first h_score_3 = user_student_work_3.work_score.nil? ? 0.0 : user_student_work_3.work_score #用户对该作业的分数
h_score_3 = user_stu_work_3.work_score.nil? ? 0.0 : user_stu_work_3.work_score #用户对该作业的分数
end end
group_score_array.push(h_score_3) group_score_array.push(h_score_3)
end end
@ -1225,11 +1217,11 @@ class CoursesController < ApplicationController
#毕设作业 #毕设作业
if tasks.count > 0 if tasks.count > 0
tasks.each do |task| tasks.each do |task|
graduation_works = task.graduation_works.find_by_task_user(user.id) graduation_work = task.score_graduation_works.find_by_user_id(user.id)
if graduation_works.empty? if graduation_work.nil?
t_score = 0.0 t_score = 0.0
else else
t_score = graduation_works.first.work_score.nil? ? 0.0 : graduation_works.first.work_score t_score = graduation_work.work_score.nil? ? 0.0 : graduation_work.work_score
end end
task_score_array.push(t_score) task_score_array.push(t_score)
end end
@ -1241,11 +1233,11 @@ class CoursesController < ApplicationController
#试卷 #试卷
if exercises.count > 0 if exercises.count > 0
exercises.each do |ex| exercises.each do |ex|
exercise_works = ex.exercise_users.exercise_commit_users(user.id) exercise_work = ex.score_exercise_users.find_by_user_id(user.id)
if exercise_works.empty? if exercise_work.nil?
e_score = 0.0 e_score = 0.0
else else
e_score = exercise_works.first.score.nil? ? 0.0 : exercise_works.first.score e_score = exercise_work.score.nil? ? 0.0 : exercise_work.score
end end
exercise_score_array.push(e_score) exercise_score_array.push(e_score)
end end
@ -1285,7 +1277,7 @@ class CoursesController < ApplicationController
#实训作业 #实训作业
if count_1 > 0 if count_1 > 0
shixun_homeworks.each_with_index do |s,index| shixun_homeworks.each_with_index do |s,index|
all_student_works = s.student_works.has_committed.order("work_score desc") #该实训题的全部用户回答 all_student_works = s.score_student_works #该实训题的全部用户回答
title_no = index.to_i + 1 title_no = index.to_i + 1
student_work_to_xlsx(all_student_works,s) student_work_to_xlsx(all_student_works,s)
shixun_work_display_name = (title_no.to_s + "." + s.name).strip.first(30) shixun_work_display_name = (title_no.to_s + "." + s.name).strip.first(30)
@ -1297,7 +1289,7 @@ class CoursesController < ApplicationController
#普通作业 #普通作业
if count_2 > 0 if count_2 > 0
common_homeworks.each_with_index do |c,index| common_homeworks.each_with_index do |c,index|
all_student_works = c.student_works.has_committed.order("work_score desc") #当前用户的对该作业的回答 all_student_works = c.score_student_works #当前用户的对该作业的回答
title_no = count_1 + index.to_i + 1 title_no = count_1 + index.to_i + 1
student_work_to_xlsx(all_student_works,c) student_work_to_xlsx(all_student_works,c)
@ -1311,7 +1303,7 @@ class CoursesController < ApplicationController
#分组作业 #分组作业
if count_3 > 0 if count_3 > 0
group_homeworks.each_with_index do |c,index| group_homeworks.each_with_index do |c,index|
all_student_works = c.student_works.has_committed.order("work_score desc") #当前用户的对该作业的回答 all_student_works = c.score_student_works #当前用户的对该作业的回答
title_no = count_1 + count_2 + index.to_i + 1 title_no = count_1 + count_2 + index.to_i + 1
student_work_to_xlsx(all_student_works,c) student_work_to_xlsx(all_student_works,c)
work_name = (title_no.to_s + "." + c.name).strip.first(30) work_name = (title_no.to_s + "." + c.name).strip.first(30)
@ -1323,7 +1315,7 @@ class CoursesController < ApplicationController
#毕设任务 #毕设任务
if count_4 > 0 if count_4 > 0
tasks.each_with_index do |c,index| tasks.each_with_index do |c,index|
all_student_works = c.graduation_works.has_committed.order("work_score desc") #当前用户的对该作业的回答 all_student_works = c.score_graduation_works #当前用户的对该作业的回答
title_no = count_1 + count_2 + count_3 + index.to_i + 1 title_no = count_1 + count_2 + count_3 + index.to_i + 1
graduation_work_to_xlsx(all_student_works,c,current_user) graduation_work_to_xlsx(all_student_works,c,current_user)
work_name = (title_no.to_s + "." + c.name).strip.first(30) work_name = (title_no.to_s + "." + c.name).strip.first(30)
@ -1336,7 +1328,7 @@ class CoursesController < ApplicationController
#试卷的导出 #试卷的导出
if count_5 > 0 if count_5 > 0
exercises.each_with_index do |c,index| exercises.each_with_index do |c,index|
all_student_works = c.exercise_users.exercise_user_committed #当前用户的对该作业的回答 all_student_works = c.score_exercise_users #当前用户的对该作业的回答
title_no = count_1 + count_2 + count_3 + count_4 + index.to_i + 1 title_no = count_1 + count_2 + count_3 + count_4 + index.to_i + 1
get_export_users(c,course,all_student_works) get_export_users(c,course,all_student_works)
work_name = (title_no.to_s + "." + c.exercise_name).strip.first(30) work_name = (title_no.to_s + "." + c.exercise_name).strip.first(30)

@ -145,7 +145,7 @@ class GraduationTasksController < ApplicationController
file = decode64(zipfile[0][:base64file]) file = decode64(zipfile[0][:base64file])
send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip'
else else
tip_exception(status == -1 ? "文件大小超过500M请通过微信或者QQ联系管理员辅助您打包下载" : "无附件可下载") tip_exception(status == -2 ? "500" : "无附件可下载")
end end
end end
} }

@ -229,7 +229,7 @@ class HomeworkCommonsController < ApplicationController
file = decode64(zipfile[0][:base64file]) file = decode64(zipfile[0][:base64file])
send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip'
else else
tip_exception(status == -1 ? "文件大小超过500M请通过微信或者QQ联系管理员辅助您打包下载" : "无附件可下载") tip_exception(status == -2 ? "500M" : "无附件可下载")
end end
end end
} }

@ -37,7 +37,7 @@ module ExportHelper
end end
normal_head_b_cells = %w(最终成绩 提交时间 更新时间 评语) normal_head_b_cells = %w(最终成绩 提交时间 更新时间 评语)
@work_head_cells = (head_cells_format + group_cells + normal_head_cells + head_cells_add + allow_late_cell + normal_head_b_cells).reject(&:blank?) @work_head_cells = (head_cells_format + group_cells + normal_head_cells + head_cells_add + allow_late_cell + normal_head_b_cells).reject(&:blank?)
works.each_with_index do |w, index| works.includes(student_works_scores: :user).each_with_index do |w, index|
w_user = w.user w_user = w.user
w_1 = (index + 1) w_1 = (index + 1)
w_2 = w_user.login w_2 = w_user.login
@ -118,7 +118,7 @@ module ExportHelper
end end
shixun_time_cells = %w(最终成绩 更新时间 提交耗时 评语) shixun_time_cells = %w(最终成绩 更新时间 提交耗时 评语)
@work_head_cells = (head_cells_format + shixun_head_cells + eff_score_cell + shixun_time_cells).reject(&:blank?) @work_head_cells = (head_cells_format + shixun_head_cells + eff_score_cell + shixun_time_cells).reject(&:blank?)
works.each_with_index do |w, index| works.includes(:myshixun).each_with_index do |w, index|
myshixun = w.try(:myshixun) myshixun = w.try(:myshixun)
w_user = w.user w_user = w.user
w_1 = (index + 1) w_1 = (index + 1)
@ -262,18 +262,8 @@ module ExportHelper
end end
export_ex_users.each_with_index do |e_user,index| export_ex_users.each_with_index do |e_user,index|
user_info = e_user.user user_info = e_user.user
user_course_id = user_info.course_members.course_find_by_ids("course_id",course.id).first member = course.students.find_by_user_id(e_user.user_id)
if user_course_id.present? user_course = member.try(:course_group_name)
get_course_group_id = user_course_id.course_group_id
if get_course_group_id.present? && get_course_group_id != 0
user_course_info = CourseGroup.by_group_ids(get_course_group_id)
user_course = user_course_info.first.name
else
user_course = "--"
end
else
user_course = "--"
end
user_obj_score = e_user.objective_score < 0.0 ? 0.0 : e_user.objective_score.round(1).to_s user_obj_score = e_user.objective_score < 0.0 ? 0.0 : e_user.objective_score.round(1).to_s
user_suj_score = e_user.subjective_score < 0.0 ? 0.0 : e_user.subjective_score.round(1).to_s user_suj_score = e_user.subjective_score < 0.0 ? 0.0 : e_user.subjective_score.round(1).to_s
user_score = e_user.score.present? ? e_user.score.round(1).to_s : 0.0 user_score = e_user.score.present? ? e_user.score.round(1).to_s : 0.0
@ -375,11 +365,11 @@ module ExportHelper
end end
if file_size > MAX_DOWN_SIZE if file_size > MAX_DOWN_SIZE
status = -1 status = -2
elsif file_count > 0 elsif file_count > 0
status = 0 status = 0
else else
status = -2 status = -1
end end
status status
end end

@ -3,7 +3,8 @@ class Exercise < ApplicationRecord
belongs_to :exercise_bank, optional: true belongs_to :exercise_bank, optional: true
belongs_to :user belongs_to :user
has_many :exercise_users, :dependent => :delete_all has_many :exercise_users, -> { where("is_delete = 0") }, :dependent => :delete_all
has_many :score_exercise_users, -> { where("is_delete = 0 and commit_status != 0").order("score desc") }, class_name: "ExerciseUser"
has_many :exercise_questions, :dependent => :delete_all has_many :exercise_questions, :dependent => :delete_all
has_many :exercise_group_settings, :dependent => :delete_all has_many :exercise_group_settings, :dependent => :delete_all
has_many :tidings, as: :container has_many :tidings, as: :container

@ -16,7 +16,8 @@ class GraduationTask < ApplicationRecord
has_many :graduation_task_group_assignations, dependent: :destroy has_many :graduation_task_group_assignations, dependent: :destroy
has_many :graduation_work_comment_assignations, dependent: :destroy has_many :graduation_work_comment_assignations, dependent: :destroy
has_many :graduation_works, -> { where("is_delete != 1") } has_many :graduation_works, -> { where("is_delete = 0") }
has_many :score_graduation_works, -> { where("is_delete = 0 and work_status != 0").order("work_score desc") }, class_name: "GraduationWork"
has_many :graduation_work_scores has_many :graduation_work_scores
belongs_to :gtask_bank, optional: true belongs_to :gtask_bank, optional: true

@ -53,7 +53,7 @@ class GraduationWork < ApplicationRecord
# 分班名 # 分班名
def class_grouping_name def class_grouping_name
CourseMember.find_by(user_id: self.user_id, course_id: self.course_id, role: 4).try(:course_group).try(:name) || '未分班' CourseMember.find_by(course_id: self.course_id, user_id: self.user_id, role: 4).try(:course_group).try(:name) || '未分班'
end end
# 分组名 # 分组名

@ -3,7 +3,8 @@ class HomeworkCommon < ApplicationRecord
enum homework_type: { normal: 1, program: 2, group: 3, practice: 4 }, _suffix: true enum homework_type: { normal: 1, program: 2, group: 3, practice: 4 }, _suffix: true
has_many :homework_group_settings, dependent: :destroy has_many :homework_group_settings, dependent: :destroy
has_many :published_settings, -> { group_published }, class_name: "HomeworkGroupSetting" has_many :published_settings, -> { group_published }, class_name: "HomeworkGroupSetting"
has_many :student_works, -> { where("is_delete != 1") } has_many :student_works, -> { where("is_delete = 0") }
has_many :score_student_works, -> { where("is_delete = 0 and work_status != 0").order("work_score desc") }, class_name: "StudentWork"
has_one :homework_detail_manual, dependent: :destroy has_one :homework_detail_manual, dependent: :destroy
# 分组作业的设置 # 分组作业的设置

@ -5,7 +5,7 @@ class Poll < ApplicationRecord
# belongs_to :exercise_bank # belongs_to :exercise_bank
has_many :poll_questions,dependent: :delete_all has_many :poll_questions,dependent: :delete_all
has_many :poll_users, :dependent => :delete_all has_many :poll_users, -> { where("is_delete != 1") }, :dependent => :delete_all
has_many :users, :through => :poll_users #该文件被哪些用户提交答案过 has_many :users, :through => :poll_users #该文件被哪些用户提交答案过
has_many :poll_group_settings, :dependent => :delete_all has_many :poll_group_settings, :dependent => :delete_all
has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :delete_all has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :delete_all

Loading…
Cancel
Save