old id update hps member

This commit is contained in:
Harry Bomrah 2017-05-24 16:57:46 +08:00
parent 34582be02b
commit 9ffdccdd97
2 changed files with 29 additions and 0 deletions

View File

@ -18,6 +18,7 @@ class HpsMember
field :score, type: Integer, :default => 0 field :score, type: Integer, :default => 0
field :enabled, :type => Boolean, :default => true field :enabled, :type => Boolean, :default => true
field :user_type, type: Integer field :user_type, type: Integer
field :old_id
# school type # school type

View File

@ -49,4 +49,32 @@ namespace :hps_task do
hpsschool.save hpsschool.save
end end
end end
task :import_school_users => :environment do
file = File.join(Rails.root, "public", "hps", "school_user.json")
data = File.read(file)
users = JSON.parse(data)
users.each do |user|
hpsm = HpsMember.where(:old_id => user["old_id"]).first rescue nil
if !hpsm.nil?
hpsm = HpsMember.new
end
hpsm.old_id = user["old_id"]
hpsm.account = user["account"]
hpsm.password = user["password"]
hpsm.name = user["name"]
hpsm.telephone = user["telephone"]
hpsm.mobile = user["mobile"]
hpsm.email = user["email"]
hpsm.address = user["address"]
hpsm.title = user["title"]
school = HpsSchool.where(:old_id => user["SchoolID"]).first
hpsm.hps_school_id = school.id.to_s
city = HpsCity.where(:old_id => user["my_county"]).first
hpsm.hps_city_id = city.id.to_s
county = HpsCounty.where(:old_id => user["cityzip"]).first
hpsm.hps_county_id = county.id.to_s
hpsm.save
end
end
end end