Merge branch 'dev_aliyun' of http://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_forum
cxt 5 years ago
commit 3ced3ef4ce

@ -1291,39 +1291,30 @@ class ExercisesController < ApplicationController
@page = params[:page] || 1 @page = params[:page] || 1
@limit = params[:limit] || 20 @limit = params[:limit] || 20
@exercise_users_list = @exercise_users_list.page(@page).per(@limit) @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 else
@exercise_users_list = [] @exercise_users_list = []
@export_ex_users = @exercise_users_list
@exercise_users_size = 0 @exercise_users_size = 0
respond_to do |format| end
format.json
format.xlsx{ if params[:format] == "xlsx"
normal_status(-1,"暂无用户提交") if @user_course_identity > Course::ASSISTANT_PROFESSOR
} tip_exception(403,"无权限操作")
format.zip{ elsif (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0)
normal_status(-1,"暂无用户提交") normal_status(-1,"暂无用户提交")
}
end 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 rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception("页面调用失败!") tip_exception("页面调用失败!")

@ -129,9 +129,13 @@ class GraduationTasksController < ApplicationController
if @user_course_identity >= Course::STUDENT if @user_course_identity >= Course::STUDENT
tip_exception(403, "无权限操作") tip_exception(403, "无权限操作")
else else
graduation_work_to_xlsx(@work_excel,@task,current_user) if @work_count > 1
exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @task.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') graduation_work_to_xlsx(@work_excel,@task,current_user)
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} 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 end
} }
format.zip{ format.zip{

@ -206,8 +206,7 @@ class HomeworkCommonsController < ApplicationController
if @user_course_identity >= Course::STUDENT if @user_course_identity >= Course::STUDENT
tip_exception(403, "无权限操作") tip_exception(403, "无权限操作")
else else
if @work_excel.present? if @work_count > 1
@homework = @homework.includes(:shixuns,:homework_detail_manual)
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')

@ -927,23 +927,35 @@ class PollsController < ApplicationController
@poll_export_questions = @poll_questions.order("question_number ASC") @poll_export_questions = @poll_questions.order("question_number ASC")
@poll_questions = @poll_questions.page(@page).per(@limit) @poll_questions = @poll_questions.page(@page).per(@limit)
respond_to do |format| if params[:format] == "xlsx"
format.json if @user_course_identity > Course::ASSISTANT_PROFESSOR
format.xlsx{ tip_exception(403,"无权限操作")
if @user_course_identity > Course::ASSISTANT_PROFESSOR elsif (@poll.polls_status == 1) || (@poll_export_questions.size == 0) || (@poll_commit_ids.size == 0)
tip_exception(403,"无权限操作") normal_status(-1,"暂无用户提交")
elsif (@poll.polls_status == 1) || (@poll_export_questions.size == 0) || (@poll_commit_ids.size == 0) else
normal_status(-1,"暂时没有提交的用户") respond_to do |format|
else format.xlsx{
polls_export_name = "#{current_user.real_name}_#{@course.name}_#{@poll.polls_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" 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: { render xlsx: "#{polls_export_name.strip.first(30)}",template: "polls/commit_result.xlsx.axlsx",locals: {
poll_questions:@poll_export_questions, poll_questions:@poll_export_questions,
poll:@poll, poll:@poll,
poll_users: @poll_users, poll_users: @poll_users,
poll_commit_ids:@poll_commit_ids} poll_commit_ids:@poll_commit_ids}
}
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("页面调用失败!")

@ -203,6 +203,13 @@ class ShixunsController < ApplicationController
new_challenge.user_id = User.current.id new_challenge.user_id = User.current.id
new_challenge.shixun_id = @new_shixun.id new_challenge.shixun_id = @new_shixun.id
new_challenge.save! 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.st == 0 # 评测题
# 同步测试集 # 同步测试集
if challenge.test_sets.present? if challenge.test_sets.present?

@ -6,9 +6,11 @@ class ZipsController < ApplicationController
before_action :require_admin_or_teacher before_action :require_admin_or_teacher
def shixun_report 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) filename = filename_for_content_disposition(service.filename)
send_file service.zip, filename: filename, type: 'application/zip' send_file service.zip, filename: filename, type: 'application/zip'
@ -47,9 +49,26 @@ class ZipsController < ApplicationController
normal_status(-1,"试卷不存在") normal_status(-1,"试卷不存在")
else else
@course = @exercise.course @course = @exercise.course
default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed
@ex_users = default_ex_users #仅导出已提交的,截止后则是全部为提交的。 @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? if group_id.present?
exercise_students = @course.students.where(course_group_id: group_id) # 试卷所分班的全部人数 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) @ex_users = @ex_users.where(user_id: user_ids)
end 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,"导出失败,暂时没有已提交的学生") normal_status(-1,"导出失败,暂时没有已提交的学生")
elsif default_ex_users_size > 100 elsif default_ex_users_size > 100
normal_status(-2,"100") normal_status(-2,"100")
@ -75,5 +99,33 @@ class ZipsController < ApplicationController
def load_homework def load_homework
@homework = HomeworkCommon.find(params[:homework_common_id]) @homework = HomeworkCommon.find(params[:homework_common_id])
@course = @homework.course @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
end end

@ -3,11 +3,15 @@ class BatchExportShixunReportService
MAX_BATCH_LIMIT = 20 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 @homework = homework
@student_work_ids = student_work_ids # @student_work_ids = student_work_ids
@all_student_works = all_student_works
end end
def filename def filename
@ -15,8 +19,8 @@ class BatchExportShixunReportService
end end
def zip def zip
validate! # validate!
student_works = homework.student_works.where(id: student_work_ids).includes(:myshixun, user: :user_extension) student_works = all_student_works.includes(:myshixun, user: :user_extension)
if student_works.count.zero? if student_works.count.zero?
raise Error, '请选择要导出的学生实训报告' raise Error, '请选择要导出的学生实训报告'
@ -41,15 +45,15 @@ class BatchExportShixunReportService
end end
end end
private # private
#
def validate! # def validate!
if student_work_ids.size.zero? # if student_work_ids.size.zero?
raise Error, '请选择学生实训作业' # raise Error, '请选择学生实训作业'
end # end
#
if student_work_ids.size > MAX_BATCH_LIMIT # if student_work_ids.size > MAX_BATCH_LIMIT
raise Error, '导出实训报告太多,请分批导出' # raise Error, '导出实训报告太多,请分批导出'
end # end
end # end
end end

Loading…
Cancel
Save