forked from Trustie/forgeplus
定制竞赛作品下载
This commit is contained in:
parent
0b34f49ea7
commit
2d067f0a18
|
|
@ -1,6 +1,6 @@
|
|||
class CompetitionInfosController < ApplicationController
|
||||
include ApplicationHelper
|
||||
before_action :find_competition, only: [:show, :update, :enroll, :upload, :enroll_status, :statistics, :enroll_list, :enroll_update, :enroll_status_update]
|
||||
before_action :find_competition, only: [:show, :update, :enroll, :upload, :enroll_status, :statistics, :enroll_list, :enroll_update, :enroll_status_update, :upload_enroll_template]
|
||||
before_action :require_admin, only: [:index, :new, :edit, :create]
|
||||
before_action :check_competition_manager, only: [:update, :enroll_status_update]
|
||||
|
||||
|
|
@ -77,12 +77,12 @@ class CompetitionInfosController < ApplicationController
|
|||
format.xlsx {
|
||||
set_export_cookies
|
||||
competition_users = params[:upload].to_s == "true" ? competition_users.where(status: [2]) : competition_users.where(status: [1,2])
|
||||
@table_columns = @competition_info.is_local? ? %w(参赛单位 参赛负责人 职务 军衔 电话 赛区 赛项 课题来源 成员) : %w(参赛单位 参赛负责人 电话 赛区 赛项 课题来源 成员)
|
||||
@table_columns = @competition_info.is_local? ? %w(ID 参赛单位 参赛负责人 职务 军衔 电话 赛区 赛项 课题来源 成员) : %w(ID 参赛单位 参赛负责人 电话 赛区 赛项 成员)
|
||||
@table_columns = @table_columns + %w(作品下载链接) if params[:upload].to_s == "true"
|
||||
@export_infos = []
|
||||
competition_users.each do |u|
|
||||
info_array = @competition_info.is_local? ? [u.org_name, u.leader, u.org_job, u.org_rank, u.phone, u.zone, u.sub_competition, u.subject_source_type == 0 ? "自主提报" : u.subject_source_name,
|
||||
u.members_to_string] : [u.org_name, u.leader, u.phone, u.zone, u.sub_competition, u.subject_source_type == 0 ? "自主提报" : u.subject_source_name,
|
||||
info_array = @competition_info.is_local? ? [u.id, u.org_name, u.leader, u.org_job, u.org_rank, u.phone, u.zone, u.sub_competition, u.subject_source_type == 0 ? "自主提报" : u.subject_source_name,
|
||||
u.members_to_string] : [u.id, u.org_name, u.leader, u.phone, u.zone, u.sub_competition,
|
||||
u.members_to_string]
|
||||
if params[:upload].to_s == "true"
|
||||
info_array = info_array + [u.attachments.blank? ? "" : "#{EduSetting.get('host_name')}/#{download_url(u.attachments.first)}"]
|
||||
|
|
@ -93,6 +93,12 @@ class CompetitionInfosController < ApplicationController
|
|||
export_name = "竞赛作品列表_#{Time.now.strftime('%Y%m%d_%H%M%S')}" if params[:upload].to_s == "true"
|
||||
render xlsx: "#{export_name.strip}", template: "competition_infos/enroll_list.xlsx.axlsx", locals: {table_columns: @table_columns, export_infos: @export_infos}
|
||||
}
|
||||
format.zip {
|
||||
competition_users = params[:upload].to_s == "true" ? competition_users.where(status: [2]) : competition_users.where(status: [1,2])
|
||||
Rails.logger.info("######_______________########competition_users.size: #{competition_users.size}")
|
||||
service = Competition::ZipWorkFileService.new(competition_users,"")
|
||||
send_file service.zip, filename: service.filename, type: 'application/zip'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -129,6 +135,14 @@ class CompetitionInfosController < ApplicationController
|
|||
render_ok
|
||||
end
|
||||
|
||||
def upload_enroll_template
|
||||
competition_user = CompetitionUser.find_by(competition_info: @competition_info.id, user_id: current_user.id)
|
||||
tip_exception "未报名,请先报名" if competition_user.blank?
|
||||
tip_exception "附件参数enroll_template_id不能为空" if params[:enroll_template_id].blank?
|
||||
competition_user.update_attributes!(enroll_template_id: params[:enroll_template_id])
|
||||
render_ok
|
||||
end
|
||||
|
||||
def enroll_status
|
||||
@competition_user = CompetitionUser.find_by(competition_info: @competition_info.id, user_id: current_user.id)
|
||||
end
|
||||
|
|
@ -163,12 +177,12 @@ class CompetitionInfosController < ApplicationController
|
|||
|
||||
def enroll_params
|
||||
params.permit(:org_name, :org_job, :org_rank, :leader, :zone, :sub_competition, :phone,
|
||||
:subject_source_type, :subject_source_name)
|
||||
:subject_source_type, :subject_source_name, :enroll_template_id)
|
||||
end
|
||||
|
||||
def competition_info_params
|
||||
params.require(:competition_info).permit(:title, :zones, :zones_local, :sub_competitions, :identifier, :content,
|
||||
:video_url, :is_local, :manager_ids, :upload_date, :enroll_date, :guide, :about_us, :banner_url)
|
||||
:video_url, :is_local, :manager_ids, :upload_date, :enroll_date, :guide, :about_us, :banner_url, :enroll_template)
|
||||
end
|
||||
|
||||
def find_competition
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
require 'rubygems'
|
||||
require 'zip'
|
||||
|
||||
class Competition::ZipWorkFileService
|
||||
|
||||
attr_reader :competition_users, :path
|
||||
|
||||
def initialize(competition_users, path)
|
||||
@competition_users = competition_users
|
||||
@path = path
|
||||
end
|
||||
|
||||
def filename
|
||||
export_name = "提案作品-#{Time.now.strftime('%Y%m%d%H%M%S')}"
|
||||
"#{export_name.strip}.zip"
|
||||
end
|
||||
|
||||
def zip
|
||||
zip_file = Rails.root.join(@path, filename)
|
||||
Zip::File.open(zip_file, Zip::File::CREATE) do |attach_zip|
|
||||
if @competition_users.present?
|
||||
@competition_users.each do |c_user|
|
||||
next if c_user.attachments.blank?
|
||||
attach = c_user.attachments.last
|
||||
attach_local_path = "#{Rails.root}/files/#{attach.disk_directory}/#{attach.disk_filename}"
|
||||
attach_filename = "#{c_user.id}_#{c_user.leader}_#{attach.filename}"
|
||||
begin
|
||||
attach_zip.add(attach_filename, attach_local_path)
|
||||
rescue => ex
|
||||
Rails.logger.error("########—————————————2222222#######" + ex.message)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
zip_file
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -32,6 +32,10 @@
|
|||
<%= form.label :video_url, "视频地址" %>
|
||||
<%= form.text_field :video_url, :style=>'width:800px;' %>
|
||||
</div>
|
||||
<div class="field">
|
||||
<%= form.label :enroll_template, "报名资料文件" %>
|
||||
<%= form.text_field :enroll_template, :style=>'width:800px;' %>
|
||||
</div>
|
||||
<div class="field">
|
||||
<%= form.label :is_local, "是否内网环境" %>
|
||||
<%= form.check_box("is_local", {}, "true", "false") %>
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@ json.data do
|
|||
json.user_id c_user.user_id
|
||||
json.user_real_name c_user.user&.real_name
|
||||
json.members c_user.members
|
||||
json.enroll_template do
|
||||
file = Attachment.find_by(id: c_user.enroll_template_id)
|
||||
json.partial! 'attachments/attachment_simple', attachment: file if file.present?
|
||||
end
|
||||
json.attachments c_user.attachments do |attachment|
|
||||
json.partial! "attachments/attachment_simple", locals: {attachment: attachment}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,12 +9,16 @@ json.data do
|
|||
json.user_id @competition_user.user_id
|
||||
json.user_real_name @competition_user.user&.real_name
|
||||
json.members @competition_user.members
|
||||
json.enroll_template do
|
||||
file = Attachment.find_by(id: @competition_user.enroll_template_id)
|
||||
json.partial! 'attachments/attachment_simple', attachment: file if file.present?
|
||||
end
|
||||
end
|
||||
end
|
||||
json.upload_status @competition_user.present? ? @competition_user.attachments.present? : false
|
||||
if @competition_user.present? && @competition_user.attachments.present?
|
||||
json.attachments @competition_user.attachments do |attachment|
|
||||
json.partial! "attachments/attachment_simple", locals: {attachment: attachment}
|
||||
json.partial! "attachments/attachment_simple", locals: { attachment: attachment }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
json.status 0
|
||||
json.message "success"
|
||||
json.data do
|
||||
json.extract! @competition_info, :id, :identifier, :title, :content, :video_url, :is_local, :enroll_date, :upload_date, :guide, :about_us,:banner_url
|
||||
json.extract! @competition_info, :id, :identifier, :title, :content, :video_url, :is_local, :enroll_date, :upload_date, :guide, :about_us,:banner_url,:enroll_template
|
||||
json.zones @competition_info.competition_zones
|
||||
json.sub_competitions @competition_info.sub_competitions.to_s.split(",")
|
||||
json.is_manager @competition_info.is_manager?(current_user)
|
||||
|
|
|
|||
|
|
@ -397,6 +397,7 @@ Rails.application.routes.draw do
|
|||
post :enroll_status_update
|
||||
post :enroll
|
||||
post :upload
|
||||
post :upload_enroll_template
|
||||
end
|
||||
resources :competition_notices, only: [:show, :index, :update, :destroy, :create]
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
class AddCompetitionInfoEnrollTemplate < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :competition_infos, :enroll_template, :string
|
||||
add_column :competition_users, :enroll_template_id, :integer
|
||||
end
|
||||
end
|
||||
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue