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(/