xlsx导出的判断修改

dev_forum
SylorHuang 5 years ago
parent 275030bb6a
commit dd49b9e9ad

@ -978,6 +978,8 @@ class CoursesController < ApplicationController
@c_tasks = @course.graduation_tasks.task_published.order("graduation_tasks.publish_time asc, graduation_tasks.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,"无权限操作")
elsif @all_members.size == 0
normal_status(-1,"课堂暂时没有学生")
else else
member_to_xlsx(@course, @all_members, @c_homeworks, @c_exercises, @c_tasks, @c_polls) 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') filename = current_user.real_name + "_" + @course.name + "_全部成绩" + Time.now.strftime('%Y%m%d_%H%M%S')

@ -1300,14 +1300,10 @@ class ExercisesController < ApplicationController
if params[:format] == "xlsx" if params[:format] == "xlsx"
if @user_course_identity > Course::ASSISTANT_PROFESSOR if @user_course_identity > Course::ASSISTANT_PROFESSOR
tip_exception(403,"无权限操作") tip_exception(403,"无权限操作")
elsif (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) elsif (@exercise_status == 1) || (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0)
normal_status(-1,"暂无用户提交") normal_status(-1,"暂无用户提交")
else
end
end
respond_to do |format| respond_to do |format|
format.json
format.xlsx{ format.xlsx{
get_export_users(@exercise,@course,@export_ex_users) get_export_users(@exercise,@course,@export_ex_users)
exercise_export_name = exercise_export_name =
@ -1315,6 +1311,8 @@ class ExercisesController < ApplicationController
render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns}
} }
end end
end
end
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception("页面调用失败!") tip_exception("页面调用失败!")

@ -123,51 +123,83 @@ class GraduationTasksController < ApplicationController
@work_count = @work_list.count @work_count = @work_list.count
@work_excel = @work_list @work_excel = @work_list
@work_list = @work_list.page(page).per(limit) @work_list = @work_list.page(page).per(limit)
respond_to do |format|
format.json if params[:format] == "xlsx"
format.xlsx{
if @user_course_identity >= Course::STUDENT if @user_course_identity >= Course::STUDENT
tip_exception(403, "无权限操作") tip_exception(403, "无权限操作")
else elsif @work_count == 0
if @work_count > 1
graduation_work_to_xlsx(@work_excel,@task,current_user)
exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@task.name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}"
render xlsx: "#{exercise_export_name.strip.first(30)}",template: "graduation_tasks/tasks_list.xlsx.axlsx",locals: {table_columns:@head_cells_column, task_users:@task_cells_column}
else
normal_status(-1,"暂无提交的学生!") normal_status(-1,"暂无提交的学生!")
else
student_work_to_xlsx(@work_excel,@homework)
exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S')
render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals:
{table_columns: @work_head_cells,task_users: @work_cells_column}
end end
end elsif params[:format] == "zip"
}
format.zip{
if @user_course_identity >= Course::STUDENT if @user_course_identity >= Course::STUDENT
tip_exception(403, "无权限操作") tip_exception(403, "无权限操作")
else else
zip_works = @work_excel.where("work_status > 0") zip_works = @work_excel.where("work_status > 0")
status = checkfileSize(zip_works) status = checkfileSize(zip_works)
if status == 0 if status == 0
zipfile = zip_homework_common @task, zip_works zipfile = zip_homework_common @homework, zip_works
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 == -2 ? "500" : "无附件可下载") tip_exception(status == -2 ? "500M" : "无附件可下载")
end end
end end
}
end end
#
# respond_to do |format|
# format.json
# format.xlsx{
# if @user_course_identity >= Course::STUDENT
# tip_exception(403, "无权限操作")
# else
# if @work_count > 1
# graduation_work_to_xlsx(@work_excel,@task,current_user)
# exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@task.name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}"
# render xlsx: "#{exercise_export_name.strip.first(30)}",template: "graduation_tasks/tasks_list.xlsx.axlsx",locals: {table_columns:@head_cells_column, task_users:@task_cells_column}
# else
# normal_status(-1,"暂无提交的学生!")
# end
# end
# }
# format.zip{
# if @user_course_identity >= Course::STUDENT
# tip_exception(403, "无权限操作")
# else
# zip_works = @work_excel.where("work_status > 0")
# status = checkfileSize(zip_works)
# if status == 0
# zipfile = zip_homework_common @task, zip_works
# file = decode64(zipfile[0][:base64file])
# send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip'
# else
# tip_exception(status == -2 ? "500" : "无附件可下载")
# end
# end
# }
# end
else else
@work_list = @work @work_list = @work
@view_work = false @view_work = false
@work_count = @work_list.count @work_count = @work_list.count
@all_work_count = @work_list.count @all_work_count = @work_list.count
respond_to do |format| if params[:format] == "xlsx" || params[:format] == "zip"
format.json
format.xlsx{
normal_status(-1,"作业未发布") normal_status(-1,"作业未发布")
}
format.zip{
normal_status(-1,"作业未发布")
}
end end
# respond_to do |format|
# format.json
# format.xlsx{
# normal_status(-1,"作业未发布")
# }
# format.zip{
# normal_status(-1,"作业未发布")
# }
# end
end end
end end

@ -200,25 +200,20 @@ class HomeworkCommonsController < ApplicationController
end end
# @members = @course.students.where(user_id: @student_works.pluck(:user_id)).includes(:course_group) # @members = @course.students.where(user_id: @student_works.pluck(:user_id)).includes(:course_group)
end end
respond_to do |format|
format.json if params[:format] == "xlsx"
format.xlsx{
if @user_course_identity >= Course::STUDENT if @user_course_identity >= Course::STUDENT
tip_exception(403, "无权限操作") tip_exception(403, "无权限操作")
elsif @work_count == 0
normal_status(-1,"暂无提交的学生!")
else else
if @work_count > 1
student_work_to_xlsx(@work_excel,@homework) student_work_to_xlsx(@work_excel,@homework)
exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S')
render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals:
{table_columns: @work_head_cells,task_users: @work_cells_column} {table_columns: @work_head_cells,task_users: @work_cells_column}
else
normal_status(-1,"暂无提交的学生!")
end
end end
} elsif params[:format] == "zip"
format.zip{
if @user_course_identity >= Course::STUDENT if @user_course_identity >= Course::STUDENT
tip_exception(403, "无权限操作") tip_exception(403, "无权限操作")
else else
@ -232,8 +227,41 @@ class HomeworkCommonsController < ApplicationController
tip_exception(status == -2 ? "500M" : "无附件可下载") tip_exception(status == -2 ? "500M" : "无附件可下载")
end end
end end
}
end end
# respond_to do |format|
# format.json
# format.xlsx{
# if @user_course_identity >= Course::STUDENT
# tip_exception(403, "无权限操作")
# else
# if @work_count > 1
# student_work_to_xlsx(@work_excel,@homework)
# exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S')
#
# render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals:
# {table_columns: @work_head_cells,task_users: @work_cells_column}
# else
# normal_status(-1,"暂无提交的学生!")
# end
#
# end
# }
# format.zip{
# if @user_course_identity >= Course::STUDENT
# tip_exception(403, "无权限操作")
# else
# zip_works = @work_excel.where("work_status > 0")
# status = checkfileSize(zip_works)
# if status == 0
# zipfile = zip_homework_common @homework, zip_works
# file = decode64(zipfile[0][:base64file])
# send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip'
# else
# tip_exception(status == -2 ? "500M" : "无附件可下载")
# end
# end
# }
# end
end end
end end

@ -945,17 +945,6 @@ class PollsController < ApplicationController
end end
end end
end end
# respond_to do |format|
# format.json
# format.xlsx{
# polls_export_name = "#{current_user.real_name}_#{@course.name}_#{@poll.polls_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}"
# render xlsx: "#{polls_export_name.strip.first(30)}",template: "polls/commit_result.xlsx.axlsx",locals: {
# poll_questions:@poll_export_questions,
# poll:@poll,
# poll_users: @poll_users,
# poll_commit_ids:@poll_commit_ids}
# }
# end
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception("页面调用失败!") tip_exception("页面调用失败!")

Loading…
Cancel
Save