导入作业
This commit is contained in:
parent
353b9ac670
commit
00e250f1b8
1
Gemfile
1
Gemfile
|
@ -14,6 +14,7 @@ unless RUBY_PLATFORM =~ /w32/
|
|||
gem 'nokogiri'
|
||||
end
|
||||
|
||||
gem 'simple_xlsx_reader'
|
||||
gem 'wechat',path: 'lib/wechat'
|
||||
gem 'grack', path:'lib/grack'
|
||||
gem 'gitlab', path: 'lib/gitlab-cli'
|
||||
|
|
|
@ -32,30 +32,40 @@ class CoursesController < ApplicationController
|
|||
|
||||
before_filter :require_login, :only => [:join, :unjoin]
|
||||
#before_filter :allow_join, :only => [:join]
|
||||
require 'simple_xlsx_reader'
|
||||
|
||||
def sync_temp_excel
|
||||
unless User.current.admin?
|
||||
render_403
|
||||
return
|
||||
end
|
||||
# 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
|
||||
homework = HomeworkCommon.find params[:homework]
|
||||
if homework.present?
|
||||
lists.each do |list, index|
|
||||
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.student_id='#{list[0]}'").first
|
||||
# 用户存在并且用户是非课程成员
|
||||
if user.present?
|
||||
logger.info("#{index}---------------------------------#{user.id}")
|
||||
work = homework.student_works.where(:user_id => user.id, :work_score => nil).first
|
||||
if work.present?
|
||||
work.update_attributes(:work_status => 1, :work_score => list[2])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def readData(xlsx)
|
||||
doc = SimpleXlsxReader.open(xlsx)
|
||||
sheet = doc.sheets.first
|
||||
sheet.rows
|
||||
end
|
||||
|
||||
# 邀请码停用/启用
|
||||
def set_invite_code_halt
|
||||
if User.current.allowed_to?(:as_teacher, @course) || User.current.admin?
|
||||
|
|
Loading…
Reference in New Issue