diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index d19de52c4..dd19c36d1 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1291,39 +1291,30 @@ class ExercisesController < ApplicationController @page = params[:page] || 1 @limit = params[:limit] || 20 @exercise_users_list = @exercise_users_list.page(@page).per(@limit) - respond_to do |format| - format.json - format.xlsx{ - if @user_course_identity > Course::ASSISTANT_PROFESSOR - tip_exception(403,"无权限操作") - else - 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')}" - 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,"暂无用户提交") - } - format.zip{ - 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,"暂无用户提交") + 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 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/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("页面调用失败!") diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 3a4592b2f..5a1773a10 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 = ChallengeAnswer.new + new_answer.attributes = 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? diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index a70d4c332..984bef6d2 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' @@ -47,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) # 试卷所分班的全部人数 @@ -57,9 +76,14 @@ class ZipsController < ApplicationController @ex_users = @ex_users.where(user_id: user_ids) end - default_ex_users_size = @ex_users.size + #搜索 + 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 == 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 +99,33 @@ 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) + 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,"导出失败,暂时没有已提交的学生") + 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