dev_forum
SylorHuang 5 years ago
parent c22ec7dff2
commit a53c20e028

@ -1173,6 +1173,7 @@ class ExercisesController < ApplicationController
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
@current_user_id = current_user.id @current_user_id = current_user.id
@exercise = @exercise.includes(:exercise_questions)
exercise_ids = [@exercise.id] exercise_ids = [@exercise.id]
@exercise_status = @exercise.get_exercise_status(current_user.id) @exercise_status = @exercise.get_exercise_status(current_user.id)
@course_all_members = @course.students @course_all_members = @course.students
@ -1254,14 +1255,6 @@ class ExercisesController < ApplicationController
end end
end end
if order == "student_id"
@exercise_users_list = @exercise_users_list.joins(user: [:user_extension]).order("user_extensions.student_id DESC")
elsif order == "score"
@exercise_users_list = @exercise_users_list.order("#{order} DESC")
else
@exercise_users_list = @exercise_users_list.order("end_at DESC, start_at DESC")
end
#答题状态的选择 #答题状态的选择
if params[:commit_status].present? if params[:commit_status].present?
choose_type = params[:commit_status] choose_type = params[:commit_status]
@ -1282,9 +1275,17 @@ class ExercisesController < ApplicationController
@exercise_users_list = @exercise_users_list.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%") @exercise_users_list = @exercise_users_list.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%")
end end
if order == "student_id"
@exercise_users_list = @exercise_users_list.joins(user: :user_extension).order("user_extensions.student_id DESC")
elsif order == "score"
@exercise_users_list = @exercise_users_list.joins(user: :user_extension).order("#{order} DESC")
else
@exercise_users_list = @exercise_users_list.order("end_at DESC, start_at DESC")
end
@export_ex_users = @exercise_users_list @export_ex_users = @exercise_users_list
@exercise_users_size = @exercise_users_list.count @exercise_users_size = @exercise_users_list.size
# 分页 # 分页
@page = params[:page] || 1 @page = params[:page] || 1
@ -1296,10 +1297,14 @@ class ExercisesController < ApplicationController
if @user_course_identity > Course::ASSISTANT_PROFESSOR if @user_course_identity > Course::ASSISTANT_PROFESSOR
tip_exception(403,"无权限操作") tip_exception(403,"无权限操作")
else else
get_export_users(@exercise,@course,@export_ex_users) if @exercise_users_size.size > 0
exercise_export_name = normal_status(-1,"暂无用户提交")
"#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" else
render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} 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
} }
end end

@ -186,7 +186,7 @@ class HomeworkCommonsController < ApplicationController
end end
@work_count = @student_works.size @work_count = @student_works.size
@work_excel = @student_works.includes(:student_works_scores) @work_excel = @student_works.includes(:student_works_scores, user: :user_extension, myshixun: :games)
@students = @course.students @students = @course.students
# 分页参数 # 分页参数
@ -207,7 +207,7 @@ class HomeworkCommonsController < ApplicationController
tip_exception(403, "无权限操作") tip_exception(403, "无权限操作")
else else
if @work_excel.present? if @work_excel.present?
@homework = @homework.includes() @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')

@ -18,7 +18,7 @@ class PollsController < ApplicationController
before_action :check_user_id_start_answer,only: [:start_answer] before_action :check_user_id_start_answer,only: [:start_answer]
before_action :check_poll_question_complete,only: [:commit_poll] #问卷提交前来判断问题是否完成 before_action :check_poll_question_complete,only: [:commit_poll] #问卷提交前来判断问题是否完成
before_action :check_poll_commit_result,only: [:commit_result] before_action :check_poll_commit_result,only: [:commit_result]
before_action :get_all_polls_commit, only: [:commit_result] #该问卷全部的用户 # before_action :get_all_polls_commit, only: [:commit_result] #该问卷全部的用户
before_action :get_left_banner_id, only:[:common_header,:start_answer,:new,:edit,:index] before_action :get_left_banner_id, only:[:common_header,:start_answer,:new,:edit,:index]
include PollsHelper include PollsHelper
@ -920,19 +920,32 @@ class PollsController < ApplicationController
def commit_result def commit_result
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
# @poll_questions = @poll.poll_questions.order("question_number ASC")
# 全部页面,需返回
# @poll_questions_count = @poll_questions.size
# 分页 # 分页
@poll = @poll.includes(:poll_users,user: :user_extension,)
@poll_users = @poll.poll_users
@poll_commit_ids = @poll_users.commit_by_status(1).pluck(:user_id) #问卷提交用户的id
@page = params[:page] || 1 @page = params[:page] || 1
@limit = params[:limit] || 10 @limit = params[:limit] || 10
@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| respond_to do |format|
format.json format.json
format.xlsx{ format.xlsx{
if @user_course_identity > Course::ASSISTANT_PROFESSOR if @user_course_identity > Course::ASSISTANT_PROFESSOR
tip_exception(403,"无权限操作") tip_exception(403,"无权限操作")
elsif @poll_export_questions.size == 0 || (@poll_users.where("commit_status = ?",1).size == 0)
normal_status(-1,"暂时没有提交的用户")
else else
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: {poll_questions:@poll_export_questions} 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 end
@ -1028,15 +1041,12 @@ class PollsController < ApplicationController
@poll_users_list = @poll_users_list.joins(user: :user_extension).order("end_at DESC") @poll_users_list = @poll_users_list.joins(user: :user_extension).order("end_at DESC")
end end
logger.info("#######F_______@poll_users_list_last___@users_ids________________####{@poll_users_list.pluck(:user_id)}")
@poll_users_size = @poll_users_list.count @poll_users_size = @poll_users_list.count
# 分页 # 分页
page = params[:page] || 1 page = params[:page] || 1
limit = params[:limit] || 20 limit = params[:limit] || 20
@poll_users_list = @poll_users_list.page(page).per(limit) @poll_users_list = @poll_users_list.page(page).per(limit)
logger.info("#####page_user: #{@poll_users_list.pluck(:id, :user_id)}")
else else
@poll_users_list = [] @poll_users_list = []
@poll_users_size = 0 @poll_users_size = 0
@ -1146,10 +1156,10 @@ class PollsController < ApplicationController
def get_questions_count def get_questions_count
@poll_questions = @poll.poll_questions&.includes(:poll_answers,:poll_votes).order("question_number ASC") @poll_questions = @poll.poll_questions&.includes(:poll_answers,:poll_votes).order("question_number ASC")
@poll_questions_count = @poll_questions.count # 全部的题目数 @poll_questions_count = @poll_questions.size # 全部的题目数
@poll_question_singles = @poll_questions.ques_count(1).all.count # 单选题 @poll_question_singles = @poll_questions.ques_count(1).all.size # 单选题
@poll_question_doubles = @poll_questions.ques_count(2).all.count # 多选题 @poll_question_doubles = @poll_questions.ques_count(2).all.size # 多选题
@poll_question_mains = @poll_questions.ques_count(3).all.count #主观题 @poll_question_mains = @poll_questions.ques_count(3).all.size #主观题
end end
def check_poll_question_complete #commit_poll 的权限 def check_poll_question_complete #commit_poll 的权限

@ -262,14 +262,14 @@ module ExportHelper
end end
export_ex_users.each_with_index do |e_user,index| export_ex_users.each_with_index do |e_user,index|
user_info = e_user.user user_info = e_user.user
user_course_id = user_info.course_members.course_find_by_ids("course_id",course.id).first user_course_id = user_info.course_members.course_find_by_ids("course_id",course.id)&.first
if user_course_id.present? if user_course_id.present?
get_course_group_id = user_course_id.course_group_id get_course_group_id = user_course_id.course_group_id
if get_course_group_id.present? && get_course_group_id != 0 if get_course_group_id.present? && get_course_group_id != 0
user_course_info = CourseGroup.by_group_ids(get_course_group_id) user_course_info = CourseGroup.by_group_ids(get_course_group_id)
user_course = user_course_info.first.name user_course = user_course_info.first.name
else else
user_course = "--" user_course = "未分班"
end end
else else
user_course = "--" user_course = "--"

@ -9,7 +9,7 @@ wb.styles do |s|
sheet.sheet_view.show_grid_lines = false sheet.sheet_view.show_grid_lines = false
poll_users_info = %w(序号) poll_users_info = %w(序号)
poll_ques_titles = poll_questions.pluck(:question_title).map {|k| strip_export_title(k) if k.present?} poll_ques_titles = poll_questions.pluck(:question_title).map {|k| strip_export_title(k) if k.present?}
poll_un_anony = @poll.un_anonymous poll_un_anony = poll.un_anonymous
if poll_un_anony #是否匿名默认为false if poll_un_anony #是否匿名默认为false
user_info = %w(登陆名 真实姓名 邮箱 学号) user_info = %w(登陆名 真实姓名 邮箱 学号)
else else
@ -18,13 +18,13 @@ wb.styles do |s|
poll_users_info = poll_users_info + user_info + poll_ques_titles poll_users_info = poll_users_info + user_info + poll_ques_titles
poll_questions.each do |q| poll_questions.each do |q|
if q.question_type != 3 #问题不为主观题 if q.question_type != 3 #问题不为主观题
question_vote_user = q.poll_votes.find_current_vote("user_id",@poll_commit_ids).count #该问题的有效填写量 question_vote_user = q.poll_votes.find_current_vote("user_id",poll_commit_ids).count #该问题的有效填写量
sheet_row = ["第#{q.question_number}题"] #选择题答案选项的数组 sheet_row = ["第#{q.question_number}题"] #选择题答案选项的数组
sheet_answer_row = ["小计"] #选择题回答的答案人数,数组 sheet_answer_row = ["小计"] #选择题回答的答案人数,数组
sheet_answer_percent = ["比例"] sheet_answer_percent = ["比例"]
sheet_answer_useful = ["有效填写人次",question_vote_user] sheet_answer_useful = ["有效填写人次",question_vote_user]
q.poll_answers.each do |a| #问卷的答案选项 q.poll_answers.each do |a| #问卷的答案选项
answer_users_count = a.poll_votes.find_current_vote("user_id",@poll_commit_ids).count answer_users_count = a.poll_votes.find_current_vote("user_id",poll_commit_ids).count
answer_percent = number_to_percentage((answer_users_count.to_f / question_vote_user.to_f)*100,precision:1) answer_percent = number_to_percentage((answer_users_count.to_f / question_vote_user.to_f)*100,precision:1)
sheet_row.push(a.answer_text) sheet_row.push(a.answer_text)
sheet_answer_row.push(answer_users_count) sheet_answer_row.push(answer_users_count)
@ -49,7 +49,7 @@ wb.styles do |s|
end #each_with_index end #each_with_index
sheet.add_row poll_users_info, :height =>15, :style => blue_cell sheet.add_row poll_users_info, :height =>15, :style => blue_cell
@poll.poll_users.each_with_index do |u,index| poll_users.each_with_index do |u,index|
u_user = u.user u_user = u.user
user_answer_array = [] user_answer_array = []
poll_questions.each do |q| poll_questions.each do |q|

Loading…
Cancel
Save