From 0f22210bf5f3da0a9300bd28fd86ee2f17285048 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 12 Mar 2020 12:00:48 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AB=98=E6=A0=A1=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/schools.rake | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lib/tasks/schools.rake 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