批量倒入学生的修改

dev_bj
SylorHuang 6 years ago
parent c5c2a86745
commit 2928eb5e5a

@ -239,29 +239,53 @@ class WelcomeController < ApplicationController
def import_users
begin
lists = read_xlsx_data("files/users.xlsx")
logger.info("#########____________lists___________#################{lists}")
lists.each_with_index do |list|
logger.info("#{list[0]}---#{list[1]}")
mail = list[1] + "@educoder.net"
login = "edu" + list[1]
if User.where(:login => login).blank?
us = UsersService.new
user = us.register phone: mail, password: 'wuhan12345678'
@user = user
@user.login = login
@se = @user.extensions
@user.lastname = list[0]
@user.firstname = ""
@user.show_realname = 0
@user.nickname = list[0]
@se.school_id = 117
if @user.save && @se.save
reward_grade(@user, @user.id, 'Account', 500)
user.update_attributes!(authentication:1)
school_id = lists[0][0] #学院id
school_name = lists[0][1] #学院名称
account_before = lists[1][0] #用户名前缀
lists.each_with_index do |list,index|
if index > 2
mail = list[0] + "@educoder.net"
login = account_before + list[0]
if User.where(:login => login).blank?
us = UsersService.new
user = us.register mail: mail, password: '12345678'
@user = user
@user.login = login
@se = @user.extensions
@user.lastname = list[1]
@user.firstname = ""
@user.show_realname = 0
@user.nickname = list[1]
@se.school_id = school_id
if @user.save && @se.save
reward_grade(@user, @user.id, 'Account', 500)
user.update_attributes!(authentication:1)
end
render :json => {:message => "sucess"}
end
render :json => {:message => "sucess"}
end
#logger.info("#{list[0]}---#{list[1]}")
# login = "edu" + list[1]
# if User.where(:login => login).blank?
# us = UsersService.new
# user = us.register phone: mail, password: 'wuhan12345678'
# @user = user
# @user.login = login
# @se = @user.extensions
# @user.lastname = list[0]
# @user.firstname = ""
# @user.show_realname = 0
# @user.nickname = list[0]
#
# @se.school_id = 117
# if @user.save && @se.save
# reward_grade(@user, @user.id, 'Account', 500)
# user.update_attributes!(authentication:1)
# end
# render :json => {:message => "sucess"}
# end
end
rescue Exception => e
logger.error(e.message)

Loading…
Cancel
Save