From 254a643b4f8ab7eb2145726813c01bfdb4fbcd7b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 2 Jul 2019 18:10:08 +0800 Subject: [PATCH 01/17] fix bug --- app/controllers/exercises_controller.rb | 2 -- .../graduation_tasks_controller.rb | 10 ++++-- .../homework_commons_controller.rb | 3 +- app/controllers/zips_controller.rb | 19 +++++++--- .../batch_export_shixun_report_service.rb | 36 ++++++++++--------- 5 files changed, 43 insertions(+), 27 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index d19de52c4..79bed2d25 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1300,8 +1300,6 @@ class ExercisesController < ApplicationController if @export_ex_users.exercise_user_committed.size == 0 normal_status(-1,"暂无用户提交") else - @exercise = @exercise.includes(:exercise_questions) - @export_ex_users = @export_ex_users.includes(user: :user_extension) 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')}" diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index 41ddb7659..1931c26a0 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -129,9 +129,13 @@ class GraduationTasksController < ApplicationController if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") 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} + 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{ diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index b3953c7dd..89e301f93 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -206,8 +206,7 @@ class HomeworkCommonsController < ApplicationController if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") else - if @work_excel.present? - @homework = @homework.includes(:shixuns,:homework_detail_manual) + 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') diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index a70d4c332..e88f4d552 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -6,9 +6,11 @@ class ZipsController < ApplicationController before_action :require_admin_or_teacher def shixun_report - student_work_ids = Array.wrap(params[:student_work_ids]) + # student_work_ids = Array.wrap(params[:student_work_ids]) + + # service = BatchExportShixunReportService.new(@homework, @student_work_ids) + service = BatchExportShixunReportService.new(@homework, @all_student_works) - service = BatchExportShixunReportService.new(@homework, student_work_ids) filename = filename_for_content_disposition(service.filename) send_file service.zip, filename: filename, type: 'application/zip' @@ -57,9 +59,9 @@ class ZipsController < ApplicationController @ex_users = @ex_users.where(user_id: user_ids) end - default_ex_users_size = @ex_users.size + default_ex_users_size = @ex_users&.size - if default_ex_users_size == 0 + if default_ex_users_size.blank? || default_ex_users_size == 0 normal_status(-1,"导出失败,暂时没有已提交的学生") elsif default_ex_users_size > 100 normal_status(-2,"100") @@ -75,5 +77,14 @@ class ZipsController < ApplicationController def load_homework @homework = HomeworkCommon.find(params[:homework_common_id]) @course = @homework.course + ##7。2 -hs新增 + @member = @course.course_member(current_user.id) + @all_student_works = @homework.teacher_works(@member) + student_work_sizes = @all_student_works&.size + if student_work_sizes.blank? || student_work_sizes == 0 + normal_status(-1,"导出失败,暂时没有已提交的学生") + elsif student_work_sizes > 100 + normal_status(-2,"100") + end end end diff --git a/app/services/batch_export_shixun_report_service.rb b/app/services/batch_export_shixun_report_service.rb index 6ea38b23f..ebb273a87 100644 --- a/app/services/batch_export_shixun_report_service.rb +++ b/app/services/batch_export_shixun_report_service.rb @@ -3,11 +3,15 @@ class BatchExportShixunReportService MAX_BATCH_LIMIT = 20 - attr_reader :homework, :student_work_ids + # attr_reader :homework, :student_work_ids + attr_reader :homework, :all_student_works - def initialize(homework, student_work_ids) + + def initialize(homework, all_student_works) @homework = homework - @student_work_ids = student_work_ids + # @student_work_ids = student_work_ids + @all_student_works = all_student_works + end def filename @@ -15,8 +19,8 @@ class BatchExportShixunReportService end def zip - validate! - student_works = homework.student_works.where(id: student_work_ids).includes(:myshixun, user: :user_extension) + # validate! + student_works = all_student_works.includes(:myshixun, user: :user_extension) if student_works.count.zero? raise Error, '请选择要导出的学生实训报告' @@ -41,15 +45,15 @@ class BatchExportShixunReportService end end - private - - def validate! - if student_work_ids.size.zero? - raise Error, '请选择学生实训作业' - end - - if student_work_ids.size > MAX_BATCH_LIMIT - raise Error, '导出实训报告太多,请分批导出' - end - end + # private + # + # def validate! + # if student_work_ids.size.zero? + # raise Error, '请选择学生实训作业' + # end + # + # if student_work_ids.size > MAX_BATCH_LIMIT + # raise Error, '导出实训报告太多,请分批导出' + # end + # end end From 74e613e8045c063c235220e936b9a239c160ee2a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 09:21:08 +0800 Subject: [PATCH 02/17] =?UTF-8?q?pdf=E6=89=B9=E9=87=8F=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=AD=9B=E9=80=89=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/zips_controller.rb | 43 +++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index e88f4d552..984bef6d2 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -49,9 +49,26 @@ class ZipsController < ApplicationController normal_status(-1,"试卷不存在") else @course = @exercise.course - default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed @ex_users = default_ex_users #仅导出已提交的,截止后则是全部为提交的。 + + #是否评阅 + if params[:review].present? + review_type = params[:review].first.to_i #已评,则数据为1,未评,则数据为0,前端传过来的为数组 + if review_type == 1 + @ex_users = @ex_users.where("subjective_score >= ?",0.0) + else + @ex_users = @ex_users.where("subjective_score < ?",0.0) + end + end + + #答题状态的选择 + if params[:commit_status].present? && (params[:commit_status].to_i == 1) + @exercise_users_list = @exercise_users_list.where(commit_status:params[:commit_status]) + elsif params[:commit_status].present? && (params[:commit_status].to_i == 0) + normal_status(-1,"仅支持导出已提交的学生!") + end + #可以分班选择 if group_id.present? exercise_students = @course.students.where(course_group_id: group_id) # 试卷所分班的全部人数 @@ -59,6 +76,11 @@ class ZipsController < ApplicationController @ex_users = @ex_users.where(user_id: user_ids) end + #搜索 + if params[:search].present? + @ex_users = @ex_users.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%") + end + default_ex_users_size = @ex_users&.size if default_ex_users_size.blank? || default_ex_users_size == 0 @@ -80,6 +102,25 @@ class ZipsController < ApplicationController ##7。2 -hs新增 @member = @course.course_member(current_user.id) @all_student_works = @homework.teacher_works(@member) + work_status = params[:work_status] + group_id = params[:course_group] + + if work_status.present? && !work_status.include?(0) + @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? + group_user_ids = @course.students.where(course_group_id: params[:course_group]).pluck(:user_id) + @all_student_works = @all_student_works.where(user_id: group_user_ids) + end + + unless params[:search].blank? + @all_student_works = @all_student_works.joins(user: :user_extension).where("concat(lastname, firstname) like ? + or student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%") + end + student_work_sizes = @all_student_works&.size if student_work_sizes.blank? || student_work_sizes == 0 normal_status(-1,"导出失败,暂时没有已提交的学生") From dfe784a051c14398029a9aaae96ecfbd51471cae Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 09:38:22 +0800 Subject: [PATCH 03/17] fix bug --- app/controllers/exercises_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 79bed2d25..d8278faff 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1297,7 +1297,7 @@ class ExercisesController < ApplicationController if @user_course_identity > Course::ASSISTANT_PROFESSOR tip_exception(403,"无权限操作") else - if @export_ex_users.exercise_user_committed.size == 0 + if (@exercise_users_size == 0) ||( @export_ex_users&.exercise_user_committed.size == 0) normal_status(-1,"暂无用户提交") else get_export_users(@exercise,@course,@export_ex_users) From 8768f4cb237abde1eda6f9e9221d8049f8e8e2ab Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 09:43:04 +0800 Subject: [PATCH 04/17] fix bug --- app/controllers/exercises_controller.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index d8278faff..72e075d31 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1291,13 +1291,15 @@ class ExercisesController < ApplicationController @page = params[:page] || 1 @limit = params[:limit] || 20 @exercise_users_list = @exercise_users_list.page(@page).per(@limit) + logger.info("#######___________@exercise_users_size_________##################{@exercise_users_size}") + logger.info("#######__________@export_ex_users&.exercise_user_committed.size_________##################{@export_ex_users&.exercise_user_committed.size}") respond_to do |format| format.json format.xlsx{ if @user_course_identity > Course::ASSISTANT_PROFESSOR tip_exception(403,"无权限操作") else - if (@exercise_users_size == 0) ||( @export_ex_users&.exercise_user_committed.size == 0) + if (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) normal_status(-1,"暂无用户提交") else get_export_users(@exercise,@course,@export_ex_users) @@ -1316,9 +1318,6 @@ class ExercisesController < ApplicationController format.xlsx{ normal_status(-1,"暂无用户提交") } - format.zip{ - normal_status(-1,"暂无用户提交") - } end end From 09a2eca61846b1ef58154a3352a08d2d756557fb Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 3 Jul 2019 09:58:59 +0800 Subject: [PATCH 05/17] =?UTF-8?q?fork=E5=AE=9E=E8=AE=AD=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E5=A4=8D=E5=88=B6=E5=8F=82=E8=80=83=E7=AD=94=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 3a4592b2f..b91ce9580 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -203,6 +203,13 @@ class ShixunsController < ApplicationController new_challenge.user_id = User.current.id new_challenge.shixun_id = @new_shixun.id new_challenge.save! + # 同步参考答案 + challenge.challenge_answers.each do |answer| + new_answer = Challenge.new + new_answer = answer.attributes.dup.except("id","challenge_id") + new_answer.challenge_id = new_challenge.id + new_answer.save! + end if challenge.st == 0 # 评测题 # 同步测试集 if challenge.test_sets.present? From 14dc08892ce247719bbc6e3a200b93690b9f0740 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 10:14:16 +0800 Subject: [PATCH 06/17] =?UTF-8?q?=E9=AA=8C=E8=AF=81=20format.xlsx=E4=B8=8B?= =?UTF-8?q?=E7=9A=84render=20json=E6=98=AF=E5=90=A6=E6=9C=89=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 45 +++++++++++++++++-------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 72e075d31..a1db41d79 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1291,23 +1291,40 @@ class ExercisesController < ApplicationController @page = params[:page] || 1 @limit = params[:limit] || 20 @exercise_users_list = @exercise_users_list.page(@page).per(@limit) - logger.info("#######___________@exercise_users_size_________##################{@exercise_users_size}") - logger.info("#######__________@export_ex_users&.exercise_user_committed.size_________##################{@export_ex_users&.exercise_user_committed.size}") respond_to do |format| format.json + if @user_course_identity > Course::ASSISTANT_PROFESSOR + tip_exception(403,"无权限操作") + elsif (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) + logger.info("#######___________@exercise_users_size_________##################{@exercise_users_size}") + logger.info("#######__________@export_ex_users&.exercise_user_committed.size_________##################{@export_ex_users&.exercise_user_committed.size}") + + + normal_status(-1,"暂无用户提交") + else + 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 format.xlsx{ - if @user_course_identity > Course::ASSISTANT_PROFESSOR - tip_exception(403,"无权限操作") - else - if (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) - normal_status(-1,"暂无用户提交") - else - 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 + # if @user_course_identity > Course::ASSISTANT_PROFESSOR + # tip_exception(403,"无权限操作") + # else + # if (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) + # logger.info("#######__________@export_ex_users&.exercise_user_committed.size_________##################{@export_ex_users&.exercise_user_committed.size}") + # logger.info("#######___________@exercise_users_size_________##################{@exercise_users_size}") + # + # normal_status(-1,"暂无用户提交") + # else + # 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 else From d7649d04421ab02105d40d987072a75a2d46f254 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 10:16:18 +0800 Subject: [PATCH 07/17] fix bug --- app/controllers/exercises_controller.rb | 46 ++++++++----------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index a1db41d79..038d9a87c 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1293,38 +1293,22 @@ class ExercisesController < ApplicationController @exercise_users_list = @exercise_users_list.page(@page).per(@limit) respond_to do |format| format.json - if @user_course_identity > Course::ASSISTANT_PROFESSOR - tip_exception(403,"无权限操作") - elsif (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) - logger.info("#######___________@exercise_users_size_________##################{@exercise_users_size}") - logger.info("#######__________@export_ex_users&.exercise_user_committed.size_________##################{@export_ex_users&.exercise_user_committed.size}") - - - normal_status(-1,"暂无用户提交") - else - 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 format.xlsx{ - # if @user_course_identity > Course::ASSISTANT_PROFESSOR - # tip_exception(403,"无权限操作") - # else - # if (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) - # logger.info("#######__________@export_ex_users&.exercise_user_committed.size_________##################{@export_ex_users&.exercise_user_committed.size}") - # logger.info("#######___________@exercise_users_size_________##################{@exercise_users_size}") - # - # normal_status(-1,"暂无用户提交") - # else - # 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 + if @user_course_identity > Course::ASSISTANT_PROFESSOR + tip_exception(403,"无权限操作") + else + if (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) + logger.info("#######__________@export_ex_users&.exercise_user_committed.size_________##################{@export_ex_users&.exercise_user_committed.size}") + logger.info("#######___________@exercise_users_size_________##################{@exercise_users_size}") + + normal_status(-1,"暂无用户提交") + else + 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 else From 9fc9bf97e56bbbaf6d2fc4bda6e089c90c4fae44 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 10:23:43 +0800 Subject: [PATCH 08/17] fix bug --- app/controllers/exercises_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 038d9a87c..a10e5ad1b 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1291,6 +1291,7 @@ class ExercisesController < ApplicationController @page = params[:page] || 1 @limit = params[:limit] || 20 @exercise_users_list = @exercise_users_list.page(@page).per(@limit) + tip_exception(403,"无权限操作") respond_to do |format| format.json format.xlsx{ From 39f75a0dc75de9401453b8da6ab3b332ba8d92a4 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 10:30:46 +0800 Subject: [PATCH 09/17] fix bug --- app/controllers/exercises_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index a10e5ad1b..090386361 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1291,7 +1291,7 @@ class ExercisesController < ApplicationController @page = params[:page] || 1 @limit = params[:limit] || 20 @exercise_users_list = @exercise_users_list.page(@page).per(@limit) - tip_exception(403,"无权限操作") + logger.info("###########______________format.xlsx_______#######{format.xlsx}") respond_to do |format| format.json format.xlsx{ From ca4c84d6c2f6f6b425bf0e59f2cd2eb33133f5c9 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 10:35:09 +0800 Subject: [PATCH 10/17] fix bug --- app/controllers/exercises_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 090386361..a050e7eaa 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1291,7 +1291,10 @@ class ExercisesController < ApplicationController @page = params[:page] || 1 @limit = params[:limit] || 20 @exercise_users_list = @exercise_users_list.page(@page).per(@limit) - logger.info("###########______________format.xlsx_______#######{format.xlsx}") + if params[:format] == "xlsx" + logger.info("###########______________format.xlsx______111111111_#######") + + end respond_to do |format| format.json format.xlsx{ From 92006341b66a9a21e878982206b30a0108238eea Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 10:48:12 +0800 Subject: [PATCH 11/17] fix bug --- app/controllers/exercises_controller.rb | 56 ++++++++++++------------- app/controllers/polls_controller.rb | 42 ++++++++++++------- 2 files changed, 54 insertions(+), 44 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index a050e7eaa..2fcf45cda 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1291,39 +1291,37 @@ class ExercisesController < ApplicationController @page = params[:page] || 1 @limit = params[:limit] || 20 @exercise_users_list = @exercise_users_list.page(@page).per(@limit) - if params[:format] == "xlsx" - logger.info("###########______________format.xlsx______111111111_#######") - - end - respond_to do |format| - format.json - format.xlsx{ - if @user_course_identity > Course::ASSISTANT_PROFESSOR - tip_exception(403,"无权限操作") - else - if (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) - logger.info("#######__________@export_ex_users&.exercise_user_committed.size_________##################{@export_ex_users&.exercise_user_committed.size}") - logger.info("#######___________@exercise_users_size_________##################{@exercise_users_size}") - - normal_status(-1,"暂无用户提交") - else - 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 else @exercise_users_list = [] + @export_ex_users = @exercise_users_list @exercise_users_size = 0 - respond_to do |format| - format.json - format.xlsx{ - normal_status(-1,"暂无用户提交") - } + end + + 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) + 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 + # else + # 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 end rescue Exception => e diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 44cdc6512..7075ac0ef 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -927,23 +927,35 @@ class PollsController < ApplicationController @poll_export_questions = @poll_questions.order("question_number ASC") @poll_questions = @poll_questions.page(@page).per(@limit) - respond_to do |format| - format.json - format.xlsx{ - if @user_course_identity > Course::ASSISTANT_PROFESSOR - tip_exception(403,"无权限操作") - elsif (@poll.polls_status == 1) || (@poll_export_questions.size == 0) || (@poll_commit_ids.size == 0) - normal_status(-1,"暂时没有提交的用户") - else - 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} + if params[:format] == "xlsx" + if @user_course_identity > Course::ASSISTANT_PROFESSOR + tip_exception(403,"无权限操作") + elsif (@poll.polls_status == 1) || (@poll_export_questions.size == 0) || (@poll_commit_ids.size == 0) + normal_status(-1,"暂无用户提交") + else + respond_to do |format| + 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 - } + 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 e6f5a2b13a314ab4ec6625cd7ea19f545a0b38b8 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 10:58:24 +0800 Subject: [PATCH 12/17] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84xlsx=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E6=8F=90=E7=A4=BA=E7=9A=84=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 2fcf45cda..c5cf7390f 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1298,9 +1298,16 @@ class ExercisesController < ApplicationController end if params[:format] == "xlsx" + logger.info("#######___________params_xlsx____________##########") + logger.info("#######___________@exercise_users_size____________##########{@exercise_users_size}") + logger.info("#######___________@export_ex_users&.exercise_user_committed.size____________##########{@export_ex_users&.exercise_user_committed.size}") + + if @user_course_identity > Course::ASSISTANT_PROFESSOR tip_exception(403,"无权限操作") elsif (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) + logger.info("#######___________@exercise_users_size == 0____________##########") + normal_status(-1,"暂无用户提交") else respond_to do |format| @@ -1312,18 +1319,7 @@ class ExercisesController < ApplicationController } end end - # else - # 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 end - rescue Exception => e uid_logger_error(e.message) tip_exception("页面调用失败!") From 1b4103a54b1377da8dbd17d661b33681fff65f07 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 3 Jul 2019 11:00:29 +0800 Subject: [PATCH 13/17] =?UTF-8?q?copy=E5=8F=82=E8=80=83=E7=AD=94=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index b91ce9580..265398833 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -205,7 +205,7 @@ class ShixunsController < ApplicationController new_challenge.save! # 同步参考答案 challenge.challenge_answers.each do |answer| - new_answer = Challenge.new + new_answer = ChallengeAnswer.new new_answer = answer.attributes.dup.except("id","challenge_id") new_answer.challenge_id = new_challenge.id new_answer.save! From 04dc476b8854cd3f03178017f030e4c099c37296 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 3 Jul 2019 11:02:45 +0800 Subject: [PATCH 14/17] =?UTF-8?q?copy=E5=8F=82=E8=80=83=E7=AD=94=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 265398833..fdd55e6cf 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -206,7 +206,7 @@ class ShixunsController < ApplicationController # 同步参考答案 challenge.challenge_answers.each do |answer| new_answer = ChallengeAnswer.new - new_answer = answer.attributes.dup.except("id","challenge_id") + new_answer = new_answer.attributes.dup.except("id","challenge_id") new_answer.challenge_id = new_challenge.id new_answer.save! end From af4922ea72ac791332f2fea62e96bc243b25049c Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 3 Jul 2019 11:05:31 +0800 Subject: [PATCH 15/17] 1 --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index fdd55e6cf..265398833 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -206,7 +206,7 @@ class ShixunsController < ApplicationController # 同步参考答案 challenge.challenge_answers.each do |answer| new_answer = ChallengeAnswer.new - new_answer = new_answer.attributes.dup.except("id","challenge_id") + new_answer = answer.attributes.dup.except("id","challenge_id") new_answer.challenge_id = new_challenge.id new_answer.save! end From 35c3cc1e2937ac9d86e6653601676f8ecbac82b2 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 3 Jul 2019 11:07:29 +0800 Subject: [PATCH 16/17] =?UTF-8?q?copy=E5=AE=9E=E8=AE=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 265398833..5a1773a10 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -206,7 +206,7 @@ class ShixunsController < ApplicationController # 同步参考答案 challenge.challenge_answers.each do |answer| new_answer = ChallengeAnswer.new - new_answer = answer.attributes.dup.except("id","challenge_id") + new_answer.attributes = answer.attributes.dup.except("id","challenge_id") new_answer.challenge_id = new_challenge.id new_answer.save! end From 275030bb6a3221f7eaa91bb14231d1928713438a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 11:07:31 +0800 Subject: [PATCH 17/17] fix bug --- app/controllers/exercises_controller.rb | 27 ++++++++++--------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index c5cf7390f..dd19c36d1 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1298,28 +1298,23 @@ class ExercisesController < ApplicationController end if params[:format] == "xlsx" - logger.info("#######___________params_xlsx____________##########") - logger.info("#######___________@exercise_users_size____________##########{@exercise_users_size}") - logger.info("#######___________@export_ex_users&.exercise_user_committed.size____________##########{@export_ex_users&.exercise_user_committed.size}") - - if @user_course_identity > Course::ASSISTANT_PROFESSOR tip_exception(403,"无权限操作") elsif (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) - logger.info("#######___________@exercise_users_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("页面调用失败!")