excel导入功能

This commit is contained in:
huang 2017-11-12 11:30:00 +08:00
parent aadba839ae
commit 353b9ac670
4 changed files with 39 additions and 1 deletions

View File

@ -75,7 +75,7 @@ group :development, :test do
gem 'pry-byebug' gem 'pry-byebug'
gem "test-unit", "~>3.0" gem "test-unit", "~>3.0"
end end
gem 'rspec-rails', '~> 3.0' # gem 'rspec-rails', '~> 3.0'
gem 'factory_girl_rails' gem 'factory_girl_rails'
end end

View File

@ -33,6 +33,29 @@ class CoursesController < ApplicationController
before_filter :require_login, :only => [:join, :unjoin] before_filter :require_login, :only => [:join, :unjoin]
#before_filter :allow_join, :only => [:join] #before_filter :allow_join, :only => [:join]
def sync_temp_excel
unless User.current.admin?
render_403
return
end
attachment = Attachment.find(params[:attachment_id])
path = attachment.disk_directory
name = attachment.disk_filename
lists = readData("files/#{path}/#{name}")
lists.each do |list|
logger.info("#{list[0]}---#{list[1]}")
user = User.find_by_sql("SELECT u.* FROM `users` u, `user_extensions` ue where u.id = ue.user_id and CONCAT(u.lastname,u.firstname) ='#{list[1]}' and ue.school_id='#{school_id}' and ue.student_id='#{list[0]}'").first
# 用户存在并且用户是非课程成员
if user.present? && Member.where(:course_id => @course, :user_id => user.id).blank?
members = []
members << Member.new(:role_ids => [10], :user_id => user.id)
@course.members << members
StudentsForCourse.create(:student_id => user.id, :course_id => @course.id)
@had_import_count += 1
end
end
end
# 邀请码停用/启用 # 邀请码停用/启用
def set_invite_code_halt def set_invite_code_halt
if User.current.allowed_to?(:as_teacher, @course) || User.current.admin? if User.current.allowed_to?(:as_teacher, @course) || User.current.admin?

View File

@ -1379,6 +1379,7 @@ RedmineApp::Application.routes.draw do
# 课程路由设置 # 课程路由设置
resources :courses do resources :courses do
member do member do
get 'sync_temp_excel'
get 'settings(/:tab)', :action => 'settings', :as => 'settings' get 'settings(/:tab)', :action => 'settings', :as => 'settings'
get 'search_member', :action => 'search_member' get 'search_member', :action => 'search_member'
get 'file', :action => 'file', :as => 'file' get 'file', :action => 'file', :as => 'file'

View File

@ -0,0 +1,14 @@
namespace :import do
desc "fix import name"
task :fix => :environment do
HomeworkCommon.find_each do |homework|
name = homework.name.sub("\n", " ").sub("\r\n", " ")
if name != homework.name
homework.name = name
homework.save!
end
end
end
end