diff --git a/lib/tasks/schools.rake b/lib/tasks/schools.rake new file mode 100644 index 000000000..f5a66a786 --- /dev/null +++ b/lib/tasks/schools.rake @@ -0,0 +1,21 @@ +#coding=utf-8 + +desc "合并高校的数据,第一个参数是: 正确高校的id, 第二个参数是: 错误高校需要合并到正确高校的id" +# 命令: bundle exec rake schools:merge_school_data f_school=1 s_school=2,3 +namespace :schools do + task merge_school_data: :environment do + f_school = ENV['f_school'].to_i + school = School.find_by(id: f_school) + return if school.blank? + + s_school = ENV['s_school'].split(",") + merge_schools = School.where(id: s_school) + + # 改变用户的学校id 和 单位 + UserExtension.where(school_id: merge_schools) + .update_all(school_id: f_school, department_id: nil) + + # 改变课堂的学校id + Course.where(school_id: merge_schools).update_all(school_id: f_school) + end +end \ No newline at end of file