From 7d0d89d4e29f6596b486c6cb15081e4a4fb8560a Mon Sep 17 00:00:00 2001 From: daiao <35855898@qq.com> Date: Thu, 21 Mar 2019 15:50:02 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B6=85=E7=BA=A7=E7=AE=A1=E7=90=86=E5=91=98?= =?UTF-8?q?=E7=9A=84=E5=AE=9E=E8=AE=AD=E5=8F=8D=E9=A6=88=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0excel=E5=AF=BC=E5=87=BA=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=92=8C=E5=AE=9E=E8=AE=AD=E5=90=8D=E7=A7=B0=E6=A3=80?= =?UTF-8?q?=E7=B4=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/managements_controller.rb | 47 ++++++++++++++++++- .../shixun_feedback_message.html.erb | 19 ++++---- .../shixun_feedback_message.js.erb | 3 +- config/routes.rb | 2 +- 4 files changed, 59 insertions(+), 12 deletions(-) diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index 7a8e6495..4d249508 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -791,7 +791,14 @@ class ManagementsController < ApplicationController def shixun_feedback_message @menu_type = 8 @sub_type = 2 - @discusses = Discuss.where(:dis_type => "Shixun").reorder("created_at desc") + @search = params[:search] + if @search.present? + shixun_ids = Shixun.where("name like ?", "%#{params[:search]}%").pluck(:id) + @discusses = Discuss.where(:dis_type => "Shixun", :dis_id => shixun_ids).reorder("created_at desc") + else + @discusses = Discuss.where(:dis_type => "Shixun").reorder("created_at desc") + end + @all_discusses = @discusses @discusses_count = @discusses.count @limit = 20 @is_remote = true @@ -802,6 +809,11 @@ class ManagementsController < ApplicationController respond_to do |format| format.js format.html + format.xls{ + shixun_ids = @all_discusses.pluck(:dis_id).uniq + filename = "#{Time.now.strftime("%Y%m%d")}-实训反馈.xls" + send_data(shixun_feedback_xls(shixun_ids), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename)) + } end end @@ -4045,6 +4057,39 @@ end return sheet.rows end + def shixun_feedback_xls shixun_ids + xls_report = StringIO.new + book = Spreadsheet::Workbook.new + sheet1 = book.create_worksheet :name => "报名列表" + blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10 + sheet1.row(0).default_format = blue + count_row = 1 + shixuns = Shixun.where(:id => shixun_ids).includes(discusses: [:user]) + sheet1.row(0).concat(["序号", "实训ID", "实训名称","评论数", "评论内容", "关卡", "评论者", "评论者职业", + "评论者单位", "评论时间", "社区导师是否已回复"]) + shixuns.each_with_index do |shixun, i| + discusses = shixun.discusses.where("user_id != ?", 1) + sheet1[count_row, 0] = i + 1 + sheet1[count_row, 1] = shixun.identifier + sheet1[count_row, 2] = shixun.name + sheet1[count_row, 3] = discusses.count + discusses.each_with_index do |discuss, j| + user = discuss.user + sheet1[count_row, 4] = discuss.content.gsub(//, "【图片评论】").gsub(/!\[\].+\)/, "【图片评论】") + sheet1[count_row, 5] = "第#{discuss.position}关" + sheet1[count_row, 6] = user.show_real_name + sheet1[count_row, 7] = user.identity + sheet1[count_row, 8] = user.school_name + sheet1[count_row, 9] = format_time discuss.created_at + sheet1[count_row, 10] = discuss.children.pluck(:user_id).include?(1) ? "是" : "否" + count_row += 1 + end + #count_row += 1 + end + book.write xls_report + xls_report.string + end + def competition_member_xls members, competition xls_report = StringIO.new book = Spreadsheet::Workbook.new diff --git a/app/views/managements/shixun_feedback_message.html.erb b/app/views/managements/shixun_feedback_message.html.erb index 52d15e10..4d4914c3 100644 --- a/app/views/managements/shixun_feedback_message.html.erb +++ b/app/views/managements/shixun_feedback_message.html.erb @@ -1,13 +1,14 @@
- <%#= form_tag(url_for(shixuns_managements_path), :id => "managements_shixuns_search", :method => "post", :remote => true ) do %> - - - - - - - - <%# end %> + <%= form_tag(url_for(shixun_feedback_message_managements_path), :id => "managements_shixuns_search", :method => "post", :remote => true ) do %> + + <% end %>
<%= render :partial => "shixun_feedback_list" %>
diff --git a/app/views/managements/shixun_feedback_message.js.erb b/app/views/managements/shixun_feedback_message.js.erb index b25de121..135f4107 100644 --- a/app/views/managements/shixun_feedback_message.js.erb +++ b/app/views/managements/shixun_feedback_message.js.erb @@ -1 +1,2 @@ -$("#management_shixun_feedback_list").html("<%= j(render :partial => 'shixun_feedback_list') %>"); \ No newline at end of file +$("#management_shixun_feedback_list").html("<%= j(render :partial => 'shixun_feedback_list') %>"); +$("#shixun_search").attr("href", "<%= shixun_feedback_message_managements_path(:search => @search, :format => "xls") %>") \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 79c46a54..0078eb48 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -600,7 +600,7 @@ RedmineApp::Application.routes.draw do ## oauth相关 get 'create_departments' post 'add_department' get 'shixun_feedback' - get 'shixun_feedback_message' + match 'shixun_feedback_message', :via => [:get, :post] get 'leave_message' get 'messages_list' get 'course_messages_list'