From dd49b9e9adca84254a5fc552acb5a0920354fa8a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 11:26:16 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=20xlsx=E5=AF=BC=E5=87=BA=E7=9A=84=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 2 + app/controllers/exercises_controller.rb | 22 ++-- .../graduation_tasks_controller.rb | 104 ++++++++++++------ .../homework_commons_controller.rb | 86 ++++++++++----- app/controllers/polls_controller.rb | 11 -- 5 files changed, 137 insertions(+), 88 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 2d379b555..6d1964840 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -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") if @user_course_identity > Course::ASSISTANT_PROFESSOR tip_exception(403,"无权限操作") + elsif @all_members.size == 0 + normal_status(-1,"课堂暂时没有学生") 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') diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index dd19c36d1..07113792d 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1300,21 +1300,19 @@ class ExercisesController < ApplicationController if params[:format] == "xlsx" if @user_course_identity > Course::ASSISTANT_PROFESSOR 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,"暂无用户提交") - + else + respond_to do |format| + format.xlsx{ + get_export_users(@exercise,@course,@export_ex_users) + exercise_export_name = + "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + 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 - - respond_to do |format| - format.json - format.xlsx{ - get_export_users(@exercise,@course,@export_ex_users) - exercise_export_name = - "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" - render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} - } - end rescue Exception => e uid_logger_error(e.message) tip_exception("页面调用失败!") diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index 1931c26a0..23344e7fc 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -123,51 +123,83 @@ class GraduationTasksController < ApplicationController @work_count = @work_list.count @work_excel = @work_list @work_list = @work_list.page(page).per(limit) - 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, "无权限操作") + + if params[:format] == "xlsx" + if @user_course_identity >= Course::STUDENT + tip_exception(403, "无权限操作") + elsif @work_count == 0 + 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 + elsif params[: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 - 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 + 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 @work_count = @work_list.count @all_work_count = @work_list.count - 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 + # respond_to do |format| + # format.json + # format.xlsx{ + # normal_status(-1,"作业未发布") + # } + # format.zip{ + # normal_status(-1,"作业未发布") + # } + # end end end diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 89e301f93..5de65210f 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -200,40 +200,68 @@ class HomeworkCommonsController < ApplicationController end # @members = @course.students.where(user_id: @student_works.pluck(:user_id)).includes(:course_group) 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 + if params[:format] == "xlsx" + if @user_course_identity >= Course::STUDENT + tip_exception(403, "无权限操作") + elsif @work_count == 0 + 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') - end - } - format.zip{ - if @user_course_identity >= Course::STUDENT - tip_exception(403, "无权限操作") + 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 + elsif params[: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 - 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 + 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 + # 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 diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 7075ac0ef..244cdf57f 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -945,17 +945,6 @@ class PollsController < ApplicationController 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 uid_logger_error(e.message) tip_exception("页面调用失败!") From 515b6aef09aa4433140305143ebb0700e7787266 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 12:15:30 +0800 Subject: [PATCH 2/5] fix bug --- app/controllers/homework_commons_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 5de65210f..6cffa866d 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -202,6 +202,7 @@ class HomeworkCommonsController < ApplicationController end if params[:format] == "xlsx" + logger.info("#########______@work_count_________#######{@work_count}") if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") elsif @work_count == 0 From 9e720b3d00ac61573eb97ab3987fbd7bcb3e639b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 12:24:09 +0800 Subject: [PATCH 3/5] fix bug --- .../graduation_tasks_controller.rb | 9 ++++---- .../graduation_topics_controller.rb | 2 +- .../homework_commons_controller.rb | 23 +++++++++++++------ 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index 23344e7fc..a518ac954 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -130,11 +130,10 @@ class GraduationTasksController < ApplicationController elsif @work_count == 0 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} + 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 elsif params[:format] == "zip" if @user_course_identity >= Course::STUDENT @@ -143,7 +142,7 @@ class GraduationTasksController < ApplicationController zip_works = @work_excel.where("work_status > 0") status = checkfileSize(zip_works) if status == 0 - zipfile = zip_homework_common @homework, zip_works + 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 diff --git a/app/controllers/graduation_topics_controller.rb b/app/controllers/graduation_topics_controller.rb index c611069a8..2c9132520 100644 --- a/app/controllers/graduation_topics_controller.rb +++ b/app/controllers/graduation_topics_controller.rb @@ -269,7 +269,7 @@ class GraduationTopicsController < ApplicationController 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') + 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} end diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 6cffa866d..50ec4f7db 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -208,11 +208,16 @@ class HomeworkCommonsController < ApplicationController elsif @work_count == 0 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') + respond_to do |format| + format.xlsx{ + 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 - 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 elsif params[:format] == "zip" if @user_course_identity >= Course::STUDENT @@ -221,9 +226,13 @@ class HomeworkCommonsController < ApplicationController 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' + respond_to do |format| + format.zip{ + 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' + } + end else tip_exception(status == -2 ? "500M" : "无附件可下载") end From 44e4496928a1a8ae9a7fcc4c363070d8f60428fb Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 12:56:43 +0800 Subject: [PATCH 4/5] =?UTF-8?q?xlsx=E5=AF=BC=E5=87=BA=E7=9A=84=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=E5=88=A4=E6=96=AD=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../graduation_tasks_controller.rb | 65 +++++-------------- .../graduation_topics_controller.rb | 15 +++-- .../homework_commons_controller.rb | 49 ++------------ app/helpers/export_helper.rb | 11 +++- 4 files changed, 40 insertions(+), 100 deletions(-) diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index a518ac954..aebd8b092 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -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 diff --git a/app/controllers/graduation_topics_controller.rb b/app/controllers/graduation_topics_controller.rb index 2c9132520..b20b767a4 100644 --- a/app/controllers/graduation_topics_controller.rb +++ b/app/controllers/graduation_topics_controller.rb @@ -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 diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 50ec4f7db..2d52b6aa0 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -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 diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index edb2b7e74..a23cb8a65 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -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] From af2f6ae95e4581c1aeebfc76055911fb1c23ea28 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 13:46:52 +0800 Subject: [PATCH 5/5] fix bug --- app/controllers/zips_controller.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 984bef6d2..3b9fa7c02 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -101,14 +101,12 @@ class ZipsController < ApplicationController @course = @homework.course ##7。2 -hs新增 @member = @course.course_member(current_user.id) - @all_student_works = @homework.teacher_works(@member) + @all_student_works = @homework.teacher_works(@member).where("work_status > 0") work_status = params[:work_status] group_id = params[:course_group] - if work_status.present? && !work_status.include?(0) + if work_status.present? @all_student_works = @all_student_works.where(work_status:work_status) - elsif work_status.present? && work_status.include?(0) - normal_status(-1,"仅支持导出已提交的学生!") end if group_id.present?