xlsx导出的条件判断修改

dev_forum
SylorHuang 5 years ago
parent 9e720b3d00
commit 44e4496928

@ -125,15 +125,19 @@ class GraduationTasksController < ApplicationController
@work_list = @work_list.page(page).per(limit)
if params[:format] == "xlsx"
complete_works = @work_excel.where("work_status > 0").size
if @user_course_identity >= Course::STUDENT
tip_exception(403, "无权限操作")
elsif @work_count == 0
elsif complete_works == 0
normal_status(-1,"暂无提交的学生!")
else
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}
respond_to do |format|
format.xlsx{
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}
}
end
end
elsif params[:format] == "zip"
if @user_course_identity >= Course::STUDENT
@ -142,46 +146,18 @@ class GraduationTasksController < ApplicationController
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'
respond_to do |format|
format.zip{
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'
}
end
else
tip_exception(status == -2 ? "500M" : "无附件可下载")
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
@work_list = @work
@view_work = false
@ -190,15 +166,6 @@ class GraduationTasksController < ApplicationController
if params[:format] == "xlsx" || params[:format] == "zip"
normal_status(-1,"作业未发布")
end
# respond_to do |format|
# format.json
# format.xlsx{
# normal_status(-1,"作业未发布")
# }
# format.zip{
# normal_status(-1,"作业未发布")
# }
# end
end
end

@ -266,11 +266,16 @@ class GraduationTopicsController < ApplicationController
# 导出功能
def export
course = @course
students = course.students.joins(user: :user_extension).order("user_extensions.student_id")
graduation_topic_to_xlsx(students,course)
exercise_export_name = "#{current_user.real_name}_#{course.name}_毕设选题_#{Time.now.strftime('%Y%m%d_%H%M%S')}"
render xlsx: "#{exercise_export_name.strip.first(30)}",template: "graduation_topics/export.xlsx.axlsx",locals: {table_columns:@topic_head_cells,topic_users:@topic_body_cells}
begin
course = @course
students = course.students.joins(user: :user_extension).order("user_extensions.student_id")
graduation_topic_to_xlsx(students,course)
exercise_export_name = "#{current_user.real_name}_#{course.name}_毕设选题_#{Time.now.strftime('%Y%m%d_%H%M%S')}"
render xlsx: "#{exercise_export_name.strip.first(30)}",template: "graduation_topics/export.xlsx.axlsx",locals: {table_columns:@topic_head_cells,topic_users:@topic_body_cells}
rescue Exception => e
uid_logger(e.message)
missing_template
end
end
private

@ -108,14 +108,8 @@ class HomeworkCommonsController < ApplicationController
@all_member_count = student_works.size
if @homework.publish_time.nil? || @homework.publish_time > Time.now
@student_works = []
respond_to do |format|
format.json
format.xlsx{
normal_status(-1,"作业未发布")
}
format.zip{
normal_status(-1,"作业未发布")
}
if params[:format] == "xlsx" || params[:format] == "zip"
normal_status(-1,"作业未发布")
end
else
if @user_course_identity == Course::STUDENT
@ -202,10 +196,10 @@ class HomeworkCommonsController < ApplicationController
end
if params[:format] == "xlsx"
logger.info("#########______@work_count_________#######{@work_count}")
complete_works = @work_excel.where("work_status > 0").size
if @user_course_identity >= Course::STUDENT
tip_exception(403, "无权限操作")
elsif @work_count == 0
elsif complete_works == 0
normal_status(-1,"暂无提交的学生!")
else
respond_to do |format|
@ -217,7 +211,6 @@ class HomeworkCommonsController < ApplicationController
{table_columns: @work_head_cells,task_users: @work_cells_column}
}
end
end
elsif params[:format] == "zip"
if @user_course_identity >= Course::STUDENT
@ -238,40 +231,6 @@ class HomeworkCommonsController < ApplicationController
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

@ -217,7 +217,16 @@ module ExportHelper
else
w_6 = nil
end
w_7 = work.work_status
w_status = work.work_status.to_i
if w_status == 0
w_7 = "未提交"
elsif w_status == 1
w_7 = "按时提交"
elsif w_status == 2
w_7 = "延时提交"
else
w_7 = "--"
end
if task_project_boolean #关联项目
w_project = project_info work, current_user, @user_course_identity #因为课堂引用了export_helper
w_8 = w_project[:name]

Loading…
Cancel
Save