Merge branches 'dev_aliyun' and 'dev_new_shixunsrepository' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_new_shixunsrepository

dev_new_shixunsrepository
杨树明 5 years ago
commit b9460e7f43

@ -7,7 +7,7 @@ class Admins::DisciplinesController < Admins::BaseController
def create
name = params[:name].to_s.strip
return render_error('名称重复') if Discipline.where(name: name).exists?
Discipline.create!(name: name, position: Discipline.all.pluck(:position).max + 1)
Discipline.create!(name: name, position: Discipline.all.pluck(:position).max.to_i + 1)
render_ok
end
@ -46,7 +46,7 @@ class Admins::DisciplinesController < Admins::BaseController
end
def adjust_position
max_position = Discipline.all.pluck(:position).max
max_position = Discipline.all.pluck(:position).max.to_i
opr = params[:opr] || "down"
if (params[:opr] == "up" && current_discipline.position == 1) || (params[:opr] == "down" && current_discipline.position == max_position)
@message = "超出范围"

@ -9,7 +9,7 @@ class Admins::SubDisciplinesController < Admins::BaseController
name = params[:name].to_s.strip
return render_error('名称不能为空') if name.blank?
return render_error('名称重复') if current_discipline.sub_disciplines.where(name: name).exists?
SubDiscipline.create!(name: name, discipline_id: current_discipline.id, position: current_discipline.sub_disciplines.pluck(:position).max + 1)
SubDiscipline.create!(name: name, discipline_id: current_discipline.id, position: current_discipline.sub_disciplines.pluck(:position).max.to_i + 1)
render_ok
end
@ -47,7 +47,7 @@ class Admins::SubDisciplinesController < Admins::BaseController
def adjust_position
discipline = current_sub_discipline.discipline
max_position = discipline.sub_disciplines.pluck(:position).max
max_position = discipline.sub_disciplines.pluck(:position).max.to_i
opr = params[:opr] || "down"
if (params[:opr] == "up" && current_sub_discipline.position == 1) || (params[:opr] == "down" && current_sub_discipline.position == max_position)
@message = "超出范围"

@ -9,7 +9,7 @@ class Admins::TagDisciplinesController < Admins::BaseController
name = params[:name].to_s.strip
return render_error('名称重复') if current_sub_discipline.tag_disciplines.where(name: name).exists?
TagDiscipline.create!(name: name, sub_discipline_id: current_sub_discipline.id, user_id: current_user.id,
position: current_sub_discipline.tag_disciplines.pluck(:position).max + 1)
position: current_sub_discipline.tag_disciplines.pluck(:position).max.to_i + 1)
render_ok
end
@ -42,7 +42,7 @@ class Admins::TagDisciplinesController < Admins::BaseController
def adjust_position
sub_discipline = current_tag_discipline.sub_discipline
max_position = sub_discipline.tag_disciplines.pluck(:position).max
max_position = sub_discipline.tag_disciplines.pluck(:position).max.to_i
opr = params[:opr] || "down"
if (params[:opr] == "up" && current_tag_discipline.position == 1) || (params[:opr] == "down" && current_tag_discipline.position == max_position)
@message = "超出范围"

@ -34,8 +34,9 @@ class ItemBasketsController < ApplicationController
def delete_item_type
baskets = basket_items.where(item_type: params[:item_type])
item_ids = baskets.pluck(:item_bank_id)
baskets.destroy_all
render_ok
render_ok({item_ids: item_ids})
end
def set_score

@ -5,7 +5,7 @@ class TagDisciplinesController < ApplicationController
sub_discipline = SubDiscipline.find_by!(id: params[:sub_discipline_id])
tip_exception("重复的知识点") if sub_discipline.tag_disciplines.exists?(name: params[:name].to_s.strip)
tag_discipline = TagDiscipline.create!(name: params[:name].to_s.strip, sub_discipline: sub_discipline, user_id: current_user.id,
position: sub_discipline.tag_disciplines.pluck(:position).max + 1)
position: sub_discipline.tag_disciplines.pluck(:position).max.to_i + 1)
render_ok({tag_discipline_id: tag_discipline.id})
end
end

@ -9,7 +9,7 @@ class Weapps::ChallengesController < Weapps::BaseController
play = @shixun.is_jupyter? || @shixun.vnc ||
@shixun.hide_code? || (@shixun.small_mirror_name & ["Css", "Html", "Web"]).present?
if play
if @challenge.st != 1 && play
normal_status(-5, "该关卡暂不支持小程序")
else
render_ok

@ -257,10 +257,10 @@ class Course < ApplicationRecord
# 老师负责的分班id
def charge_group_ids user
member = user.is_a?(CourseMember) ? user : course_member(user.id)
member = user.is_a?(CourseMember) ? user : course_member(user&.id)
group_ids = if member.present?
member.teacher_course_groups.size > 0 ? member.teacher_course_groups.pluck(:course_group_id) : course_groups.pluck(:id)
elsif user.admin_or_business?
elsif user&.admin_or_business?
course_groups.pluck(:id)
else
[]

@ -118,8 +118,8 @@ class User < ApplicationRecord
has_many :manage_courses, through: :manage_course_members, source: :course
# 关注
has_many :be_watchers, foreign_key: :user_id, dependent: :destroy # 我的关注
has_many :be_watcher_users, through: :be_watchers, dependent: :destroy # 我关注的用户
# has_many :be_watchers, foreign_key: :user_id, dependent: :destroy # 我的关注
# has_many :be_watcher_users, through: :be_watchers, dependent: :destroy # 我关注的用户
# 认证
has_many :apply_user_authentication
@ -655,6 +655,7 @@ class User < ApplicationRecord
# 邮箱w***l@qq.com
def hidden_mail
Rails.logger.info("######-----: #{mail}")
Util.conceal(mail, :email).to_s
end
@ -726,8 +727,8 @@ class User < ApplicationRecord
end
def validate_sensitive_string
raise("真实姓名包含敏感词汇,请重新输入") if lastname && !HarmoniousDictionary.clean?(lastname)
raise("昵称包含敏感词汇,请重新输入") if nickname && !HarmoniousDictionary.clean?(nickname)
raise("真实姓名包含敏感词汇,请重新输入#{lastname}") if lastname && !HarmoniousDictionary.clean?(lastname)
raise("昵称包含敏感词汇,请重新输入#{nickname}") if nickname && !HarmoniousDictionary.clean?(nickname)
end
def set_laboratory

@ -29,14 +29,14 @@ class Admins::ImportDisciplineService < ApplicationService
return unless discipline_name.present?
discipline = Discipline.find_by(name: discipline_name)
if discipline.blank?
discipline = Discipline.create!(name: discipline_name, position: Discipline.all.pluck(:position).max + 1)
discipline = Discipline.create!(name: discipline_name, position: Discipline.all.pluck(:position).max.to_i + 1)
count += 1
end
if sub_discipline_name.present?
sub_discipline = SubDiscipline.find_by(name: discipline_name, discipline: discipline)
if sub_discipline.blank?
SubDiscipline.create!(name: sub_discipline_name, discipline: discipline, position: discipline.sub_disciplines.pluck(:position).max + 1)
SubDiscipline.create!(name: sub_discipline_name, discipline: discipline, position: discipline.sub_disciplines.pluck(:position).max.to_i + 1)
count += 1
end
end

@ -14,7 +14,7 @@ class Oauth::CreateORFindCasUserService < ApplicationService
return [open_user.user, false] if open_user.persisted?
@user = User.new(login: User.generate_login('C'), type: 'User', status: User::STATUS_ACTIVE, lastname: @params['comsys_name'])
@user = User.new(login: "tfxy#{@params['user']}", type: 'User', status: User::STATUS_ACTIVE, lastname: @params['comsys_name'])
ActiveRecord::Base.transaction do
@user.save!

@ -3,7 +3,7 @@ class Videos::DispatchCallbackService < ApplicationService
def initialize(params)
@video = Video.find_by(uuid: params[:VideoId])
@params = params``
@params = params
end
def call

@ -25,8 +25,8 @@ json.homeworks @homework_commons.each do |homework|
json.upper_category_name homework.course_second_category&.name unless params[:category]
charge_ids = @course.charge_group_ids(@member)
json.publish_immediately @user_course_identity < Course::STUDENT && homework.publish_immediately(charge_ids)
json.end_immediately @user_course_identity < Course::STUDENT && homework.end_immediately(charge_ids)
json.publish_immediately @user.logged? && @user_course_identity < Course::STUDENT && homework.publish_immediately(charge_ids)
json.end_immediately @user.logged? && @user_course_identity < Course::STUDENT && homework.end_immediately(charge_ids)
unless curr_status[:status].include?("未发布")
work_count = calculate_work_count homework, @member

@ -357,7 +357,6 @@ H漫画
学生暴动
镇压学生
广安第二人民医院
胡新宇
趙紫陽
自由亚州
践踏中国女性
@ -682,7 +681,6 @@ A片
被迫
被逼
强暴
口技
破处
精液
幼交
@ -996,7 +994,6 @@ A片
李少民
李淑娴
李旺阳
李文斌
李月月鸟
李志绥
连胜德
@ -1157,7 +1154,6 @@ A片
信用危机
邢铮
熊炎
熊焱
徐邦秦
徐才厚
徐匡迪
@ -1194,7 +1190,6 @@ A片
张伯笠
张宏堡
张万年
张伟国
张昭富
张志清
赵海青

@ -0,0 +1,232 @@
# 执行示例 RAILS_ENV=production bundle exec rake migrate_course_resource:import_attachments args=3835,2526
#
desc "同步课堂学生数据"
namespace :migrate_course_resource do
if ENV['args']
source_id = ENV['args'].split(",")[0] # 源课堂id
target_id = ENV['args'].split(",")[1] # 目标课堂id
end
task import_attachments: :environment do
source_course = Course.find_by(id: source_id)
target_course = Course.find_by(id: target_id)
return if source_course.blank? || target_course.blank?
source_course.attachments.each do |atta|
if atta.course_second_category.present?
target_category = CourseSecondCategory.find_by(name: atta.course_second_category.name, course_id: target_course.id, category_type: "attachment")
unless target_category.present?
course_module = Course.course_modules.find_by(module_type: "attachment")
target_category = CourseSecondCategory.create(name: atta.course_second_category.name, course_id: target_course.id,
category_type: "attachment", course_module_id: course_module&.id,
position: course_module&.course_second_categories&.count.to_i + 1)
end
end
target_course.attachments << target_course.attachments.build(atta.attributes.except("id").merge(
quotes: 0,
downloads: 0,
author_id: target_course.tea_id,
created_on: Time.now,
course_second_category_id: target_category&.id.to_i
))
end
end
task import_videos: :environment do
source_course = Course.find_by(id: source_id)
target_course = Course.find_by(id: target_id)
return if source_course.blank? || target_course.blank?
source_course.course_videos.each do |video|
target_course.course_videos << CourseVideo.new(video_id: video.video_id)
end
end
task import_homeworks: :environment do
source_course = Course.find_by(id: source_id)
target_course = Course.find_by(id: target_id)
return if source_course.blank? || target_course.blank?
source_course.homework_commons.each do |homework|
ActiveRecord::Base.transaction do
if homework.course_second_category.present?
target_category = CourseSecondCategory.find_by(name: homework.course_second_category.name, course_id: target_course.id, category_type: "shixun_homework")
unless target_category.present?
course_module = Course.course_modules.find_by(module_type: "shixun_homework")
target_category = CourseSecondCategory.create(name: homework.course_second_category.name, course_id: target_course.id,
category_type: "shixun_homework", course_module_id: course_module&.id,
position: course_module&.course_second_categories&.count.to_i + 1)
end
end
# 复制作业的基本信息
new_homework = HomeworkCommon.new(name: homework.name, user_id: target_course.tea_id, description: homework.description,
homework_type: homework.homework_type, course_id: target_course.id,
reference_answer: homework.reference_answer, course_second_category_id: target_category&.id.to_i)
# 作业的基本设置复制
new_homework.homework_detail_manual = HomeworkDetailManual.new
new_homework_detail_manual = new_homework.homework_detail_manual
new_homework_detail_manual.te_proportion = 0.7
new_homework_detail_manual.ta_proportion = 0.3
if new_homework.homework_type == "group"
# 分组作业表的复制
old_homework_group = homework.homework_detail_group
new_homework.homework_detail_group = HomeworkDetailGroup.new
new_homework.homework_detail_group.min_num = old_homework_group&.min_num
new_homework.homework_detail_group.max_num = old_homework_group&.max_num
new_homework.homework_detail_group.base_on_project = old_homework_group&.base_on_project
end
if new_homework.homework_type == "practice"
# 分组作业表的复制
new_homework.homework_commons_shixun = HomeworkCommonsShixun.new
new_homework.homework_commons_shixun.shixun_id = homework.homework_commons_shixun&.shixun_id
homework.position = HomeworkCommon.where(course_id:target_course.id, homework_type: "practice").pluck(:position).max.to_i + 1
homework.homework_challenge_settings.each do |setting|
new_homework.homework_challenge_settings << HomeworkChallengeSetting.new(challenge_id: setting.challenge_id,
shixun_id: setting.shixun_id, score: setting.score)
end
end
# 附件
if new_homework.save
homework.attachments.try(:each) do |attachment|
att = attachment.copy
att.container_id = nil
att.container_type = nil
att.author_id = homework.user_id
att.attachtype = attachment.attachtype || 1
# att.attachtype = 1
att.copy_from = attachment.id
att.save!
new_homework.attachments << att
end
new_homework_detail_manual.save if new_homework_detail_manual
new_homework.homework_detail_group.save if new_homework.homework_detail_group
new_homework.homework_commons_shixun.save if new_homework.homework_commons_shixun
CreateStudentWorkJob.perform_later(new_homework.id)
end
end
end
end
task import_exercises: :environment do
source_course = Course.find_by(id: source_id)
target_course = Course.find_by(id: target_id)
return if source_course.blank? || target_course.blank?
source_course.exercises.each do |exercise|
ActiveRecord::Base.transaction do
new_exercise = Exercise.new(:exercise_name => exercise.exercise_name, :exercise_description => exercise.exercise_description,
:user_id => target_course.tea_id, :course_id => target_course.id)
# 复制试卷基本信息
exercise.exercise_questions.each do |q|
option = {
:question_title => q.question_title,
:question_type => q.question_type || 1,
:question_number => q.question_number,
:question_score => q.question_score,
:shixun_name => q.shixun_name,
:shixun_id => q.shixun_id,
:is_ordered => q.is_ordered
}
exercise_question = new_exercise.exercise_questions.new option
# question_type5实训题其他是非实训题
if q.question_type != 5
# 复制选择题题目选项
q.exercise_choices.try(:each_with_index) do |choice, index|
exercise_question.exercise_choices.new({choice_position: index+1, choice_text: choice.choice_text})
end
# 复制标准答案(填空题和问答题) 多空填空题的话应该是原标准答案的exercise_choice_id即为题空的位置。
q.exercise_standard_answers.try(:each) do |answer|
exercise_question.exercise_standard_answers.new({exercise_choice_id: answer.exercise_choice_id, answer_text: answer.answer_text})
end
else
# 复制实训题
q.exercise_shixun_challenges.try(:each_with_index) do |sc, index|
exercise_question.exercise_shixun_challenges.new({position: index+1, challenge_id: sc.challenge_id,
shixun_id: sc.shixun_id, question_score: sc.question_score})
end
end
end
new_exercise.save!
end
end
end
task import_polls: :environment do
source_course = Course.find_by(id: source_id)
target_course = Course.find_by(id: target_id)
return if source_course.blank? || target_course.blank?
source_course.polls.each do |poll|
new_poll = Poll.new(:polls_name => poll.polls_name, :polls_description => poll.polls_description, :user_id => target_course.tea_id,
:polls_type => 'Course', :course_id => target_course.id)
poll.poll_questions.try(:each) do |q|
option = {
:question_title => q.question_title,
:question_type => q.question_type || 1,
:is_necessary => q.is_necessary,
:question_number => q.question_number,
:max_choices => q.max_choices,
:min_choices => q.min_choices
}
poll_question = new_poll.poll_questions.new option
q.poll_answers.try(:each_with_index) do |choice, index|
poll_question.poll_answers.new({answer_position: index+1, answer_text: choice.answer_text})
end
end
new_poll.save!
end
end
task import_members: :environment do
source_course = Course.find_by(id: source_id)
target_course = Course.find_by(id: target_id)
return if source_course.blank? || target_course.blank?
source_course.course_members.where(role: %i[PROFESSOR ASSISTANT_PROFESSOR]).each do |teacher|
new_member = target_course.teachers.find_by(user_id: teacher.user_id)
unless new_member.present?
new_member = CourseMember.create!(course_id: target_course.id, user_id: teacher.user_id, role: teacher.role)
end
end
source_course.course_groups.each do |group|
unless target_course.course_groups.where(name: group.name).exists?
new_group = CourseGroup.create!(course_id: target_course.id, name: group.name, position: target_course.course_groups.pluck(:position).max.to_i + 1)
else
new_group = target_course.course_groups.find_by(name: group.name)
end
new_user_ids = []
group.course_members.where(role: 4).each do |member|
new_member = target_course.course_members.find_by(user_id: member.user_id)
if new_member.present?
new_member.update_column("course_group_id", new_group.id)
else
CourseMember.create!(course_id: target_course.id, course_group_id: new_group.id, user_id: member.user_id, role: member.role)
new_user_ids << member.user_id
end
end
# CourseAddStudentCreateWorksJob.perform_later(target_course.id, new_user_ids) unless new_user_ids.blank?
group.teacher_course_groups.each do |teacher_group|
member = CourseMember.find_by(course_id: target_course.id, user_id: teacher_group.user_id, role: %i[CREATOR PROFESSOR ASSISTANT_PROFESSOR])
if member.present?
TeacherCourseGroup.create!(course_group_id: new_group.id, course_id: target_course.id, course_member_id: member&.id, user_id: member&.user_id)
end
end
end
end
end

@ -1,32 +0,0 @@
# 执行示例 RAILS_ENV=production bundle exec rake migrate_course_student:student args=3835,2526,21950,1000
# args 第一个课程 course_id第二个参数是学校school_id第三个参数是部门id第四个参数是迁移数量
#
desc "同步学校的学生"
namespace :migrate_course_student do
if ENV['args']
course_id = ENV['args'].split(",")[0] # 对应课堂的id
school_id = ENV['args'].split(",")[1] # 对应学校id
department_id = ENV['args'].split(",")[2] # 对应部门id
limit = ENV['args'].split(",")[3] # 限制导入的数量
end
task :student => :environment do
course = Course.find course_id
users = User.joins(:user_extension).where(user_extensions: {school_id: school_id, department_id: department_id, identity: 1}).limit(limit)
user_ids = []
users.each do |user|
if user.student_id.present? && !course.students.exists?(user_id: user.id)
begin
CourseMember.create!(course_id: course_id, user_id: user.id, role: 4)
user_ids << user.id
rescue Exception => e
Rails.logger(e.message)
end
end
end
CourseAddStudentCreateWorksJob.perform_later(course_id, user_ids)
end
end

@ -0,0 +1,261 @@
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 teach_data.cell(r, 6).to_s&.strip.present?
old_user = User.where("phone = '#{teach_data.cell(r, 5)}' OR mail = '#{teach_data.cell(r, 6).to_s.strip}' OR login = 'tfxy#{teach_data.cell(r, 1)}' " ).first
else
old_user = User.where("phone = '#{teach_data.cell(r, 5)}' OR login = 'tfxy#{teach_data.cell(r, 1)}' ").first
end
if !old_user.present?
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).to_s&.strip.present? ? teach_data.cell(r, 6).to_s&.strip : nil,
profile_completed: true,
professional_certification: 1,
certification: 1,
authentication: true,
laboratory_id: Laboratory.find(1)&.id
)
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: teach_data.cell(r, 1)) do |u|
u.extra = {phone: teach_data.cell(r, 8)}
u.user_id = user.id
end
p "-------user -----#{user.inspect}"
open_user.save
end
else
old_user.update(
lastname: teach_data.cell(r, 2),
nickname: teach_data.cell(r, 2),
certification: true,
professional_certification: true,
authentication: true,
profile_completed: true)
OpenUsers::Cas.find_or_create_by(uid: teach_data.cell(r, 1)) do |u|
u.extra = {phone: teach_data.cell(r, 5)}
u.user_id = old_user.id
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_info = {"C程序设计与实践"=>4, "数据库技术应用"=>2, "数据库应用"=>2, "数据库原理"=>2, "数据库实践"=>2, "面向对象程序设计与实践"=>2, "JavaSE程序设计及实践辅修"=>4, "编译原理"=>2, "电路与电子技术"=>3, "传感器原理与应用"=>3, "物联网技术与应用"=>2, "人工智能实践"=>3, "计算机组成原理"=>2, "移动应用开发实训"=>4, "面向对象程序课程设计"=>1, "Web程序设计"=>2, "数据仓库与数据挖掘"=>2, "定量分析技术"=>4, "Python程序设计"=>4, "信息系统分析与设计"=>3, "数据处理综合实训"=>2, "绘画基础Ⅱ(色彩构成)"=>2, "数字图像处理"=>4, "虚拟现实技术及应用"=>4, "三维建模技术"=>4, "游戏技术基础"=>4, "传感器与单片机实训"=>2, "数据库原理与实践"=>4, "高级程序设计(二)"=>4, "数据结构与算法分析"=>4, "实训"=>1, "Linux 操作系统"=>4, "Java Web程序设计与实践"=>8, "软件测试与项目管理"=>4, "Android程序设计"=>8, "移动应用开发"=>4, "商业智能案例分析"=>4, "数据分析与挖掘"=>4, "Oracle DBA"=>4, "信息网络安全测试与评估"=>4, "Android编程"=>8, "电子线路CAD设计"=>2, "ARM接口技术"=>4, "嵌入式Linux应用系统设计"=>4, "信息系统开发实训"=>2, "绘画基础I平面构成"=>2, "智能信息处理技术"=>3}
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, 3))
teach_user = OpenUsers::Cas.find_by(uid: course_data.cell(r, 5))&.user
puts "----teach_user-----uid-----#{course_data.cell(r, 5)}------#{teach_user.inspect}---"
if !course_group.persisted? && teach_user.present?
course = Course.find_or_initialize_by(school_id: school.id, name: course_data.cell(r, 2), invite_code: course_data.cell(r, 1)[3..7]) do |d|
d.is_public = 0
d.tea_id = teach_user.id
d.laboratory_id = Laboratory.find(1)&.id
d.credit = course_info[course_data.cell(r, 1)]
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.invite_code = course_data.cell(r, 1)[3..7]
course.save!
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, 4)
course_group.course = course
course_group.save!
puts "---course_group----#{course_group.inspect}"
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 = 0
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).to_s&.strip.present?
old_user = User.where("phone = '#{student_data.cell(r, 8)}' OR mail = '#{student_data.cell(r, 9).to_s.strip}' 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).to_s&.strip.present? ? student_data.cell(r, 9).to_s&.strip : nil,
profile_completed: true,
professional_certification: 1,
certification: 1,
authentication: true,
laboratory_id: Laboratory.find(1)&.id
)
puts "----user #{user.inspect}"
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,
student_id: student_data.cell(r, 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(
lastname: student_data.cell(r, 2),
nickname: student_data.cell(r, 2),
certification: true,
professional_certification: true,
authentication: true,
profile_completed: true)
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, 5))
student = OpenUsers::Cas.find_by(uid: course_member_data.cell(r, 1))&.user
puts "------student --- #{course_member_data.cell(r, 1)}--course group--#{course_member_data.cell(r, 5)}"
if student.present? && course_group.present?
course_member = CourseMember.find_or_initialize_by(course_id: course_group.course_id, user_id: student.id) do |d|
d.role = 4
d.course_group_id = course_group.id
end
puts "--------course_member #{course_member.inspect}"
course_member.save! if !course_member.persisted?
end
end
end
end

Binary file not shown.
Loading…
Cancel
Save