From fe2438215797849367648f01f1dc043503e0c99a Mon Sep 17 00:00:00 2001 From: cxt Date: Tue, 10 Jan 2017 11:00:18 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AB=9E=E8=B5=9B=E7=9A=84=E6=88=90=E5=91=98?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E9=A1=B5=EF=BC=8C=E5=A2=9E=E5=8A=A0=E2=80=9C?= =?UTF-8?q?=E5=8D=95=E4=BD=8D=E5=90=8D=E7=A7=B0=E2=80=9D=E7=9A=84=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=EF=BC=8C=E5=90=8C=E6=97=B6=E5=A2=9E=E5=8A=A0excel?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/contests_controller.rb | 46 ++++++++++++++++++++- app/views/contests/_contest_member.html.erb | 8 +++- app/views/contests/_members.html.erb | 3 +- config/routes.rb | 1 + public/stylesheets/css/contest.css | 3 +- 5 files changed, 56 insertions(+), 5 deletions(-) diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index fee9f451f..91ea92629 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -9,7 +9,7 @@ class ContestsController < ApplicationController include AvatarHelper before_filter :find_contest, :only => [:show, :settings, :update, :destroy, :contest_activities, :search_member, :private_or_public, :switch_role, :set_invite_code_halt, :renew, - :member] + :member, :export_all_members] before_filter :is_logged, :only => [:index, :new, :create] before_filter :is_admin?, :only => [:settings, :set_invite_code_halt, :destroy] before_filter :is_member?, :only => [:show, :contest_activities] @@ -284,8 +284,52 @@ class ContestsController < ApplicationController end end + def export_all_members + sql = "SELECT DISTINCT(cmr.id) AS cmr_id, cmr.role_id, users.`login`, users.id AS user_id, users.`mail`, cmr.created_at FROM users, contest_members cm, contest_member_roles cmr, user_extensions ue, schools " + + "WHERE users.id = cm.`user_id` AND users.id=ue.`user_id` AND cmr.`contest_member_id` = cm.`id` AND cm.`contest_id` = #{@contest.id} AND (ue.`school_id` IS NULL OR ue.`school_id` = schools.`id`) " + + "ORDER BY role_id ASC, CONVERT(schools.`name` USING gbk) COLLATE gbk_chinese_ci DESC, CONVERT(users.`lastname` USING gbk) COLLATE gbk_chinese_ci DESC" + @members = ContestMemberRole.find_by_sql sql + respond_to do |format| + format.xls { + filename = "#{@contest.name.to_s}-成员列表-#{DateTime.parse(Time.now.to_s).strftime('%Y%m%d%H%M%S').to_s}.xls" + send_data(member_to_xls(@members), :type => "text/excel;charset=utf-8; header=present", + :filename => filename_for_content_disposition("#{filename}.xls")) + } + end + end + private + def member_to_xls members + 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 + #sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_class),l(:excel_f_score),l(:excel_commit_time)]) + sheet1[0,0] = "id" + sheet1[0,1] = "姓名" + sheet1[0,2] = "登录名" + sheet1[0,3] = "电子邮箱" + sheet1[0,4] = "单位" + sheet1[0,5] = "角色" + sheet1[0,6] = "加入时间" + count_row = 1 + members.each_with_index do |member, i| + user = User.find(member.user_id) + sheet1[count_row,0]= user.id + sheet1[count_row,1] = user.show_name + sheet1[count_row,2] = user.login + sheet1[count_row,3] = user.mail + sheet1[count_row,4] = user.user_extensions.school_id.blank? ? "" : (user.user_extensions.school.blank? ? "" : user.user_extensions.school.name) + sheet1[count_row,5] = member.role_id == 13 ? "管理员" : (member.role_id == 14 ? "评委" : "参赛者") + sheet1[count_row,6] = format_time member.created_at + count_row += 1 + end + book.write xls_report + xls_report.string + end + def find_contest if params[:id].to_i < 780 render_403 diff --git a/app/views/contests/_contest_member.html.erb b/app/views/contests/_contest_member.html.erb index 6cca7d599..923ba1320 100644 --- a/app/views/contests/_contest_member.html.erb +++ b/app/views/contests/_contest_member.html.erb @@ -2,7 +2,8 @@ 序号 - 姓名 + 姓名 + 单位 角色 操作 @@ -12,7 +13,10 @@ <%= index + 1 %> - <%= link_to member.user.show_name, user_path(member.user), :class => "pro_new_idname ml10", :title => "#{member.user.show_name}" %> + <%= link_to member.user.show_name, user_path(member.user), :class => "pro_new_idname ml10 mr10", :title => "#{member.user.show_name}" %> + + + <%=member.user.user_extensions.school ? member.user.user_extensions.school.name : '--' %> <%= zh_contest_role(h member.roles.sort.collect(&:to_s).join(', ')) %> diff --git a/app/views/contests/_members.html.erb b/app/views/contests/_members.html.erb index aeefcfc79..da4de072d 100644 --- a/app/views/contests/_members.html.erb +++ b/app/views/contests/_members.html.erb @@ -1,5 +1,6 @@
- 添加成员 + 添加成员 + <%= link_to "Excel导出", export_all_members_contest_path(@contest, :format => 'xls'), :class => 'fl sy_btn_green mb10 ml15' %>
<%= form_tag url_for(:controller => 'contest_members', :action => 'create', :contest => @contest.id),:id => 'contest_member_add_form', :remote => true do |f|%> diff --git a/config/routes.rb b/config/routes.rb index cb1218965..d95d04d68 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -637,6 +637,7 @@ RedmineApp::Application.routes.draw do get 'set_invite_code_halt' get 'renew' get 'member' + get 'export_all_members' end resources :boards diff --git a/public/stylesheets/css/contest.css b/public/stylesheets/css/contest.css index 3f62bd956..28fdd8c8b 100644 --- a/public/stylesheets/css/contest.css +++ b/public/stylesheets/css/contest.css @@ -12,7 +12,8 @@ .mt12{ margin-top:12px;} .pro_new_idbox{ width: 40%; padding-left: 30px;} .pro_new_idlist{ width: 50%; border-right: 1px solid #e5e5e5; padding-right: 30px; min-height: 100px;} -.pro_new_idname{display:block;width:300px; overflow:hidden;white-space: nowrap; text-overflow:ellipsis;} +.pro_new_idname{display:block;width:160px; overflow:hidden;white-space: nowrap; text-overflow:ellipsis;} +.pro_new_school_name{display:block;width:130px; overflow:hidden;white-space: nowrap; text-overflow:ellipsis;} .sy_new_tchbox p{ line-height: 30px;} .pro_newsetting_con p,.pro_newsetting_con { line-height: 30px;} .w650{ width: 650px;}