|
|
|
@ -0,0 +1,209 @@
|
|
|
|
|
desc "同步天府学院数据, 执行顺序依次 import_teaches、 import_courses、 import_students、import_course_members"
|
|
|
|
|
|
|
|
|
|
namespace :tfxy do
|
|
|
|
|
|
|
|
|
|
xlsx =Roo::Spreadsheet.open(Rails.root.join("tfxy.xlsx").to_s)
|
|
|
|
|
|
|
|
|
|
task import_teaches: :environment do
|
|
|
|
|
desc "同步天府学院老师数据"
|
|
|
|
|
xlsx =Roo::Spreadsheet.open(Rails.root.join("tfxy.xlsx").to_s)
|
|
|
|
|
|
|
|
|
|
school = School.find_or_create_by(name: '西南财经大学天府学院') do |d|
|
|
|
|
|
d.province = '四川省'
|
|
|
|
|
d.city = '成都'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#导入教师用户
|
|
|
|
|
teach_data = xlsx.sheet(3)
|
|
|
|
|
teach_data_last_row = teach_data.last_row
|
|
|
|
|
|
|
|
|
|
2.upto(teach_data_last_row) do |r|
|
|
|
|
|
|
|
|
|
|
if !User.where("phone = '#{teach_data.cell(r, 5)}' OR mail = '#{teach_data.cell(r, 6)}' OR login = 'tfxy#{teach_data.cell(r, 1)}' " ).exists?
|
|
|
|
|
user = User.new(
|
|
|
|
|
phone: teach_data.cell(r, 5),
|
|
|
|
|
login: "tfxy#{teach_data.cell(r, 1)}",
|
|
|
|
|
type: 'User',
|
|
|
|
|
status: User::STATUS_ACTIVE,
|
|
|
|
|
lastname: teach_data.cell(r, 2),
|
|
|
|
|
nickname: teach_data.cell(r, 2),
|
|
|
|
|
password: "Edu#{teach_data.cell(r, 5)}",
|
|
|
|
|
mail: teach_data.cell(r, 6),
|
|
|
|
|
profile_completed: true,
|
|
|
|
|
professional_certification: 1,
|
|
|
|
|
certification: 1
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if user.save!
|
|
|
|
|
departemnt = school.departments.find_or_create_by!(name: teach_data.cell(r, 4))
|
|
|
|
|
|
|
|
|
|
user.create_user_extension!(
|
|
|
|
|
school_id: school.id,
|
|
|
|
|
location: school.province,
|
|
|
|
|
location_city: school.city,
|
|
|
|
|
gender: teach_data.cell(r, 3) == '女' ? 1 : 0,
|
|
|
|
|
identity: 0,
|
|
|
|
|
technical_title: '教师',
|
|
|
|
|
department_id: departemnt.id
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
open_user = OpenUsers::Cas.find_or_initialize_by(uid: student_data.cell(r, 1)) do |u|
|
|
|
|
|
u.extra = {phone: student_data.cell(r, 8)}
|
|
|
|
|
u.user_id = user.id
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
open_user.save
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
task import_courses: :environment do
|
|
|
|
|
desc "同步天府学院课堂数据"
|
|
|
|
|
|
|
|
|
|
school = School.find_or_create_by(name: '西南财经大学天府学院') do |d|
|
|
|
|
|
d.province = '四川省'
|
|
|
|
|
d.city = '成都'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
course_data = xlsx.sheet(4)
|
|
|
|
|
course_data_last_row = course_data.last_row
|
|
|
|
|
|
|
|
|
|
2.upto(course_data_last_row) do |r|
|
|
|
|
|
course_group = CourseGroup.find_or_initialize_by(invite_code: "#{course_data.cell(r, 1)}#{course_data.cell(r, 3)}")
|
|
|
|
|
|
|
|
|
|
teach_user = User.find_by(login: "tfxy#{course_data.cell(r, 5)}")
|
|
|
|
|
|
|
|
|
|
if !course_group.persisted?
|
|
|
|
|
course = Course.find_or_initialize_by(school_id: school.id, name: course_data.cell(r, 2)) do |d|
|
|
|
|
|
d.is_public = 0
|
|
|
|
|
d.tea_id = teach_user.id
|
|
|
|
|
d.laboratory_id = Laboratory.first.id
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !course.persisted?
|
|
|
|
|
# 创建课堂
|
|
|
|
|
course_list = CourseList.find_or_initialize_by(name: course_data.cell(r, 2), user_id: teach_user.id) do |d|
|
|
|
|
|
d.is_admin = 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
course.course_list = course_list
|
|
|
|
|
course.save!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
course.generate_invite_code
|
|
|
|
|
CourseInfo.create!(user_id: teach_user.id, course_id: course.id)
|
|
|
|
|
course.create_course_modules(["shixun_homework", "common_homework", "group_homework", "exercise", "attachment", "course_group", "video"])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
course_group.position = course.course_groups_count + 1
|
|
|
|
|
course_group.name = "#{course_data.cell(r, 2)}#{course_data.cell(r, 3)}"
|
|
|
|
|
course_group.course = course
|
|
|
|
|
|
|
|
|
|
course_group.save!
|
|
|
|
|
|
|
|
|
|
course_member = CourseMember.find_or_initialize_by(course_id: course.id, user_id: teach_user.id) do |d|
|
|
|
|
|
d.role = 2
|
|
|
|
|
d.course_group_id = course_group.id
|
|
|
|
|
end
|
|
|
|
|
course_member.save! if !course_member.persisted?
|
|
|
|
|
|
|
|
|
|
TeacherCourseGroup.create!(course_id: course.id, course_member_id: course_member.id, user_id: teach_user.id, course_group_id: course_group.id)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
task import_students: :environment do
|
|
|
|
|
desc "同步天府学院学生数据"
|
|
|
|
|
student_data = xlsx.sheet(5)
|
|
|
|
|
student_data_last_row = student_data.last_row
|
|
|
|
|
|
|
|
|
|
school = School.find_or_create_by(name: '西南财经大学天府学院') do |d|
|
|
|
|
|
d.province = '四川省'
|
|
|
|
|
d.city = '成都'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
2.upto(student_data_last_row) do |r|
|
|
|
|
|
# 邮箱存在
|
|
|
|
|
if student_data.cell(r, 9).present?
|
|
|
|
|
old_user = User.where("phone = '#{student_data.cell(r, 8)}' OR mail = '#{student_data.cell(r, 9)}' OR login = 'tfxy#{student_data.cell(r, 1)}' " ).first
|
|
|
|
|
else
|
|
|
|
|
old_user = User.where("phone = '#{student_data.cell(r, 8)}' OR login = 'tfxy#{student_data.cell(r, 1)}' " ).first
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if !old_user.present?
|
|
|
|
|
user = User.new(
|
|
|
|
|
phone: student_data.cell(r, 8),
|
|
|
|
|
login: "tfxy#{student_data.cell(r, 1)}",
|
|
|
|
|
type: 'User',
|
|
|
|
|
status: User::STATUS_ACTIVE,
|
|
|
|
|
lastname: student_data.cell(r, 2),
|
|
|
|
|
nickname: student_data.cell(r, 2),
|
|
|
|
|
password: "Edu#{student_data.cell(r, 1)}",
|
|
|
|
|
mail: student_data.cell(r, 9),
|
|
|
|
|
profile_completed: true,
|
|
|
|
|
professional_certification: 1,
|
|
|
|
|
certification: 1
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if user.save!
|
|
|
|
|
departemnt = school.departments.find_or_create_by!(name: student_data.cell(r, 4))
|
|
|
|
|
|
|
|
|
|
user.create_user_extension!(
|
|
|
|
|
school_id: school.id,
|
|
|
|
|
location: school.province,
|
|
|
|
|
location_city: school.city,
|
|
|
|
|
gender: student_data.cell(r, 3) == '女' ? 1 : 0,
|
|
|
|
|
identity: 1,
|
|
|
|
|
department_id: departemnt.id
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
OpenUsers::Cas.find_or_create_by(uid: student_data.cell(r, 1)) do |u|
|
|
|
|
|
u.extra = {phone: student_data.cell(r, 8)}
|
|
|
|
|
u.user_id = user.id
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
# 系统已有用户,关联sso认证用户
|
|
|
|
|
old_user.update(login: "tfxy#{student_data.cell(r, 1)}")
|
|
|
|
|
|
|
|
|
|
OpenUsers::Cas.find_or_create_by(uid: student_data.cell(r, 1)) do |u|
|
|
|
|
|
u.extra = {phone: student_data.cell(r, 8)}
|
|
|
|
|
u.user_id = old_user.id
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
task import_course_members: :environment do
|
|
|
|
|
desc "天府学院学生到课程分班"
|
|
|
|
|
course_member_data = xlsx.sheet(6)
|
|
|
|
|
course_member_data_last_row = course_member_data.last_row
|
|
|
|
|
|
|
|
|
|
school = School.find_or_create_by(name: '西南财经大学天府学院') do |d|
|
|
|
|
|
d.province = '四川省'
|
|
|
|
|
d.city = '成都'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
2.upto(course_member_data_last_row) do |r|
|
|
|
|
|
course_group = CourseGroup.find_by(invite_code: "#{course_member_data.cell(r, 3)}#{course_member_data.cell(r, 5)}")
|
|
|
|
|
student = User.find_by(login: "tfxy#{course_member_data.cell(r, 1)}")
|
|
|
|
|
|
|
|
|
|
CourseMember.find_or_create_by!(course_id: course_group.course_id, user_id: student.id, course_group_id: course_group.id) do |d|
|
|
|
|
|
d.role = 4
|
|
|
|
|
end if student.present?
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|