From 2344e3d07f753e643e7dbdc363c24ccdc5203e20 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Thu, 2 Jul 2015 10:41:08 +0800 Subject: [PATCH] =?UTF-8?q?admin=E7=94=A8=E6=88=B7=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E7=BC=BA=E5=A4=B1=E6=96=87=E4=BB=B6=E5=88=97=E8=A1=A8=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/stores_controller.rb | 39 +++++++++++++++++++++++++++ app/views/stores/_search_bar.html.erb | 5 ++-- config/locales/zh.yml | 2 ++ config/routes.rb | 1 + 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/app/controllers/stores_controller.rb b/app/controllers/stores_controller.rb index b1705c826..85ea85241 100644 --- a/app/controllers/stores_controller.rb +++ b/app/controllers/stores_controller.rb @@ -72,6 +72,22 @@ class StoresController < ApplicationController l(:label_borad_project), #l(:label_contest_innovate), l(:label_forum) ] end + + #缺失文件列表 + def lost_file + attachments = [] + Attachment.where("container_id is not null and container_type is not null and container_type <> 'Bid' and container_type <> 'HomeworkAttach'").each do |attachment| + unless File.exist?(attachment.diskfile) + attachments << attachment + end + end + respond_to do |format| + format.xls { + send_data(homework_to_xls(attachments), :type => "text/excel;charset=utf-8; header=present", + :filename => "#{l(:label_file_lost_list)}.xls") + } + end + end private @@ -117,4 +133,27 @@ class StoresController < ApplicationController else end end + + #作品列表转换为excel + def homework_to_xls attachments + xls_report = StringIO.new + book = Spreadsheet::Workbook.new + sheet1 = book.create_worksheet :name => "homework" + blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10 + sheet1.row(0).default_format = blue + sheet1.row(0).concat(["文件ID","文件名","硬盘路径","上传时间","是否公开","所属对象","所属对象Id"]) + count_row = 1 + attachments.each do |attachment| + sheet1[count_row,0] = attachment.id + sheet1[count_row,1] = attachment.filename + sheet1[count_row,2] = attachment.diskfile + sheet1[count_row,3] = format_time(attachment.created_on) + sheet1[count_row,4] = (attachment.is_public == 1 || attachment.is_public) ? "是" :"否" + sheet1[count_row,5] = attachment.container_type + sheet1[count_row,6] = attachment.container_id + count_row += 1 + end + book.write xls_report + xls_report.string + end end diff --git a/app/views/stores/_search_bar.html.erb b/app/views/stores/_search_bar.html.erb index e4dea7a02..8a7481aa6 100644 --- a/app/views/stores/_search_bar.html.erb +++ b/app/views/stores/_search_bar.html.erb @@ -1,8 +1,9 @@ -