@ -959,18 +959,20 @@ class CoursesController < ApplicationController
def export_member_scores_excel
ActiveRecord :: Base . transaction do
begin
name = params [ :name ] ? " #{ params [ :name ] . strip } " : " " #用户名或学生学号id搜索
search = params [ :search ] ? " #{ params [ :search ] . strip } " : " " #用户名或学生学号id搜索
group_id = params [ :group_id ] #分班的班级id
if group_id && group_id != " 0 " && group_id != " -1 "
@all_members = @course . students . course_find_by_ids ( " course_group_id " , group_id )
elsif group_id && group_id == " 0 " # 未分班
@all_members = @course . course_members . ungroup_students
else
@all_members = @course . students
end
if name . present?
@all_members = @all_members . joins ( user : [ :user_extension ] ) . where ( 'concat(users.lastname, users.firstname) like ? or user_extensions.student_id like ?' , " % #{ name } % " , " % #{ name } % " )
end
# if group_id && group_id != "0" && group_id != "-1"
# @all_members = @course.students.course_find_by_ids("course_group_id",group_id)
# elsif group_id && group_id == "0" # 未分班
# @all_members = @course.course_members.ungroup_students
# else
# @all_members = @course.students
# end
# if name.present?
# @all_members = @all_members.joins(user: [:user_extension]).where('concat(users.lastname, users.firstname) like ? or user_extensions.student_id like ?',"%#{name}%","%#{name}%")
# end
@all_members = student_act_score group_id , search
@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 ( " exercises.publish_time asc, exercises.created_at asc " )
@ -981,7 +983,7 @@ class CoursesController < ApplicationController
else
member_to_xlsx ( @course , @all_members , @c_homeworks , @c_exercises , @c_tasks , @c_polls )
filename = current_user . real_name + " _ " + @course . name + " _全部成绩 " + Time . now . strftime ( '%Y%m%d_%H%M%S' )
render xlsx : " #{ f ilename. strip . first ( 30 ) } " , template : " courses/export_member_scores_excel.xlsx.axlsx " ,
render xlsx : " #{ f ormat_sheet_name f ilename. strip . first ( 30 ) } " , template : " courses/export_member_scores_excel.xlsx.axlsx " ,
locals : { course_info : @course_info , activity_level : @user_activity_level ,
course_scores : @course_user_scores , shixun_works : @shixun_work_arrays ,
common_works : @common_work_arrays , group_works : @group_work_arrays , task_works : @task_work_arrays ,
@ -1051,16 +1053,68 @@ class CoursesController < ApplicationController
end
end
def member_to_xlsx ( course , all_members , homeworks , exercises , tasks , polls )
def student_act_score group_id , search
sql_select = %Q{ SELECT cm.*,(
SELECT SUM ( student_works . work_score )
FROM student_works , homework_commons
WHERE student_works . homework_common_id = homework_commons . id
AND homework_commons . course_id = #{@course.id}
AND student_works . user_id = cm . user_id
) AS score ,
( SELECT SUM ( gw . work_score ) FROM graduation_works gw , graduation_tasks gt WHERE gw . graduation_task_id = gt . id
AND gt . course_id = #{@course.id} AND gw.user_id = cm.user_id) AS graduation_score,
( SELECT SUM ( exercise_users . score ) FROM exercise_users , exercises WHERE exercise_users . exercise_id = exercises . id
AND exercises . course_id = #{@course.id} AND exercise_users.user_id = cm.user_id) AS ex_score,
( SELECT max ( student_id ) FROM user_extensions WHERE user_extensions . user_id = cm . user_id ) AS student_id ,
( SELECT max ( message_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = cm.user_id) AS message_num,
( SELECT max ( message_reply_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = cm.user_id) AS message_reply_num,
( SELECT max ( resource_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = cm.user_id) AS resource_num,
( SELECT max ( homework_journal_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = cm.user_id) AS homework_journal_num,
( SELECT COUNT ( gw . id ) FROM graduation_works AS gw , graduation_tasks AS gt WHERE gw . graduation_task_id = gt . id AND gt . course_id = #{@course.id} AND gw.work_status != 0 AND gw.user_id = cm.user_id) AS graduation_num,
( SELECT COUNT ( ss . id ) FROM student_works AS ss , homework_commons AS hc WHERE ss . homework_common_id = hc . id AND hc . course_id = #{@course.id} AND ss.work_status != 0 AND ss.user_id = cm.user_id) AS homework_num,
( SELECT COUNT ( eu . id ) FROM exercise_users AS eu , exercises WHERE eu . exercise_id = exercises . id AND exercises . course_id = #{@course.id} AND eu.commit_status = 1 AND eu.user_id = cm.user_id) AS exercise_num,
( SELECT COUNT ( pu . id ) FROM poll_users AS pu , polls WHERE pu . poll_id = polls . id AND polls . course_id = #{@course.id} AND pu.commit_status = 1 AND pu.user_id = cm.user_id) AS poll_num
FROM course_members cm }
if search . present? && group_id . present?
sql_select += %Q{ join users on cm.user_id = users.id
joins user_extensions ue on ue . user_id = users . id
WHERE cm . role = 4 and cm . course_id = #{@course.id} and cm.course_group_id = #{group_id} and
( concat ( users . lastname , users . firstname ) like '%#{search}%' or ue . student_id like '%#{search}%' ) ORDER BY score desc }
elsif search . present?
ql_select += %Q{ join users on cm.user_id = users.id
joins user_extensions ue on ue . user_id = users . id
WHERE cm . role = 4 and
( concat ( users . lastname , users . firstname ) like '%#{search}%' or ue . student_id like '%#{search}%' ) ORDER BY score desc }
elsif group_id . present?
sql_select += %Q{ WHERE cm.role = 4 and cm.course_id = #{ @course . id } and cm.course_group_id = #{ group_id } ORDER BY score desc }
else
sql_select += %Q{ WHERE cm.role = 4 and cm.course_id = #{ @course . id } ORDER BY score desc }
end
act_scores = CourseMember . find_by_sql ( sql_select )
act_scores
end
def member_to_xlsx ( course , all_members , homeworks , exercises , tasks )
#课堂的作业信息
shixun_homeworks = homeworks . search_homework_type ( 4 ) . includes ( :score_student_works ) #全部实训作业
shixun_homeworks = homeworks . search_homework_type ( 4 ) #全部实训作业
shixun_titles = shixun_homeworks . pluck ( :name ) + [ " 总得分 " ]
common_homeworks = homeworks . search_homework_type ( 1 ) . includes ( :score_student_works ) #全部普通作业
shixun_homeworks = shixun_homeworks . includes ( :score_student_works )
common_homeworks = homeworks . search_homework_type ( 1 ) #全部普通作业
common_titles = common_homeworks . pluck ( :name ) + [ " 总得分 " ]
common_homeworks = common_homeworks . includes ( :score_student_works )
group_homeworks = homeworks . search_homework_type ( 3 ) . includes ( :score_student_works ) #全部分组作业
group_titles = group_homeworks . pluck ( :name ) + [ " 总得分 " ]
task_titles = tasks . includes ( :score_graduation_works ) . pluck ( :name ) + [ " 总得分 " ]
exercise_titles = exercises . includes ( :score_exercise_users ) . pluck ( :exercise_name ) + [ " 总得分 " ]
group_homeworks = group_homeworks . includes ( :score_student_works )
task_titles = tasks . pluck ( :name ) + [ " 总得分 " ]
tasks = tasks . includes ( :score_graduation_works )
exercise_titles = exercises . pluck ( :exercise_name ) + [ " 总得分 " ]
exercises = exercises . includes ( :score_exercise_users )
total_user_score_array = [ ] #学生总成绩集合
#课堂信息
@ -1075,7 +1129,7 @@ class CoursesController < ApplicationController
course_teacher_member = course . course_members . course_user_role ( % i [ CREATOR ] )
course_teacher = course_teacher_member . present? ? course_teacher_member . first . user . real_name : " -- "
course_class_counts = course . course_groups_count
course_students_count = course . students . count
course_students_count = course . students . size
course_1 = [ " 课堂编号 " , course_id ]
course_2 = [ " 课程名称 " , course_list_name ]
course_3 = [ " 课堂名称 " , course_name ]
@ -1100,16 +1154,11 @@ class CoursesController < ApplicationController
@course_info += [ course_info_title , course_main_info , course_group_info ]
#课堂活跃度
course_homework_ids = homeworks . pluck ( :id ) #该课堂的全部作业id
course_graduate_task_ids = tasks . pluck ( :id ) #该课堂的全部毕业任务id
course_exercise_ids = exercises . pluck ( :id ) #课堂的全部试卷数
course_poll_ids = polls . pluck ( :id ) #课堂的全部问卷数
course_board_ids = course . boards . pluck ( :id ) #课堂的全部讨论区
@user_activity_level = [ ]
course_user_level = [ ]
course_activity_title = " 课堂活跃度统计 "
user_cell_head = %w( 排名 真实姓名 登录名 邮箱 学号 分班 作业完成数 ( *10 ) 试卷完成数 ( *10 ) 问卷完成数 ( *7 ) 资源发布数 ( *5 ) 帖子发布数 ( *2 ) 帖子回复数 ( *1 ) 作业回复数 ( *1 ) 活跃度 )
all_members . includes( user : :user_extension ) . each do | u |
all_members . each do | u |
#用户的基本信息
user = u . user
user_login = user . login
@ -1121,15 +1170,14 @@ class CoursesController < ApplicationController
user_work_scores = [ ]
#课堂活跃度统计
user_homeworks_num = user . student_works . find_by_homework ( course_homework_ids ) . has_committed . count #完成的作业数
user_graduate_num = user . graduation_works . find_by_task ( course_graduate_task_ids ) . has_committed . count #毕业任务完成数
user_exercise_num = user . exercise_users . search_by_exercise ( course_exercise_ids ) . commit_exercise_by_status ( 1 ) . count #根据试卷的id来查找
user_poll_num = user . poll_users . search_by_poll ( course_poll_ids ) . commit_by_status ( 1 ) . count #已完成问卷
user_file_num = user . attachments . search_by_container ( course . id ) . count
user_messages = user . messages
user_messages_num = user_messages . root_nodes . find_by_boards ( course_board_ids ) . count #帖子发布数
user_reply_num = user_messages . reply_nodes . find_by_boards ( course_board_ids ) . count #帖子回复数
user_work_reply_num = user . journals_for_messages . search_by_jour_type ( " HomeworkCommon " , course_homework_ids ) . count #作业回复数的数量
user_homeworks_num = u . homework_num . to_i #完成的作业数
user_graduate_num = u . graduation_num . to_i #毕业任务完成数
user_exercise_num = u . exercise_num . to_i #根据试卷的id来查找
user_poll_num = u . poll_num . to_i #已完成问卷
user_file_num = u . resource_num . to_i
user_messages_num = u . message_num . to_i #帖子发布数
user_reply_num = u . message_reply_num . to_i #帖子回复数
user_work_reply_num = u . homework_journal_num . to_i #作业回复数的数量
c_works_num = ( user_homeworks_num + user_graduate_num ) * 10
c_exercise_num = user_exercise_num * 10
c_poll_num = user_poll_num * 7
@ -1167,7 +1215,7 @@ class CoursesController < ApplicationController
exercise_score_array = [ ]
#实训作业
if shixun_homeworks . count > 0
if shixun_homeworks . size > 0
shixun_homeworks . each do | s |
user_student_work = s . score_student_works . select { | work | work . user_id == user . id } . first #当前用户的对该作业的回答
if user_student_work . nil?
@ -1183,7 +1231,7 @@ class CoursesController < ApplicationController
user_work_scores += user_info_array + shixun_score_array #单个用户的实训作业得分信息
#普通作业
if common_homeworks . count > 0
if common_homeworks . size > 0
common_homeworks . each do | c |
user_student_work_1 = c . score_student_works . select { | work | work . user_id == user . id } . first #当前用户的对该作业的回答
if user_student_work_1 . nil?
@ -1199,7 +1247,7 @@ class CoursesController < ApplicationController
user_work_scores += common_score_array #单个用户的普通作业得分信息
#分组作业
if group_homeworks . count > 0
if group_homeworks . size > 0
group_homeworks . each do | g |
user_student_work_3 = g . score_student_works . select { | work | work . user_id == user . id } . first #当前用户的对该作业的回答
if user_student_work_3 . nil?
@ -1215,7 +1263,7 @@ class CoursesController < ApplicationController
user_work_scores += group_score_array #单个用户的分组作业得分信息
#毕设作业
if tasks . count > 0
if tasks . size > 0
tasks . each do | task |
graduation_work = task . score_graduation_works . select { | work | work . user_id == user . id } . first
if graduation_work . nil?
@ -1231,7 +1279,7 @@ class CoursesController < ApplicationController
user_work_scores += task_score_array #单个用户的分组作业得分信息
#试卷
if exercises . count > 0
if exercises . size > 0
exercises . each do | ex |
exercise_work = ex . score_exercise_users . select { | work | work . user_id == user . id } . first
if exercise_work . nil?
@ -1269,73 +1317,63 @@ class CoursesController < ApplicationController
@common_work_arrays = [ ]
@task_work_arrays = [ ]
@exercise_work_arrays = [ ]
count_1 = shixun_homeworks . count
count_2 = common_homeworks . count
count_3 = group_homeworks . count
count_4 = tasks . count
count_5 = exercises . count
count_1 = shixun_homeworks . size
count_2 = common_homeworks . size
count_3 = group_homeworks . size
count_4 = tasks . size
count_5 = exercises . size
#实训作业
if count_1 > 0
shixun_homeworks . each_with_index do | s , index |
all_student_works = s . score_student_works #该实训题的全部用户回答
title_no = index . to_i + 1
student_work_to_xlsx ( all_student_works , s )
shixun_work_display_name = ( title_no . to_s + " . " + s . name ) . strip . first ( 30 )
shixun_work_content = [ shixun_work_display_name , @work_head_cells , @work_cells_column ]
@shixun_work_arrays . push ( shixun_work_content )
end
shixun_homeworks . each_with_index do | s , index |
all_student_works = s . score_student_works #该实训题的全部用户回答
title_no = index . to_i + 1
student_work_to_xlsx ( all_student_works , s )
shixun_work_display_name = format_sheet_name ( title_no . to_s + " . " + s . name ) . strip . first ( 30 )
shixun_work_content = [ shixun_work_display_name , @work_head_cells , @work_cells_column ]
@shixun_work_arrays . push ( shixun_work_content )
end
#普通作业
if count_2 > 0
common_homeworks . each_with_index do | c , index |
all_student_works = c . score_student_works #当前用户的对该作业的回答
title_no = count_1 + index . to_i + 1
student_work_to_xlsx ( all_student_works , c )
work_name = ( title_no . to_s + " . " + c . name ) . strip . first ( 30 )
work_content = [ work_name , @work_head_cells , @work_cells_column ]
@common_work_arrays . push ( work_content )
title_no
end
common_homeworks . each_with_index do | c , index |
all_student_works = c . score_student_works #当前用户的对该作业的回答
title_no = count_1 + index . to_i + 1
student_work_to_xlsx ( all_student_works , c )
work_name = format_sheet_name ( title_no . to_s + " . " + c . name ) . strip . first ( 30 )
work_content = [ work_name , @work_head_cells , @work_cells_column ]
@common_work_arrays . push ( work_content )
title_no
end
#分组作业
if count_3 > 0
group_homeworks . each_with_index do | c , index |
all_student_works = c . score_student_works #当前用户的对该作业的回答
title_no = count_1 + count_2 + index . to_i + 1
student_work_to_xlsx ( all_student_works , c )
work_name = ( title_no . to_s + " . " + c . name ) . strip . first ( 30 )
work_content = [ work_name , @work_head_cells , @work_cells_column ]
@group_work_arrays . push ( work_content )
end
group_homeworks . each_with_index do | c , index |
all_student_works = c . score_student_works #当前用户的对该作业的回答
title_no = count_1 + count_2 + index . to_i + 1
student_work_to_xlsx ( all_student_works , c )
work_name = format_sheet_name ( title_no . to_s + " . " + c . name ) . strip . first ( 30 )
work_content = [ work_name , @work_head_cells , @work_cells_column ]
@group_work_arrays . push ( work_content )
end
#毕设任务
if count_4 > 0
tasks . each_with_index do | c , index |
all_student_works = c . score_graduation_works #当前用户的对该作业的回答
title_no = count_1 + count_2 + count_3 + index . to_i + 1
graduation_work_to_xlsx ( all_student_works , c , current_user )
work_name = ( title_no . to_s + " . " + c . name ) . strip . first ( 30 )
# work_content = [work_name,@work_head_cells,@work_cells_column]
work_content = [ work_name , @head_cells_column , @task_cells_column ]
@task_work_arrays . push ( work_content )
end
tasks . each_with_index do | c , index |
all_student_works = c . score_graduation_works #当前用户的对该作业的回答
title_no = count_1 + count_2 + count_3 + index . to_i + 1
graduation_work_to_xlsx ( all_student_works , c , current_user )
work_name = format_sheet_name ( title_no . to_s + " . " + c . name ) . strip . first ( 30 )
# work_content = [work_name,@work_head_cells,@work_cells_column]
work_content = [ work_name , @head_cells_column , @task_cells_column ]
@task_work_arrays . push ( work_content )
end
#试卷的导出
if count_5 > 0
exercises . each_with_index do | c , index |
all_student_works = c . score_exercise_users #当前用户的对该作业的回答
title_no = count_1 + count_2 + count_3 + count_4 + index . to_i + 1
get_export_users ( c , course , all_student_works )
work_name = ( title_no . to_s + " . " + c . exercise_name ) . strip . first ( 30 )
# work_content = [work_name,@work_head_cells,@work_cells_column]
work_content = [ work_name , @table_columns , @user_columns ]
@exercise_work_arrays . push ( work_content )
end
exercises . each_with_index do | c , index |
all_student_works = c . score_exercise_users #当前用户的对该作业的回答
title_no = count_1 + count_2 + count_3 + count_4 + index . to_i + 1
get_export_users ( c , course , all_student_works )
work_name = format_sheet_name ( title_no . to_s + " . " + c . exercise_name ) . strip . first ( 30 )
# work_content = [work_name,@work_head_cells,@work_cells_column]
work_content = [ work_name , @table_columns , @user_columns ]
@exercise_work_arrays . push ( work_content )
end
end
end