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 @@ -
+
<%= form_tag( search_stores_path, method: 'post') do %> <%= text_field_tag 'name', params[:name], placeholder: l('welcome.search.information'), name: "name", :class => 'blueinputbar', :style => 'width:450px;'%>    - <%= submit_tag l(:label_search), :class => "enterprise"%> + <%= submit_tag l(:label_search), :class => "enterprise "%> <% end %> + <%= link_to("导出缺失列表",lost_file_stores_path(:format => 'xls'),:style => "background-color: #15bccf;padding: 4px 5px;color: white;") if User.current.admin?%>
<%= l(:label_resources_search_all)%>
\ No newline at end of file diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 1aab2a22c..4306b51c8 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -2023,5 +2023,7 @@ zh: label_evaluation_common: 匿评评语 label_evaluation_time: 匿评时间 + label_file_lost_list: 缺失文件列表 + diff --git a/config/routes.rb b/config/routes.rb index dea176f54..0132b8fc6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -192,6 +192,7 @@ RedmineApp::Application.routes.draw do resources :stores do collection do match 'search', :via => [:get, :post] + get 'lost_file' end end