@ -18,7 +18,7 @@ class PollsController < ApplicationController
before_action :check_user_id_start_answer , only : [ :start_answer ]
before_action :check_poll_question_complete , only : [ :commit_poll ] #问卷提交前来判断问题是否完成
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 ]
include PollsHelper
@ -920,19 +920,32 @@ class PollsController < ApplicationController
def commit_result
ActiveRecord :: Base . transaction do
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
@limit = params [ :limit ] || 10
@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_export_questions . size == 0 || ( @poll_users . where ( " commit_status = ? " , 1 ) . 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 }
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
@ -1028,15 +1041,12 @@ class PollsController < ApplicationController
@poll_users_list = @poll_users_list . joins ( user : :user_extension ) . order ( " end_at DESC " )
end
logger . info ( " # # # # # # # F_______@poll_users_list_last___@users_ids________________ # # # #{ @poll_users_list . pluck ( :user_id ) } " )
@poll_users_size = @poll_users_list . count
# 分页
page = params [ :page ] || 1
limit = params [ :limit ] || 20
@poll_users_list = @poll_users_list . page ( page ) . per ( limit )
logger . info ( " # # # # # page_user: #{ @poll_users_list . pluck ( :id , :user_id ) } " )
else
@poll_users_list = [ ]
@poll_users_size = 0
@ -1146,10 +1156,10 @@ class PollsController < ApplicationController
def get_questions_count
@poll_questions = @poll . poll_questions & . includes ( :poll_answers , :poll_votes ) . order ( " question_number ASC " )
@poll_questions_count = @poll_questions . count # 全部的题目数
@poll_question_singles = @poll_questions . ques_count ( 1 ) . all . count # 单选题
@poll_question_doubles = @poll_questions . ques_count ( 2 ) . all . count # 多选题
@poll_question_mains = @poll_questions . ques_count ( 3 ) . all . count #主观题
@poll_questions_count = @poll_questions . size # 全部的题目数
@poll_question_singles = @poll_questions . ques_count ( 1 ) . all . size # 单选题
@poll_question_doubles = @poll_questions . ques_count ( 2 ) . all . size # 多选题
@poll_question_mains = @poll_questions . ques_count ( 3 ) . all . size #主观题
end
def check_poll_question_complete #commit_poll 的权限