From 7055401525b818a1b457eea15a960e6eedfde93e Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 17:20:46 +0800 Subject: [PATCH] fix but --- app/services/exercise_user_pdf_service.rb | 6 - app/services/export_exercises_service.rb | 14 - .../exercise_export/exercise_user.html.erb | 354 +----------------- 3 files changed, 1 insertion(+), 373 deletions(-) diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index 1f2f84414..d74e66d31 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -41,14 +41,8 @@ class ExerciseUserPdfService # aa = File.open(Rails.root.join("public/123.html"),"w+") # aa.syswrite(kit.source) #正式需删掉------- - Rails.logger.info("##################_______________________file_name___________5555555555__________###########") - file = Tempfile.new(filename) - Rails.logger.info("##################_______________________file_name___________66666666__________###########") - kit.to_pdf(file.path) - Rails.logger.info("##################_______________________file_name___________7777777777__________###########") - file end diff --git a/app/services/export_exercises_service.rb b/app/services/export_exercises_service.rb index c450f6247..12b5501f9 100644 --- a/app/services/export_exercises_service.rb +++ b/app/services/export_exercises_service.rb @@ -14,29 +14,15 @@ class ExportExercisesService end def ex_zip - Rails.logger.info("##################_______________________file_name___________11111__________###########") - zip_file = Tempfile.new(filename) - Rails.logger.info("##################_______________________file_name___________2222222__________###########") - pdfs = [] Zip::File.open(zip_file.path, Zip::File::CREATE) do |zip| - Rails.logger.info("##################_______________________file_name___________3333333__________###########") - ex_users.each do |ex_user| export = ExerciseUserPdfService.new(exercise, ex_user) - Rails.logger.info("##################_______________________file_name___________444444__________###########") - pdf = export.ex_pdf - Rails.logger.info("##################_______________________file_name___________888888888__________###########") - pdfs << pdf - Rails.logger.info("##################_______________________file_name___________999999999__________###########") - begin zip.add(export.filename, pdf.path) - Rails.logger.info("##################_______________________file_name___________10000000000000__________###########") - rescue => ex Rails.logger.error(ex.message) zip.get_output_stream('FILE_NOTICE.txt'){|os| os.write("文件重复:#{export.filename}") } diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 088ff1fd4..d769ca0f0 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -1,353 +1 @@ - - - - - - - -
-
-
-
-

<%= @exercise.try(:exercise_name) %>

-
-
-

- <%= @exercise.try(:exercise_description).nil? ? "" : @exercise.try(:exercise_description)&.html_safe %> -

-
-
-
-
-

- <% if @exercise_single_ques_count > 0 %> - 单选题<%= @exercise_single_ques_count %>题, - 共<%= @exercise_single_ques_scores %> - <% end %> - <% if @exercise_double_ques_count > 0 %> - 多选题<%= @exercise_double_ques_count %>题, - 共<%= @exercise_double_ques_scores %> - <% end %> - <% if @exercise_ques_judge_count > 0 %> - 判断题<%= @exercise_ques_judge_count %>题, - 共<%= @exercise_ques_judge_scores %> - <% end %> - <% if @exercise_ques_null_count > 0 %> - 填空题<%= @exercise_ques_null_count %>题, - 共<%= @exercise_ques_null_scores %> - <% end %> - <% if @exercise_ques_main_count > 0 %> - 主观题<%= @exercise_ques_main_count %>题, - 共<%= @exercise_ques_main_scores %> - <% end %> - <% if @exercise_ques_shixun_count > 0 %> - 实训题<%= @exercise_ques_shixun_count %>题, - 共<%= @exercise_ques_shixun_scores %> - <% end %> - - <% if @exercise_ques_count > 0 %> - - 共<%= @exercise_ques_scores %>分 - - - 合计<%= @exercise_ques_count %>题 - - <% end %> -

-
-
-
- <% if @ex_obj_array.size > 0 %> -
-

- 客观题 - 正确 - 错误 - 部分得分 - 总分:<%= @exercise_user.score %>分 -

-
-
- <% @ex_obj_array.each do |s| %> - <% if s[:stand_status] == 1 %> -
- <%= s[:q_position] %> -
- <% elsif s[:stand_status] == 0 %> -
- <%= s[:q_position] %> -
- <% else %> -
- <%= s[:q_position] %> -
- <% end %> - <% end %> -
- <% end %> - <% if @ex_sub_array.size > 0 %> -
-

- 主观题 - 已评 - 未评 - 开始答题时间:<%= @exercise_user.start_at.present? ? @exercise_user.start_at.strftime("%Y-%m-%d %H:%M") : "--" %> -

-
-
- <% @ex_sub_array.each do |s| %> - <% if s[:stand_status] == 0 %> -
- <%= s[:q_position] %> -
- <% else %> -
- <%= s[:q_position] %> -
- <% end %> - <% end %> -
- <% end %> -
-
- <% @exercise_questions.each do |q| %> - <% q_type = q.question_type %> - <% user_answer = (q_type == 5 ? q.exercise_shixun_answers.where(user_id: @ex_user_user.id) : q.exercise_answers.where(user_id: @ex_user_user.id)) %> - <% this_ques_status = @ex_obj_array.detect{|f| f[:q_id] == q.id} %> - <% main_ques_status = @ex_sub_array.detect{|f| f[:q_id] == q.id} %> - <% ques_comment = q.exercise_answer_comments.where("exercise_answer_id",user_answer.first&.id) %> -
-
-
-
- <%= q.question_number %>、  - - <%= q.question_type_name %> - - (<%= q&.question_score %>分) - <% if q_type == 5 %> - - <% if this_ques_status.present? && this_ques_status[:stand_status] == 1 %> - - <%= this_ques_status[:user_score] %>分 - <% elsif this_ques_status.present? && this_ques_status[:stand_status] == 2 %> - - <%= this_ques_status[:user_score] %>分 - <% else %> - - 0.0分 - <% end %> - - <% elsif q_type == 4 %> - - <% if main_ques_status.present? && main_ques_status[:stand_status] == 1 %> - - <%= main_ques_status[:user_score] %>分 - <% elsif main_ques_status.present? && main_ques_status[:stand_status] == 2 %> - - <%= main_ques_status[:user_score] %>分 - <% else %> - 未批 - <% end %> - - <% else %> - - <% if this_ques_status.present? && this_ques_status[:stand_status] == 1 %> - - <%= this_ques_status[:user_score] %>分 - <% elsif this_ques_status.present? && this_ques_status[:stand_status] == 2 %> - - <%= this_ques_status[:user_score] %>分 - <% else %> - - 0.0分 - <% end %> - - <% end %> -
-
- <% if q_type == 5 %> - <%= q.shixun_name&.html_safe %> -
- <%= q.question_title&.html_safe %> -
- <% elsif q_type == 4 %> - <%= q.question_title&.html_safe %> - <% else %> - <%= q.question_title&.html_safe %> - <% end %> -
-
-
- <% if q_type == 0 %> - <% q.exercise_choices.each_with_index do |s,index| %> - <% check_answer = (user_answer.present? && (s.id == user_answer.first.exercise_choice_id)) ? "choose-answer" : '' %> -

- - <%= convert_to_char((index+1).to_s)%><%= s.choice_text%> -

- <% end %> - <% elsif q_type == 1 %> - <% q.exercise_choices.each_with_index do |s,index| %> - <% check_answer = (user_answer.present? && (user_answer.pluck(:exercise_choice_id).include?(s.id))) ? true : false %> -

- <% if check_answer %> - - <% else %> - - <% end %> - <%= convert_to_char((index+1).to_s)%><%= s.choice_text%> -

- <% end %> - <% elsif q_type == 2 %> -

- <% q.exercise_choices.each do |s| %> - <% if user_answer.present? && (s.id == user_answer.first.exercise_choice_id) %> - <% check_answer = 'choose-answer' %> - <% else %> - <% check_answer = '' %> - <% end %> - - - <%= s.choice_text %> - - <% end %> -

- <% elsif q_type == 3 %> - <% st_counts = q.exercise_standard_answers.pluck(:exercise_choice_id).uniq %> - <% st_counts.each_with_index do |s,index| %> - <% if user_answer.present? && user_answer.where(exercise_choice_id:s).present? %> - <% check_answer = user_answer.where(exercise_choice_id:s).first.answer_text %> - <% else %> - <% check_answer = "--" %> - <% end %> -

- 答案(填空<%= index+1 %>): - <%= check_answer&.html_safe %> -

- <% end %> - <% elsif q_type == 4 %> - <% check_answer = (user_answer.present? ? user_answer.first.answer_text : '--') %> -

- <%= check_answer&.html_safe %> -

- <% else %> -
-

- 阶段成绩 -

- - - - - - - - - - - - <% if @games.size > 0 %> - <% @games.each_with_index do |game, index| %> - <% user_score = q.exercise_shixun_answers.where(exercise_shixun_challenge_id:game.challenge.id,user_id: @ex_user_user.id) %> - <% game_score = q.exercise_shixun_challenges.where(challenge_id:game.challenge.id) %> - - - - - - - - - - <% end %> - <% else %> - <% q.exercise_shixun_challenges.each_with_index do |game, index| %> - <% game_score = q.exercise_shixun_challenges.where(challenge_id:game.challenge.id) %> - - - - - - - - - - <% end %> - <% end %> - -
关卡任务名称评测次数完成时间耗时经验值得分/满分
<%= index + 1 %> - <%= game.challenge.subject %> - <%= game.evaluate_count %><%= game.end_time.present? ? game.end_time.strftime("%Y-%m-%d %H:%M") : "--" %><%= ApplicationController.helpers.time_consuming game %><%= game.final_score %> / <%= game.challenge.all_score %><%= user_score.present? ? user_score.first.score : 0.0 %> / <%= game_score.present? ? game_score.first.question_score : 0.0 %>
<%= index + 1 %> - <%= game.challenge.subject %> - 0----0.0 / <%= game.challenge.all_score %>0.0 / <%= game_score.present? ? game_score.first.question_score : 0.0 %>
-
-
-

- 实训详情 -

- <% @games.each_with_index do |game, index| %> -
-

- 第<%= index+1 %>关<%= game.challenge.subject %> -

-
- <% if game.outputs.present? %> - - - - - - - <% outputs = game.outputs.group("query_index") %> - <% outputs.reverse.try(:each) do |output| %> - - - - - <% end %> - -
评测次数评测信息
<%= "第#{output.query_index}次" %><%= output_detail(game, output) %>
- <% end %> - <% if game.try(:lastest_code).present? && game.challenge.st == 0 %> - <% con_rows = content_line(game.lastest_code) %> -
-

- - 最近通过的代码 - <%= game.challenge.path %> - -

-
- -
-
- <% end %> -
-
- <% end %> -
- <% end %> -
-
-
- <% if ques_comment.present? && ques_comment.first.comment.present? %> - <% ques_user = ques_comment.first.user %> -
-
-
- -
-
-

<%= ques_user.real_name %><%= ques_comment.first.updated_at.strftime('%Y-%m-%d %H:%M') %>

-

<%= ques_comment.first.comment %>

-
-
-
- <% end %> - <% end %> -
-
-
- - +11111111111111 \ No newline at end of file